Commit aede5af81afc7a74f16d6ff3e77b7e832ab63158

Authored by ww
1 parent e75bd238

perf: 迁移脚本管理/转换函数至规则引擎页面

  1 +export { default as RuleChainConversionScript } from './index.vue';
... ...
  1 +<template>
  2 + <div>
  3 + <BasicTable @register="registerTable" v-show="isStatus === 0">
  4 + <template #toolbar>
  5 + <Authority value="api:yt:convert:js:post">
  6 + <a-button type="primary" @click="handleCreate"> 新增转换脚本 </a-button>
  7 + </Authority>
  8 + <Authority value="api:yt:convert:js:delete">
  9 + <Popconfirm
  10 + title="您确定要批量删除数据"
  11 + ok-text="确定"
  12 + cancel-text="取消"
  13 + @confirm="handleDeleteOrBatchDelete(null)"
  14 + >
  15 + <a-button color="error" :disabled="hasBatchDelete"> 批量删除 </a-button>
  16 + </Popconfirm>
  17 + </Authority>
  18 + </template>
  19 + <template #status="{ record }">
  20 + <Switch
  21 + :checked="record.status === 1"
  22 + :loading="record.pendingStatus"
  23 + checkedChildren="启用"
  24 + unCheckedChildren="禁用"
  25 + @change="(checked:boolean)=>statusChange(checked,record)"
  26 + />
  27 + </template>
  28 + <template #action="{ record }">
  29 + <TableAction
  30 + :actions="[
  31 + {
  32 + label: '查看',
  33 + auth: 'api:yt:convert:js:get',
  34 + icon: 'ant-design:eye-outlined',
  35 + onClick: handleView.bind(null, record),
  36 + ifShow: record.status == 1,
  37 + },
  38 + {
  39 + label: '编辑',
  40 + auth: 'api:yt:convert:js:update',
  41 + icon: 'clarity:note-edit-line',
  42 + onClick: handleEdit.bind(null, record),
  43 + ifShow: record.status == 0,
  44 + },
  45 + {
  46 + label: '删除',
  47 + auth: 'api:yt:convert:js:delete',
  48 + icon: 'ant-design:delete-outlined',
  49 + ifShow: record.status == 0,
  50 + color: 'error',
  51 + popConfirm: {
  52 + title: '是否确认删除',
  53 + confirm: handleDeleteOrBatchDelete.bind(null, record),
  54 + },
  55 + },
  56 + ]"
  57 + />
  58 + </template>
  59 + </BasicTable>
  60 + <ScriptDrawer
  61 + @register="registerDrawer"
  62 + @isStatus="handleIsStatus"
  63 + ref="scriptDrawerRef"
  64 + @success="handleSuccess"
  65 + />
  66 + <TestScript v-show="isStatus === 1" @isStatus="handleCancelStatus" ref="testScriptRef" />
  67 + </div>
  68 +</template>
  69 +
  70 +<script lang="ts" setup>
  71 + import { ref, nextTick } from 'vue';
  72 + import { Switch, Popconfirm } from 'ant-design-vue';
  73 + import { BasicTable, useTable, TableAction } from '/@/components/Table';
  74 + import { columns } from '../config/config.data';
  75 + import { getConvertApi, deleteTransformApi } from '/@/api/device/TransformScriptApi';
  76 + import { useDrawer } from '/@/components/Drawer/index';
  77 + import ScriptDrawer from '../cpns/ScriptDrawer.vue';
  78 + import TestScript from '../cpns/TestScript.vue';
  79 + import { useMessage } from '/@/hooks/web/useMessage';
  80 + import { updateTransformScriptStatusApi } from '/@/api/device/TransformScriptApi';
  81 + import { useBatchDelete } from '/@/hooks/web/useBatchDelete';
  82 + import { Authority } from '/@/components/Authority';
  83 + import { computed, unref } from 'vue';
  84 +
  85 + const props = defineProps<{ searchInfo: Recordable }>();
  86 +
  87 + const getSearchInfo = computed(() => props.searchInfo);
  88 +
  89 + const handleSuccess = () => {
  90 + reload();
  91 + };
  92 +
  93 + const [registerTable, { reload, setProps, setSelectedRowKeys }] = useTable({
  94 + api: getConvertApi,
  95 + title: '转换脚本列表',
  96 + columns,
  97 + useSearchForm: false,
  98 + showTableSetting: true,
  99 + bordered: true,
  100 + showIndexColumn: false,
  101 + clickToRowSelect: false,
  102 + rowKey: 'id',
  103 + beforeFetch: (params: Recordable) => {
  104 + return { ...unref(getSearchInfo), ...params };
  105 + },
  106 + actionColumn: {
  107 + width: 180,
  108 + title: '操作',
  109 + dataIndex: 'action',
  110 + slots: { customRender: 'action' },
  111 + fixed: 'right',
  112 + },
  113 + });
  114 +
  115 + const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions, resetSelectedRowKeys } =
  116 + useBatchDelete(deleteTransformApi, handleSuccess, setProps);
  117 + selectionOptions.rowSelection.getCheckboxProps = (record: Recordable) => {
  118 + // Demo:status为1的选择框禁用
  119 + if (record.status === 1) {
  120 + return { disabled: true };
  121 + } else {
  122 + return { disabled: false };
  123 + }
  124 + };
  125 + nextTick(() => {
  126 + setProps(selectionOptions);
  127 + });
  128 + const [registerDrawer, { openDrawer }] = useDrawer();
  129 +
  130 + const isStatus = ref(0);
  131 + const testScriptRef = ref();
  132 + const scriptDrawerRef = ref();
  133 + const handleIsStatus = ({ status, jsCode }) => {
  134 + isStatus.value = status;
  135 + testScriptRef.value.aceEditor.setValue(jsCode);
  136 + };
  137 + const handleCancelStatus = ({ status, emitType }) => {
  138 + openDrawer(true);
  139 + isStatus.value = status;
  140 + if (emitType === 'ok') {
  141 + const jsCode = testScriptRef.value.aceEditor.getValue();
  142 + scriptDrawerRef.value.aceEditor.setValue(jsCode);
  143 + }
  144 + };
  145 + const handleCreate = () => {
  146 + nextTick(() => {
  147 + openDrawer(true, {
  148 + isUpdate: false,
  149 + });
  150 + });
  151 + };
  152 + const handleEdit = (record: Recordable) => {
  153 + nextTick(() => {
  154 + openDrawer(true, { isUpdate: true, record });
  155 + });
  156 + };
  157 + const statusChange = async (checked, record) => {
  158 + setProps({
  159 + loading: true,
  160 + });
  161 + setSelectedRowKeys([]);
  162 + resetSelectedRowKeys();
  163 + const newStatus = checked ? 1 : 0;
  164 + const { createMessage } = useMessage();
  165 + try {
  166 + await updateTransformScriptStatusApi(newStatus, record.id);
  167 + if (newStatus) {
  168 + createMessage.success(`启用成功`);
  169 + } else {
  170 + createMessage.success('禁用成功');
  171 + }
  172 + } finally {
  173 + setProps({
  174 + loading: false,
  175 + });
  176 + reload();
  177 + }
  178 + };
  179 + function handleView(record: Recordable) {
  180 + nextTick(() => {
  181 + openDrawer(true, {
  182 + record,
  183 + isUpdate: 'view',
  184 + });
  185 + });
  186 + }
  187 +
  188 + defineExpose({
  189 + reload: () => reload(),
  190 + });
  191 +</script>
... ...
src/views/rule/script/TcpConversionScript/ConverScript.vue renamed from src/views/scriptmanage/converscript/ConverScript.vue
src/views/rule/script/TcpConversionScript/ConverScriptModal.less renamed from src/views/scriptmanage/converscript/ConverScriptModal.less
src/views/rule/script/TcpConversionScript/ConverScriptModal.vue renamed from src/views/scriptmanage/converscript/ConverScriptModal.vue
src/views/rule/script/TcpConversionScript/TestScriptModal.vue renamed from src/views/scriptmanage/converscript/TestScriptModal.vue
src/views/rule/script/TcpConversionScript/config.data.ts renamed from src/views/scriptmanage/converscript/config.data.ts
  1 +export { default as TcpConversionScript } from './index.vue';
... ...
src/views/rule/script/TcpConversionScript/index.vue renamed from src/views/scriptmanage/converscript/index.vue
1   -<template>
2   - <div>
3   - <BasicTable :clickToRowSelect="false" @register="registerTable" :searchInfo="searchInfo">
4   - <template #toolbar>
5   - <Authority value="api:yt:js:post">
6   - <a-button type="primary" @click="handleCreateOrEdit(null)"> 新增转换脚本 </a-button>
7   - </Authority>
8   - <Authority value="api:yt:js:delete">
9   - <Popconfirm
10   - title="您确定要批量删除数据"
11   - ok-text="确定"
12   - cancel-text="取消"
13   - @confirm="handleDeleteOrBatchDelete(null)"
14   - >
15   - <a-button type="primary" color="error" :disabled="hasBatchDelete"> 批量删除 </a-button>
16   - </Popconfirm>
17   - </Authority>
18   - </template>
19   - <template #convertJs="{ record }">
20   - <a-button type="text" @click="handleScriptView(record)">
21   - <span style="color: #377dff">查看脚本</span>
22   - </a-button>
23   - </template>
24   - <template #action="{ record }">
25   - <TableAction
26   - :actions="[
27   - {
28   - label: '测试',
29   - icon: 'ant-design:font-size-outlined',
30   - auth: 'api:yt:js:test',
31   - onClick: handleBindTest.bind(null, record),
32   - },
33   - {
34   - label: '编辑',
35   - icon: 'clarity:note-edit-line',
36   - auth: 'api:yt:js:update',
37   - onClick: handleCreateOrEdit.bind(null, record),
38   - ifShow: record.status == 0,
39   - },
40   - {
41   - label: '删除',
42   - icon: 'ant-design:delete-outlined',
43   - auth: 'api:yt:js:delete',
44   - color: 'error',
45   - ifShow: record.status == 0,
46   - popConfirm: {
47   - title: '是否确认删除',
48   - confirm: handleDeleteOrBatchDelete.bind(null, record),
49   - },
50   - },
51   - ]"
52   - />
53   - </template>
54   - <template #status="{ record }">
55   - <Authority value="api:yt:js:update:status">
56   - <Switch
57   - :checked="record.status === 1"
58   - :loading="record.pendingStatus"
59   - checkedChildren="启用"
60   - unCheckedChildren="禁用"
61   - @change="(checked:boolean)=>statusChange(checked,record)"
62   - />
63   - </Authority>
64   - </template>
65   - </BasicTable>
66   - <ConverScriptModal @register="registerModal" @success="handleSuccess" />
67   - </div>
68   -</template>
69   -
70   -<script lang="ts" setup>
71   - import { reactive, nextTick } from 'vue';
72   - import { BasicTable, useTable, TableAction } from '/@/components/Table';
73   - import { searchFormSchema, columns } from './config.data';
74   - import { Authority } from '/@/components/Authority';
75   - import { useBatchDelete } from '/@/hooks/web/useBatchDelete';
76   - import { Switch, Popconfirm } from 'ant-design-vue';
77   - import { useModal } from '/@/components/Modal';
78   - import ConverScriptModal from './ConverScriptModal.vue';
79   - import {
80   - ScriptPage,
81   - deleteScriptManage,
82   - scriptPagePutApi,
83   - } from '/@/api/scriptmanage/scriptManager';
84   - import { useMessage } from '/@/hooks/web/useMessage';
85   -
86   - const searchInfo = reactive<Recordable>({});
87   - const [registerTable, { reload, setProps, setSelectedRowKeys }] = useTable({
88   - title: '转换脚本列表',
89   - api: ScriptPage,
90   - columns,
91   - showIndexColumn: false,
92   - clickToRowSelect: false,
93   - formConfig: {
94   - labelWidth: 120,
95   - schemas: searchFormSchema,
96   - fieldMapToTime: [['sendTime', ['startTime', 'endTime'], 'x']],
97   - },
98   - useSearchForm: true,
99   - showTableSetting: true,
100   - bordered: true,
101   - rowKey: 'id',
102   - actionColumn: {
103   - width: 200,
104   - title: '操作',
105   - dataIndex: 'action',
106   - slots: { customRender: 'action' },
107   - fixed: 'right',
108   - },
109   - });
110   -
111   - const handleSuccess = () => {
112   - reload();
113   - };
114   -
115   - const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions, resetSelectedRowKeys } =
116   - useBatchDelete(deleteScriptManage, handleSuccess, setProps);
117   - selectionOptions.rowSelection.getCheckboxProps = (record: Recordable) => {
118   - // Demo:status为1的选择框禁用
119   - if (record.status === 1) {
120   - return { disabled: true };
121   - } else {
122   - return { disabled: false };
123   - }
124   - };
125   -
126   - nextTick(() => {
127   - setProps(selectionOptions);
128   - });
129   -
130   - const [registerModal, { openModal }] = useModal();
131   -
132   - // 新增或编辑
133   - const handleCreateOrEdit = (record: Recordable | null) => {
134   - if (record) {
135   - openModal(true, {
136   - isUpdate: false,
137   - record,
138   - isAuth: '',
139   - isView: false,
140   - isTest: false,
141   - isText: 'confirm',
142   - isTitle: 'edit',
143   - });
144   - } else {
145   - openModal(true, {
146   - isAuth: '',
147   - isUpdate: true,
148   - isView: false,
149   - isTest: false,
150   - isText: 'confirm',
151   - isTitle: 'add',
152   - });
153   - }
154   - };
155   - const handleBindTest = (record: Recordable | null) => {
156   - if (record) {
157   - openModal(true, {
158   - isAuth: '',
159   - isUpdate: false,
160   - record: record.id,
161   - isTest: true,
162   - isText: 'test',
163   - isTitle: 'test',
164   - });
165   - }
166   - };
167   - const handleScriptView = (record: Recordable | null) => {
168   - if (record) {
169   - openModal(true, {
170   - isUpdate: true,
171   - record,
172   - isView: true,
173   - });
174   - }
175   - };
176   - const statusChange = async (checked, record) => {
177   - setProps({
178   - loading: true,
179   - });
180   - setSelectedRowKeys([]);
181   - resetSelectedRowKeys();
182   - const newStatus = checked ? 1 : 0;
183   - const { createMessage } = useMessage();
184   - try {
185   - await scriptPagePutApi(record.id, newStatus);
186   - if (newStatus) {
187   - createMessage.success(`启用成功`);
188   - } else {
189   - createMessage.success('禁用成功');
190   - }
191   - } finally {
192   - setProps({
193   - loading: false,
194   - });
195   - reload();
196   - }
197   - };
198   -</script>
  1 +<template>
  2 + <div>
  3 + <BasicTable :clickToRowSelect="false" @register="registerTable" :searchInfo="searchInfo">
  4 + <template #toolbar>
  5 + <Authority value="api:yt:js:post">
  6 + <a-button type="primary" @click="handleCreateOrEdit(null)"> 新增转换脚本 </a-button>
  7 + </Authority>
  8 + <Authority value="api:yt:js:delete">
  9 + <Popconfirm
  10 + title="您确定要批量删除数据"
  11 + ok-text="确定"
  12 + cancel-text="取消"
  13 + @confirm="handleDeleteOrBatchDelete(null)"
  14 + >
  15 + <a-button type="primary" color="error" :disabled="hasBatchDelete"> 批量删除 </a-button>
  16 + </Popconfirm>
  17 + </Authority>
  18 + </template>
  19 + <template #convertJs="{ record }">
  20 + <a-button type="text" @click="handleScriptView(record)">
  21 + <span style="color: #377dff">查看脚本</span>
  22 + </a-button>
  23 + </template>
  24 + <template #action="{ record }">
  25 + <TableAction
  26 + :actions="[
  27 + {
  28 + label: '测试',
  29 + icon: 'ant-design:font-size-outlined',
  30 + auth: 'api:yt:js:test',
  31 + onClick: handleBindTest.bind(null, record),
  32 + },
  33 + {
  34 + label: '编辑',
  35 + icon: 'clarity:note-edit-line',
  36 + auth: 'api:yt:js:update',
  37 + onClick: handleCreateOrEdit.bind(null, record),
  38 + ifShow: record.status == 0,
  39 + },
  40 + {
  41 + label: '删除',
  42 + icon: 'ant-design:delete-outlined',
  43 + auth: 'api:yt:js:delete',
  44 + color: 'error',
  45 + ifShow: record.status == 0,
  46 + popConfirm: {
  47 + title: '是否确认删除',
  48 + confirm: handleDeleteOrBatchDelete.bind(null, record),
  49 + },
  50 + },
  51 + ]"
  52 + />
  53 + </template>
  54 + <template #status="{ record }">
  55 + <Authority value="api:yt:js:update:status">
  56 + <Switch
  57 + :checked="record.status === 1"
  58 + :loading="record.pendingStatus"
  59 + checkedChildren="启用"
  60 + unCheckedChildren="禁用"
  61 + @change="(checked:boolean)=>statusChange(checked,record)"
  62 + />
  63 + </Authority>
  64 + </template>
  65 + </BasicTable>
  66 + <ConverScriptModal @register="registerModal" @success="handleSuccess" />
  67 + </div>
  68 +</template>
  69 +
  70 +<script lang="ts" setup>
  71 + import { reactive, nextTick, unref } from 'vue';
  72 + import { BasicTable, useTable, TableAction } from '/@/components/Table';
  73 + import { columns } from './config.data';
  74 + import { Authority } from '/@/components/Authority';
  75 + import { useBatchDelete } from '/@/hooks/web/useBatchDelete';
  76 + import { Switch, Popconfirm } from 'ant-design-vue';
  77 + import { useModal } from '/@/components/Modal';
  78 + import ConverScriptModal from './ConverScriptModal.vue';
  79 + import {
  80 + ScriptPage,
  81 + deleteScriptManage,
  82 + scriptPagePutApi,
  83 + } from '/@/api/scriptmanage/scriptManager';
  84 + import { useMessage } from '/@/hooks/web/useMessage';
  85 +
  86 + const props = defineProps<{ searchInfo: Recordable }>();
  87 + const searchInfo = reactive<Recordable>({});
  88 + const [registerTable, { reload, setProps, setSelectedRowKeys }] = useTable({
  89 + title: '转换脚本列表',
  90 + api: ScriptPage,
  91 + columns,
  92 + showIndexColumn: false,
  93 + clickToRowSelect: false,
  94 + showTableSetting: true,
  95 + bordered: true,
  96 + rowKey: 'id',
  97 + beforeFetch: (params: Recordable) => {
  98 + return { ...unref(props.searchInfo), ...params };
  99 + },
  100 + actionColumn: {
  101 + width: 200,
  102 + title: '操作',
  103 + dataIndex: 'action',
  104 + slots: { customRender: 'action' },
  105 + fixed: 'right',
  106 + },
  107 + });
  108 +
  109 + const handleSuccess = () => {
  110 + reload();
  111 + };
  112 +
  113 + const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions, resetSelectedRowKeys } =
  114 + useBatchDelete(deleteScriptManage, handleSuccess, setProps);
  115 + selectionOptions.rowSelection.getCheckboxProps = (record: Recordable) => {
  116 + // Demo:status为1的选择框禁用
  117 + if (record.status === 1) {
  118 + return { disabled: true };
  119 + } else {
  120 + return { disabled: false };
  121 + }
  122 + };
  123 +
  124 + nextTick(() => {
  125 + setProps(selectionOptions);
  126 + });
  127 +
  128 + const [registerModal, { openModal }] = useModal();
  129 +
  130 + // 新增或编辑
  131 + const handleCreateOrEdit = (record: Recordable | null) => {
  132 + if (record) {
  133 + openModal(true, {
  134 + isUpdate: false,
  135 + record,
  136 + isAuth: '',
  137 + isView: false,
  138 + isTest: false,
  139 + isText: 'confirm',
  140 + isTitle: 'edit',
  141 + });
  142 + } else {
  143 + openModal(true, {
  144 + isAuth: '',
  145 + isUpdate: true,
  146 + isView: false,
  147 + isTest: false,
  148 + isText: 'confirm',
  149 + isTitle: 'add',
  150 + });
  151 + }
  152 + };
  153 + const handleBindTest = (record: Recordable | null) => {
  154 + if (record) {
  155 + openModal(true, {
  156 + isAuth: '',
  157 + isUpdate: false,
  158 + record: record.id,
  159 + isTest: true,
  160 + isText: 'test',
  161 + isTitle: 'test',
  162 + });
  163 + }
  164 + };
  165 + const handleScriptView = (record: Recordable | null) => {
  166 + if (record) {
  167 + openModal(true, {
  168 + isUpdate: true,
  169 + record,
  170 + isView: true,
  171 + });
  172 + }
  173 + };
  174 + const statusChange = async (checked, record) => {
  175 + setProps({
  176 + loading: true,
  177 + });
  178 + setSelectedRowKeys([]);
  179 + resetSelectedRowKeys();
  180 + const newStatus = checked ? 1 : 0;
  181 + const { createMessage } = useMessage();
  182 + try {
  183 + await scriptPagePutApi(record.id, newStatus);
  184 + if (newStatus) {
  185 + createMessage.success(`启用成功`);
  186 + } else {
  187 + createMessage.success('禁用成功');
  188 + }
  189 + } finally {
  190 + setProps({
  191 + loading: false,
  192 + });
  193 + reload();
  194 + }
  195 + };
  196 +
  197 + defineExpose({
  198 + reload: () => {
  199 + reload();
  200 + },
  201 + });
  202 +</script>
... ...
1 1 import { BasicColumn, FormSchema } from '/@/components/Table';
2 2 import { h } from 'vue';
3 3 import { Tag } from 'ant-design-vue';
  4 +import moment from 'moment';
  5 +
  6 +export enum StatusEnum {
  7 + ENABLE = 1,
  8 + DISABLE = 0,
  9 +}
  10 +
4 11 export const columns: BasicColumn[] = [
5 12 {
6 13 title: '名称',
... ... @@ -44,12 +51,23 @@ export const searchFormSchema: FormSchema[] = [
44 51 componentProps: {
45 52 placeholder: '请选择状态',
46 53 options: [
47   - { label: '已启用', value: '1' },
48   - { label: '未启用', value: '0' },
  54 + { label: '已启用', value: StatusEnum.ENABLE },
  55 + { label: '未启用', value: StatusEnum.DISABLE },
49 56 ],
50 57 },
51 58 colProps: { span: 6 },
52 59 },
  60 + {
  61 + field: 'createTime',
  62 + label: '创建时间',
  63 + component: 'RangePicker',
  64 + colProps: { span: 10 },
  65 + componentProps: {
  66 + showTime: {
  67 + defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('23:59:59', 'HH:mm:ss')],
  68 + },
  69 + },
  70 + },
53 71 ];
54 72
55 73 export const formSchema: FormSchema[] = [
... ...
1   -<template>
2   - <div>
3   - <BasicTable @register="registerTable" v-show="isStatus === 0">
4   - <template #toolbar>
5   - <Authority value="api:yt:convert:js:post">
6   - <a-button type="primary" @click="handleCreate"> 新增转换脚本 </a-button>
7   - </Authority>
8   - <Authority value="api:yt:convert:js:delete">
9   - <Popconfirm
10   - title="您确定要批量删除数据"
11   - ok-text="确定"
12   - cancel-text="取消"
13   - @confirm="handleDeleteOrBatchDelete(null)"
14   - >
15   - <a-button color="error" :disabled="hasBatchDelete"> 批量删除 </a-button>
16   - </Popconfirm>
17   - </Authority>
18   - </template>
19   - <template #status="{ record }">
20   - <Switch
21   - :checked="record.status === 1"
22   - :loading="record.pendingStatus"
23   - checkedChildren="启用"
24   - unCheckedChildren="禁用"
25   - @change="(checked:boolean)=>statusChange(checked,record)"
26   - />
27   - </template>
28   - <template #action="{ record }">
29   - <TableAction
30   - :actions="[
31   - {
32   - label: '查看',
33   - auth: 'api:yt:convert:js:get',
34   - icon: 'ant-design:eye-outlined',
35   - onClick: handleView.bind(null, record),
36   - ifShow: record.status == 1,
37   - },
38   - {
39   - label: '编辑',
40   - auth: 'api:yt:convert:js:update',
41   - icon: 'clarity:note-edit-line',
42   - onClick: handleEdit.bind(null, record),
43   - ifShow: record.status == 0,
44   - },
45   - {
46   - label: '删除',
47   - auth: 'api:yt:convert:js:delete',
48   - icon: 'ant-design:delete-outlined',
49   - ifShow: record.status == 0,
50   - color: 'error',
51   - popConfirm: {
52   - title: '是否确认删除',
53   - confirm: handleDeleteOrBatchDelete.bind(null, record),
54   - },
55   - },
56   - ]"
57   - />
58   - </template>
59   - </BasicTable>
60   - <ScriptDrawer
61   - @register="registerDrawer"
62   - @isStatus="handleIsStatus"
63   - ref="scriptDrawerRef"
64   - @success="handleSuccess"
65   - />
66   - <TestScript v-show="isStatus === 1" @isStatus="handleCancelStatus" ref="testScriptRef" />
67   - </div>
68   -</template>
69   -
70 1 <script lang="ts" setup>
71   - import { ref, nextTick } from 'vue';
72   - import { Switch, Popconfirm } from 'ant-design-vue';
73   - import { BasicTable, useTable, TableAction } from '/@/components/Table';
74   - import { columns, searchFormSchema } from './config/config.data';
75   - import { getConvertApi, deleteTransformApi } from '/@/api/device/TransformScriptApi';
76   - import { useDrawer } from '/@/components/Drawer/index';
77   - import ScriptDrawer from './cpns/ScriptDrawer.vue';
78   - import TestScript from './cpns/TestScript.vue';
79   - import { useMessage } from '/@/hooks/web/useMessage';
80   - import { updateTransformScriptStatusApi } from '/@/api/device/TransformScriptApi';
81   - import { useBatchDelete } from '/@/hooks/web/useBatchDelete';
82   - import { Authority } from '/@/components/Authority';
  2 + import { Tabs } from 'ant-design-vue';
  3 + import { RuleChainConversionScript } from './RuleChainConversionScript';
  4 + import { TcpConversionScript } from './TcpConversionScript';
  5 + import { BasicForm, useForm } from '/@/components/Form';
  6 + import { searchFormSchema } from './config/config.data';
  7 + import { nextTick, ref, unref } from 'vue';
  8 +
  9 + enum ActiveKey {
  10 + RULE = 'rule',
  11 + TCP = 'tco',
  12 + }
  13 + const ruleChainTableRefEl = ref<Nullable<InstanceType<typeof RuleChainConversionScript>>>(null);
  14 + const tcpTableRefEl = ref<Nullable<InstanceType<typeof TcpConversionScript>>>(null);
83 15
84   - const handleSuccess = () => {
85   - reload();
86   - };
  16 + const searchInfo = ref<Recordable>({});
87 17
88   - const [registerTable, { reload, setProps, setSelectedRowKeys }] = useTable({
89   - api: getConvertApi,
90   - title: '转换脚本列表',
91   - columns,
92   - useSearchForm: true,
93   - showTableSetting: true,
94   - bordered: true,
95   - showIndexColumn: false,
96   - formConfig: {
97   - labelWidth: 100,
98   - schemas: searchFormSchema,
  18 + const activeKey = ref(ActiveKey.RULE);
  19 +
  20 + const [register, { getFieldsValue }] = useForm({
  21 + schemas: searchFormSchema,
  22 + labelWidth: 120,
  23 + showAdvancedButton: true,
  24 + compact: true,
  25 + fieldMapToTime: [['createTime', ['startTime', 'endTime'], 'x']],
  26 + submitFunc: async () => {
  27 + const value = getFieldsValue();
  28 + searchInfo.value = value;
  29 + console.log(searchInfo);
  30 + await nextTick();
  31 + if (unref(activeKey) === ActiveKey.RULE) {
  32 + unref(ruleChainTableRefEl)?.reload();
  33 + } else {
  34 + unref(tcpTableRefEl)?.reload();
  35 + }
99 36 },
100   - clickToRowSelect: 'false',
101   - rowKey: 'id',
102   - actionColumn: {
103   - width: 180,
104   - title: '操作',
105   - dataIndex: 'action',
106   - slots: { customRender: 'action' },
107   - fixed: 'right',
  37 + resetFunc: async () => {
  38 + searchInfo.value = {};
  39 + await nextTick();
  40 + if (unref(activeKey) === ActiveKey.RULE) {
  41 + unref(ruleChainTableRefEl)?.reload();
  42 + } else {
  43 + unref(tcpTableRefEl)?.reload();
  44 + }
108 45 },
109 46 });
  47 +</script>
110 48
111   - const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions, resetSelectedRowKeys } =
112   - useBatchDelete(deleteTransformApi, handleSuccess, setProps);
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   - };
121   - nextTick(() => {
122   - setProps(selectionOptions);
123   - });
124   - const [registerDrawer, { openDrawer }] = useDrawer();
  49 +<template>
  50 + <section class="w-full h-full p-4">
  51 + <BasicForm @register="register" class="rule-script-manage-form w-full bg-light-50 !pt-4" />
  52 + <main class="mt-4">
  53 + <Tabs v-model:activeKey="activeKey" type="card" class="w-full h-full bg-light-50 !p-4">
  54 + <Tabs.TabPane tab="规则链转换脚本" :key="ActiveKey.RULE">
  55 + <RuleChainConversionScript
  56 + ref="ruleChainTableRefEl"
  57 + :search-info="searchInfo"
  58 + class="p-4 bg-neutral-100"
  59 + />
  60 + </Tabs.TabPane>
  61 + <Tabs.TabPane tab="TCP转换脚本" :key="ActiveKey.TCP">
  62 + <TcpConversionScript
  63 + ref="tcpTableRefEl"
  64 + :search-info="searchInfo"
  65 + class="p-4 bg-neutral-100"
  66 + />
  67 + </Tabs.TabPane>
  68 + </Tabs>
  69 + </main>
  70 + </section>
  71 +</template>
125 72
126   - const isStatus = ref(0);
127   - const testScriptRef = ref();
128   - const scriptDrawerRef = ref();
129   - const handleIsStatus = ({ status, jsCode }) => {
130   - isStatus.value = status;
131   - testScriptRef.value.aceEditor.setValue(jsCode);
132   - };
133   - const handleCancelStatus = ({ status, emitType }) => {
134   - openDrawer(true);
135   - isStatus.value = status;
136   - if (emitType === 'ok') {
137   - const jsCode = testScriptRef.value.aceEditor.getValue();
138   - scriptDrawerRef.value.aceEditor.setValue(jsCode);
  73 +<style lang="less" scoped>
  74 + .rule-script-manage-form {
  75 + :deep(.ant-row) {
  76 + @apply w-full;
139 77 }
140   - };
141   - const handleCreate = () => {
142   - nextTick(() => {
143   - openDrawer(true, {
144   - isUpdate: false,
145   - });
146   - });
147   - };
148   - const handleEdit = (record: Recordable) => {
149   - nextTick(() => {
150   - openDrawer(true, { isUpdate: true, record });
151   - });
152   - };
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   - await updateTransformScriptStatusApi(newStatus, record.id);
163   - if (newStatus) {
164   - createMessage.success(`启用成功`);
165   - } else {
166   - createMessage.success('禁用成功');
167   - }
168   - } finally {
169   - setProps({
170   - loading: false,
171   - });
172   - reload();
173   - }
174   - };
175   - function handleView(record: Recordable) {
176   - nextTick(() => {
177   - openDrawer(true, {
178   - record,
179   - isUpdate: 'view',
180   - });
181   - });
182 78 }
183   -</script>
  79 +</style>
... ...