-
Notifications
You must be signed in to change notification settings - Fork 7
/
row-setting.vue
85 lines (82 loc) · 2.27 KB
/
row-setting.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<template>
<section class="row-setting">
<i class="el-icon-copy-document" @click="copyRow"></i>
<i class="el-icon-delete" @click="delRow"></i>
</section>
</template>
<script>
import shortid from 'js-shortid'
export default {
inject: ['fg'],
props: {
activeRow: Number
},
computed: {
activeSchema () {
return this.fg.layoutSections[this.activeRow] || []
}
},
methods: {
copyRow () {
let propList = []
let _result = this.activeSchema.map(item => {
if (item.prop) {
let _cur = {
oldProp: item.prop,
newProp: shortid.gen()
}
propList.push(_cur)
return {
...item,
prop: _cur.newProp
}
}
return item
})
this.fg.layoutSections.splice(this.activeRow + 1, 0, _result)
propList.forEach(list => {
this.addModuleAndOption(list)
})
console.log('this.fg.layoutSections: ', this.fg.layoutSections)
this.$emit('delRowSuccess', { activeRow: this.activeRow + 1 })
},
delRow () {
this.activeSchema.forEach(grid => {
this.delModuleAndOption(grid)
})
let _activeSection = this.activeRow === 0 ? 0 : this.activeRow - 1
this.fg.layoutSections.splice(this.activeRow, 1)
this.$emit('delRowSuccess', { activeRow: _activeSection })
},
delModuleAndOption (grid) {
// 删除module
if (this.fg.formModel.hasOwnProperty(grid.prop)) this.$delete(this.fg.formModel, grid.prop)
// 删除option
if (this.fg.formOptions.hasOwnProperty(grid.prop)) this.$delete(this.fg.formOptions, grid.prop)
},
addModuleAndOption ({ oldProp, newProp }) {
// 增加module
if (this.fg.formModel.hasOwnProperty(oldProp)) this.$set(this.fg.formModel, newProp, this.fg.formModel[oldProp])
// 删除option
if (this.fg.formOptions.hasOwnProperty(oldProp)) this.$set(this.fg.formOptions, newProp, this.fg.formOptions[oldProp])
}
}
}
</script>
<style lang="less" scoped>
@primary: #7367f0;
.row-setting{
position: absolute;
bottom:0;
right:0;
width: 40px;
padding: 0 5px;
height: 20px;
background: @primary;
font-size:16px;
color: #fff;
display: flex;
justify-content: space-between;
align-items: center;
}
</style>