diff --git a/src/views/home/gridLayout.vue b/src/views/home/gridLayout.vue index f4a2ff59..6e285f1b 100644 --- a/src/views/home/gridLayout.vue +++ b/src/views/home/gridLayout.vue @@ -9,17 +9,16 @@ @@ -68,12 +98,20 @@ }, data() { return { - layout: [18,6], //数组总数不能大于24, [16,8]:分两列左16右8 还可以设置 [18,6] [8,8,8] [6,12,6] + layout: [18,6], //数组总数不能大于24, [16,8]:分两列左16右8 还可以设置 [24] [18,6] [8,8,8] [6,12,6] allComps: allComps, + allCompsList: [], showPush: false, + pushForm: { + selectComps: null + }, + rules: { + selectComps: [ + { required: true, message: '请选择添加的组件', trigger: 'blur' } + ] + }, showSet: false, - selectComps: '', - defaultGrid:[ + defaultGrid: [ [ { title: "模块1", com: 'C1' }, { title: "模块2", com: 'C2' } @@ -85,7 +123,7 @@ ] ], - grid:[] + grid: [] } }, created(){ @@ -93,18 +131,56 @@ this.grid = grid || this.defaultGrid; }, mounted(){ - console.log(allComps); + //console.log(allComps); }, methods: { + //输出可添加的组件 + setAllCompsList(){ + var allCompsList = [] + for(var key in allComps){ + allCompsList.push({ + title: allComps[key].title, + com: key + }) + } + var nowGrid_arr = this.grid.reduce(function(a, b){return a.concat(b)}); + for(let comp of allCompsList){ + const _item = nowGrid_arr.find((item)=>{return item.com === comp.com}); + if(_item){ + comp.disabled = true + } + } + this.allCompsList = allCompsList; + + }, //拖动结束后 end(){ this.$TOOL.data.set("grid", this.grid); }, + //分栏设置 + set(){ + this.showSet = true; + }, //添加组件 push(){ + this.setAllCompsList() this.showPush = true; }, - submitPush(){ + submitPush(formName){ + this.$refs[formName].validate((valid) => { + if (valid) { + var formModel = this.$refs[formName].model; + this.grid[0].unshift(formModel.selectComps); + this.$TOOL.data.set("grid", this.grid); + this.$refs[formName].resetFields(); + this.showPush = false; + }else{ + return false; + } + }) + }, + closePush(){ + this.$refs.pushForm.resetFields(); this.showPush = false; }, //刷新组件 @@ -128,7 +204,7 @@ }, //恢复默认 backDefaul(){ - this.grid = this.defaultGrid; + this.grid = this.$options.data().defaultGrid; this.$TOOL.data.remove("grid"); } } @@ -140,9 +216,64 @@ display: flex; justify-content: space-between; align-items: center; + cursor: move; + } + .diy-grid-layout .el-card__header .el-dropdown-link { + color: #999; + border-radius: 3px; + cursor: pointer; + padding:3px 5px; + } + .diy-grid-layout .el-card__header .el-dropdown-link:hover { + color: #555; + background: #ecf5ff; + } + .diy-grid-layout .el-card__header .el-dropdown-link:focus { + color: #555; + background: #ecf5ff; } .diy-grid-layout .sortable-ghost { opacity: 0.5; background: #c8ebfb; } + .diy-grid-layout-set { + display: flex; + justify-content: center + } + .diy-grid-layout-set div { + width:80px; + height:80px; + background: #ecf5ff; + margin:10px; + cursor: pointer; + } + .diy-grid-layout-set div span{ + background: #b1e0ff; + } + .diy-grid-layout-set .col { + display: flex; + flex-direction: column; + align-content: space-between; + padding:0 5px 5px 5px; + } + .diy-grid-layout-set .col span { + height:20px; + width: 100%; + margin-top:5px; + } + .diy-grid-layout-set .row { + display: flex; + justify-content: flex-start; + padding:5px 5px 5px 0; + } + .diy-grid-layout-set .row span { + height: 70px; + width: 20px; + margin-left:5px; + } + .diy-grid-layout-set div.active { + background: #09f; + } + +