Update gridLayout.vue

This commit is contained in:
sakuya 2021-04-26 23:34:00 +08:00
parent 8ba898dffc
commit 32b9c037fe
1 changed files with 159 additions and 28 deletions

View File

@ -9,17 +9,16 @@
<el-card shadow="hover" style="margin-bottom:15px;">
<template #header>
<span>{{element.title}}</span>
<el-dropdown>
<el-dropdown trigger="click">
<span class="el-dropdown-link">
下拉菜单<i class="el-icon-arrow-down el-icon--right"></i>
<i class="el-icon-menu"></i>
</span>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item @click="refresh(element)">刷新</el-dropdown-item>
<el-dropdown-item @click="remove(element)">隐藏</el-dropdown-item>
<el-dropdown-item @click="push()" divided>添加组件</el-dropdown-item>
<el-dropdown-item>分栏设置</el-dropdown-item>
<el-dropdown-item @click="push()">添加组件</el-dropdown-item>
<el-dropdown-item @click="set()">分栏设置</el-dropdown-item>
<el-dropdown-item @click="backDefaul()">恢复默认</el-dropdown-item>
<el-dropdown-item @click="remove(element)" divided>移除</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
@ -33,25 +32,56 @@
</el-row>
</div>
<el-dialog title="添加组件" v-model="showPush" :width="400" destroy-on-close :append-to-body='true'>
<el-alert title="添加的元素自动会添加至最左侧分栏的最后,请勿添加过多的组件导致系统运行缓慢" type="warning" show-icon></el-alert>
<div style="margin-top: 15px;">
<el-select v-model="selectComps" filterable clearable placeholder="请选择组件" style="width: 100%;">
<el-option v-for="(item,key) in allComps" :key="key" :label="item.title" :value="key">
<el-dialog title="添加组件" v-model="showPush" :width="400" :before-close="closePush" destroy-on-close :append-to-body='true'>
<el-alert title="添加的元素自动会添加至最左侧" type="warning" show-icon style="margin-bottom:20px;"></el-alert>
<el-form :model="pushForm" ref="pushForm" :rules="rules" label-width="0">
<el-form-item prop="selectComps">
<el-select v-model="pushForm.selectComps" value-key="title" filterable clearable placeholder="请选择组件" style="width: 100%;">
<el-option v-for="item in allCompsList" :key="item.com" :label="item.title" :value="item" :disabled="item.disabled">
<span style="float: left">{{ item.title }}</span>
<span style="float: right; color: #8492a6; font-size: 13px">{{ key }}</span>
<span style="float: right; color: #8492a6; font-size: 13px">{{ item.com }}</span>
</el-option>
</el-select>
</div>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="showPush = false"> </el-button>
<el-button type="primary" @click="submitPush()"> </el-button>
</span>
<el-button @click="closePush"> </el-button>
<el-button type="primary" @click="submitPush('pushForm')"> </el-button>
</template>
</el-dialog>
<el-dialog title="分栏设置" v-model="showSet" :width="500" destroy-on-close :append-to-body='true'>
<div class="diy-grid-layout-set">
<el-tooltip content="通栏">
<div class="col active">
<span></span>
<span></span>
<span></span>
</div>
</el-tooltip>
<el-tooltip content="左大右小布局">
<div class="row">
<span style="width: 60%;"></span>
<span style="width: 30%;"></span>
</div>
</el-tooltip>
<el-tooltip content="等分布局">
<div class="row">
<span></span>
<span></span>
<span></span>
</div>
</el-tooltip>
<el-tooltip content="左右辅助布局">
<div class="row">
<span style="width: 25%;"></span>
<span style="width: 50%;"></span>
<span style="width: 25%;"></span>
</div>
</el-tooltip>
</div>
</el-dialog>
</template>
@ -68,11 +98,19 @@
},
data() {
return {
layout: [18,6], //24, [16,8]:168 [18,6] [8,8,8] [6,12,6]
layout: [18,6], //24, [16,8]:168 [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: [
[
{ title: "模块1", com: 'C1' },
@ -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;
}
</style>