Commit 03e4203ed724b3e0ef68644b89abe52cbae4b4b0

Authored by xp.Huang
2 parents f49abb9b 8d9d93a2

Merge branch 'ft_local_dev' into 'main'

联调脚本管理

See merge request huang/yun-teng-iot-front!369
  1 +import { BasicPageParams } from '/@/api/model/baseModel';
  2 +export type ScriptQueryParam = BasicPageParams & ScriptParam;
  3 +
  4 +export type ScriptParam = {
  5 + name?: string;
  6 + transportType?: string;
  7 + status?: number;
  8 +};
  9 +
  10 +export interface ScriptModel {
  11 + convertJs: string;
  12 + createTime: '2022-10-31T01:19:57.912Z';
  13 + creator: string;
  14 + description: string;
  15 + id: string;
  16 + name: string;
  17 + status: 0;
  18 + tenantId: string;
  19 + updateTime: '2022-10-31T01:19:57.912Z';
  20 + updater: string;
  21 +}
  22 +
  23 +export interface ScriptRecord {
  24 + id: string;
  25 + creator: string;
  26 + createTime: string;
  27 + updater: string;
  28 + updateTime: string;
  29 + name: string;
  30 + convertJs: string;
  31 + enabled: boolean;
  32 + tenantId: string;
  33 + description: string;
  34 + status: boolean;
  35 +}
... ...
  1 +import { defHttp } from '/@/utils/http/axios';
  2 +import { ScriptParam, ScriptQueryParam, ScriptRecord } from './model/scriptModel';
  3 +import { PaginationResult } from '/#/axios';
  4 +
  5 +enum ScriptManagerApi {
  6 + SCRIPT_POST_URL = '/js',
  7 + SCRIPT_GET_URL = '/js',
  8 + SCRIPT_DELETE_URL = '/js',
  9 + SCRIPT_MELIST_URL = '/js/me/list',
  10 + SCRIPT_TEST_URL = '/js/test',
  11 +}
  12 +
  13 +export const ScriptPage = (params: ScriptQueryParam) => {
  14 + return defHttp.get<PaginationResult<ScriptRecord>>({
  15 + url: ScriptManagerApi.SCRIPT_GET_URL,
  16 + params,
  17 + });
  18 +};
  19 +
  20 +//删除脚本
  21 +export const deleteScriptManage = (ids: string[]) => {
  22 + return defHttp.delete({
  23 + url: ScriptManagerApi.SCRIPT_DELETE_URL,
  24 + data: {
  25 + ids: ids,
  26 + },
  27 + });
  28 +};
  29 +
  30 +// 创建或编辑脚本
  31 +export const createOrEditScriptManage = (data) => {
  32 + return defHttp.post<ScriptParam>({
  33 + url: ScriptManagerApi.SCRIPT_POST_URL,
  34 + data,
  35 + });
  36 +};
  37 +
  38 +// 查询脚本详情
  39 +export const getScriptManageDetail = (id: string) => {
  40 + return defHttp.get({
  41 + url: ScriptManagerApi.SCRIPT_GET_URL + `/${id}`,
  42 + });
  43 +};
  44 +
  45 +// 获取脚本选项列表
  46 +export const getScriptManageMeList = () => {
  47 + return defHttp.get({
  48 + url: ScriptManagerApi.SCRIPT_MELIST_URL,
  49 + });
  50 +};
  51 +
  52 +// 测试脚本执行结果
  53 +export const testScriptManage = (data) => {
  54 + return defHttp.post<ScriptParam>({
  55 + url: ScriptManagerApi.SCRIPT_TEST_URL,
  56 + data,
  57 + });
  58 +};
... ...
1   -<template>
2   - <div>
3   - <BasicModal
4   - destroyOnClose
5   - v-bind="$attrs"
6   - width="60rem"
7   - @register="register"
8   - :title="getTitle"
9   - :minHeight="500"
10   - @cancel="handleCancel"
11   - @ok="handleSubmit"
12   - >
13   - <ConverScript :ifAdd="!isUpdate ? false : true" ref="converScriptRef" />
14   - </BasicModal>
15   - </div>
16   -</template>
17   -<script setup lang="ts">
18   - import { ref, computed, unref } from 'vue';
19   - import { BasicModal, useModalInner } from '/@/components/Modal';
20   - import ConverScript from '/@/views/scriptmanage/converscript/ConverScript.vue';
21   -
22   - const converScriptRef = ref<InstanceType<typeof ConverScript>>();
23   - const getTitle = computed(() => (isUpdate.value ? '测试脚本' : '新建脚本'));
24   - const isUpdate = ref(false);
25   - const [register, { setModalProps, closeModal }] = useModalInner(async (data) => {
26   - setModalProps({ loading: true });
27   - handleCancel(false);
28   - isUpdate.value = data.isUpdate;
29   - converScriptRef.value?.initEditor(data.record?.configuration?.jsScript);
30   - setModalProps({ loading: false });
31   - const title = !unref(isUpdate) ? '测试脚本' : '新建脚本';
32   - const okText = !unref(isUpdate) ? '测试' : '确定';
33   - setModalProps({ title, showOkBtn: true, showCancelBtn: true, okText });
34   - // converScriptRef.value?.setFormData();
35   - });
36   - const handleSubmit = async () => {
37   - const val = await converScriptRef.value?.getFormData();
38   - console.log(val);
39   - handleCancel(true);
40   - };
41   - const handleCancel = (flag) => {
42   - if (flag) {
43   - closeModal();
44   - }
45   - converScriptRef.value?.resetFormData();
46   - };
47   -</script>
48   -<style lang="less" scoped>
49   - @import url('/@/views/scriptmanage/converscript/ConverScriptModal.less');
50   -</style>
... ... @@ -27,7 +27,7 @@
27 27 >
28 28 </template>
29 29 </BasicForm>
30   - <ConverScriptModal @register="registerModal" />
  30 + <ConverScriptModal @register="registerModal" @success="handleSuccess" />
31 31 </div>
32 32 </template>
33 33 <script lang="ts" setup>
... ... @@ -37,24 +37,33 @@
37 37 import { SelectTypes } from 'ant-design-vue/es/select';
38 38 import { Select } from 'ant-design-vue';
39 39 import { useModal } from '/@/components/Modal';
40   - import ConverScriptModal from './ConverScriptModal.vue';
41 40 import { useMessage } from '/@/hooks/web/useMessage';
  41 + import { getScriptManageMeList } from '/@/api/scriptmanage/scriptManager';
  42 + import ConverScriptModal from '/@/views/scriptmanage/converscript/ConverScriptModal.vue';
42 43
43 44 const { createMessage } = useMessage();
44 45 const selectScript = reactive({
45 46 script: null,
46 47 });
47   - const selectOptions: Ref<SelectTypes['options']> = ref([
48   - {
49   - label: '电表转换脚本',
50   - value: '2dadsasd212asddafd1',
51   - },
52   - {
53   - label: '水表转换脚本',
54   - value: 'dasdads776216dasdb1212sx',
55   - },
56   - ]);
57   - onMounted(() => {});
  48 + const selectOptions: Ref<SelectTypes['options']> = ref([]);
  49 + onMounted(async () => {
  50 + const res = await getScriptManageMeList();
  51 + selectOptions.value = res.map((m) => {
  52 + return {
  53 + label: m.name,
  54 + value: m.id,
  55 + };
  56 + });
  57 + });
  58 + const handleSuccess = async () => {
  59 + const res = await getScriptManageMeList();
  60 + selectOptions.value = res.map((m) => {
  61 + return {
  62 + label: m.name,
  63 + value: m.id,
  64 + };
  65 + });
  66 + };
58 67
59 68 const [register] = useForm({
60 69 labelWidth: 180,
... ... @@ -70,10 +79,17 @@
70 79 if (c === 'add') {
71 80 openModal(true, {
72 81 isUpdate: true,
  82 + isView: false,
  83 + isTest: false,
  84 + isText: 'confirm',
  85 + isTitle: 'add',
73 86 });
74 87 } else {
75 88 openModal(true, {
76 89 isUpdate: false,
  90 + isTest: true,
  91 + isText: 'test',
  92 + isTitle: 'test',
77 93 });
78 94 }
79 95 };
... ... @@ -96,7 +112,7 @@
96 112 selectScript.script = null;
97 113 };
98 114 const setFormData = (v) => {
99   - selectScript.script = v;
  115 + selectScript.script = v?.scriptId;
100 116 };
101 117 defineExpose({
102 118 getFormData,
... ...
... ... @@ -10,22 +10,22 @@
10 10 >
11 11 <a-form-item
12 12 :label="ifAdd ? '名称' : '输入参数'"
13   - :name="ifAdd ? 'scriptName' : 'inputParams'"
  13 + :name="ifAdd ? 'name' : 'inputParams'"
14 14 :rules="[{ required: true, message: ifAdd ? '请输入脚本名称' : '请输入参数' }]"
15 15 >
16   - <a-input v-if="ifAdd" v-model:value="scriptForm.scriptName" placeholder="请输入脚本名称" />
  16 + <a-input v-if="ifAdd" v-model:value="scriptForm.name" placeholder="请输入脚本名称" />
17 17 <a-input v-else v-model:value="scriptForm.inputParams" placeholder="请输入参数" />
18 18 </a-form-item>
19 19 <a-form-item
20 20 label="上报数据类型"
21 21 name="reportType"
22   - :rules="[{ required: true, message: '请选择上报数据类型' }]"
  22 + :rules="[{ required: false, message: '请选择上报数据类型' }]"
23 23 >
24 24 <a-space direction="vertical">
25 25 <a-radio-group v-model:value="scriptForm.reportType" :options="typeOptions" />
26 26 </a-space>
27 27 </a-form-item>
28   - <a-form-item label="脚本内容" name="scriptContent">
  28 + <a-form-item label="脚本内容" name="convertJs">
29 29 <Card title="脚本内容" :bodyStyle="{ padding: 0, height: '280px' }">
30 30 <template #extra>
31 31 <a-button @click="handleFormat" size="small">格式化</a-button>
... ... @@ -41,12 +41,12 @@
41 41 </a-form-item>
42 42 <a-form-item
43 43 :label="ifAdd ? '备注' : '输出参数'"
44   - :name="ifAdd ? 'scriptRemark' : 'outputParams'"
  44 + :name="ifAdd ? 'description' : 'outputParams'"
45 45 >
46 46 <a-textarea
47 47 :rows="5"
48 48 v-if="ifAdd"
49   - v-model:value="scriptForm.scriptRemark"
  49 + v-model:value="scriptForm.description"
50 50 placeholder="请输入备注"
51 51 />
52 52 <a-textarea
... ... @@ -76,9 +76,9 @@
76 76 ifAdd: { type: Boolean, default: true },
77 77 });
78 78 const scriptForm = reactive({
79   - scriptName: '',
80   - scriptRemark: '',
81   - scriptContent: '',
  79 + name: '',
  80 + description: '',
  81 + convertJs: '',
82 82 inputParams: '',
83 83 outputParams: '',
84 84 reportType: 'HEX',
... ... @@ -127,7 +127,7 @@
127 127 `
128 128 );
129 129 beautify(aceEditor.value.session);
130   - scriptForm.scriptContent = aceEditor.value.getValue();
  130 + scriptForm.convertJs = aceEditor.value.getValue();
131 131 };
132 132 const handleCopy = () => {
133 133 const valueRef = aceEditor.value.getValue();
... ... @@ -144,21 +144,27 @@
144 144 const formRef = ref();
145 145 const getFormData = async () => {
146 146 const value = await formRef.value.validateFields();
147   - scriptForm.scriptContent = aceEditor.value.getValue();
148   - if (scriptForm.scriptContent == '') {
  147 + scriptForm.convertJs = aceEditor.value.getValue();
  148 + if (scriptForm.convertJs == '') {
149 149 createMessage.error('请编写脚本内容');
150 150 throw '请编写脚本内容';
151 151 }
152 152 if (!value) return;
153 153 return {
154 154 ...value,
155   - ...{ scriptContent: scriptForm.scriptContent },
  155 + ...{ convertJs: scriptForm.convertJs },
156 156 };
157 157 };
158 158 const setFormData = (v) => {
159 159 for (let i in scriptForm) {
160 160 Reflect.set(scriptForm, i, v[i]);
161 161 }
  162 + aceEditor.value.setValue(v.convertJs);
  163 + handleFormat();
  164 + };
  165 + const setScriptContentData = (v) => {
  166 + aceEditor.value.setValue(v.convertJs);
  167 + handleFormat();
162 168 };
163 169 const resetFormData = () => {
164 170 for (let i in scriptForm) {
... ... @@ -172,6 +178,7 @@
172 178 getFormData,
173 179 resetFormData,
174 180 setFormData,
  181 + setScriptContentData,
175 182 });
176 183 </script>
177 184 <style lang="less" scoped>
... ...
... ... @@ -15,10 +15,18 @@
15 15 </div>
16 16 </template>
17 17 <script setup lang="ts">
18   - import { ref, computed, unref } from 'vue';
  18 + import { ref, computed, unref, reactive } from 'vue';
19 19 import { BasicModal, useModalInner } from '/@/components/Modal';
20 20 import ConverScript from './ConverScript.vue';
  21 + import {
  22 + createOrEditScriptManage,
  23 + getScriptManageDetail,
  24 + testScriptManage,
  25 + } from '/@/api/scriptmanage/scriptManager';
  26 + import { useMessage } from '/@/hooks/web/useMessage';
21 27
  28 + const emits = defineEmits(['success', 'register']);
  29 + const { createMessage } = useMessage();
22 30 const converScriptRef = ref<InstanceType<typeof ConverScript>>();
23 31 const getTitle = computed(() => (isUpdate.value ? '编辑转换脚本' : '新增转换脚本'));
24 32 const isUpdate = ref(false);
... ... @@ -26,6 +34,9 @@
26 34 const isTest = ref(false);
27 35 const isText = ref('');
28 36 const isTitle = ref('');
  37 + const editData = reactive({
  38 + data: {},
  39 + });
29 40 const [register, { setModalProps, closeModal }] = useModalInner(async (data) => {
30 41 setModalProps({ loading: true });
31 42 handleCancel(false);
... ... @@ -34,6 +45,7 @@
34 45 isTest.value = data.isTest;
35 46 isText.value = data.isText;
36 47 isTitle.value = data.isTitle;
  48 + editData.data = data.record;
37 49 converScriptRef.value?.initEditor(data.record?.configuration?.jsScript);
38 50 setModalProps({ loading: false });
39 51 if (!unref(isViewDetail)) {
... ... @@ -44,17 +56,44 @@
44 56 ? '新增转换脚本'
45 57 : '测试转换脚本';
46 58 const okText = isText.value == 'test' ? '测试' : '确定';
  59 + if (unref(isTitle) == 'edit') {
  60 + converScriptRef.value?.setFormData(data.record);
  61 + }
  62 + if (unref(isTitle) == 'test') {
  63 + converScriptRef.value?.setScriptContentData(data.record);
  64 + }
47 65 setModalProps({ title, showOkBtn: true, showCancelBtn: true, okText });
48 66 if (!unref(isUpdate)) {
49 67 }
50 68 } else {
51 69 setModalProps({ showOkBtn: false, showCancelBtn: false, title: '查看转换脚本' });
  70 + const res = await getScriptManageDetail(data.record.id);
  71 + converScriptRef.value?.setFormData(res || {});
52 72 }
53 73 });
  74 +
54 75 const handleSubmit = async () => {
55   - const val = await converScriptRef.value?.getFormData();
56   - console.log(val);
57   - handleCancel(true);
  76 + setModalProps({ loading: true });
  77 + try {
  78 + const val = await converScriptRef.value?.getFormData();
  79 + const tempObj = {
  80 + ...editData.data,
  81 + ...val,
  82 + };
  83 + (await isText.value) == 'test' ? testScriptManage(val) : createOrEditScriptManage(tempObj);
  84 + createMessage.success(
  85 + unref(isTitle) == 'edit'
  86 + ? '编辑转换脚本成功'
  87 + : unref(isTitle) == 'add'
  88 + ? '新增转换脚本成功'
  89 + : '测试转换脚本成功'
  90 + );
  91 + closeModal();
  92 + emits('success');
  93 + } catch {
  94 + } finally {
  95 + setModalProps({ loading: false });
  96 + }
58 97 };
59 98 const handleCancel = (flag) => {
60 99 if (flag) {
... ...
... ... @@ -8,15 +8,15 @@ import { findDictItemByCode } from '/@/api/system/dict';
8 8 export const columns: BasicColumn[] = [
9 9 {
10 10 title: '脚本名称',
11   - dataIndex: 'reportConfigName',
  11 + dataIndex: 'name',
12 12 width: 80,
13 13 },
14 14 {
15 15 title: '脚本状态',
16   - dataIndex: 'organizationName',
  16 + dataIndex: 'status',
17 17 width: 120,
18 18 customRender: ({ record }) => {
19   - const status = record.organizationName;
  19 + const status = record.status;
20 20 const color = status == 1 ? 'green' : 'red';
21 21 const text = status == 1 ? '启用' : '禁用';
22 22 return h(Tag, { color: color }, () => text);
... ... @@ -24,18 +24,18 @@ export const columns: BasicColumn[] = [
24 24 },
25 25 {
26 26 title: '脚本内容',
27   - dataIndex: 'dataType',
  27 + dataIndex: 'convertJs',
28 28 width: 120,
29   - slots: { customRender: 'dataType' },
  29 + slots: { customRender: 'convertJs' },
30 30 },
31 31 {
32 32 title: '描述',
33   - dataIndex: 'executeWay',
  33 + dataIndex: 'description',
34 34 width: 120,
35 35 },
36 36 {
37 37 title: '创建时间',
38   - dataIndex: 'executeTime',
  38 + dataIndex: 'createTime',
39 39 width: 180,
40 40 },
41 41 ];
... ...
... ... @@ -2,10 +2,10 @@
2 2 <div>
3 3 <BasicTable :clickToRowSelect="false" @register="registerTable" :searchInfo="searchInfo">
4 4 <template #toolbar>
5   - <Authority value="">
  5 + <Authority value="api:yt:js:post">
6 6 <a-button type="primary" @click="handleCreateOrEdit(null)"> 新增转换脚本 </a-button>
7 7 </Authority>
8   - <Authority value="">
  8 + <Authority value="api:yt:js:delete">
9 9 <Popconfirm
10 10 title="您确定要批量删除数据"
11 11 ok-text="确定"
... ... @@ -16,7 +16,7 @@
16 16 </Popconfirm>
17 17 </Authority>
18 18 </template>
19   - <template #dataType="{ record }">
  19 + <template #convertJs="{ record }">
20 20 <a-button type="text" @click="handleScriptView(record)">
21 21 <span style="color: #377dff">查看脚本</span>
22 22 </a-button>
... ... @@ -33,13 +33,13 @@
33 33 {
34 34 label: '编辑',
35 35 icon: 'clarity:note-edit-line',
36   - auth: '',
  36 + auth: 'api:yt:js:update',
37 37 onClick: handleCreateOrEdit.bind(null, record),
38 38 },
39 39 {
40 40 label: '删除',
41 41 icon: 'ant-design:delete-outlined',
42   - auth: '',
  42 + auth: 'api:yt:js:delete',
43 43 color: 'error',
44 44 popConfirm: {
45 45 title: '是否确认删除',
... ... @@ -50,26 +50,25 @@
50 50 />
51 51 </template>
52 52 </BasicTable>
53   - <ConverScriptModal @register="registerModal" />
  53 + <ConverScriptModal @register="registerModal" @success="handleSuccess" />
54 54 </div>
55 55 </template>
56 56
57 57 <script lang="ts" setup>
58 58 import { reactive, nextTick } from 'vue';
59 59 import { BasicTable, useTable, TableAction } from '/@/components/Table';
60   - import { searchFormSchema, columns, mockData } from './config.data';
  60 + import { searchFormSchema, columns } from './config.data';
61 61 import { Authority } from '/@/components/Authority';
62 62 import { useBatchDelete } from '/@/hooks/web/useBatchDelete';
63 63 import { Popconfirm } from 'ant-design-vue';
64 64 import { useModal } from '/@/components/Modal';
65 65 import ConverScriptModal from './ConverScriptModal.vue';
66   - import { deleteExportManage } from '/@/api/export/exportManager';
  66 + import { ScriptPage, deleteScriptManage } from '/@/api/scriptmanage/scriptManager';
67 67
68 68 const searchInfo = reactive<Recordable>({});
69 69 const [registerTable, { reload, setProps }] = useTable({
70 70 title: '转换脚本列表',
71   - // api: exportPage,
72   - api: mockData,
  71 + api: ScriptPage,
73 72 columns,
74 73 showIndexColumn: false,
75 74 clickToRowSelect: false,
... ... @@ -96,7 +95,7 @@
96 95 };
97 96
98 97 const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions } = useBatchDelete(
99   - deleteExportManage,
  98 + deleteScriptManage,
100 99 handleSuccess,
101 100 setProps
102 101 );
... ...