index.vue
13.6 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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
<script lang="ts" setup name="Drawer">
import { computed } from "vue";
import { ClickOutside as vClickOutside } from "element-plus";
import type { FormInstance } from "element-plus";
import { Download, Upload } from "@element-plus/icons-vue";
import Table from "../Table/index.vue";
import Form from "../Form/index.vue";
import Tree from "../Tree/index.vue";
import ListPanel from "../ListPanel/index.vue";
import UploadFiles from "../Upload/index.vue";
const emits = defineEmits([
"drawerBtnClick",
"radioGroupChange",
"drawerSelectChange",
"drawerTableSelectChange",
"drawerTableBtnClick",
"drawerTableToolBtnClick",
"drawerFormBtnClick",
"listItemClick",
"drawerTableInputChange",
"drawerToolBtnClick",
"drawerTableSelectionChange",
"drawerTablePageChange",
"uploadBtnClick",
"beforeUPload",
"uploadFile",
"onUpload",
"onClickOutside",
]);
const props = defineProps({
drawerInfo: {
type: Object,
default: {},
},
});
const drawerTableRef = ref();
const drawerFormRef = ref();
const selectRowData = ref([]);
const formListRef = ref();
const formTreeRef = ref();
const uploadRef = ref();
const drawerVisible = computed(() => {
nextTick(() => {
if (props.drawerInfo.visible) {
drawerOpen();
}
})
return props.drawerInfo.visible;
});
const drawerDirection = computed(() => {
return props.drawerInfo.direction;
});
const drawerModal = computed(() => {
return props.drawerInfo.modal ?? true;
});
const modalClose = computed(() => {
return props.drawerInfo.modalClose ?? false;
});
const drawerModalClass = computed(() => {
nextTick(() => {
drawerOpen();
})
return props.drawerInfo.modalClass ?? "";
});
const drawerSize = computed(() => {
return props.drawerInfo.size ?? "30%";
});
const drawerType = computed(() => {
return props.drawerInfo.type ?? "form";
});
const drawerTitle = computed(() => {
return props.drawerInfo.header.title;
});
const selectOptions = computed(() => {
return props.drawerInfo.container.relateOptions ?? [];
});
const formItems = computed(() => {
return props.drawerInfo.container.formItems ?? [];
});
const formRules = computed(() => {
return props.drawerInfo.container.rules ?? {};
});
const selectData = computed(() => {
return props.drawerInfo.container.selectData ?? [];
});
const contents = computed(() => {
return props.drawerInfo.container.contents ?? [];
});
const footer = computed(() => {
return props.drawerInfo.footer;
});
const onClickOutside = (e: any) => {
emits("onClickOutside");
};
const getDrawerConRef = (refName) => {
if(refName == 'drawerTableRef'){
const dtf = drawerTableRef.value[0] || drawerTableRef.value
return dtf?.tableRef
}
}
defineExpose({
// selections,
getDrawerConRef
});
const toolBtnClick = (btn, type: any = null) => {
if (type && type == "table") {
let selectData = [];
if (drawerTableRef.value) {
const drawerTable = drawerTableRef.value[0] || drawerTableRef.value;
selectData = drawerTable.tableRef.getSelectionRows();
}
emits("drawerTableToolBtnClick", btn, selectData);
} else {
emits("drawerToolBtnClick", btn);
}
};
const tableSelectionChange = (val, tId) => {
selectRowData.value = val;
emits("drawerTableSelectionChange", val, tId);
};
const tableSelectChange = (val, scope) => {
emits("drawerTableSelectChange", val, scope);
};
const tableInputChange = (val, scope) => {
emits("drawerTableInputChange", val, scope);
};
const tablePageChange = (info) => {
emits("drawerTablePageChange", info);
}
const tableBtnClick = (scope, btn) => {
emits("drawerTableBtnClick", scope, btn);
};
const submitForm = async (formEl: FormInstance | undefined, btn) => {
if (!formEl) return;
await formEl.validate((valid, fields) => {
if (valid) {
const drawerForm = drawerFormRef.value[0] || drawerFormRef.value;
const formInfo = drawerForm.formInline;
emits("drawerBtnClick", btn, formInfo);
} else {
console.log("error submit!", fields);
}
});
};
const btnClick = (btn, type) => {
if (btn.disabled) return;
if (
btn.value != "cancel" &&
(btn.value.indexOf("submit") > -1 || btn.value.indexOf("save") > -1)
) {
if (drawerFormRef.value) {
const drawerForm = drawerFormRef.value[0] || drawerFormRef.value;
const formRef = drawerForm.ruleFormRef;
submitForm(formRef, btn);
} else {
emits("drawerBtnClick", btn);
}
} else {
emits("drawerBtnClick", btn);
}
};
const radioGroupChange = (val, info) => {
emits("radioGroupChange", val, info);
};
const formSelectChange = (val, row, info) => {
emits("drawerSelectChange", val, row, info);
};
const formBtnClick = (btn) => {
emits("drawerFormBtnClick", btn);
};
const listItemClick = (row) => {
emits("listItemClick", row);
};
const onUpload = (file, fileList) => {
emits("onUpload", file, fileList);
};
const beforeUPload = (file) => {
emits("beforeUPload", file);
};
const uploadFile = (file) => {
emits("uploadFile", file);
};
const uploadBtnClick = (btn) => {
emits("uploadBtnClick", btn);
};
const drawerOpen = () => {
const wrap: any = drawerModalClass.value && document.getElementsByClassName(drawerModalClass.value)[0];
if (wrap) {
wrap.style.width = `${drawerSize.value + 1}px`
} else {
const dom: any = document.getElementsByClassName('el-overlay')[0];
dom && (dom.style.width = '100%');
}
};
const drawerClose = () => {
btnClick({ value: "cancel" }, null);
if (drawerFormRef.value) {
const drawerForm = drawerFormRef.value[0] || drawerFormRef.value;
const formRef = drawerForm.ruleFormRef;
drawerForm?.resetForm(formRef);
}
};
</script>
<template>
<el-drawer
v-model="drawerVisible"
:direction="drawerDirection"
:size="drawerSize"
:modal="drawerModal"
:close-on-click-modal="modalClose"
:close-on-press-escape="modalClose"
:modal-class="drawerModalClass"
destroy-on-close
:z-index="props.drawerInfo.zIndex ?? null"
@close="drawerClose"
>
<template #header>
<span class="title">{{ drawerTitle }}</span>
</template>
<template #default>
<div class="drawer-body-loading" v-if="drawerInfo.loading ?? false" v-loading="drawerInfo.loading ?? false"></div>
<div
v-else
class="drawer_panel"
:class="[con.col]"
:style="con.style"
v-for="con in contents"
>
<div class="panel_title" v-if="con.title">{{ con.title }}</div>
<template v-if="con.type && con.type.indexOf('table') > -1">
<div
class="table_tool"
:class="[con.tableTool.col]"
v-if="con.tableTool && (con.tableTool.visible ?? true)"
>
<template v-for="bar in con.tableTool.btns">
<el-popover
v-if="bar.popover"
:visible="bar.popover.visible"
:title="bar.popover.title"
:popper-class="bar.popover.class ?? ''"
placement="bottom-start"
:width="bar.popover.width ?? 200"
trigger="click"
>
<template #reference>
<el-button
:type="bar.type"
@click="toolBtnClick(bar, con.type)"
v-click-outside="onClickOutside"
v-preReClick
>{{ bar.label }}</el-button
>
</template>
<template #default>
<span v-html="bar.popover.content"></span>
</template>
</el-popover>
<el-button
:type="bar.type"
:plain="bar.plain"
v-else
@click="toolBtnClick(bar, 'table')"
v-preReClick
>{{ bar.label }}</el-button
>
</template>
</div>
<div class="table_panel_wrap" :style="con.tableInfo.style">
<Table
ref="drawerTableRef"
:class="[con.tableInfo.col]"
:tableInfo="con.tableInfo"
@tableSelectChange="tableSelectChange"
@tableBtnClick="tableBtnClick"
@tableSelectionChange="tableSelectionChange"
@tableInputChange="tableInputChange"
@tablePageChange="tablePageChange"
/>
</div>
</template>
<template v-else-if="con.type && con.type.indexOf('tree') > -1">
<div class="list_tree" v-if="con.type.indexOf('list') > -1">
<ListPanel
ref="formListRef"
:listInfo="con.listInfo"
@itemClick="listItemClick"
/>
<Tree ref="formTreeRef" :treeInfo="con.treeInfo" />
</div>
<Tree ref="formTreeRef" :treeInfo="con.treeInfo" v-else />
</template>
<template v-else-if="con.type && con.type == 'field-list'">
<div class="field_list_panel" v-if="con.listInfo.data.length > 0">
<div class="list_item" v-for="item in con.listInfo.data">
<span class="item_field">{{ item[con.listInfo.field] }}</span>
<span class="item_text">{{ item[con.listInfo.label] }}</span>
</div>
</div>
<div class="field_list_panel">
<div class="empty_tips">暂无数据</div>
</div>
</template>
<template v-else-if="con.type && con.type.indexOf('upload') > -1">
<div class="upload_tool">
<UploadFiles
ref="uploadRef"
:upload-info="con.uploadInfo"
@onUpload="onUpload"
@beforeUPload="beforeUPload"
@uploadFile="uploadFile"
@uploadBtnClick="uploadBtnClick"
/>
<div class="tool_btns" v-if="con.tools && con.tools.visible">
<template v-for="btn in con.tools.btns">
<el-button
v-if="btn.visible ?? true"
:type="btn.type"
:plain="btn.plain"
@click="toolBtnClick(btn, 'table')"
v-preReClick
>
<el-icon v-if="btn.icon && btn.icon == 'Upload'">
<Upload />
</el-icon>
<el-icon v-else-if="btn.icon && btn.icon == 'Download'">
<Download />
</el-icon>
<span>{{ btn.label }}</span>
</el-button>
</template>
</div>
</div>
<div
class="upload_table_panel_wrap"
v-if="con.tableInfo && Object.keys(con.tableInfo).length"
>
<Table
ref="drawerTableRef"
:class="[con.tableInfo.col]"
:tableInfo="con.tableInfo"
@tableSelectChange="tableSelectChange"
@tableBtnClick="tableBtnClick"
@tableSelectionChange="tableSelectionChange"
@tableInputChange="tableInputChange"
@tablePageChange="tablePageChange"
/>
</div>
</template>
<template v-else>
<Form
ref="drawerFormRef"
:itemList="con.formInfo.items"
:formId="con.formInfo.id"
:rules="con.formInfo.rules"
:col="con.formInfo.col"
:readonly="con.formInfo.readonly"
@radioGroupChange="radioGroupChange"
@selectChange="formSelectChange"
@btnClick="formBtnClick"
/>
</template>
</div>
</template>
<template #footer v-if="footer.visible ?? true">
<div style="flex: auto">
<template v-for="btn in footer.btns">
<el-button
v-if="btn.visible ?? true"
:type="btn.type"
:disabled="btn.disabled ?? false"
@click="btnClick(btn, null)"
v-preReClick
:loading="btn.loading ?? false"
>{{ btn.label }}</el-button
>
</template>
</div>
</template>
</el-drawer>
</template>
<style lang="scss" scoped>
.drawer-body-loading {
height: 100%;
}
.drawer_panel {
position: relative;
&.no-margin {
margin-top: 0;
}
&.height_auto {
.table_panel_wrap {
.table_panel {
min-height: unset;
}
}
}
}
.panel_title {
line-height: 40px;
font-size: 14px;
color: var(--el-color-regular);
font-weight: 600;
}
.table_tool {
height: 40px;
display: flex;
align-items: center;
&.float-right {
position: absolute;
top: 0;
right: 0;
}
}
.table_panel_wrap {
.table_panel {
padding: 0;
&.auto-height {
min-height: unset;
}
}
}
.list_tree {
max-height: 400px;
display: flex;
justify-content: space-between;
box-shadow: 0 0 0 1px #d9d9d9;
.list_panel_wrap {
width: 158px;
box-shadow: 1px 0 0 0 #d9d9d9;
}
.tree_panel {
width: calc(100% - 159px);
:deep(.el-tree) {
margin: 0;
height: 100%;
overflow: hidden auto;
}
}
}
.field_list_panel {
width: 100%;
height: calc(100vh - 70px);
position: relative;
.list_item {
display: flex;
font-size: 12px;
color: var(--el-color-regular);
margin: 4px 0;
.item_field {
width: 130px;
color: var(--el-text-color-regular);
}
.item_text {
width: calc(100% - 130px);
word-wrap: break-word;
}
}
.empty_tips {
text-align: center;
color: var(--el-disabled-text-color);
position: absolute;
top: 50px;
left: 50%;
transform: translate(-50%);
}
}
.upload_tool {
margin-bottom: 8px;
position: relative;
.tool_btns {
position: absolute;
top: 0;
right: 0;
}
}
.upload_table_panel_wrap {
.table_panel {
min-height: unset;
}
}
</style>