...
|
...
|
@@ -9,8 +9,6 @@ |
9
|
9
|
<BasicTable
|
10
|
10
|
@register="registerTable"
|
11
|
11
|
:searchInfo="searchInfo"
|
12
|
|
- @selection-change="useSelectionChange"
|
13
|
|
- :rowSelection="{ type: 'checkbox' }"
|
14
|
12
|
class="w-3/4 xl:w-4/5"
|
15
|
13
|
:clickToRowSelect="false"
|
16
|
14
|
>
|
...
|
...
|
@@ -35,6 +33,15 @@ |
35
|
33
|
查看联系方式
|
36
|
34
|
</a-button>
|
37
|
35
|
</template>
|
|
36
|
+ <template #status="{ record }">
|
|
37
|
+ <Switch
|
|
38
|
+ :checked="record.status === 1"
|
|
39
|
+ :loading="record.pendingStatus"
|
|
40
|
+ checkedChildren="启用"
|
|
41
|
+ unCheckedChildren="禁用"
|
|
42
|
+ @change="(checked:boolean)=>statusChange(checked,record)"
|
|
43
|
+ />
|
|
44
|
+ </template>
|
38
|
45
|
<template #action="{ record }">
|
39
|
46
|
<TableAction
|
40
|
47
|
:actions="[
|
...
|
...
|
@@ -68,10 +75,9 @@ |
68
|
75
|
</template>
|
69
|
76
|
|
70
|
77
|
<script lang="ts">
|
71
|
|
- import { defineComponent, reactive, ref, h } from 'vue';
|
|
78
|
+ import { defineComponent, reactive, h } from 'vue';
|
72
|
79
|
import { BasicTable, useTable, TableAction } from '/@/components/Table';
|
73
|
80
|
import { PageWrapper } from '/@/components/Page';
|
74
|
|
- import { useMessage } from '/@/hooks/web/useMessage';
|
75
|
81
|
import { useDrawer } from '/@/components/Drawer';
|
76
|
82
|
import ContactDrawer from './ContactDrawer.vue';
|
77
|
83
|
import { useResetOrganizationTree, OrganizationIdTree } from '/@/views/common/organizationIdTree';
|
...
|
...
|
@@ -81,6 +87,10 @@ |
81
|
87
|
import { JsonPreview } from '/@/components/CodeEditor';
|
82
|
88
|
import { findDictItemByCode } from '/@/api/system/dict';
|
83
|
89
|
import { alarmContactGetPage } from '/@/api/device/deviceConfigApi';
|
|
90
|
+ import { useBatchDelete } from '/@/hooks/web/useBatchDelete';
|
|
91
|
+ import { Switch } from 'ant-design-vue';
|
|
92
|
+ import { putAlarmConfigStatus } from '/@/api/alarm/config/alarmConfig';
|
|
93
|
+ import { useMessage } from '/@/hooks/web/useMessage';
|
84
|
94
|
|
85
|
95
|
export default defineComponent({
|
86
|
96
|
components: {
|
...
|
...
|
@@ -89,18 +99,30 @@ |
89
|
99
|
BasicTable,
|
90
|
100
|
TableAction,
|
91
|
101
|
ContactDrawer,
|
|
102
|
+ Switch,
|
92
|
103
|
},
|
93
|
104
|
setup() {
|
94
|
|
- let selectArray: any = [];
|
95
|
|
- const hasBatchDelete = ref(true);
|
96
|
105
|
const searchInfo = reactive<Recordable>({});
|
97
|
106
|
const { organizationIdTreeRef, resetFn } = useResetOrganizationTree(searchInfo);
|
|
107
|
+ // 刷新
|
|
108
|
+ const handleSuccess = () => {
|
|
109
|
+ reload();
|
|
110
|
+ };
|
|
111
|
+ const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions, resetSelectedRowKeys } =
|
|
112
|
+ useBatchDelete(deleteAlarmConfig, handleSuccess);
|
|
113
|
+ selectionOptions.rowSelection.getCheckboxProps = (record: Recordable) => {
|
|
114
|
+ // Demo:status为1的选择框禁用
|
|
115
|
+ if (record.status === 1) {
|
|
116
|
+ return { disabled: true };
|
|
117
|
+ } else {
|
|
118
|
+ return { disabled: false };
|
|
119
|
+ }
|
|
120
|
+ };
|
98
|
121
|
// 表格hooks
|
99
|
|
- const [registerTable, { reload, getSelectRows, getSelectRowKeys }] = useTable({
|
|
122
|
+ const [registerTable, { reload, setProps, setSelectedRowKeys }] = useTable({
|
100
|
123
|
title: '告警配置列表',
|
101
|
124
|
api: queryAlarmConfig,
|
102
|
125
|
columns,
|
103
|
|
- clickToRowSelect: false,
|
104
|
126
|
showIndexColumn: false,
|
105
|
127
|
formConfig: {
|
106
|
128
|
labelWidth: 120,
|
...
|
...
|
@@ -110,7 +132,6 @@ |
110
|
132
|
useSearchForm: true,
|
111
|
133
|
showTableSetting: true,
|
112
|
134
|
bordered: true,
|
113
|
|
- rowKey: 'id',
|
114
|
135
|
actionColumn: {
|
115
|
136
|
width: 200,
|
116
|
137
|
title: '操作',
|
...
|
...
|
@@ -118,15 +139,11 @@ |
118
|
139
|
slots: { customRender: 'action' },
|
119
|
140
|
fixed: 'right',
|
120
|
141
|
},
|
|
142
|
+ ...selectionOptions,
|
121
|
143
|
});
|
122
|
144
|
// 弹框
|
123
|
145
|
const [registerDrawer, { openDrawer }] = useDrawer();
|
124
|
|
- const { createMessage } = useMessage();
|
125
|
146
|
|
126
|
|
- // 刷新
|
127
|
|
- const handleSuccess = () => {
|
128
|
|
- reload();
|
129
|
|
- };
|
130
|
147
|
// 新增或编辑
|
131
|
148
|
const handleCreateOrEdit = (record: Recordable | null) => {
|
132
|
149
|
if (record) {
|
...
|
...
|
@@ -140,45 +157,6 @@ |
140
|
157
|
});
|
141
|
158
|
}
|
142
|
159
|
};
|
143
|
|
- const useSelectionChange = () => {
|
144
|
|
- selectArray = getSelectRowKeys();
|
145
|
|
- if (selectArray.length > 0) {
|
146
|
|
- hasBatchDelete.value = false;
|
147
|
|
- }
|
148
|
|
- let getRows = getSelectRows();
|
149
|
|
- const isJudge = getRows.map((m) => m.status);
|
150
|
|
- if (isJudge.length === 0) {
|
151
|
|
- hasBatchDelete.value = true;
|
152
|
|
- }
|
153
|
|
- if (isJudge.includes(1) && isJudge.includes(0)) {
|
154
|
|
- hasBatchDelete.value = true;
|
155
|
|
- } else if (isJudge.includes(1) && !isJudge.includes(0)) {
|
156
|
|
- hasBatchDelete.value = true;
|
157
|
|
- } else if (!isJudge.includes(1) && isJudge.includes(0)) {
|
158
|
|
- hasBatchDelete.value = false;
|
159
|
|
- }
|
160
|
|
- };
|
161
|
|
- // 删除或批量删除
|
162
|
|
- const handleDeleteOrBatchDelete = async (record: Recordable | null) => {
|
163
|
|
- if (record) {
|
164
|
|
- try {
|
165
|
|
- await deleteAlarmConfig([record.id]);
|
166
|
|
- createMessage.success('删除成功');
|
167
|
|
- handleSuccess();
|
168
|
|
- } catch (e: any) {}
|
169
|
|
- } else {
|
170
|
|
- try {
|
171
|
|
- await deleteAlarmConfig(selectArray);
|
172
|
|
- createMessage.success('批量删除成功');
|
173
|
|
- handleSuccess();
|
174
|
|
- selectArray.length = 0;
|
175
|
|
- } catch (e: any) {
|
176
|
|
- selectArray.length = 0;
|
177
|
|
- } finally {
|
178
|
|
- selectArray.length = 0;
|
179
|
|
- }
|
180
|
|
- }
|
181
|
|
- };
|
182
|
160
|
|
183
|
161
|
// 树形选择器
|
184
|
162
|
const handleSelect = (organizationId: string) => {
|
...
|
...
|
@@ -226,8 +204,29 @@ |
226
|
204
|
content: h(JsonPreview, { data: JSON.parse(JSON.stringify(arr4)) }),
|
227
|
205
|
});
|
228
|
206
|
};
|
|
207
|
+ const statusChange = async (checked, record) => {
|
|
208
|
+ setProps({
|
|
209
|
+ loading: true,
|
|
210
|
+ });
|
|
211
|
+ setSelectedRowKeys([]);
|
|
212
|
+ resetSelectedRowKeys();
|
|
213
|
+ const newStatus = checked ? 1 : 0;
|
|
214
|
+ const { createMessage } = useMessage();
|
|
215
|
+ try {
|
|
216
|
+ await putAlarmConfigStatus(newStatus, record.id);
|
|
217
|
+ if (newStatus) {
|
|
218
|
+ createMessage.success(`启用成功`);
|
|
219
|
+ } else {
|
|
220
|
+ createMessage.success('禁用成功');
|
|
221
|
+ }
|
|
222
|
+ } finally {
|
|
223
|
+ setProps({
|
|
224
|
+ loading: false,
|
|
225
|
+ });
|
|
226
|
+ reload();
|
|
227
|
+ }
|
|
228
|
+ };
|
229
|
229
|
return {
|
230
|
|
- useSelectionChange,
|
231
|
230
|
searchInfo,
|
232
|
231
|
hasBatchDelete,
|
233
|
232
|
handleCreateOrEdit,
|
...
|
...
|
@@ -239,6 +238,7 @@ |
239
|
238
|
organizationIdTreeRef,
|
240
|
239
|
showAlarmContact,
|
241
|
240
|
showMessageMode,
|
|
241
|
+ statusChange,
|
242
|
242
|
};
|
243
|
243
|
},
|
244
|
244
|
});
|
...
|
...
|
|