From dcc4992bd51e9ee4a97099cd3a15085f7e247f23 Mon Sep 17 00:00:00 2001 From: gaoshp <291585735@qq.com> Date: 星期日, 03 十一月 2024 20:21:41 +0800 Subject: [PATCH] update --- src/views/home/widgets/index.vue | 179 +++++++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 123 insertions(+), 56 deletions(-) diff --git a/src/views/home/widgets/index.vue b/src/views/home/widgets/index.vue index 3cb7f6f..837a33b 100644 --- a/src/views/home/widgets/index.vue +++ b/src/views/home/widgets/index.vue @@ -17,9 +17,9 @@ </div> <el-row :gutter="15"> <el-col v-for="(item, index) in grid.layout" v-bind:key="index" :md="item" :xs="24"> - <draggable v-model="grid.copmsList[index]" animation="200" handle=".customize-overlay" group="people" item-key="com" dragClass="aaaaa" force-fallback fallbackOnBody class="draggable-box"> + <draggable v-model="grid.copmsList[index]" animation="200" handle=".customize-overlay" group="people" item-key="com" dragClass="aaaaa" force-fallback fallbackOnBody class="draggable-box" @add="endDraggable"> <template #item="{ element }"> - <div class="widgets-item"> + <div class="widgets-item" :ref="element"> <component :is="allComps[element]"></component> <div v-if="customizing" class="customize-overlay"> <el-button class="close" type="danger" plain icon="el-icon-close" size="small" @click="remove(element)"></el-button> @@ -41,7 +41,7 @@ </el-header> <el-header style="height:auto"> <div class="selectLayout"> - <div class="selectLayout-item item01" :class="{active:grid.layout.join(',')=='12,6,6'}" @click="setLayout([12,6,6])"> + <!-- <div class="selectLayout-item item01" :class="{active:grid.layout.join(',')=='12,6,6'}" @click="setLayout([12,6,6])"> <el-row :gutter="2"> <el-col :span="12"><span></span></el-col> <el-col :span="6"><span></span></el-col> @@ -61,7 +61,7 @@ <el-col :span="24"><span></span></el-col> <el-col :span="24"><span></span></el-col> </el-row> - </div> + </div> --> <div class="selectLayout-item item04" :class="{active:grid.layout.join(',').indexOf('24,12,6,6')>-1}" @click="setLayout([24,12,6,6])"> <el-row :gutter="2"> <el-col :span="24"><span></span></el-col> @@ -90,7 +90,7 @@ </div> </el-main> <el-footer style="height:51px;"> - <el-button size="small" @click="backDefaul()">鎭㈠榛樿</el-button> + <el-button size="small" @click="backDefaul()">鍏抽棴</el-button> </el-footer> </el-container> </div> @@ -120,7 +120,7 @@ this.getWorkbenchCarList(); }, mounted() { - this.$emit('on-mounted') + this.$emit('on-mounted'); }, computed: { allCompsList(){ @@ -133,14 +133,7 @@ description: allComps[key].description }) } - var myCopmsList = this.grid.copmsList.reduce(function(a, b){return a.concat(b)}) - for(let comp of allCompsList){ - const _item = myCopmsList.find((item)=>{return item === comp.key}) - if(_item){ - comp.disabled = true - } - } - return allCompsList + return allCompsList; }, myCompsList(){ var copmsList = []; @@ -150,7 +143,6 @@ }) var myGrid = copmsList; this.$TOOL.data.set("DASHBOARDGRID", copmsList); - //return this.allCompsList.filter(item => !item.disabled && myGrid.includes(item.key)) return this.allCompsList; }, nowCompsList(){ @@ -163,6 +155,9 @@ } }, methods: { + endDraggable(e) { + //console.log(this.grid,e,111) + }, getWorkbenchCarList() { var data = this.$TOOL.data.get("MENU"); this.workid = data[0].children[0].id; //璁板綍绗竴涓猚hildren鐨刬d @@ -174,39 +169,83 @@ //鎸墆coordinate杩涜浠庡皬鍒板ぇ鎺掑簭锛屽鏋測coordinate涓�鏍锋椂锛屾寜鐓coordinate浠庡皬鍒板ぇ鎺掑簭 //cardWide浠h〃瀹藉害 //cardKey浠h〃缁勪欢鍚嶇О - cards.sort((a, b) => { - // 鍏堟瘮杈� ycoordinate - if (a.ycoordinate < b.ycoordinate) { - return -1; - } - if (a.ycoordinate > b.ycoordinate) { - return 1; - } - // 濡傛灉 ycoordinate 鐩稿悓锛屽垯姣旇緝 xcoordinate - if (a.xcoordinate < b.xcoordinate) { - return -1; - } - if (a.xcoordinate > b.xcoordinate) { - return 1; - } - // 濡傛灉 xcoordinate 涔熺浉鍚岋紝鍒欎笉浜ゆ崲浣嶇疆 - return 0; - }); - console.log(cards) - cards.forEach((item,index)=> { - this.$CONFIG.DEFAULT_GRID.copmsList[index] = [item.cardKey]; - this.$CONFIG.DEFAULT_GRID.layout[index] = item.cardWide * 2; - }) - console.log(this.$CONFIG.DEFAULT_GRID.copmsList,this.$CONFIG.DEFAULT_GRID.layout,234) - this.$CONFIG.DEFAULT_GRID.data = cards; + // cards.sort((a, b) => { + // // 鍏堟瘮杈� ycoordinate + // if (a.ycoordinate < b.ycoordinate) { + // return -1; + // } + // if (a.ycoordinate > b.ycoordinate) { + // return 1; + // } + // // 濡傛灉 ycoordinate 鐩稿悓锛屽垯姣旇緝 xcoordinate + // if (a.xcoordinate < b.xcoordinate) { + // return -1; + // } + // if (a.xcoordinate > b.xcoordinate) { + // return 1; + // } + // // 濡傛灉 xcoordinate 涔熺浉鍚岋紝鍒欎笉浜ゆ崲浣嶇疆 + // return 0; + // }); + // var layout = [...new Set(cards.map(v => v.cardWide *2))]; //甯冨眬 + // if(layout.length < 3) { + // layout = [24,12,6,6]; + // } + var result = {} + //鎺掑簭 + // cards.forEach(v=> { + // if(!result[`${v.cardWide}-${v.xcoordinate}`]) { + // result[`${v.cardWide}-${v.xcoordinate}`] = [] + // } + // result[`${v.cardWide}-${v.xcoordinate}`].push(v) + // }) + // let resdata = [] + // Object.values(result).forEach(v => { + // let min = v.sort((a,b) => a.ycoordinate - b.ycoordinate)[0]; + // let minYX = Number(min.ycoordinate)*10 + Number(min.xcoordinate); + // let obj = {}; + // obj[minYX] = v; + // resdata.push(obj); + // }) + // var lastData = resdata.map(v => Object.values(v)); + // //杞寲 + // var copmsList = lastData.map(function(outerArray) { + // // 璁块棶鏈�鍐呭眰鐨勫璞℃暟缁� + // var innerArray = outerArray[0]; + // return innerArray.map(function(obj) { + // return obj.cardKey; + // }); + // }); + //淇濊瘉鏈�4涓暟缁勶紝鎵嶈兘鎷栨嫿 + // var neededLength = 4 - copmsList.length; + // for (var i = 0; i < neededLength; i++) { + // copmsList.push([]); + // } + // this.$CONFIG.DEFAULT_GRID.copmsList = copmsList; + // this.$CONFIG.DEFAULT_GRID.layout = layout; + // this.$CONFIG.DEFAULT_GRID.data = cards; + //this.$CONFIG.DEFAULT_GRID.copmsList = [["mdcDeviceStatus"],["mdcRunning","mdcEquipmentRun"],[],[]] + if(res.data.length == 0) { + this.$CONFIG.DEFAULT_GRID.copmsList = [[],[],[],[]]; + }else { + var layoutConfig = JSON.parse(res.data[0].layoutConfig); + //涓嶆弧瓒�4锛岃ˉ瓒� + var newArr = [...layoutConfig]; + for (let i = 0; i < (4-newArr.length); i++) { + layoutConfig.push([]); + } + this.$CONFIG.DEFAULT_GRID.copmsList = res.data[0].layoutConfig == null?[]:layoutConfig; + } + this.$CONFIG.DEFAULT_GRID.layout = [24,12,6,6]; + this.$CONFIG.DEFAULT_GRID.data = res.data; this.defaultGrid = this.$CONFIG.DEFAULT_GRID; - this.grid = this.$TOOL.data.get("grid") || JSON.parse(JSON.stringify(this.defaultGrid)) + this.grid = this.$TOOL.data.get("grid") || JSON.parse(JSON.stringify(this.defaultGrid)); } }) }, //寮�鍚嚜瀹氫箟 custom(){ - this.customizing = true + this.customizing = true; const oldWidth = this.$refs.widgets.offsetWidth this.$nextTick(() => { const scale = this.$refs.widgets.offsetWidth / oldWidth @@ -224,28 +263,57 @@ }, //杩藉姞 push(item){ - let target = this.grid.copmsList[0] - target.push(item.key) + var that = this; + var target = this.grid; + if(this.grid.copmsList.length == 0) { + target.copmsList.push([item.key]); + }else { + target.copmsList[0].push(item.key) + } + this.$nextTick(()=> { + //var height = String(Math.floor(this.$refs.Access[0].offsetHeight/ 57)); + //item.cardLength = height; + //item.cardWide = '12'; + //item.xcoordinate = '0'; + //item.ycoordinate = '4'; + item.cardKey = item.key; + item.workbenchId = that.workid; + target.data.push(item); + }) }, //闅愯棌缁勪欢 remove(item){ - var newCopmsList = this.grid.copmsList - newCopmsList.forEach((obj, index) => { - var newObj = obj.filter(o=>o!=item) - newCopmsList[index] = newObj; + this.$nextTick(()=> { + var newCopmsList = this.grid.copmsList; + newCopmsList.forEach((obj, index) => { + var newObj = obj.filter(o=>o!=item) + newCopmsList[index] = newObj; + }) + this.grid.data.forEach((item1,index1)=> { + if(item1.cardKey == item) { + this.grid.data.splice(index1,1); + } + }) }) }, //淇濆瓨 save(){ this.customizing = false this.$refs.widgets.style.removeProperty('transform') - this.$TOOL.data.set("grid", this.grid) + this.$TOOL.data.set("grid", this.grid); + //this.apiResource.workStationIdList //淇濆瓨鎺ュ彛 - var copmsList = this.grid.copmsList; - var flattened = copmsList.reduce((acc, val) => acc.concat(val), []); //鎵佸钩鍖� - var data = this.grid.data.filter(item=>flattened.includes(item.cardKey)); + //var copmsList = this.grid.copmsList; + //var flattened = copmsList.reduce((acc, val) => acc.concat(val), []); //鎵佸钩鍖� + //var data = this.grid.data.filter(item=>this.nowCompsList.includes(item.cardKey)); + this.grid.data.forEach(item=> { + item.layoutConfig = JSON.stringify(this.grid.copmsList); + if(item.cardKey == "mdcRunning") { + item.apiResource = JSON.stringify({workStationIdList: []}) + } + }) var obj = { - workbenchCardAddVOList: data, + workbenchCardAddVOList: this.grid.data, workbenchId: this.workid } this.$HTTP.post(`/api/blade-system/workbench-card/create-workbench-card`,obj).then(res=> { @@ -253,14 +321,13 @@ this.$message.success("鎿嶄綔鎴愬姛"); } }) - console.log(this.grid,111) }, //鎭㈠榛樿 backDefaul(){ this.customizing = false this.$refs.widgets.style.removeProperty('transform') - this.grid = JSON.parse(JSON.stringify(this.defaultGrid)) - this.$TOOL.data.remove("grid") + // this.grid = JSON.parse(JSON.stringify(this.defaultGrid)) + // this.$TOOL.data.remove("grid") }, //鍏抽棴 close(){ -- Gitblit v1.9.3