dynamicAddSvg.vue
4.75 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<template>
<div>
<el-button
type="primary"
size="small"
icon="el-icon-plus"
plain
@click="handleAddClick"
>新增</el-button
>
<el-table :data="formData" style="width: 100%">
<el-table-column prop="name" label="名称" width="130" />
<el-table-column prop="key" label="判断值" width="70" />
<el-table-column label="操作" width="100">
<template slot-scope="scope">
<div class="button-group">
<el-button
@click="handleEditorClick(scope.$index, scope.row)"
type="text"
size="small"
>编辑</el-button
>
<el-button
type="text"
size="small"
@click="handleDeleteClick(scope.$index, scope.row)"
>删除</el-button
>
</div>
</template>
</el-table-column>
</el-table>
<el-dialog
title="新增"
:visible.sync="dialogVisible"
width="30%"
:before-close="handleClose"
>
<el-form :model="rowFormData" label-width="70px">
<el-form-item label="名称:">
<el-input
v-model.trim="rowFormData['name']"
placeholder="请输入名称"
size="mini"
>
</el-input>
</el-form-item>
<el-form-item label="判断值:" label-width="70px">
<el-input
v-model.trim="rowFormData['key']"
placeholder="请输入判断值"
size="mini"
>
</el-input>
</el-form-item>
<el-form-item label="SVG值:">
<el-input
v-model.trim="rowFormData['value']"
placeholder="请输入SVG值"
size="mini"
>
</el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button size="mini" @click="dialogVisible = false">取 消</el-button>
<el-button size="mini" type="primary" @click="handleSaveClick"
>确 定</el-button
>
</span>
</el-dialog>
</div>
</template>
<script>
export default {
model: {
prop: "formData",
event: "input"
},
props: {
formData: Array
},
data() {
return {
dialogVisible: false,
rowFormData: {
name: "",
key: "",
value:""
},
flag: true, // true 新增, false 编辑
indexEditor: -1, // 编辑第几个数据
tableData: []
};
},
methods: {
// 新增
handleAddClick() {
this.rowFormData = {};
this.flag = true;
this.dialogVisible = true;
},
// 编辑
handleEditorClick(index, row) {
this.flag = false;
this.rowFormData = this.deepClone(row);
this.indexEditor = index;
this.dialogVisible = true;
},
// 关闭
handleClose() {
this.dialogVisible = false;
},
// 保存
handleSaveClick() {
if (this.flag) {
// 新增
this.formData.push(this.rowFormData);
this.dialogVisible = false;
} else {
// 编辑
this.formData[this.indexEditor] = this.rowFormData;
this.$set(this.formData, this.indexEditor, this.rowFormData);
this.dialogVisible = false;
}
this.$emit("input", this.formData);
this.$emit("change", this.formData);
},
// 删除
handleDeleteClick(index) {
this.formData.splice(index, 1);
this.$emit("input", this.formData);
this.$emit("change", this.formData);
}
}
};
</script>
<style lang="scss" scoped>
// 滚动条轨道背景(透明)
:deep(::-webkit-scrollbar-track-piece) {
background-color: transparent;
}
// 表格滚动条:隐藏横向,设置纵向高度
:deep(.el-table__body-wrapper::-webkit-scrollbar) {
width: 0; // 隐藏横向滚动条
height: 8px; // 纵向滚动条高度(必须设置才显示)
}
// 滚动条滑块样式
:deep(.el-table__body-wrapper::-webkit-scrollbar-thumb) {
border-radius: 5px;
background-color: rgba(144, 146, 152, 0.3);
}
// 表格整体样式:背景、文字颜色、字体大小
:deep(.el-table),
:deep(.el-table__expanded-cell),
:deep(.el-table th),
:deep(.el-table tr) {
background-color: transparent !important;
color: #859094 !important;
font-size: 12px !important;
}
// 表格单元格:去除下边框,调整行高
:deep(.el-table td),
:deep(.el-table th.is-leaf) {
border-bottom: none;
line-height: 26px;
}
// 表格行 hover 背景色(合并两条规则)
:deep(.el-table tbody tr:hover),
:deep(.el-table tbody tr:hover > td) {
background-color: #263445 !important;
}
// 去除 el-table 底部默认的横线(伪元素)
:deep(.el-table::before) {
height: 0;
}
// 按钮组内按钮内边距
.button-group .el-button {
padding: 0;
}
</style>