@tmagic/form 1.6.1 → 1.7.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/style.css +23 -3
- package/dist/tmagic-form.js +1741 -1501
- package/dist/tmagic-form.umd.cjs +1774 -1530
- package/package.json +4 -4
- package/src/Form.vue +70 -9
- package/src/containers/Container.vue +109 -134
- package/src/containers/Fieldset.vue +31 -7
- package/src/containers/FlexLayout.vue +59 -0
- package/src/containers/Tabs.vue +11 -1
- package/src/fields/Cascader.vue +25 -16
- package/src/fields/Checkbox.vue +3 -3
- package/src/fields/CheckboxGroup.vue +1 -1
- package/src/fields/ColorPicker.vue +2 -2
- package/src/fields/Date.vue +2 -2
- package/src/fields/DateTime.vue +2 -2
- package/src/fields/Daterange.vue +2 -2
- package/src/fields/Number.vue +2 -2
- package/src/fields/NumberRange.vue +6 -6
- package/src/fields/RadioGroup.vue +7 -15
- package/src/fields/Select.vue +2 -2
- package/src/fields/Switch.vue +2 -2
- package/src/fields/Text.vue +20 -8
- package/src/fields/Textarea.vue +3 -2
- package/src/fields/Time.vue +2 -2
- package/src/fields/Timerange.vue +2 -2
- package/src/index.ts +5 -2
- package/src/table/ActionsColumn.vue +97 -0
- package/src/table/SortColumn.vue +101 -0
- package/src/table/Table.vue +170 -0
- package/src/table/type.ts +18 -0
- package/src/table/useAdd.ts +111 -0
- package/src/table/useFullscreen.ts +28 -0
- package/src/table/useImport.ts +68 -0
- package/src/table/usePagination.ts +30 -0
- package/src/table/useSelection.ts +34 -0
- package/src/table/useSortable.ts +48 -0
- package/src/table/useTableColumns.ts +194 -0
- package/src/theme/container.scss +17 -0
- package/src/theme/form.scss +15 -3
- package/src/utils/form.ts +56 -2
- package/types/index.d.ts +65 -36
- package/src/containers/Table.vue +0 -681
package/src/containers/Table.vue
DELETED
|
@@ -1,681 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="m-fields-table-wrap">
|
|
3
|
-
<teleport to="body" :disabled="!isFullscreen">
|
|
4
|
-
<div ref="mTable" class="m-fields-table" :class="{ 'm-fields-table-item-extra': config.itemExtra }">
|
|
5
|
-
<span v-if="config.extra" style="color: rgba(0, 0, 0, 0.45)" v-html="config.extra"></span>
|
|
6
|
-
<TMagicTooltip content="拖拽可排序" placement="left-start" :disabled="config.dropSort !== true">
|
|
7
|
-
<TMagicTable
|
|
8
|
-
v-if="model[modelName]"
|
|
9
|
-
ref="tMagicTable"
|
|
10
|
-
style="width: 100%"
|
|
11
|
-
:row-key="config.rowKey || 'id'"
|
|
12
|
-
:data="data"
|
|
13
|
-
:lastData="lastData"
|
|
14
|
-
:border="config.border"
|
|
15
|
-
:max-height="config.maxHeight"
|
|
16
|
-
:default-expand-all="true"
|
|
17
|
-
:key="updateKey"
|
|
18
|
-
@select="selectHandle"
|
|
19
|
-
@sort-change="sortChange"
|
|
20
|
-
>
|
|
21
|
-
<TMagicTableColumn v-if="config.itemExtra && !config.dropSort" :fixed="'left'" width="30" type="expand">
|
|
22
|
-
<template v-slot="scope">
|
|
23
|
-
<span v-html="itemExtra(config.itemExtra, scope.$index)" class="m-form-tip"></span>
|
|
24
|
-
</template>
|
|
25
|
-
</TMagicTableColumn>
|
|
26
|
-
|
|
27
|
-
<TMagicTableColumn
|
|
28
|
-
label="操作"
|
|
29
|
-
:width="config.operateColWidth || 100"
|
|
30
|
-
align="center"
|
|
31
|
-
:fixed="config.fixed === false ? undefined : 'left'"
|
|
32
|
-
>
|
|
33
|
-
<template v-slot="scope">
|
|
34
|
-
<slot name="operateCol" :scope="scope"></slot>
|
|
35
|
-
<TMagicButton
|
|
36
|
-
v-show="showDelete(scope.$index + 1 + pagecontext * pagesize - 1)"
|
|
37
|
-
size="small"
|
|
38
|
-
type="danger"
|
|
39
|
-
link
|
|
40
|
-
title="删除"
|
|
41
|
-
:icon="Delete"
|
|
42
|
-
@click="removeHandler(scope.$index + 1 + pagecontext * pagesize - 1)"
|
|
43
|
-
></TMagicButton>
|
|
44
|
-
|
|
45
|
-
<TMagicButton
|
|
46
|
-
v-if="copyable(scope.$index + 1 + pagecontext * pagesize - 1)"
|
|
47
|
-
link
|
|
48
|
-
size="small"
|
|
49
|
-
type="primary"
|
|
50
|
-
title="复制"
|
|
51
|
-
:icon="DocumentCopy"
|
|
52
|
-
:disabled="disabled"
|
|
53
|
-
@click="copyHandler(scope.$index + 1 + pagecontext * pagesize - 1)"
|
|
54
|
-
></TMagicButton>
|
|
55
|
-
</template>
|
|
56
|
-
</TMagicTableColumn>
|
|
57
|
-
|
|
58
|
-
<TMagicTableColumn v-if="sort && model[modelName] && model[modelName].length > 1" label="排序" width="60">
|
|
59
|
-
<template v-slot="scope">
|
|
60
|
-
<TMagicTooltip
|
|
61
|
-
v-if="scope.$index + 1 + pagecontext * pagesize - 1 !== 0"
|
|
62
|
-
content="点击上移,双击置顶"
|
|
63
|
-
placement="top"
|
|
64
|
-
>
|
|
65
|
-
<TMagicButton
|
|
66
|
-
plain
|
|
67
|
-
size="small"
|
|
68
|
-
type="primary"
|
|
69
|
-
:icon="ArrowUp"
|
|
70
|
-
:disabled="disabled"
|
|
71
|
-
link
|
|
72
|
-
@click="upHandler(scope.$index + 1 + pagecontext * pagesize - 1)"
|
|
73
|
-
@dblclick="topHandler(scope.$index + 1 + pagecontext * pagesize - 1)"
|
|
74
|
-
></TMagicButton>
|
|
75
|
-
</TMagicTooltip>
|
|
76
|
-
<TMagicTooltip
|
|
77
|
-
v-if="scope.$index + 1 + pagecontext * pagesize - 1 !== model[modelName].length - 1"
|
|
78
|
-
content="点击下移,双击置底"
|
|
79
|
-
placement="top"
|
|
80
|
-
>
|
|
81
|
-
<TMagicButton
|
|
82
|
-
plain
|
|
83
|
-
size="small"
|
|
84
|
-
type="primary"
|
|
85
|
-
:icon="ArrowDown"
|
|
86
|
-
:disabled="disabled"
|
|
87
|
-
link
|
|
88
|
-
@click="downHandler(scope.$index + 1 + pagecontext * pagesize - 1)"
|
|
89
|
-
@dblclick="bottomHandler(scope.$index + 1 + pagecontext * pagesize - 1)"
|
|
90
|
-
></TMagicButton>
|
|
91
|
-
</TMagicTooltip>
|
|
92
|
-
</template>
|
|
93
|
-
</TMagicTableColumn>
|
|
94
|
-
|
|
95
|
-
<TMagicTableColumn
|
|
96
|
-
v-if="selection"
|
|
97
|
-
align="center"
|
|
98
|
-
header-align="center"
|
|
99
|
-
type="selection"
|
|
100
|
-
width="45"
|
|
101
|
-
></TMagicTableColumn>
|
|
102
|
-
|
|
103
|
-
<TMagicTableColumn width="60" label="序号" v-if="showIndex && config.showIndex">
|
|
104
|
-
<template v-slot="scope">{{ scope.$index + 1 + pagecontext * pagesize }}</template>
|
|
105
|
-
</TMagicTableColumn>
|
|
106
|
-
|
|
107
|
-
<template v-for="(column, index) in config.items">
|
|
108
|
-
<TMagicTableColumn
|
|
109
|
-
v-if="column.type !== 'hidden' && display(column.display)"
|
|
110
|
-
:prop="column.name"
|
|
111
|
-
:width="column.width"
|
|
112
|
-
:label="column.label"
|
|
113
|
-
:sortable="column.sortable"
|
|
114
|
-
:sort-orders="['ascending', 'descending']"
|
|
115
|
-
:key="column[mForm?.keyProp || '__key'] ?? index"
|
|
116
|
-
:class-name="config.dropSort === true ? 'el-table__column--dropable' : ''"
|
|
117
|
-
>
|
|
118
|
-
<template #default="scope">
|
|
119
|
-
<Container
|
|
120
|
-
v-if="scope.$index > -1"
|
|
121
|
-
labelWidth="0"
|
|
122
|
-
:disabled="disabled"
|
|
123
|
-
:prop="getProp(scope.$index)"
|
|
124
|
-
:rules="column.rules"
|
|
125
|
-
:config="makeConfig(column, scope.row)"
|
|
126
|
-
:model="scope.row"
|
|
127
|
-
:lastValues="lastData[scope.$index]"
|
|
128
|
-
:is-compare="isCompare"
|
|
129
|
-
:size="size"
|
|
130
|
-
@change="changeHandler"
|
|
131
|
-
@addDiffCount="onAddDiffCount()"
|
|
132
|
-
></Container>
|
|
133
|
-
</template>
|
|
134
|
-
</TMagicTableColumn>
|
|
135
|
-
</template>
|
|
136
|
-
</TMagicTable>
|
|
137
|
-
</TMagicTooltip>
|
|
138
|
-
<slot></slot>
|
|
139
|
-
|
|
140
|
-
<div style="display: flex; justify-content: space-between; margin: 10px 0">
|
|
141
|
-
<TMagicButton v-if="addable" size="small" type="primary" :disabled="disabled" plain @click="newHandler()"
|
|
142
|
-
>新增一行</TMagicButton
|
|
143
|
-
>
|
|
144
|
-
|
|
145
|
-
<div style="display: flex">
|
|
146
|
-
<TMagicButton
|
|
147
|
-
:icon="Grid"
|
|
148
|
-
size="small"
|
|
149
|
-
type="primary"
|
|
150
|
-
@click="toggleMode"
|
|
151
|
-
v-if="enableToggleMode && config.enableToggleMode !== false && !isFullscreen"
|
|
152
|
-
>展开配置</TMagicButton
|
|
153
|
-
>
|
|
154
|
-
<TMagicButton
|
|
155
|
-
:icon="FullScreen"
|
|
156
|
-
size="small"
|
|
157
|
-
type="primary"
|
|
158
|
-
@click="toggleFullscreen"
|
|
159
|
-
v-if="config.enableFullscreen !== false"
|
|
160
|
-
>
|
|
161
|
-
{{ isFullscreen ? '退出全屏' : '全屏编辑' }}
|
|
162
|
-
</TMagicButton>
|
|
163
|
-
<TMagicUpload
|
|
164
|
-
v-if="importable"
|
|
165
|
-
style="display: inline-block"
|
|
166
|
-
ref="excelBtn"
|
|
167
|
-
action="/noop"
|
|
168
|
-
:disabled="disabled"
|
|
169
|
-
:on-change="excelHandler"
|
|
170
|
-
:auto-upload="false"
|
|
171
|
-
>
|
|
172
|
-
<TMagicButton size="small" type="success" :disabled="disabled" plain>导入EXCEL</TMagicButton>
|
|
173
|
-
</TMagicUpload>
|
|
174
|
-
<TMagicButton
|
|
175
|
-
v-if="importable"
|
|
176
|
-
size="small"
|
|
177
|
-
type="warning"
|
|
178
|
-
:disabled="disabled"
|
|
179
|
-
plain
|
|
180
|
-
@click="clearHandler()"
|
|
181
|
-
>清空</TMagicButton
|
|
182
|
-
>
|
|
183
|
-
</div>
|
|
184
|
-
</div>
|
|
185
|
-
|
|
186
|
-
<div class="bottom" style="text-align: right" v-if="config.pagination">
|
|
187
|
-
<TMagicPagination
|
|
188
|
-
layout="total, sizes, prev, pager, next, jumper"
|
|
189
|
-
:hide-on-single-page="model[modelName].length < pagesize"
|
|
190
|
-
:current-page="pagecontext + 1"
|
|
191
|
-
:page-sizes="[pagesize, 60, 120, 300]"
|
|
192
|
-
:page-size="pagesize"
|
|
193
|
-
:total="model[modelName].length"
|
|
194
|
-
@size-change="handleSizeChange"
|
|
195
|
-
@current-change="handleCurrentChange"
|
|
196
|
-
>
|
|
197
|
-
</TMagicPagination>
|
|
198
|
-
</div>
|
|
199
|
-
</div>
|
|
200
|
-
</teleport>
|
|
201
|
-
</div>
|
|
202
|
-
</template>
|
|
203
|
-
|
|
204
|
-
<script setup lang="ts">
|
|
205
|
-
import { computed, inject, onMounted, ref, toRefs, watchEffect } from 'vue';
|
|
206
|
-
import { ArrowDown, ArrowUp, Delete, DocumentCopy, FullScreen, Grid } from '@element-plus/icons-vue';
|
|
207
|
-
import { cloneDeep } from 'lodash-es';
|
|
208
|
-
import Sortable, { SortableEvent } from 'sortablejs';
|
|
209
|
-
|
|
210
|
-
import {
|
|
211
|
-
TMagicButton,
|
|
212
|
-
tMagicMessage,
|
|
213
|
-
TMagicPagination,
|
|
214
|
-
TMagicTable,
|
|
215
|
-
TMagicTableColumn,
|
|
216
|
-
TMagicTooltip,
|
|
217
|
-
TMagicUpload,
|
|
218
|
-
useZIndex,
|
|
219
|
-
} from '@tmagic/design';
|
|
220
|
-
import { asyncLoadJs } from '@tmagic/utils';
|
|
221
|
-
|
|
222
|
-
import type { ContainerChangeEventData, FormState, SortProp, TableColumnConfig, TableConfig } from '../schema';
|
|
223
|
-
import { display as displayFunc, initValue } from '../utils/form';
|
|
224
|
-
|
|
225
|
-
import Container from './Container.vue';
|
|
226
|
-
|
|
227
|
-
defineOptions({
|
|
228
|
-
name: 'MFormTable',
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
const props = withDefaults(
|
|
232
|
-
defineProps<{
|
|
233
|
-
model: any;
|
|
234
|
-
lastValues?: any;
|
|
235
|
-
isCompare?: boolean;
|
|
236
|
-
config: TableConfig;
|
|
237
|
-
name: string;
|
|
238
|
-
prop?: string;
|
|
239
|
-
labelWidth?: string;
|
|
240
|
-
sort?: boolean;
|
|
241
|
-
disabled?: boolean;
|
|
242
|
-
sortKey?: string;
|
|
243
|
-
text?: string;
|
|
244
|
-
size?: string;
|
|
245
|
-
enableToggleMode?: boolean;
|
|
246
|
-
showIndex?: boolean;
|
|
247
|
-
}>(),
|
|
248
|
-
{
|
|
249
|
-
prop: '',
|
|
250
|
-
sortKey: '',
|
|
251
|
-
enableToggleMode: true,
|
|
252
|
-
showIndex: true,
|
|
253
|
-
lastValues: () => ({}),
|
|
254
|
-
isCompare: false,
|
|
255
|
-
},
|
|
256
|
-
);
|
|
257
|
-
|
|
258
|
-
const emit = defineEmits(['change', 'select', 'addDiffCount']);
|
|
259
|
-
|
|
260
|
-
let timer: any | null = null;
|
|
261
|
-
const mForm = inject<FormState | undefined>('mForm');
|
|
262
|
-
|
|
263
|
-
const { nextZIndex } = useZIndex();
|
|
264
|
-
|
|
265
|
-
const tMagicTable = ref<InstanceType<typeof TMagicTable>>();
|
|
266
|
-
const excelBtn = ref<InstanceType<typeof TMagicUpload>>();
|
|
267
|
-
const mTable = ref<HTMLDivElement>();
|
|
268
|
-
|
|
269
|
-
const pagesize = ref(10);
|
|
270
|
-
const pagecontext = ref(0);
|
|
271
|
-
const updateKey = ref(1);
|
|
272
|
-
const isFullscreen = ref(false);
|
|
273
|
-
|
|
274
|
-
const modelName = computed(() => props.name || props.config.name || '');
|
|
275
|
-
|
|
276
|
-
const getDataByPage = (data: any[] = []) =>
|
|
277
|
-
data.filter(
|
|
278
|
-
(item: any, index: number) =>
|
|
279
|
-
index >= pagecontext.value * pagesize.value && index + 1 <= (pagecontext.value + 1) * pagesize.value,
|
|
280
|
-
);
|
|
281
|
-
|
|
282
|
-
const pageinationData = computed(() => getDataByPage(props.model[modelName.value]));
|
|
283
|
-
|
|
284
|
-
const data = computed(() => (props.config.pagination ? pageinationData.value : props.model[modelName.value]));
|
|
285
|
-
|
|
286
|
-
const lastData = computed(() =>
|
|
287
|
-
props.config.pagination ? getDataByPage(props.lastValues[modelName.value]) : props.lastValues[modelName.value] || [],
|
|
288
|
-
);
|
|
289
|
-
|
|
290
|
-
const sortChange = ({ prop, order }: SortProp) => {
|
|
291
|
-
if (order === 'ascending') {
|
|
292
|
-
props.model[modelName.value] = props.model[modelName.value].sort((a: any, b: any) => a[prop] - b[prop]);
|
|
293
|
-
} else if (order === 'descending') {
|
|
294
|
-
props.model[modelName.value] = props.model[modelName.value].sort((a: any, b: any) => b[prop] - a[prop]);
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
const swapArray = (index1: number, index2: number) => {
|
|
299
|
-
props.model[modelName.value].splice(index1, 0, props.model[modelName.value].splice(index2, 1)[0]);
|
|
300
|
-
|
|
301
|
-
if (props.sortKey) {
|
|
302
|
-
for (let i = props.model[modelName.value].length - 1, v = 0; i >= 0; i--, v++) {
|
|
303
|
-
props.model[modelName.value][v][props.sortKey] = i;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
mForm?.$emit('field-change', props.prop, props.model[modelName.value]);
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
let sortable: Sortable | undefined;
|
|
310
|
-
const rowDrop = () => {
|
|
311
|
-
sortable?.destroy();
|
|
312
|
-
const tableEl = tMagicTable.value?.instance.$el;
|
|
313
|
-
const tBodyEl = tableEl?.querySelector('.el-table__body > tbody');
|
|
314
|
-
if (!tBodyEl) {
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
sortable = Sortable.create(tBodyEl, {
|
|
318
|
-
draggable: '.tmagic-design-table-row',
|
|
319
|
-
filter: 'input', // 表单组件选字操作和触发拖拽会冲突,优先保证选字操作
|
|
320
|
-
preventOnFilter: false, // 允许选字
|
|
321
|
-
direction: 'vertical',
|
|
322
|
-
onEnd: ({ newIndex, oldIndex }: SortableEvent) => {
|
|
323
|
-
if (typeof newIndex === 'undefined') return;
|
|
324
|
-
if (typeof oldIndex === 'undefined') return;
|
|
325
|
-
swapArray(newIndex, oldIndex);
|
|
326
|
-
emit('change', props.model[modelName.value]);
|
|
327
|
-
mForm?.$emit('field-change', props.prop, props.model[modelName.value]);
|
|
328
|
-
},
|
|
329
|
-
});
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
const newHandler = async (row?: any) => {
|
|
333
|
-
if (props.config.max && props.model[modelName.value].length >= props.config.max) {
|
|
334
|
-
tMagicMessage.error(`最多新增配置不能超过${props.config.max}条`);
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
if (typeof props.config.beforeAddRow === 'function') {
|
|
339
|
-
const beforeCheckRes = props.config.beforeAddRow(mForm, {
|
|
340
|
-
model: props.model[modelName.value],
|
|
341
|
-
formValue: mForm?.values,
|
|
342
|
-
prop: props.prop,
|
|
343
|
-
});
|
|
344
|
-
if (!beforeCheckRes) return;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
const columns = props.config.items;
|
|
348
|
-
const enumValues = props.config.enum || [];
|
|
349
|
-
let enumV = [];
|
|
350
|
-
const { length } = props.model[modelName.value];
|
|
351
|
-
const key = props.config.key || 'id';
|
|
352
|
-
let inputs: any = {};
|
|
353
|
-
|
|
354
|
-
if (enumValues.length) {
|
|
355
|
-
if (length >= enumValues.length) {
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
enumV = enumValues.filter((item) => {
|
|
359
|
-
let i = 0;
|
|
360
|
-
for (; i < length; i++) {
|
|
361
|
-
if (item[key] === props.model[modelName.value][i][key]) {
|
|
362
|
-
break;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
return i === length;
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
if (enumV.length > 0) {
|
|
369
|
-
// eslint-disable-next-line prefer-destructuring
|
|
370
|
-
inputs = enumV[0];
|
|
371
|
-
}
|
|
372
|
-
} else if (Array.isArray(row)) {
|
|
373
|
-
columns.forEach((column, index) => {
|
|
374
|
-
column.name && (inputs[column.name] = row[index]);
|
|
375
|
-
});
|
|
376
|
-
} else {
|
|
377
|
-
if (typeof props.config.defaultAdd === 'function') {
|
|
378
|
-
inputs = await props.config.defaultAdd(mForm, {
|
|
379
|
-
model: props.model[modelName.value],
|
|
380
|
-
formValue: mForm?.values,
|
|
381
|
-
});
|
|
382
|
-
} else if (props.config.defaultAdd) {
|
|
383
|
-
inputs = props.config.defaultAdd;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
inputs = await initValue(mForm, {
|
|
387
|
-
config: columns,
|
|
388
|
-
initValues: inputs,
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
if (props.sortKey && length) {
|
|
393
|
-
inputs[props.sortKey] = props.model[modelName.value][length - 1][props.sortKey] - 1;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
props.model[modelName.value].push(inputs);
|
|
397
|
-
|
|
398
|
-
emit('change', props.model[modelName.value], {
|
|
399
|
-
changeRecords: [
|
|
400
|
-
{
|
|
401
|
-
propPath: `${props.prop}.${props.model[modelName.value].length - 1}`,
|
|
402
|
-
value: inputs,
|
|
403
|
-
},
|
|
404
|
-
],
|
|
405
|
-
});
|
|
406
|
-
};
|
|
407
|
-
|
|
408
|
-
onMounted(() => {
|
|
409
|
-
if (props.config.defautSort) {
|
|
410
|
-
sortChange(props.config.defautSort);
|
|
411
|
-
} else if (props.config.defaultSort) {
|
|
412
|
-
sortChange(props.config.defaultSort);
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
if (props.sort && props.sortKey) {
|
|
416
|
-
props.model[modelName.value].sort((a: any, b: any) => b[props.sortKey] - a[props.sortKey]);
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
watchEffect(() => {
|
|
421
|
-
if (props.config.dropSort) {
|
|
422
|
-
rowDrop();
|
|
423
|
-
}
|
|
424
|
-
});
|
|
425
|
-
|
|
426
|
-
const addable = computed(() => {
|
|
427
|
-
if (!props.model[modelName.value].length) {
|
|
428
|
-
return true;
|
|
429
|
-
}
|
|
430
|
-
if (typeof props.config.addable === 'function') {
|
|
431
|
-
return props.config.addable(mForm, {
|
|
432
|
-
model: props.model[modelName.value],
|
|
433
|
-
formValue: mForm?.values,
|
|
434
|
-
prop: props.prop,
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
return typeof props.config.addable === 'undefined' ? true : props.config.addable;
|
|
438
|
-
});
|
|
439
|
-
|
|
440
|
-
const selection = computed(() => {
|
|
441
|
-
if (typeof props.config.selection === 'function') {
|
|
442
|
-
return props.config.selection(mForm, { model: props.model[modelName.value] });
|
|
443
|
-
}
|
|
444
|
-
return props.config.selection;
|
|
445
|
-
});
|
|
446
|
-
|
|
447
|
-
const importable = computed(() => {
|
|
448
|
-
if (typeof props.config.importable === 'function') {
|
|
449
|
-
return props.config.importable(mForm, {
|
|
450
|
-
formValue: mForm?.values,
|
|
451
|
-
model: props.model[modelName.value],
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
return typeof props.config.importable === 'undefined' ? false : props.config.importable;
|
|
455
|
-
});
|
|
456
|
-
|
|
457
|
-
const display = (fuc: any) => displayFunc(mForm, fuc, props);
|
|
458
|
-
|
|
459
|
-
const itemExtra = (fuc: any, index: number) => {
|
|
460
|
-
if (typeof fuc === 'function') {
|
|
461
|
-
return fuc(mForm, {
|
|
462
|
-
values: mForm?.initValues,
|
|
463
|
-
model: props.model,
|
|
464
|
-
formValue: mForm ? mForm.values : props.model,
|
|
465
|
-
prop: props.prop,
|
|
466
|
-
index,
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
return fuc;
|
|
471
|
-
};
|
|
472
|
-
|
|
473
|
-
const removeHandler = (index: number) => {
|
|
474
|
-
if (props.disabled) return;
|
|
475
|
-
props.model[modelName.value].splice(index, 1);
|
|
476
|
-
emit('change', props.model[modelName.value]);
|
|
477
|
-
};
|
|
478
|
-
|
|
479
|
-
const selectHandle = (selection: any, row: any) => {
|
|
480
|
-
if (typeof props.config.selection === 'string' && props.config.selection === 'single') {
|
|
481
|
-
tMagicTable.value?.clearSelection();
|
|
482
|
-
tMagicTable.value?.toggleRowSelection(row, true);
|
|
483
|
-
}
|
|
484
|
-
emit('select', selection, row);
|
|
485
|
-
if (typeof props.config.onSelect === 'function') {
|
|
486
|
-
props.config.onSelect(mForm, { selection, row, config: props.config });
|
|
487
|
-
}
|
|
488
|
-
};
|
|
489
|
-
|
|
490
|
-
const toggleRowSelection = (row: any, selected: boolean) => {
|
|
491
|
-
tMagicTable.value?.toggleRowSelection.call(tMagicTable.value, row, selected);
|
|
492
|
-
};
|
|
493
|
-
|
|
494
|
-
const makeConfig = (config: TableColumnConfig, row: any) => {
|
|
495
|
-
const newConfig = cloneDeep(config);
|
|
496
|
-
if (typeof config.itemsFunction === 'function') {
|
|
497
|
-
newConfig.items = config.itemsFunction(row);
|
|
498
|
-
}
|
|
499
|
-
delete newConfig.display;
|
|
500
|
-
return newConfig;
|
|
501
|
-
};
|
|
502
|
-
|
|
503
|
-
const upHandler = (index: number) => {
|
|
504
|
-
if (timer) {
|
|
505
|
-
clearTimeout(timer);
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
timer = setTimeout(() => {
|
|
509
|
-
swapArray(index, index - 1);
|
|
510
|
-
timer = undefined;
|
|
511
|
-
}, 300);
|
|
512
|
-
};
|
|
513
|
-
|
|
514
|
-
const topHandler = (index: number) => {
|
|
515
|
-
if (timer) {
|
|
516
|
-
clearTimeout(timer);
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
// 首先判断当前元素需要上移几个位置,置底移动到数组的第一位
|
|
520
|
-
const moveNum = index;
|
|
521
|
-
|
|
522
|
-
// 循环出需要一个一个上移的次数
|
|
523
|
-
for (let i = 0; i < moveNum; i++) {
|
|
524
|
-
swapArray(index, index - 1);
|
|
525
|
-
index -= 1;
|
|
526
|
-
}
|
|
527
|
-
};
|
|
528
|
-
|
|
529
|
-
const downHandler = (index: number) => {
|
|
530
|
-
if (timer) {
|
|
531
|
-
clearTimeout(timer);
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
timer = setTimeout(() => {
|
|
535
|
-
swapArray(index, index + 1);
|
|
536
|
-
timer = undefined;
|
|
537
|
-
}, 300);
|
|
538
|
-
};
|
|
539
|
-
|
|
540
|
-
const bottomHandler = (index: number) => {
|
|
541
|
-
if (timer) {
|
|
542
|
-
clearTimeout(timer);
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
// 首先判断当前元素需要上移几个位置,置底移动到数组的第一位
|
|
546
|
-
const moveNum = props.model[modelName.value].length - 1 - index;
|
|
547
|
-
|
|
548
|
-
// 循环出需要一个一个上移的次数
|
|
549
|
-
for (let i = 0; i < moveNum; i++) {
|
|
550
|
-
swapArray(index, index + 1);
|
|
551
|
-
index += 1;
|
|
552
|
-
}
|
|
553
|
-
};
|
|
554
|
-
|
|
555
|
-
// 希望支持单行可控制是否显示删除按钮,不会影响现有逻辑
|
|
556
|
-
const showDelete = (index: number) => {
|
|
557
|
-
const deleteFunc = props.config.delete;
|
|
558
|
-
if (deleteFunc && typeof deleteFunc === 'function') {
|
|
559
|
-
return deleteFunc(props.model[modelName.value], index, mForm?.values);
|
|
560
|
-
}
|
|
561
|
-
return true;
|
|
562
|
-
};
|
|
563
|
-
|
|
564
|
-
const copyable = (index: number) => {
|
|
565
|
-
const copyableFunc = props.config.copyable;
|
|
566
|
-
if (copyableFunc && typeof copyableFunc === 'function') {
|
|
567
|
-
return copyableFunc(mForm, {
|
|
568
|
-
values: mForm?.initValues || {},
|
|
569
|
-
model: props.model,
|
|
570
|
-
parent: mForm?.parentValues || {},
|
|
571
|
-
formValue: mForm?.values || props.model,
|
|
572
|
-
prop: props.prop,
|
|
573
|
-
config: props.config,
|
|
574
|
-
index,
|
|
575
|
-
});
|
|
576
|
-
}
|
|
577
|
-
return true;
|
|
578
|
-
};
|
|
579
|
-
|
|
580
|
-
const clearHandler = () => {
|
|
581
|
-
const len = props.model[modelName.value].length;
|
|
582
|
-
props.model[modelName.value].splice(0, len);
|
|
583
|
-
mForm?.$emit('field-change', props.prop, props.model[modelName.value]);
|
|
584
|
-
};
|
|
585
|
-
|
|
586
|
-
const excelHandler = async (file: any) => {
|
|
587
|
-
if (!file?.raw) {
|
|
588
|
-
return false;
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
if (!(globalThis as any).XLSX) {
|
|
592
|
-
await asyncLoadJs('https://cdn.bootcdn.net/ajax/libs/xlsx/0.17.0/xlsx.full.min.js');
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
const reader = new FileReader();
|
|
596
|
-
reader.onload = () => {
|
|
597
|
-
const data = reader.result;
|
|
598
|
-
const pdata = (globalThis as any).XLSX.read(data, { type: 'array' });
|
|
599
|
-
pdata.SheetNames.forEach((sheetName: string) => {
|
|
600
|
-
const arr = (globalThis as any).XLSX.utils.sheet_to_json(pdata.Sheets[sheetName], { header: 1 });
|
|
601
|
-
if (arr?.[0]) {
|
|
602
|
-
arr.forEach((row: any) => {
|
|
603
|
-
newHandler(row);
|
|
604
|
-
});
|
|
605
|
-
}
|
|
606
|
-
setTimeout(() => {
|
|
607
|
-
excelBtn.value?.clearFiles();
|
|
608
|
-
}, 300);
|
|
609
|
-
});
|
|
610
|
-
};
|
|
611
|
-
reader.readAsArrayBuffer(file.raw);
|
|
612
|
-
|
|
613
|
-
return false;
|
|
614
|
-
};
|
|
615
|
-
|
|
616
|
-
const handleSizeChange = (val: number) => {
|
|
617
|
-
pagesize.value = val;
|
|
618
|
-
};
|
|
619
|
-
|
|
620
|
-
const handleCurrentChange = (val: number) => {
|
|
621
|
-
pagecontext.value = val - 1;
|
|
622
|
-
};
|
|
623
|
-
|
|
624
|
-
const copyHandler = (index: number) => {
|
|
625
|
-
props.model[modelName.value].push(cloneDeep(props.model[modelName.value][index]));
|
|
626
|
-
};
|
|
627
|
-
|
|
628
|
-
const toggleMode = () => {
|
|
629
|
-
const calcLabelWidth = (label: string) => {
|
|
630
|
-
if (!label) return '0px';
|
|
631
|
-
const zhLength = label.match(/[^\x00-\xff]/g)?.length || 0;
|
|
632
|
-
const chLength = label.length - zhLength;
|
|
633
|
-
return `${Math.max(chLength * 8 + zhLength * 20, 80)}px`;
|
|
634
|
-
};
|
|
635
|
-
|
|
636
|
-
// 切换为groupList的形式
|
|
637
|
-
props.config.type = 'groupList';
|
|
638
|
-
props.config.enableToggleMode = true;
|
|
639
|
-
props.config.tableItems = props.config.items;
|
|
640
|
-
props.config.items =
|
|
641
|
-
props.config.groupItems ||
|
|
642
|
-
props.config.items.map((item: any) => {
|
|
643
|
-
const text = item.text || item.label;
|
|
644
|
-
const labelWidth = calcLabelWidth(text);
|
|
645
|
-
return {
|
|
646
|
-
...item,
|
|
647
|
-
text,
|
|
648
|
-
labelWidth,
|
|
649
|
-
span: item.span || 12,
|
|
650
|
-
};
|
|
651
|
-
});
|
|
652
|
-
};
|
|
653
|
-
|
|
654
|
-
const toggleFullscreen = () => {
|
|
655
|
-
if (!mTable.value) return;
|
|
656
|
-
|
|
657
|
-
if (isFullscreen.value) {
|
|
658
|
-
mTable.value.classList.remove('fixed');
|
|
659
|
-
isFullscreen.value = false;
|
|
660
|
-
} else {
|
|
661
|
-
mTable.value.classList.add('fixed');
|
|
662
|
-
mTable.value.style.zIndex = `${nextZIndex()}`;
|
|
663
|
-
isFullscreen.value = true;
|
|
664
|
-
}
|
|
665
|
-
};
|
|
666
|
-
|
|
667
|
-
const getProp = (index: number) => {
|
|
668
|
-
const { prop } = toRefs(props);
|
|
669
|
-
return `${prop.value}${prop.value ? '.' : ''}${index + 1 + pagecontext.value * pagesize.value - 1}`;
|
|
670
|
-
};
|
|
671
|
-
|
|
672
|
-
const onAddDiffCount = () => emit('addDiffCount');
|
|
673
|
-
|
|
674
|
-
const changeHandler = (v: any, eventData: ContainerChangeEventData) => {
|
|
675
|
-
emit('change', props.model, eventData);
|
|
676
|
-
};
|
|
677
|
-
|
|
678
|
-
defineExpose({
|
|
679
|
-
toggleRowSelection,
|
|
680
|
-
});
|
|
681
|
-
</script>
|