HomepageGrid.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <grid-layout :layout.sync="layout"
  3. :col-num="12"
  4. :row-height="30"
  5. :is-draggable="draggable"
  6. :is-resizable="resizable"
  7. :vertical-compact="true"
  8. :use-css-transforms="true"
  9. >
  10. <grid-item v-for="item in layout"
  11. :static="item.static"
  12. :x="item.x"
  13. :y="item.y"
  14. :w="item.w"
  15. :h="item.h"
  16. :i="item.i"
  17. >
  18. <span class="text">{{itemTitle(item)}}</span>
  19. </grid-item>
  20. </grid-layout>
  21. </template>
  22. <script>
  23. import { GridLayout, GridItem } from "vue-grid-layout"
  24. export default {
  25. name: "HomepageGrid",
  26. components: {
  27. GridLayout,
  28. GridItem
  29. },
  30. data() {
  31. return {
  32. layout: [
  33. {"x":0,"y":0,"w":2,"h":2,"i":"0", static: false},
  34. {"x":2,"y":0,"w":2,"h":4,"i":"1", static: true},
  35. {"x":4,"y":0,"w":2,"h":5,"i":"2", static: false},
  36. {"x":6,"y":0,"w":2,"h":3,"i":"3", static: false},
  37. {"x":8,"y":0,"w":2,"h":3,"i":"4", static: false},
  38. {"x":10,"y":0,"w":2,"h":3,"i":"5", static: false},
  39. {"x":0,"y":5,"w":2,"h":5,"i":"6", static: false},
  40. {"x":2,"y":5,"w":2,"h":5,"i":"7", static: false},
  41. {"x":4,"y":5,"w":2,"h":5,"i":"8", static: false},
  42. {"x":6,"y":3,"w":2,"h":4,"i":"9", static: true},
  43. {"x":8,"y":4,"w":2,"h":4,"i":"10", static: false},
  44. {"x":10,"y":4,"w":2,"h":4,"i":"11", static: false},
  45. {"x":0,"y":10,"w":2,"h":5,"i":"12", static: false},
  46. {"x":2,"y":10,"w":2,"h":5,"i":"13", static: false},
  47. {"x":4,"y":8,"w":2,"h":4,"i":"14", static: false},
  48. {"x":6,"y":8,"w":2,"h":4,"i":"15", static: false},
  49. {"x":8,"y":10,"w":2,"h":5,"i":"16", static: false},
  50. {"x":10,"y":4,"w":2,"h":2,"i":"17", static: false},
  51. {"x":0,"y":9,"w":2,"h":3,"i":"18", static: false},
  52. {"x":2,"y":6,"w":2,"h":2,"i":"19", static: false}
  53. ],
  54. draggable: true,
  55. resizable: true,
  56. index: 0
  57. }
  58. },
  59. methods: {
  60. itemTitle(item) {
  61. let result = item.i;
  62. if (item.static) {
  63. result += " - Static";
  64. }
  65. return result;
  66. }
  67. }
  68. }
  69. </script>
  70. <style scoped>
  71. .vue-grid-layout {
  72. background: #eee;
  73. }
  74. .vue-grid-item:not(.vue-grid-placeholder) {
  75. background: #ccc;
  76. border: 1px solid black;
  77. }
  78. .vue-grid-item .resizing {
  79. opacity: 0.9;
  80. }
  81. .vue-grid-item .static {
  82. background: #cce;
  83. }
  84. .vue-grid-item .text {
  85. font-size: 24px;
  86. text-align: center;
  87. position: absolute;
  88. top: 0;
  89. bottom: 0;
  90. left: 0;
  91. right: 0;
  92. margin: auto;
  93. height: 100%;
  94. width: 100%;
  95. }
  96. .vue-grid-item .no-drag {
  97. height: 100%;
  98. width: 100%;
  99. }
  100. .vue-grid-item .minMax {
  101. font-size: 12px;
  102. }
  103. .vue-grid-item .add {
  104. cursor: pointer;
  105. }
  106. .vue-draggable-handle {
  107. position: absolute;
  108. width: 20px;
  109. height: 20px;
  110. top: 0;
  111. left: 0;
  112. background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10'><circle cx='5' cy='5' r='5' fill='#999999'/></svg>") no-repeat;
  113. background-position: bottom right;
  114. padding: 0 8px 8px 0;
  115. background-repeat: no-repeat;
  116. background-origin: content-box;
  117. box-sizing: border-box;
  118. cursor: pointer;
  119. }
  120. </style>