Commit cddbf5bf672d6fc97da0b7e5395fd853a59feea4

Authored by fengtao
1 parent d479c8df

feat转换函数新增修改状态

1 1 import { defHttp } from '/@/utils/http/axios';
2 2 import { ScriptParam, ScriptQueryParam, ScriptRecord } from './model/scriptModel';
3 3 import { PaginationResult } from '/#/axios';
  4 +import { IChangeStatus } from '../ruleengine/model/ruleengineModel';
4 5
5 6 enum ScriptManagerApi {
6 7 SCRIPT_POST_URL = '/js',
... ... @@ -8,6 +9,7 @@ enum ScriptManagerApi {
8 9 SCRIPT_DELETE_URL = '/js',
9 10 SCRIPT_MELIST_URL = '/js/me/list',
10 11 SCRIPT_TEST_URL = '/js/test',
  12 + SCRIPT_STATUS = '/js',
11 13 }
12 14
13 15 export const ScriptPage = (params: ScriptQueryParam) => {
... ... @@ -17,6 +19,16 @@ export const ScriptPage = (params: ScriptQueryParam) => {
17 19 });
18 20 };
19 21
  22 +/**
  23 + * 改变转换函数状态
  24 + * @param params id status
  25 + */
  26 +export const scriptPagePutApi = (params: IChangeStatus) =>
  27 + defHttp.post({
  28 + url: ScriptManagerApi.SCRIPT_STATUS,
  29 + data: params,
  30 + });
  31 +
20 32 //删除脚本
21 33 export const deleteScriptManage = (ids: string[]) => {
22 34 return defHttp.delete({
... ...
1 1 import { BasicColumn, FormSchema } from '/@/components/Table';
2 2 import moment from 'moment';
3   -import { h } from 'vue';
4   -import { Tag } from 'ant-design-vue';
5 3
6 4 // 表格配置
7 5 export const columns: BasicColumn[] = [
... ... @@ -14,12 +12,7 @@ export const columns: BasicColumn[] = [
14 12 title: '脚本状态',
15 13 dataIndex: 'status',
16 14 width: 120,
17   - customRender: ({ record }) => {
18   - const status = record.status;
19   - const color = status == 1 ? 'green' : 'red';
20   - const text = status == 1 ? '启用' : '禁用';
21   - return h(Tag, { color: color }, () => text);
22   - },
  15 + slots: { customRender: 'status' },
23 16 },
24 17 {
25 18 title: '脚本内容',
... ...
... ... @@ -49,6 +49,17 @@
49 49 ]"
50 50 />
51 51 </template>
  52 + <Authority value="api:yt:js:update:status">
  53 + <template #status="{ record }">
  54 + <Switch
  55 + :checked="record.status === 1"
  56 + :loading="record.pendingStatus"
  57 + checkedChildren="启用"
  58 + unCheckedChildren="禁用"
  59 + @change="(checked:boolean)=>statusChange(checked,record)"
  60 + />
  61 + </template>
  62 + </Authority>
52 63 </BasicTable>
53 64 <ConverScriptModal @register="registerModal" @success="handleSuccess" />
54 65 </div>
... ... @@ -60,13 +71,18 @@
60 71 import { searchFormSchema, columns } from './config.data';
61 72 import { Authority } from '/@/components/Authority';
62 73 import { useBatchDelete } from '/@/hooks/web/useBatchDelete';
63   - import { Popconfirm } from 'ant-design-vue';
  74 + import { Switch, Popconfirm } from 'ant-design-vue';
64 75 import { useModal } from '/@/components/Modal';
65 76 import ConverScriptModal from './ConverScriptModal.vue';
66   - import { ScriptPage, deleteScriptManage } from '/@/api/scriptmanage/scriptManager';
  77 + import {
  78 + ScriptPage,
  79 + deleteScriptManage,
  80 + scriptPagePutApi,
  81 + } from '/@/api/scriptmanage/scriptManager';
  82 + import { useMessage } from '/@/hooks/web/useMessage';
67 83
68 84 const searchInfo = reactive<Recordable>({});
69   - const [registerTable, { reload, setProps }] = useTable({
  85 + const [registerTable, { reload, setProps, setSelectedRowKeys }] = useTable({
70 86 title: '转换脚本列表',
71 87 api: ScriptPage,
72 88 columns,
... ... @@ -94,11 +110,8 @@
94 110 reload();
95 111 };
96 112
97   - const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions } = useBatchDelete(
98   - deleteScriptManage,
99   - handleSuccess,
100   - setProps
101   - );
  113 + const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions, resetSelectedRowKeys } =
  114 + useBatchDelete(deleteScriptManage, handleSuccess, setProps);
102 115
103 116 nextTick(() => {
104 117 setProps(selectionOptions);
... ... @@ -147,4 +160,26 @@
147 160 });
148 161 }
149 162 };
  163 + const statusChange = async (checked, record) => {
  164 + setProps({
  165 + loading: true,
  166 + });
  167 + setSelectedRowKeys([]);
  168 + resetSelectedRowKeys();
  169 + const newStatus = checked ? 1 : 0;
  170 + const { createMessage } = useMessage();
  171 + try {
  172 + await scriptPagePutApi({ id: record.id, status: newStatus });
  173 + if (newStatus) {
  174 + createMessage.success(`启用成功`);
  175 + } else {
  176 + createMessage.success('禁用成功');
  177 + }
  178 + } finally {
  179 + setProps({
  180 + loading: false,
  181 + });
  182 + reload();
  183 + }
  184 + };
150 185 </script>
... ...