WidgetHottableLayout.vue
9.61 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<template>
<div
@click.stop="handleSelectWidget(index)"
class="widget-hottable"
:class="{active: selectWidget.key == element.key}"
>
<div
class="drag-widget"
title="拖拽"
v-if="selectWidget.key == element.key"
>
<i class="icon-drag"></i>
</div>
<div class="widget-view-action" v-if="selectWidget.key == element.key">
<i
class="icon-trash"
title="删除"
@click.stop="handleWidgetDelete(index)"
></i>
</div>
<div style="overflow-x: auto; overflow-y: hidden; padding: 15px">
<div
v-if="element.options.showLabel"
style="font-weight: bold; padding: 10px"
>
{{ element.desc_zh || element.desc }}
</div>
<el-form label-position="top" style="padding-bottom: 10px"> </el-form>
</div>
</div>
</template>
<script>
import controlsApi from '@/api/controlsConfig.js'
export default {
name: 'widget-hottable-layout',
props: ['element', 'select', 'index', 'data'],
data() {
return {
selectWidget: this.select,
root: 'designer-hot',
hotSettings: {
data: [
//数据可以是二维数组,也可以是数组对象
{xm: '李四', xb: '男', account: 'lisi', nl: 23},
{xm: '张三', xb: '男', account: 'zhangsan', nl: 22}
],
// colHeaders: true,
startRows: 11, //行列范围
startCols: 6,
minRows: 1, //最小行列
minCols: 0,
maxRows: 200, //最大行列
maxCols: 200,
rowHeights: 25,
rowHeaders: true, //行表头,可以使布尔值(行序号),可以使字符串(左侧行表头相同显示内容,可以解析html),也可以是数组(左侧行表头单独显示内容)。
colHeaders: ['姓名', '性别', '账号', '年龄'], //自定义列表头or 布尔值
minSpareCols: 0, //列留白
minSpareRows: 0, //行留白
// currentRowClassName: 'currentRow', //为选中行添加类名,可以更改样式
// currentColClassName: 'currentCol',//为选中列添加类名
autoWrapRow: true, //自动换行
contextMenu: {
items: {
row_above: {
name: '上方插入一行'
},
row_below: {
name: '下方插入一行'
},
remove_row: {
name: '删除行'
}
}
},
licenseKey: 'non-commercial-and-evaluation',
manualColumnFreeze: true, //手动固定列 ?
manualColumnMove: true, //手动移动列
manualRowMove: true, //手动移动行
manualColumnResize: true, //手工更改列距
manualRowResize: true, //手动更改行距
comments: true, //添加注释
customBorders: [], //添加边框
columnSorting: true, //排序
stretchH: 'all', //根据宽度横向扩展,last:只扩展最后一列,none:默认不扩展
fillHandle: true, //选中拖拽复制 possible values: true, false, "horizontal", "vertical"
fixedColumnsLeft: 2, //固定左边列数
fixedRowsTop: 2, //固定上边列数
beforeRemoveRow: this.beforeRemoveRowMe,
afterCreateRow: this.afterCreateRow,
afterChange: this.afterChangeMe,
mergeCells: [
//合并
// {row: 1, col: 1, rowspan: 3, colspan: 3}, //指定合并,从(1,1)开始行3列3合并成一格
// {row: 3, col: 4, rowspan: 2, colspan: 2}
],
columns: [
{
data: 'xm',
type: 'text'
},
{
data: 'xb',
type: 'text'
},
{
data: 'account',
type: 'text'
},
{
data: 'nl',
type: 'numeric'
}
]
}
}
},
methods: {
handleSelectWidget(index) {
this.selectWidget = this.data.list[index]
},
handleWidgetColAdd($event, element) {
const newIndex = $event.newIndex
const oldIndex = $event.oldIndex
const item = $event.item
if (item.innerText == '二维码') {
this.$message.error('子表不允许存在二维码')
element.list.splice(newIndex, 1)
return false
}
if (item.innerText == '里程碑') {
this.$message.error('子表不允许存在里程碑')
element.list.splice(newIndex, 1)
return false
}
if (item.innerText == '审批预测') {
this.$message.error('子表不允许存在审批预测')
element.list.splice(newIndex, 1)
return false
}
if (item.innerText === '图表') {
this.$message.warning('子表不允许存在图表')
element.list.splice(newIndex, 1)
return false
}
if (item.innerText == '高德地图') {
this.$message.error('子表不允许存在高德地图')
element.list.splice(newIndex, 1)
return false
}
if (item.innerText == '相关流程') {
this.$message.error('子表不允许存在相关流程')
element.list.splice(newIndex, 1)
return false
}
if (!controlsApi.handleLayoutComponents(this)) {
return
}
if (!element.options.boSubEntity) {
this.$message.error('请先绑定子表')
return false
}
// 防止布局元素的嵌套拖拽
if (item.isLayout) {
element.list.list.splice(newIndex, 1)
return false
}
this.selectWidget = element.list[newIndex]
this.selectWidget.parentNodeType = 'hot'
this.selectWidget.boSubEntity = element.options.boSubEntity
},
handleWidgetDelete(index) {
if (this.data.list.length - 1 === index) {
if (index === 0) {
this.selectWidget = {options: {validateType: ''}}
} else {
this.selectWidget = this.data.list[index - 1]
}
} else {
this.selectWidget = this.data.list[index + 1]
}
this.$nextTick(() => {
this.data.list.splice(index, 1)
})
},
beforeRemoveRowMe: function(changes, source) {
// 数据改变时触发此方法
this.hotSettings.dataList.splice(changes, source)
},
// 添加行
afterCreateRowMe: function(changes) {
this.hotSettings.dataList.splice(changes, 0, {
region: '',
destination: '',
firstWeight: '',
firstWeightPrice: '',
riseWeight: '',
riseWeightPrice: ''
})
},
// 新增行时,动态改变值
afterChangeMe: function(changes) {
if (changes) {
changes.forEach(([row, prop, oldValue, newValue]) => {
try {
this.hotSettings.dataList[row][prop] = newValue
} catch (error) {}
})
}
},
// 查看-excel不可编辑
excalEdit() {
this.hotSettings.columns.forEach(par => {
par.readOnly = true
})
}
},
watch: {
select(val) {
this.selectWidget = val
},
selectWidget: {
handler(val, oldVal) {
this.$emit('update:select', val)
},
deep: true
},
'selectWidget.options.colHeadersRelations': {
handler(val, oldVal) {
if (val && val.length > 0) {
if (oldVal !== val) {
let headers = []
let columns = []
let dataList = [[]]
if (val.length > 0) {
for (let index = 0; index < val.length; index++) {
let relation = val[index]
headers.push(relation.desc)
columns.push(relation.column)
}
}
this.hotSettings.colHeaders = headers
this.hotSettings.columns = columns
this.hotSettings.data = dataList
if (
this.selectWidget.options.initFillbackData &&
this.selectWidget.options.initFillbackData.length > 0
) {
this.hotSettings.data = JSON.parse(
JSON.stringify(this.selectWidget.options.initFillbackData)
)
}
}
}
},
deep: true
},
'selectWidget.options.initFillbackData': {
handler(val, oldVal) {
if (oldVal !== val) {
if (val) {
this.hotSettings.data = JSON.parse(JSON.stringify(val))
} else {
this.hotSettings.data = [[]]
}
}
},
deep: true
}
}
}
</script>
<style lang="scss" scoped>
@import '@/assets/css/form-editor.scss';
.widget-hottable {
padding-bottom: 0;
padding: 10px 5px;
position: relative;
}
.widget-hottable.active {
outline: 1px solid $--form-design-active-color !important;
}
.widget-hottable:hover {
outline: 1px dashed #ccc;
}
div.widget-view-action {
border-color: $--form-design-active-color;
border-radius: 15px;
}
div.widget-view-action i.icon-trash {
margin: 0 10px;
}
div.drag-widget {
border-color: $--form-design-active-color;
}
div.drag-widget i.icon-drag {
color: $--form-design-active-color;
}
.widget-col-list {
min-height: 50px;
outline: 1px solid #ededed;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.widget-col-list .widget-form-item {
margin: 0;
outline: 1px solid #ededed;
height: 100%;
}
>>> .ht-form-item {
text-align: center;
padding: 0;
margin: 0;
}
>>> .el-form-item__label {
font-weight: bold;
min-width: 120px;
padding: 0;
text-align: center;
}
>>> .el-form-item__label:after {
visibility: hidden;
}
>>> .el-form-item__content {
border-top: 1px solid #ededed;
padding: 10px;
height: 50px;
}
>>> .hot-table {
max-height: 150px;
width: 95%;
}
</style>