Showing
4 changed files
with
115 additions
and
170 deletions
| 1 | 1 | import { BasicColumn } from '/@/components/Table'; |
| 2 | 2 | import { FormSchema } from '/@/components/Table'; |
| 3 | -import { h } from 'vue'; | |
| 4 | -import { Switch } from 'ant-design-vue'; | |
| 5 | -import { setMessageConfigStatus } from '/@/api/message/config'; | |
| 6 | -import { useMessage } from '/@/hooks/web/useMessage'; | |
| 7 | 3 | import { findDictItemByCode } from '/@/api/system/dict'; |
| 8 | 4 | import { MessageEnum } from '/@/enums/messageEnum'; |
| 9 | 5 | export const columns: BasicColumn[] = [ |
| ... | ... | @@ -32,30 +28,7 @@ export const columns: BasicColumn[] = [ |
| 32 | 28 | title: '状态', |
| 33 | 29 | dataIndex: 'status', |
| 34 | 30 | width: 120, |
| 35 | - customRender: ({ record }) => { | |
| 36 | - if (!Reflect.has(record, 'pendingStatus')) { | |
| 37 | - record.pendingStatus = false; | |
| 38 | - } | |
| 39 | - return h(Switch, { | |
| 40 | - checked: record.status === 1, | |
| 41 | - checkedChildren: '已启用', | |
| 42 | - unCheckedChildren: '已禁用', | |
| 43 | - loading: record.pendingStatus, | |
| 44 | - onChange(checked: boolean) { | |
| 45 | - record.pendingStatus = true; | |
| 46 | - const newStatus = checked ? 1 : 0; | |
| 47 | - const { createMessage } = useMessage(); | |
| 48 | - setMessageConfigStatus(record.id, record.messageType, newStatus, record.tenantId) | |
| 49 | - .then(() => { | |
| 50 | - record.status = newStatus; | |
| 51 | - createMessage.success(`修改成功`); | |
| 52 | - }) | |
| 53 | - .finally(() => { | |
| 54 | - record.pendingStatus = false; | |
| 55 | - }); | |
| 56 | - }, | |
| 57 | - }); | |
| 58 | - }, | |
| 31 | + slots: { customRender: 'status' }, | |
| 59 | 32 | }, |
| 60 | 33 | { |
| 61 | 34 | title: '创建时间', | ... | ... |
| 1 | 1 | <template> |
| 2 | 2 | <div> |
| 3 | - <BasicTable | |
| 4 | - @selection-change="useSelectionChange" | |
| 5 | - :rowSelection="{ type: 'checkbox' }" | |
| 6 | - @register="registerTable" | |
| 7 | - :clickToRowSelect="false" | |
| 8 | - > | |
| 3 | + <BasicTable @register="registerTable" :clickToRowSelect="false"> | |
| 9 | 4 | <template #toolbar> |
| 10 | 5 | <a-button type="primary" @click="handleCreate"> 新增消息配置 </a-button> |
| 11 | - <a-button color="error" @click="handleDeleteOrBatchDelete(null)" :disabled="disabled"> | |
| 6 | + <a-button color="error" @click="handleDeleteOrBatchDelete(null)" :disabled="hasBatchDelete"> | |
| 12 | 7 | 批量删除 |
| 13 | 8 | </a-button> |
| 14 | 9 | </template> |
| 15 | 10 | <template #config="{ record }"> |
| 16 | 11 | <a-button type="link" class="ml-2" @click="showData(record)"> 查看配置 </a-button> |
| 17 | 12 | </template> |
| 13 | + <template #status="{ record }"> | |
| 14 | + <Switch | |
| 15 | + :checked="record.status === 1" | |
| 16 | + :loading="record.pendingStatus" | |
| 17 | + checkedChildren="启用" | |
| 18 | + unCheckedChildren="禁用" | |
| 19 | + @change="(checked:boolean)=>statusChange(checked,record)" | |
| 20 | + /> | |
| 21 | + </template> | |
| 18 | 22 | <template #action="{ record }"> |
| 19 | 23 | <TableAction |
| 20 | 24 | :actions="[ |
| ... | ... | @@ -41,7 +45,7 @@ |
| 41 | 45 | </div> |
| 42 | 46 | </template> |
| 43 | 47 | <script lang="ts"> |
| 44 | - import { defineComponent, h, ref } from 'vue'; | |
| 48 | + import { defineComponent, h } from 'vue'; | |
| 45 | 49 | import { BasicTable, useTable, TableAction } from '/@/components/Table'; |
| 46 | 50 | import { messageConfigPage, deleteMessageConfig } from '/@/api/message/config'; |
| 47 | 51 | import { useDrawer } from '/@/components/Drawer'; |
| ... | ... | @@ -50,17 +54,29 @@ |
| 50 | 54 | import { Modal } from 'ant-design-vue'; |
| 51 | 55 | import { JsonPreview } from '/@/components/CodeEditor'; |
| 52 | 56 | import { useMessage } from '/@/hooks/web/useMessage'; |
| 57 | + import { useBatchDelete } from '/@/hooks/web/useBatchDelete'; | |
| 58 | + import { Switch } from 'ant-design-vue'; | |
| 59 | + import { setMessageConfigStatus } from '/@/api/message/config'; | |
| 53 | 60 | |
| 54 | 61 | export default defineComponent({ |
| 55 | 62 | name: 'MessageConfigManagement', |
| 56 | - components: { BasicTable, ConfigDrawer, TableAction }, | |
| 63 | + components: { BasicTable, ConfigDrawer, TableAction, Switch }, | |
| 57 | 64 | setup() { |
| 58 | - let selectedRowKeys: any = []; | |
| 59 | - const disabled = ref(true); | |
| 60 | - const { createMessage } = useMessage(); | |
| 61 | - | |
| 62 | 65 | const [registerDrawer, { openDrawer }] = useDrawer(); |
| 63 | - const [registerTable, { reload, getSelectRows, getSelectRowKeys }] = useTable({ | |
| 66 | + function handleSuccess() { | |
| 67 | + reload(); | |
| 68 | + } | |
| 69 | + const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions, resetSelectedRowKeys } = | |
| 70 | + useBatchDelete(deleteMessageConfig, handleSuccess); | |
| 71 | + selectionOptions.rowSelection.getCheckboxProps = (record: Recordable) => { | |
| 72 | + // Demo:status为1的选择框禁用 | |
| 73 | + if (record.status === 1) { | |
| 74 | + return { disabled: true }; | |
| 75 | + } else { | |
| 76 | + return { disabled: false }; | |
| 77 | + } | |
| 78 | + }; | |
| 79 | + const [registerTable, { reload, setProps, setSelectedRowKeys }] = useTable({ | |
| 64 | 80 | title: '消息配置列表', |
| 65 | 81 | api: messageConfigPage, |
| 66 | 82 | columns, |
| ... | ... | @@ -69,7 +85,6 @@ |
| 69 | 85 | schemas: searchFormSchema, |
| 70 | 86 | }, |
| 71 | 87 | useSearchForm: true, |
| 72 | - rowKey: 'id', | |
| 73 | 88 | showTableSetting: true, |
| 74 | 89 | bordered: true, |
| 75 | 90 | showIndexColumn: false, |
| ... | ... | @@ -80,6 +95,7 @@ |
| 80 | 95 | slots: { customRender: 'action' }, |
| 81 | 96 | fixed: 'right', |
| 82 | 97 | }, |
| 98 | + ...selectionOptions, | |
| 83 | 99 | }); |
| 84 | 100 | |
| 85 | 101 | function handleCreate() { |
| ... | ... | @@ -95,9 +111,6 @@ |
| 95 | 111 | }); |
| 96 | 112 | } |
| 97 | 113 | |
| 98 | - function handleSuccess() { | |
| 99 | - reload(); | |
| 100 | - } | |
| 101 | 114 | function showData(record: Recordable) { |
| 102 | 115 | Modal.info({ |
| 103 | 116 | title: '当前配置', |
| ... | ... | @@ -107,43 +120,29 @@ |
| 107 | 120 | content: h(JsonPreview, { data: JSON.parse(JSON.stringify(record.config)) }), |
| 108 | 121 | }); |
| 109 | 122 | } |
| 110 | - | |
| 111 | - const useSelectionChange = () => { | |
| 112 | - selectedRowKeys = getSelectRowKeys(); | |
| 113 | - if (selectedRowKeys.length > 0) { | |
| 114 | - disabled.value = false; | |
| 115 | - } | |
| 116 | - const isJudge = getSelectRows().map((m) => m.status); | |
| 117 | - if (isJudge.includes(1)) { | |
| 118 | - disabled.value = true; | |
| 119 | - } else { | |
| 120 | - disabled.value = false; | |
| 121 | - } | |
| 122 | - if (isJudge.length === 0) { | |
| 123 | - disabled.value = true; | |
| 124 | - } | |
| 125 | - }; | |
| 126 | - // 删除或批量删除 | |
| 127 | - const handleDeleteOrBatchDelete = async (record: Recordable | null) => { | |
| 128 | - if (record) { | |
| 129 | - try { | |
| 130 | - await deleteMessageConfig([record.id]); | |
| 131 | - createMessage.success('删除成功'); | |
| 132 | - handleSuccess(); | |
| 133 | - } catch (e: any) {} | |
| 134 | - } else { | |
| 135 | - try { | |
| 136 | - await deleteMessageConfig(selectedRowKeys); | |
| 137 | - createMessage.success('批量删除成功'); | |
| 138 | - handleSuccess(); | |
| 139 | - selectedRowKeys.length = 0; | |
| 140 | - } catch (e: any) { | |
| 141 | - selectedRowKeys.length = 0; | |
| 142 | - } finally { | |
| 143 | - selectedRowKeys.length = 0; | |
| 123 | + const statusChange = async (checked, record) => { | |
| 124 | + setProps({ | |
| 125 | + loading: true, | |
| 126 | + }); | |
| 127 | + setSelectedRowKeys([]); | |
| 128 | + resetSelectedRowKeys(); | |
| 129 | + const newStatus = checked ? 1 : 0; | |
| 130 | + const { createMessage } = useMessage(); | |
| 131 | + try { | |
| 132 | + await setMessageConfigStatus(record.id, record.messageType, newStatus, record.tenantId); | |
| 133 | + if (newStatus) { | |
| 134 | + createMessage.success(`启用成功`); | |
| 135 | + } else { | |
| 136 | + createMessage.success('禁用成功'); | |
| 144 | 137 | } |
| 138 | + } finally { | |
| 139 | + setProps({ | |
| 140 | + loading: false, | |
| 141 | + }); | |
| 142 | + reload(); | |
| 145 | 143 | } |
| 146 | 144 | }; |
| 145 | + | |
| 147 | 146 | return { |
| 148 | 147 | registerTable, |
| 149 | 148 | registerDrawer, |
| ... | ... | @@ -151,9 +150,9 @@ |
| 151 | 150 | handleCreate, |
| 152 | 151 | handleEdit, |
| 153 | 152 | handleSuccess, |
| 154 | - disabled, | |
| 155 | 153 | handleDeleteOrBatchDelete, |
| 156 | - useSelectionChange, | |
| 154 | + hasBatchDelete, | |
| 155 | + statusChange, | |
| 157 | 156 | }; |
| 158 | 157 | }, |
| 159 | 158 | }); | ... | ... |
| 1 | 1 | <template> |
| 2 | 2 | <div> |
| 3 | - <BasicTable | |
| 4 | - @selection-change="useSelectionChange" | |
| 5 | - :rowSelection="{ type: 'checkbox' }" | |
| 6 | - @register="registerTable" | |
| 7 | - :clickToRowSelect="false" | |
| 8 | - > | |
| 3 | + <BasicTable @register="registerTable" :clickToRowSelect="false"> | |
| 9 | 4 | <template #toolbar> |
| 10 | 5 | <a-button type="primary" @click="handleCreate"> 新增消息模板 </a-button> |
| 11 | - <a-button color="error" @click="handleDeleteOrBatchDelete(null)" :disabled="disabled"> | |
| 6 | + <a-button color="error" @click="handleDeleteOrBatchDelete(null)" :disabled="hasBatchDelete"> | |
| 12 | 7 | 批量删除 |
| 13 | 8 | </a-button> |
| 14 | 9 | </template> |
| ... | ... | @@ -17,6 +12,15 @@ |
| 17 | 12 | {{ record.messageConfig?.configName }} |
| 18 | 13 | </a-button> |
| 19 | 14 | </template> |
| 15 | + <template #status="{ record }"> | |
| 16 | + <Switch | |
| 17 | + :checked="record.status === 1" | |
| 18 | + :loading="record.pendingStatus" | |
| 19 | + checkedChildren="启用" | |
| 20 | + unCheckedChildren="禁用" | |
| 21 | + @change="(checked:boolean)=>statusChange(checked,record)" | |
| 22 | + /> | |
| 23 | + </template> | |
| 20 | 24 | <template #action="{ record }"> |
| 21 | 25 | <TableAction |
| 22 | 26 | :actions="[ |
| ... | ... | @@ -49,7 +53,7 @@ |
| 49 | 53 | </div> |
| 50 | 54 | </template> |
| 51 | 55 | <script lang="ts"> |
| 52 | - import { defineComponent, ref } from 'vue'; | |
| 56 | + import { defineComponent } from 'vue'; | |
| 53 | 57 | import { BasicTable, TableAction, useTable } from '/@/components/Table'; |
| 54 | 58 | import { useDrawer } from '/@/components/Drawer'; |
| 55 | 59 | import TemplateDrawer from './TemplateDrawer.vue'; |
| ... | ... | @@ -62,20 +66,32 @@ |
| 62 | 66 | import { MessageEnum } from '/@/enums/messageEnum'; |
| 63 | 67 | import SendEmail from '/@/views/message/template/SendEmail.vue'; |
| 64 | 68 | import { useMessage } from '/@/hooks/web/useMessage'; |
| 69 | + import { useBatchDelete } from '/@/hooks/web/useBatchDelete'; | |
| 70 | + import { Switch } from 'ant-design-vue'; | |
| 71 | + import { setMessageTemplateStatus } from '/@/api/message/template'; | |
| 65 | 72 | |
| 66 | 73 | export default defineComponent({ |
| 67 | 74 | name: 'MessageTemplateManagement', |
| 68 | - components: { SendSms, SendEmail, BasicTable, TemplateDrawer, TableAction }, | |
| 75 | + components: { SendSms, SendEmail, BasicTable, TemplateDrawer, TableAction, Switch }, | |
| 69 | 76 | setup() { |
| 70 | - let selectedRowKeys: any = []; | |
| 71 | - const disabled = ref(true); | |
| 72 | - const { createMessage } = useMessage(); | |
| 73 | 77 | const [registerModal, { openModal: openModal }] = useModal(); |
| 74 | 78 | const [registerMailModal, { openModal: openMailModal }] = useModal(); |
| 75 | 79 | const go = useGo(); |
| 80 | + function handleSuccess() { | |
| 81 | + reload(); | |
| 82 | + } | |
| 76 | 83 | const [registerDrawer, { openDrawer }] = useDrawer(); |
| 77 | - | |
| 78 | - const [registerTable, { reload, getSelectRows, getSelectRowKeys }] = useTable({ | |
| 84 | + const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions, resetSelectedRowKeys } = | |
| 85 | + useBatchDelete(deleteMessageTemplate, handleSuccess); | |
| 86 | + selectionOptions.rowSelection.getCheckboxProps = (record: Recordable) => { | |
| 87 | + // Demo:status为1的选择框禁用 | |
| 88 | + if (record.status === 1) { | |
| 89 | + return { disabled: true }; | |
| 90 | + } else { | |
| 91 | + return { disabled: false }; | |
| 92 | + } | |
| 93 | + }; | |
| 94 | + const [registerTable, { reload, setProps, setSelectedRowKeys }] = useTable({ | |
| 79 | 95 | title: '消息模板列表', |
| 80 | 96 | api: messageTemplatePage, |
| 81 | 97 | columns, |
| ... | ... | @@ -83,7 +99,6 @@ |
| 83 | 99 | labelWidth: 120, |
| 84 | 100 | schemas: searchFormSchema, |
| 85 | 101 | }, |
| 86 | - rowKey: 'id', | |
| 87 | 102 | useSearchForm: true, |
| 88 | 103 | showTableSetting: true, |
| 89 | 104 | bordered: true, |
| ... | ... | @@ -95,6 +110,7 @@ |
| 95 | 110 | slots: { customRender: 'action' }, |
| 96 | 111 | fixed: 'right', |
| 97 | 112 | }, |
| 113 | + ...selectionOptions, | |
| 98 | 114 | }); |
| 99 | 115 | |
| 100 | 116 | function handleCreate() { |
| ... | ... | @@ -130,46 +146,37 @@ |
| 130 | 146 | }); |
| 131 | 147 | } |
| 132 | 148 | } |
| 133 | - function handleSuccess() { | |
| 134 | - reload(); | |
| 135 | - } | |
| 149 | + | |
| 136 | 150 | function goConfig() { |
| 137 | 151 | go(PageEnum.MESSAGE_CONFIG); |
| 138 | 152 | } |
| 139 | - const useSelectionChange = () => { | |
| 140 | - selectedRowKeys = getSelectRowKeys(); | |
| 141 | - if (selectedRowKeys.length > 0) { | |
| 142 | - disabled.value = false; | |
| 143 | - } | |
| 144 | - const isJudge = getSelectRows().map((m) => m.status); | |
| 145 | - if (isJudge.includes(1)) { | |
| 146 | - disabled.value = true; | |
| 147 | - } else { | |
| 148 | - disabled.value = false; | |
| 149 | - } | |
| 150 | - if (isJudge.length === 0) { | |
| 151 | - disabled.value = true; | |
| 152 | - } | |
| 153 | - }; | |
| 154 | - // 删除或批量删除 | |
| 155 | - const handleDeleteOrBatchDelete = async (record: Recordable | null) => { | |
| 156 | - if (record) { | |
| 157 | - try { | |
| 158 | - await deleteMessageTemplate([record.id]); | |
| 159 | - createMessage.success('删除成功'); | |
| 160 | - handleSuccess(); | |
| 161 | - } catch (e: any) {} | |
| 162 | - } else { | |
| 163 | - try { | |
| 164 | - await deleteMessageTemplate(selectedRowKeys); | |
| 165 | - createMessage.success('批量删除成功'); | |
| 166 | - handleSuccess(); | |
| 167 | - selectedRowKeys.length = 0; | |
| 168 | - } catch (e: any) { | |
| 169 | - selectedRowKeys.length = 0; | |
| 170 | - } finally { | |
| 171 | - selectedRowKeys.length = 0; | |
| 153 | + const statusChange = async (checked, record) => { | |
| 154 | + setProps({ | |
| 155 | + loading: true, | |
| 156 | + }); | |
| 157 | + setSelectedRowKeys([]); | |
| 158 | + resetSelectedRowKeys(); | |
| 159 | + const newStatus = checked ? 1 : 0; | |
| 160 | + const { createMessage } = useMessage(); | |
| 161 | + try { | |
| 162 | + const { id, templatePurpose, messageType, tenantId } = record; | |
| 163 | + await setMessageTemplateStatus({ | |
| 164 | + id, | |
| 165 | + templatePurpose, | |
| 166 | + messageType, | |
| 167 | + tenantId, | |
| 168 | + status: newStatus, | |
| 169 | + }); | |
| 170 | + if (newStatus) { | |
| 171 | + createMessage.success(`启用成功`); | |
| 172 | + } else { | |
| 173 | + createMessage.success('禁用成功'); | |
| 172 | 174 | } |
| 175 | + } finally { | |
| 176 | + setProps({ | |
| 177 | + loading: false, | |
| 178 | + }); | |
| 179 | + reload(); | |
| 173 | 180 | } |
| 174 | 181 | }; |
| 175 | 182 | return { |
| ... | ... | @@ -182,9 +189,9 @@ |
| 182 | 189 | handleSuccess, |
| 183 | 190 | handleModal, |
| 184 | 191 | goConfig, |
| 185 | - useSelectionChange, | |
| 186 | - disabled, | |
| 187 | 192 | handleDeleteOrBatchDelete, |
| 193 | + statusChange, | |
| 194 | + hasBatchDelete, | |
| 188 | 195 | }; |
| 189 | 196 | }, |
| 190 | 197 | }); | ... | ... |
| ... | ... | @@ -3,10 +3,6 @@ import { FormSchema } from '/@/components/Table'; |
| 3 | 3 | import { findDictItemByCode } from '/@/api/system/dict'; |
| 4 | 4 | import { findMessageConfig } from '/@/api/message/config'; |
| 5 | 5 | import { isMessage } from '/@/views/message/config/config.data'; |
| 6 | -import { h } from 'vue'; | |
| 7 | -import { Switch } from 'ant-design-vue'; | |
| 8 | -import { useMessage } from '/@/hooks/web/useMessage'; | |
| 9 | -import { setMessageTemplateStatus } from '/@/api/message/template'; | |
| 10 | 6 | |
| 11 | 7 | export const columns: BasicColumn[] = [ |
| 12 | 8 | { |
| ... | ... | @@ -44,37 +40,7 @@ export const columns: BasicColumn[] = [ |
| 44 | 40 | title: '状态', |
| 45 | 41 | dataIndex: 'status', |
| 46 | 42 | width: 100, |
| 47 | - customRender: ({ record }) => { | |
| 48 | - if (!Reflect.has(record, 'pendingStatus')) { | |
| 49 | - record.pendingStatus = false; | |
| 50 | - } | |
| 51 | - return h(Switch, { | |
| 52 | - checked: record.status === 1, | |
| 53 | - checkedChildren: '已启用', | |
| 54 | - unCheckedChildren: '已禁用', | |
| 55 | - loading: record.pendingStatus, | |
| 56 | - onChange(checked: boolean) { | |
| 57 | - const { id, templatePurpose, messageType, tenantId } = record; | |
| 58 | - record.pendingStatus = true; | |
| 59 | - const newStatus = checked ? 1 : 0; | |
| 60 | - const { createMessage } = useMessage(); | |
| 61 | - setMessageTemplateStatus({ | |
| 62 | - id, | |
| 63 | - templatePurpose, | |
| 64 | - messageType, | |
| 65 | - tenantId, | |
| 66 | - status: newStatus, | |
| 67 | - }) | |
| 68 | - .then(() => { | |
| 69 | - record.status = newStatus; | |
| 70 | - createMessage.success(`修改成功`); | |
| 71 | - }) | |
| 72 | - .finally(() => { | |
| 73 | - record.pendingStatus = false; | |
| 74 | - }); | |
| 75 | - }, | |
| 76 | - }); | |
| 77 | - }, | |
| 43 | + slots: { customRender: 'status' }, | |
| 78 | 44 | }, |
| 79 | 45 | { |
| 80 | 46 | title: '模板用途', | ... | ... |