creatWebsite.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <div class="mainBox">
  3. <div class="layerBox">
  4. <tableTitle :name="headerTitle"/>
  5. <div class="menuTopBox">
  6. <div class="menuItem" @click="addModule(1)">
  7. <img src="@/assets/public/sidebar/default/index.png">
  8. 顶部菜单(含登录)
  9. </div>
  10. <div class="menuItem" @click="addModule(2)">
  11. <img src="@/assets/public/sidebar/default/index.png">
  12. Logo栏
  13. </div>
  14. <div class="menuItem" @click="addModule(3)">
  15. <img src="@/assets/public/sidebar/default/index.png">
  16. 导航菜单
  17. </div>
  18. <div class="menuItem" @click="addModule(4)">
  19. <img src="@/assets/public/sidebar/default/index.png">
  20. 轮播图
  21. </div>
  22. <div class="menuItem" @click="addModule(5)">
  23. <img src="@/assets/public/sidebar/default/index.png">
  24. 多分类列表
  25. </div>
  26. <div class="menuItem" @click="addModule(6)">
  27. <img src="@/assets/public/sidebar/default/index.png">
  28. 多图列表
  29. </div>
  30. <div class="menuItem" @click="addModule(7)">
  31. <img src="@/assets/public/sidebar/default/index.png">
  32. 纯文本列表
  33. </div>
  34. <div class="menuItem" @click="addModule(8)">
  35. <img src="@/assets/public/sidebar/default/index.png">
  36. 图文列表
  37. </div>
  38. <div class="menuItem" @click="addModule(9)">
  39. <img src="@/assets/public/sidebar/default/index.png">
  40. 排行榜列表
  41. </div>
  42. <div class="menuItem" @click="addModule(10)">
  43. <img src="@/assets/public/sidebar/default/index.png">
  44. 友情链接
  45. </div>
  46. <div class="menuItem" @click="addModule(11)">
  47. <img src="@/assets/public/sidebar/default/index.png">
  48. 纯文本
  49. </div>
  50. </div>
  51. </div>
  52. <div class="layerBox">
  53. <tableTitle :name="websiteTitle"/>
  54. <!-- 栅格布局 start ---------------------------------------->
  55. <div class="grid-layout-demo">
  56. <grid-layout :layout="layout" :col-num="12" :row-height="30" :is-draggable="true" :is-resizable="true">
  57. <grid-item
  58. v-for="(item, index) in layout"
  59. :key="item.i"
  60. :i="item.i"
  61. :x="item.x"
  62. :y="item.y"
  63. :w="item.w"
  64. :h="item.h"
  65. >
  66. <div class="grid-item-content">
  67. <!-- 模块内容 -->
  68. <div v-if="item.type == 1">
  69. 111
  70. </div>
  71. {{ item.content }}
  72. <button @click="openWindow(item)">编辑</button>
  73. </div>
  74. </grid-item>
  75. </grid-layout>
  76. </div>
  77. <!-- 栅格布局 end ---------------------------------------->
  78. </div>
  79. <!--弹出框 start------------------------------------------------------------>
  80. <el-dialog title="编辑模块" :visible.sync="windowStatus">
  81. <el-form :model="form" ref="form" autocomplete="off" label-position="left">
  82. <div class="formDiv">
  83. <el-form-item label="内容" :label-width="formLabelWidth" prop="alias" class="custom-align-right">
  84. <el-input v-model="form.content" autocomplete="off"></el-input>
  85. <input type="hidden" v-model="form.seo_title">
  86. </el-form-item>
  87. </div>
  88. </el-form>
  89. <div slot="footer" class="dialog-footer">
  90. <div>
  91. <el-button @click="closeWindow">取 消</el-button>
  92. <el-button type="primary" @click="editGridItem">确定</el-button>
  93. </div>
  94. </div>
  95. </el-dialog>
  96. <!--弹出框 end------------------------------------------------------------>
  97. </div>
  98. </template>
  99. <script>
  100. //引入公用样式
  101. import '@/styles/global.less';
  102. //引入vue-grid-layout
  103. import { GridLayout, GridItem } from 'vue-grid-layout';
  104. //标题
  105. import tableTitle from './components/tableTitle';
  106. export default {
  107. components: {
  108. GridLayout,
  109. GridItem,
  110. tableTitle
  111. },
  112. data() {
  113. return {
  114. //页面 start------------------------------------------------------------>
  115. headerTitle: '模块',
  116. websiteTitle: '预览',
  117. windowStatus: false,
  118. //页面 end------------------------------------------------------------>
  119. //弹出框 start------------------------------------------------------------>
  120. formLabelWidth: '120px',
  121. editModule: "",//待编辑的模块
  122. form: {
  123. content: '',
  124. },
  125. //弹出框 end------------------------------------------------------------>
  126. //预览 start------------------------------------------------------------>
  127. layout: [
  128. // i = id
  129. // w = 最大宽度是12
  130. // { i: "0", x: 0, y: 0, w: 12, h: 2, content:""},
  131. // { i: "1", x: 0, y: 0, w: 12, h: 2, content:""},
  132. // { i: "2", x: 3, y: 0, w: 3, h: 2, content:""},
  133. // { i: "3", x: 6, y: 0, w: 3, h: 2, content:""}
  134. ]
  135. //预览 end------------------------------------------------------------>
  136. }
  137. },
  138. methods: {
  139. //添加模块
  140. addModule(type) {
  141. console.log(type);
  142. this.layout.push({
  143. i: this.layout.length,
  144. x: 0,
  145. y: 0,
  146. w: 12,
  147. h: 1,
  148. type: type, //1=顶部菜单(含登录) ..
  149. content:""});
  150. },
  151. //打开弹出框
  152. openWindow(item) {
  153. this.editModule = item.i;
  154. this.windowStatus = true;
  155. },
  156. //编辑栅格布局
  157. editGridItem() {
  158. console.log(this.editModule);
  159. //找对在栅栏中对应的窗口,把编辑的值放进去
  160. for(let i = 0; i < this.layout.length; i++) {
  161. if(this.layout[i].i == this.editModule) {
  162. this.layout[i].content = this.form.content;
  163. }
  164. }
  165. //关闭窗口
  166. this.windowStatus = false;
  167. },
  168. //关闭弹出框
  169. closeWindow() {
  170. this.windowStatus = false;
  171. }
  172. },
  173. mounted(){
  174. const id = this.$route.query.id;
  175. console.log('Retrieved ID from route:', id);
  176. }
  177. }
  178. </script>
  179. <style scoped lang="less">
  180. //菜单 start------------------------------------------------------------>
  181. .layerBox {
  182. padding-bottom: 10px;
  183. }
  184. .menuTopBox{
  185. display: flex;
  186. flex-wrap: wrap;
  187. }
  188. .menuItem{
  189. display: flex;
  190. align-items: center;
  191. border-radius:10px;
  192. padding: 5px 10px;
  193. cursor: pointer;
  194. background: #f0f2f5;
  195. font-size: 14px;
  196. color: #666;
  197. margin-right: 10px;
  198. margin-bottom: 10px;
  199. img {
  200. margin-right: 5px;
  201. }
  202. }
  203. //栅格布局 start------------------------------------------------------------>
  204. .grid-layout-demo {
  205. background-color: #f0f2f5;
  206. padding: 20px;
  207. }
  208. .grid-item-content {
  209. display: flex;
  210. align-items: center;
  211. justify-content: center;
  212. background-color: #fff;
  213. border: 1px solid #d9d9d9;
  214. height: 100%;
  215. }
  216. //栅格布局 end------------------------------------------------------------>
  217. //执行v-deep穿透scope选择器 start------------------------------------------------------------>*/
  218. ::v-deep .custom-form-item > .el-form-item__label {
  219. line-height: 140px !important;
  220. }
  221. ::v-deep .custom-textarea .el-textarea__inner {
  222. resize: none; /* 禁止用户拖拽调整大小 */
  223. }
  224. ::v-deep .custom-align-right .el-form-item__label {
  225. text-align: right; /* 设置标签文字右对齐 */
  226. }
  227. //执行v-deep穿透scope选择器 end------------------------------------------------------------>*/
  228. </style>