Commit 8fca84036b18dfe04672169acb72d36edcdfd02b

Authored by fengtao
1 parent 64cfe362

fix[DEFECT-335]修改告警配置批量删除问题

@@ -3,10 +3,6 @@ import { getOrganizationList } from '/@/api/system/system'; @@ -3,10 +3,6 @@ import { getOrganizationList } from '/@/api/system/system';
3 import { copyTransFun } from '/@/utils/fnUtils'; 3 import { copyTransFun } from '/@/utils/fnUtils';
4 import { findDictItemByCode } from '/@/api/system/dict'; 4 import { findDictItemByCode } from '/@/api/system/dict';
5 import { alarmContactGetPage } from '/@/api/device/deviceConfigApi'; 5 import { alarmContactGetPage } from '/@/api/device/deviceConfigApi';
6 -import { Switch } from 'ant-design-vue';  
7 -import { h } from 'vue';  
8 -import { putAlarmConfigStatus } from '/@/api/alarm/config/alarmConfig';  
9 -import { useMessage } from '/@/hooks/web/useMessage';  
10 6
11 // 表格列数据 7 // 表格列数据
12 export const columns: BasicColumn[] = [ 8 export const columns: BasicColumn[] = [
@@ -36,34 +32,7 @@ export const columns: BasicColumn[] = [ @@ -36,34 +32,7 @@ export const columns: BasicColumn[] = [
36 title: '状态', 32 title: '状态',
37 dataIndex: 'status', 33 dataIndex: 'status',
38 width: 120, 34 width: 120,
39 - customRender: ({ record }) => {  
40 - if (!Reflect.has(record, 'pendingStatus')) {  
41 - record.pendingStatus = false;  
42 - }  
43 - return h(Switch, {  
44 - checked: record.status === 1,  
45 - checkedChildren: '启用',  
46 - unCheckedChildren: '未启用',  
47 - loading: record.pendingStatus,  
48 - onChange(checked: boolean) {  
49 - record.pendingStatus = true;  
50 - const newStatus = checked ? 1 : 0;  
51 - const { createMessage } = useMessage();  
52 - putAlarmConfigStatus(newStatus, record.id)  
53 - .then(() => {  
54 - record.status = newStatus;  
55 - if (record.status == 1) {  
56 - createMessage.success(`启用`);  
57 - } else {  
58 - createMessage.success('未启用');  
59 - }  
60 - })  
61 - .finally(() => {  
62 - record.pendingStatus = false;  
63 - });  
64 - },  
65 - });  
66 - }, 35 + slots: { customRender: 'status' },
67 }, 36 },
68 { 37 {
69 title: '备注', 38 title: '备注',
@@ -9,8 +9,6 @@ @@ -9,8 +9,6 @@
9 <BasicTable 9 <BasicTable
10 @register="registerTable" 10 @register="registerTable"
11 :searchInfo="searchInfo" 11 :searchInfo="searchInfo"
12 - @selection-change="useSelectionChange"  
13 - :rowSelection="{ type: 'checkbox' }"  
14 class="w-3/4 xl:w-4/5" 12 class="w-3/4 xl:w-4/5"
15 :clickToRowSelect="false" 13 :clickToRowSelect="false"
16 > 14 >
@@ -35,6 +33,15 @@ @@ -35,6 +33,15 @@
35 查看联系方式 33 查看联系方式
36 </a-button> 34 </a-button>
37 </template> 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 <template #action="{ record }"> 45 <template #action="{ record }">
39 <TableAction 46 <TableAction
40 :actions="[ 47 :actions="[
@@ -68,10 +75,9 @@ @@ -68,10 +75,9 @@
68 </template> 75 </template>
69 76
70 <script lang="ts"> 77 <script lang="ts">
71 - import { defineComponent, reactive, ref, h } from 'vue'; 78 + import { defineComponent, reactive, h } from 'vue';
72 import { BasicTable, useTable, TableAction } from '/@/components/Table'; 79 import { BasicTable, useTable, TableAction } from '/@/components/Table';
73 import { PageWrapper } from '/@/components/Page'; 80 import { PageWrapper } from '/@/components/Page';
74 - import { useMessage } from '/@/hooks/web/useMessage';  
75 import { useDrawer } from '/@/components/Drawer'; 81 import { useDrawer } from '/@/components/Drawer';
76 import ContactDrawer from './ContactDrawer.vue'; 82 import ContactDrawer from './ContactDrawer.vue';
77 import { useResetOrganizationTree, OrganizationIdTree } from '/@/views/common/organizationIdTree'; 83 import { useResetOrganizationTree, OrganizationIdTree } from '/@/views/common/organizationIdTree';
@@ -81,6 +87,10 @@ @@ -81,6 +87,10 @@
81 import { JsonPreview } from '/@/components/CodeEditor'; 87 import { JsonPreview } from '/@/components/CodeEditor';
82 import { findDictItemByCode } from '/@/api/system/dict'; 88 import { findDictItemByCode } from '/@/api/system/dict';
83 import { alarmContactGetPage } from '/@/api/device/deviceConfigApi'; 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 export default defineComponent({ 95 export default defineComponent({
86 components: { 96 components: {
@@ -89,18 +99,30 @@ @@ -89,18 +99,30 @@
89 BasicTable, 99 BasicTable,
90 TableAction, 100 TableAction,
91 ContactDrawer, 101 ContactDrawer,
  102 + Switch,
92 }, 103 },
93 setup() { 104 setup() {
94 - let selectArray: any = [];  
95 - const hasBatchDelete = ref(true);  
96 const searchInfo = reactive<Recordable>({}); 105 const searchInfo = reactive<Recordable>({});
97 const { organizationIdTreeRef, resetFn } = useResetOrganizationTree(searchInfo); 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 // 表格hooks 121 // 表格hooks
99 - const [registerTable, { reload, getSelectRows, getSelectRowKeys }] = useTable({ 122 + const [registerTable, { reload, setProps, setSelectedRowKeys }] = useTable({
100 title: '告警配置列表', 123 title: '告警配置列表',
101 api: queryAlarmConfig, 124 api: queryAlarmConfig,
102 columns, 125 columns,
103 - clickToRowSelect: false,  
104 showIndexColumn: false, 126 showIndexColumn: false,
105 formConfig: { 127 formConfig: {
106 labelWidth: 120, 128 labelWidth: 120,
@@ -110,7 +132,6 @@ @@ -110,7 +132,6 @@
110 useSearchForm: true, 132 useSearchForm: true,
111 showTableSetting: true, 133 showTableSetting: true,
112 bordered: true, 134 bordered: true,
113 - rowKey: 'id',  
114 actionColumn: { 135 actionColumn: {
115 width: 200, 136 width: 200,
116 title: '操作', 137 title: '操作',
@@ -118,15 +139,11 @@ @@ -118,15 +139,11 @@
118 slots: { customRender: 'action' }, 139 slots: { customRender: 'action' },
119 fixed: 'right', 140 fixed: 'right',
120 }, 141 },
  142 + ...selectionOptions,
121 }); 143 });
122 // 弹框 144 // 弹框
123 const [registerDrawer, { openDrawer }] = useDrawer(); 145 const [registerDrawer, { openDrawer }] = useDrawer();
124 - const { createMessage } = useMessage();  
125 146
126 - // 刷新  
127 - const handleSuccess = () => {  
128 - reload();  
129 - };  
130 // 新增或编辑 147 // 新增或编辑
131 const handleCreateOrEdit = (record: Recordable | null) => { 148 const handleCreateOrEdit = (record: Recordable | null) => {
132 if (record) { 149 if (record) {
@@ -140,45 +157,6 @@ @@ -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 const handleSelect = (organizationId: string) => { 162 const handleSelect = (organizationId: string) => {
@@ -226,8 +204,29 @@ @@ -226,8 +204,29 @@
226 content: h(JsonPreview, { data: JSON.parse(JSON.stringify(arr4)) }), 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 return { 229 return {
230 - useSelectionChange,  
231 searchInfo, 230 searchInfo,
232 hasBatchDelete, 231 hasBatchDelete,
233 handleCreateOrEdit, 232 handleCreateOrEdit,
@@ -239,6 +238,7 @@ @@ -239,6 +238,7 @@
239 organizationIdTreeRef, 238 organizationIdTreeRef,
240 showAlarmContact, 239 showAlarmContact,
241 showMessageMode, 240 showMessageMode,
  241 + statusChange,
242 }; 242 };
243 }, 243 },
244 }); 244 });