index.vue
10.3 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
<template>
<div>
<BasicTable
@selection-change="useSelectionChange"
@register="registerTable"
:loading="loading"
:rowSelection="{ type: 'checkbox' }"
>
<template #toolbar>
<a-button type="primary" @click="handleAdd"> 添加转换 </a-button>
<a-button
:disabled="disabledStatus1"
@click="handleDelete"
:type="disabledStatus1 ? 'default' : 'primary'"
>
<span :style="{ color: disabledStatus1 ? 'grey' : 'white' }">批量删除</span>
</a-button>
<a-button
:disabled="disabledStatus2"
@click="handleMutiuteDisable"
:type="disabledStatus2 ? 'default' : 'primary'"
>
<span :style="{ color: disabledStatus2 ? 'grey' : 'white' }">批量禁用</span>
</a-button>
<a-button
:disabled="disabledStatus3"
@click="handleMutiuteEnable"
:type="disabledStatus3 ? 'default' : 'primary'"
>
<span :style="{ color: disabledStatus3 ? 'grey' : 'white' }">批量启用</span>
</a-button>
</template>
<template #action="{ record }">
<TableAction
:actions="[
{
label: '编辑',
icon: 'clarity:note-edit-line',
onClick: handleEdit.bind(null, record),
ifShow: (_action) => {
return record.status == 0;
},
},
{
label: '删除',
icon: 'ant-design:delete-outlined',
color: 'error',
popConfirm: {
title: '是否确认删除',
confirm: handleSingleDelete.bind(null, record),
},
ifShow: (_action) => {
return record.status == 0;
},
},
{
label: '启用',
icon: 'ant-design:check-circle-outlined',
color: 'success',
popConfirm: {
title: '是否启用?',
confirm: handleEnableOrDisable.bind(null, record),
},
ifShow: (_action) => {
return record.status == 0;
},
},
{
label: '禁用',
icon: 'ant-design:close-circle-outlined',
popConfirm: {
title: '是否禁用?',
confirm: handleDisable.bind(null, record),
},
ifShow: (_action) => {
return record.status == 1;
},
},
]"
/>
</template>
</BasicTable>
<div>
<DataTransferDrawer @register="registerModal" @success="handleSuccess" />
</div>
</div>
</template>
<script lang="ts">
import { defineComponent, reactive, ref } from 'vue';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { columns, searchFormSchema } from './config';
import { useModal } from '/@/components/Modal';
import DataTransferDrawer from './addDataTransferDrawer.vue';
import {
getConvertApi,
isEnableOrDisableApi,
deleteConvertApi,
} from '/@/api/datamanager/dataManagerApi';
import { useMessage } from '/@/hooks/web/useMessage';
export default defineComponent({
name: 'Index',
components: { BasicTable, TableAction, DataTransferDrawer },
setup() {
const enableObj = reactive({
convertIds: [],
status: 0,
});
const disabledStatus1 = ref(true);
const disabledStatus2 = ref(true);
const disabledStatus3 = ref(true);
const loading = ref(true);
const { createMessage } = useMessage();
let selectedRowKeys: any = ref([]);
let getSelectRowsArr: any = ref([]);
let isJudgeSelectRowsArr: any = ref([]);
const [registerModal, { openModal }] = useModal();
const [
registerTable,
{ reload, getSelectRowKeys, getSelectRows, setLoading, clearSelectedRowKeys },
] = useTable({
title: '数据流转列表',
clickToRowSelect: false,
columns,
api: getConvertApi,
formConfig: {
labelWidth: 120,
schemas: searchFormSchema,
},
rowKey: 'id',
useSearchForm: true,
showTableSetting: true,
bordered: true,
showIndexColumn: false,
actionColumn: {
width: 180,
title: '操作',
dataIndex: 'action',
slots: { customRender: 'action' },
fixed: 'right',
},
});
//新增
const handleAdd = () => {
setTimeout(() => {
openModal(true, {
isUpdate: false,
});
}, 10);
};
const handleSuccess = () => {
reload();
};
const handleEdit = (record: Recordable) => {
setTimeout(() => {
openModal(true, {
record,
isUpdate: true,
});
}, 10);
};
const handleEnableOrDisable = async (record: Recordable) => {
setLoading(true);
enableObj.convertIds.length = 0;
try {
enableObj.status = record.status;
enableObj.convertIds.push(record.id as never);
if (enableObj.status == 0) {
enableObj.status = 1;
}
const res = await isEnableOrDisableApi(enableObj as never);
if (res !== '') {
createMessage.success('转换配置启用成功');
setLoading(false);
reload();
} else {
createMessage.error('转换配置启用失败');
}
} catch (e) {
return e;
} finally {
setLoading(false);
}
};
const handleDisable = async (record: Recordable) => {
setLoading(true);
enableObj.convertIds.length = 0;
try {
enableObj.status = record.status;
enableObj.convertIds.push(record.id as never);
if (enableObj.status == 1) {
enableObj.status = 0;
}
const res = await isEnableOrDisableApi(enableObj as never);
if (res !== '') {
createMessage.success('转换配置禁用成功');
setLoading(false);
reload();
} else {
createMessage.error('转换配置禁用失败');
}
} catch (e) {
} finally {
setLoading(false);
}
};
const handleSingleDelete = async (record: Recordable) => {
try {
let ids = [record.id];
await deleteConvertApi(ids);
createMessage.success('删除成功');
reload();
} catch (e) {
return e;
}
};
const useSelectionChange = () => {
selectedRowKeys.value = getSelectRowKeys();
isJudgeSelectRowsArr.value = getSelectRows();
const hasDisableStatus = isJudgeSelectRowsArr.value.map((m) => {
return m.status;
});
if (hasDisableStatus.length == 0) {
disabledStatus1.value = true;
disabledStatus2.value = true;
disabledStatus3.value = true;
}
hasDisableStatus.every((e) => {
if (e == 1) {
disabledStatus3.value = true;
disabledStatus2.value = false;
} else if (e == 0) {
disabledStatus2.value = true;
disabledStatus3.value = false;
}
});
let i1 = hasDisableStatus.indexOf(0);
let i2 = hasDisableStatus.indexOf(1);
if (i1 !== -1 && i2 !== -1) {
disabledStatus2.value = true;
disabledStatus3.value = true;
}
if (isJudgeSelectRowsArr.value.length == 0) {
disabledStatus1.value = true;
} else {
disabledStatus1.value = false;
}
};
const handleDelete = async () => {
try {
setLoading(true);
const data = await deleteConvertApi(selectedRowKeys.value);
if (data == true) {
createMessage.success('删除成功');
setLoading(false);
reload();
} else {
createMessage.error('删除失败');
}
} catch (e) {
return e;
} finally {
setLoading(false);
clearSelectedRowKeys();
}
};
const handleMutiuteDisable = async () => {
enableObj.convertIds.length = 0;
try {
setLoading(true);
getSelectRowsArr.value = getSelectRows();
getSelectRowsArr.value.forEach((f) => {
if (f.id) {
enableObj.status = 0;
enableObj.convertIds.push(f.id as never);
}
});
const res = await isEnableOrDisableApi(enableObj as never);
if (res !== '') {
createMessage.success('转换配置多项禁用成功');
setLoading(false);
reload();
} else {
createMessage.error('转换配置多项禁用失败');
}
} catch (e) {
return e;
} finally {
setLoading(false);
clearSelectedRowKeys();
}
};
const handleMutiuteEnable = async () => {
enableObj.convertIds.length = 0;
try {
setLoading(true);
getSelectRowsArr.value = getSelectRows();
getSelectRowsArr.value.forEach((f) => {
if (f.id) {
enableObj.status = 1;
enableObj.convertIds.push(f.id as never);
}
});
const res = await isEnableOrDisableApi(enableObj as never);
if (res !== '') {
createMessage.success('转换配置多项启用成功');
setLoading(false);
reload();
} else {
createMessage.error('转换配置多项启用失败');
}
} catch (e) {
return e;
} finally {
setLoading(false);
clearSelectedRowKeys();
}
};
return {
disabledStatus1,
disabledStatus2,
disabledStatus3,
handleMutiuteEnable,
loading,
registerTable,
handleAdd,
handleDelete,
registerModal,
handleSuccess,
handleEdit,
handleEnableOrDisable,
handleSingleDelete,
useSelectionChange,
handleMutiuteDisable,
handleDisable,
};
},
});
</script>
<style lang="less" scoped></style>