Commit 4c930d7b3bb424b5617313a300e427efefc81fae

Authored by fengwotao
1 parent 53e42e29

chore: 恢复合并到main_dev丢失的代码(公共接口管理)

@@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
18 placeholder="请选择" 18 placeholder="请选择"
19 :options="selectOptions" 19 :options="selectOptions"
20 @change="handleChange" 20 @change="handleChange"
  21 + @dropdownVisibleChange="hanldeDropdownVisibleChange"
21 allowClear 22 allowClear
22 /> 23 />
23 </td> 24 </td>
@@ -121,6 +122,8 @@ @@ -121,6 +122,8 @@
121 } 122 }
122 }; 123 };
123 124
  125 + const hanldeDropdownVisibleChange = () => handleChange();
  126 +
124 //Select互斥 127 //Select互斥
125 const handleChange = () => { 128 const handleChange = () => {
126 selectOptions.value.forEach((ele) => { 129 selectOptions.value.forEach((ele) => {
@@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
18 placeholder="请选择" 18 placeholder="请选择"
19 :options="selectOptions" 19 :options="selectOptions"
20 @change="handleChange" 20 @change="handleChange"
  21 + @dropdownVisibleChange="hanldeDropdownVisibleChange"
21 allowClear 22 allowClear
22 /> 23 />
23 </td> 24 </td>
@@ -139,6 +140,8 @@ @@ -139,6 +140,8 @@
139 }); 140 });
140 }; 141 };
141 142
  143 + const hanldeDropdownVisibleChange = () => handleChange();
  144 +
142 //获取数据 145 //获取数据
143 const getValue = () => { 146 const getValue = () => {
144 const assemblyData = tableArray.content.map((it) => { 147 const assemblyData = tableArray.content.map((it) => {
@@ -31,6 +31,7 @@ @@ -31,6 +31,7 @@
31 import moment from 'moment'; 31 import moment from 'moment';
32 import { useUtils } from '../../../hooks/useUtils'; 32 import { useUtils } from '../../../hooks/useUtils';
33 import JsonEditor from '../../SimpleRequest/components/jsonEditor.vue'; 33 import JsonEditor from '../../SimpleRequest/components/jsonEditor.vue';
  34 + import { useMessage } from '/@/hooks/web/useMessage';
34 35
35 const emits = defineEmits(['testBodyInterface']); 36 const emits = defineEmits(['testBodyInterface']);
36 37
@@ -40,6 +41,8 @@ @@ -40,6 +41,8 @@
40 }, 41 },
41 }); 42 });
42 43
  44 + const { createMessage } = useMessage();
  45 +
43 const showTestEditCell = ref(false); 46 const showTestEditCell = ref(false);
44 47
45 const excuteData = ref({}); 48 const excuteData = ref({});
@@ -111,6 +114,7 @@ @@ -111,6 +114,7 @@
111 return { 114 return {
112 key, 115 key,
113 value, 116 value,
  117 + required: it.required,
114 }; 118 };
115 }); 119 });
116 }; 120 };
@@ -120,6 +124,11 @@ @@ -120,6 +124,11 @@
120 let params: any = {}; 124 let params: any = {};
121 if (props.data?.type === 'x-www-form-urlencoded' || props.data?.type === 'form-data') { 125 if (props.data?.type === 'x-www-form-urlencoded' || props.data?.type === 'form-data') {
122 const getTable = getTestTableKeyValue(); 126 const getTable = getTestTableKeyValue();
  127 + const hasRequired = getTable?.some((it) => it.required === true && !it.value);
  128 + if (hasRequired) {
  129 + createMessage.error('参数不能为空');
  130 + throw new Error('参数不能为空');
  131 + }
123 getTable?.map((it) => (params[it.key!] = it.value!)); 132 getTable?.map((it) => (params[it.key!] = it.value!));
124 } else if (props.data?.type === 'json') { 133 } else if (props.data?.type === 'json') {
125 params = jsonEditorRef.value?.getJsonValue(); 134 params = jsonEditorRef.value?.getJsonValue();
@@ -243,7 +243,9 @@ @@ -243,7 +243,9 @@
243 if (f.key === 'organizationId') organizationId = f.value; 243 if (f.key === 'organizationId') organizationId = f.value;
244 if (f.key === 'entityId') f.value = null; 244 if (f.key === 'entityId') f.value = null;
245 }); 245 });
246 - getAttributeOptions({ deviceProfileId: e.value }); 246 + if (e.value) {
  247 + getAttributeOptions({ deviceProfileId: e.value });
  248 + }
247 if (organizationId !== '') { 249 if (organizationId !== '') {
248 getEntityOptions(organizationId, e.value); 250 getEntityOptions(organizationId, e.value);
249 } 251 }
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 <a-col :span="2"> 测试结果 </a-col> 8 <a-col :span="2"> 测试结果 </a-col>
9 <a-col :span="22"> 9 <a-col :span="22">
10 <a-textarea 10 <a-textarea
11 - v-if="ifWebSocket === '2'" 11 + v-if="isWebSocketType === '2'"
12 allow-clear 12 allow-clear
13 show-count 13 show-count
14 v-model:value="testResult" 14 v-model:value="testResult"
@@ -29,14 +29,13 @@ @@ -29,14 +29,13 @@
29 </div> 29 </div>
30 </template> 30 </template>
31 <script lang="ts" setup name="testRequest"> 31 <script lang="ts" setup name="testRequest">
32 - import { nextTick, ref, reactive } from 'vue'; 32 + import { nextTick, ref, reactive, onUnmounted } from 'vue';
33 import { Button } from 'ant-design-vue'; 33 import { Button } from 'ant-design-vue';
34 import { otherHttp } from '/@/utils/http/axios'; 34 import { otherHttp } from '/@/utils/http/axios';
35 import { useWebSocket } from '@vueuse/core'; 35 import { useWebSocket } from '@vueuse/core';
36 import { JWT_TOKEN_KEY } from '/@/enums/cacheEnum'; 36 import { JWT_TOKEN_KEY } from '/@/enums/cacheEnum';
37 import { getAuthCache } from '/@/utils/auth'; 37 import { getAuthCache } from '/@/utils/auth';
38 - import { useMessage } from '/@/hooks/web/useMessage';  
39 - // import { useGlobSetting } from '/@/hooks/setting'; 38 + import { useUtils } from '../../../hooks/useUtils';
40 39
41 const emits = defineEmits(['emitExcute']); 40 const emits = defineEmits(['emitExcute']);
42 41
@@ -48,16 +47,10 @@ @@ -48,16 +47,10 @@
48 47
49 const showTestFlag = ref(false); 48 const showTestFlag = ref(false);
50 49
51 - const ifWebSocket = ref('');  
52 -  
53 - const { createMessage } = useMessage();  
54 -  
55 const token = getAuthCache(JWT_TOKEN_KEY); 50 const token = getAuthCache(JWT_TOKEN_KEY);
56 51
57 const socketUrls = ref(''); 52 const socketUrls = ref('');
58 53
59 - // const { socketUrl } = useGlobSetting();  
60 -  
61 const socketMessage: any = reactive({ 54 const socketMessage: any = reactive({
62 server: ``, 55 server: ``,
63 sendValue: { 56 sendValue: {
@@ -89,6 +82,8 @@ @@ -89,6 +82,8 @@
89 82
90 const httpResult = ref(''); 83 const httpResult = ref('');
91 84
  85 + const isWebSocketType = ref('');
  86 +
92 //执行测试接口 87 //执行测试接口
93 const handleExcute = () => { 88 const handleExcute = () => {
94 emits('emitExcute'); 89 emits('emitExcute');
@@ -99,18 +94,23 @@ @@ -99,18 +94,23 @@
99 await nextTick(); 94 await nextTick();
100 //获取Params和Header和Body 95 //获取Params和Header和Body
101 const Objects = props.data; 96 const Objects = props.data;
102 - const isWebSocketType = Objects?.method; 97 + isWebSocketType.value = Objects?.method;
103 const apiType = Objects?.apiType; 98 const apiType = Objects?.apiType;
104 const url = Objects?.apiGetUrl; 99 const url = Objects?.apiGetUrl;
105 const headers = Objects?.Header?.params; 100 const headers = Objects?.Header?.params;
106 const params = Objects?.Params?.params; 101 const params = Objects?.Params?.params;
107 const body = Objects?.Body?.params; 102 const body = Objects?.Body?.params;
108 const apiUrl = url?.restfulFormat(params); 103 const apiUrl = url?.restfulFormat(params);
109 - ifWebSocket.value = isWebSocketType;  
110 - if (isWebSocketType === '2') { 104 + if (isWebSocketType.value === '2') {
111 socketUrls.value = url; 105 socketUrls.value = url;
112 socketMessage.server = `${socketUrls.value}?token=${token}`; 106 socketMessage.server = `${socketUrls.value}?token=${token}`;
113 - websocketRequest(params); 107 + const list = Object.values(params);
  108 + const isEmpty = list.some((it) => it === '' || null || undefined);
  109 + if (!isEmpty) {
  110 + websocketRequest(params);
  111 + } else {
  112 + resetValue(false);
  113 + }
114 } else { 114 } else {
115 const resp = await otherHttpRequest(apiType, apiUrl?.split('{?')[0], headers, params, body); 115 const resp = await otherHttpRequest(apiType, apiUrl?.split('{?')[0], headers, params, body);
116 if (!resp) return; 116 if (!resp) return;
@@ -119,7 +119,7 @@ @@ -119,7 +119,7 @@
119 }; 119 };
120 120
121 //websocket请求 121 //websocket请求
122 - const websocketRequest = (params) => { 122 + const websocketRequest = (params, destroy = false) => {
123 //websocket请求 123 //websocket请求
124 Reflect.deleteProperty(params, 'deviceProfileId'); 124 Reflect.deleteProperty(params, 'deviceProfileId');
125 Reflect.deleteProperty(params, 'organizationId'); 125 Reflect.deleteProperty(params, 'organizationId');
@@ -140,12 +140,17 @@ @@ -140,12 +140,17 @@
140 console.log('断开连接了'); 140 console.log('断开连接了');
141 close(); 141 close();
142 }, 142 },
143 - onError() {  
144 - createMessage.error('webSocket连接超时,请联系管理员');  
145 - }, 143 + onError() {},
146 }); 144 });
  145 + if (destroy) close();
147 }; 146 };
148 147
  148 + onUnmounted(() => {
  149 + if (isWebSocketType.value === '2') {
  150 + websocketRequest(null, true);
  151 + }
  152 + });
  153 +
149 //TODO: 待优化 项目自带第三方请求 154 //TODO: 待优化 项目自带第三方请求
150 const otherHttpRequest = async ( 155 const otherHttpRequest = async (
151 apiType, 156 apiType,
@@ -165,8 +170,9 @@ @@ -165,8 +170,9 @@
165 } 170 }
166 ); 171 );
167 case 'POST': 172 case 'POST':
  173 + const { convertObj } = useUtils();
168 return await otherHttp.post( 174 return await otherHttp.post(
169 - { url: apiUrl, data: body, headers, params }, 175 + { url: `${apiUrl}?${convertObj(params)}`, data: body, headers },
170 { 176 {
171 apiUrl: '', 177 apiUrl: '',
172 joinPrefix, 178 joinPrefix,
@@ -189,7 +195,7 @@ @@ -189,7 +195,7 @@
189 } 195 }
190 httpResult.value = '测试结果为:'; 196 httpResult.value = '测试结果为:';
191 testResult.value = '测试结果为:'; 197 testResult.value = '测试结果为:';
192 - ifWebSocket.value = '0'; 198 + isWebSocketType.value = '0';
193 }; 199 };
194 200
195 const showTest = () => (showTestFlag.value = true); 201 const showTest = () => (showTestFlag.value = true);
@@ -20,6 +20,7 @@ @@ -20,6 +20,7 @@
20 import { ref, nextTick } from 'vue'; 20 import { ref, nextTick } from 'vue';
21 import { Button } from 'ant-design-vue'; 21 import { Button } from 'ant-design-vue';
22 import TestHeaderEditCellTable from './testEditHeaderCellTable.vue'; 22 import TestHeaderEditCellTable from './testEditHeaderCellTable.vue';
  23 + import { useMessage } from '/@/hooks/web/useMessage';
23 24
24 const emits = defineEmits(['testHeaderInterface']); 25 const emits = defineEmits(['testHeaderInterface']);
25 26
@@ -29,6 +30,8 @@ @@ -29,6 +30,8 @@
29 }, 30 },
30 }); 31 });
31 32
  33 + const { createMessage } = useMessage();
  34 +
32 const showTestEditCell = ref(false); 35 const showTestEditCell = ref(false);
33 36
34 const excuteData = ref({}); 37 const excuteData = ref({});
@@ -59,6 +62,11 @@ @@ -59,6 +62,11 @@
59 //获取数据 62 //获取数据
60 const getTestValue = () => { 63 const getTestValue = () => {
61 const getTable = getTestTableKeyValue(); 64 const getTable = getTestTableKeyValue();
  65 + const hasRequired = getTable?.some((it) => it.required === true && !it.value);
  66 + if (hasRequired) {
  67 + createMessage.error('参数不能为空');
  68 + throw new Error('参数不能为空');
  69 + }
62 const params: any = {}; 70 const params: any = {};
63 getTable?.map((it: any) => (params[it.key!] = it.value!)); 71 getTable?.map((it: any) => (params[it.key!] = it.value!));
64 excuteData.value = { 72 excuteData.value = {
@@ -22,6 +22,7 @@ @@ -22,6 +22,7 @@
22 import TestParamsCellTable from './testEditParamsCellTable.vue'; 22 import TestParamsCellTable from './testEditParamsCellTable.vue';
23 import moment from 'moment'; 23 import moment from 'moment';
24 import { useUtils } from '../../../hooks/useUtils'; 24 import { useUtils } from '../../../hooks/useUtils';
  25 + import { useMessage } from '/@/hooks/web/useMessage';
25 26
26 const emits = defineEmits(['testParamsInterface']); 27 const emits = defineEmits(['testParamsInterface']);
27 28
@@ -31,6 +32,8 @@ @@ -31,6 +32,8 @@
31 }, 32 },
32 }); 33 });
33 34
  35 + const { createMessage } = useMessage();
  36 +
34 const showTestEditCell = ref(false); 37 const showTestEditCell = ref(false);
35 38
36 const excuteData = ref({}); 39 const excuteData = ref({});
@@ -92,6 +95,7 @@ @@ -92,6 +95,7 @@
92 return { 95 return {
93 key, 96 key,
94 value, 97 value,
  98 + required: it.required,
95 }; 99 };
96 }); 100 });
97 }; 101 };
@@ -99,6 +103,11 @@ @@ -99,6 +103,11 @@
99 //获取数据 103 //获取数据
100 const getTestValue = () => { 104 const getTestValue = () => {
101 const getTable = getTestTableKeyValue(); 105 const getTable = getTestTableKeyValue();
  106 + const hasRequired = getTable?.some((it) => it.required === true && !it.value);
  107 + if (hasRequired) {
  108 + createMessage.error('参数不能为空');
  109 + throw new Error('参数不能为空');
  110 + }
102 const params: any = {}; 111 const params: any = {};
103 getTable?.map((it) => (params[it.key!] = it.value!)); 112 getTable?.map((it) => (params[it.key!] = it.value!));
104 if (params['keys']) { 113 if (params['keys']) {
@@ -235,7 +235,9 @@ @@ -235,7 +235,9 @@
235 if (f.key === 'organizationId') organizationId = f.value; 235 if (f.key === 'organizationId') organizationId = f.value;
236 if (f.key === 'entityId') f.value = null; 236 if (f.key === 'entityId') f.value = null;
237 }); 237 });
238 - getAttributeOptions({ deviceProfileId: e.value }); 238 + if (e.value) {
  239 + getAttributeOptions({ deviceProfileId: e.value });
  240 + }
239 if (organizationId !== '') { 241 if (organizationId !== '') {
240 getEntityOptions(organizationId, e.value); 242 getEntityOptions(organizationId, e.value);
241 } 243 }
@@ -46,7 +46,7 @@ @@ -46,7 +46,7 @@
46 import { useMessage } from '/@/hooks/web/useMessage'; 46 import { useMessage } from '/@/hooks/web/useMessage';
47 import { useUtils } from './hooks/useUtils'; 47 import { useUtils } from './hooks/useUtils';
48 48
49 - const { resetReqHttpType, resetUpdateSchema } = useUtils(); 49 + const { resetReqHttpType } = useUtils();
50 50
51 const emits = defineEmits(['success', 'register']); 51 const emits = defineEmits(['success', 'register']);
52 52
@@ -69,10 +69,15 @@ @@ -69,10 +69,15 @@
69 const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => { 69 const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
70 await resetFields(); 70 await resetFields();
71 await nextTick(); 71 await nextTick();
72 - updateSchema(resetUpdateSchema);  
73 setFieldsValue(resetReqHttpType); 72 setFieldsValue(resetReqHttpType);
74 const title = `${!data.isUpdate ? '新增' : '修改'}公共接口`; 73 const title = `${!data.isUpdate ? '新增' : '修改'}公共接口`;
75 setDrawerProps({ title }); 74 setDrawerProps({ title });
  75 + updateSchema({
  76 + field: 'requestHttpTypeAndUrl',
  77 + componentProps: {
  78 + type: '0',
  79 + },
  80 + });
76 isUpdate.value = data.isUpdate; 81 isUpdate.value = data.isUpdate;
77 !isUpdate.value ? (putId.value = '') : (putId.value = data.record.id); 82 !isUpdate.value ? (putId.value = '') : (putId.value = data.record.id);
78 simpleRequestRef.value?.resetValue() && testSqlRef.value?.resetValue(); 83 simpleRequestRef.value?.resetValue() && testSqlRef.value?.resetValue();
@@ -36,5 +36,20 @@ export const useUtils = () => { @@ -36,5 +36,20 @@ export const useUtils = () => {
36 type: '0', 36 type: '0',
37 }, 37 },
38 }; 38 };
39 - return { getMultipleKeys, pushObj, resetReqHttpType, resetUpdateSchema }; 39 + //对象转get params参数
  40 + const convertObj = (data: object) => {
  41 + const _result: any = [];
  42 + for (const key in data) {
  43 + const value = data[key];
  44 + if (value.constructor == Array) {
  45 + value.forEach(function (_value) {
  46 + _result.push(key + '=' + _value);
  47 + });
  48 + } else {
  49 + _result.push(key + '=' + value);
  50 + }
  51 + }
  52 + return _result.join('&');
  53 + };
  54 + return { getMultipleKeys, pushObj, resetReqHttpType, resetUpdateSchema, convertObj };
40 }; 55 };
@@ -39,7 +39,7 @@ @@ -39,7 +39,7 @@
39 icon: 'ant-design:node-expand-outlined', 39 icon: 'ant-design:node-expand-outlined',
40 onClick: handlePublish.bind(null, 'publish', record), 40 onClick: handlePublish.bind(null, 'publish', record),
41 ifShow: () => { 41 ifShow: () => {
42 - return record.state === 0; 42 + return record.state === 0 && record.creator === userId;
43 }, 43 },
44 }, 44 },
45 { 45 {
@@ -47,7 +47,7 @@ @@ -47,7 +47,7 @@
47 icon: 'ant-design:node-collapse-outlined', 47 icon: 'ant-design:node-collapse-outlined',
48 onClick: handlePublish.bind(null, 'canelPublish', record), 48 onClick: handlePublish.bind(null, 'canelPublish', record),
49 ifShow: () => { 49 ifShow: () => {
50 - return record.state === 1; 50 + return record.state === 1 && record.creator === userId;
51 }, 51 },
52 }, 52 },
53 { 53 {
@@ -55,7 +55,7 @@ @@ -55,7 +55,7 @@
55 icon: 'clarity:note-edit-line', 55 icon: 'clarity:note-edit-line',
56 onClick: handleCreateOrEdit.bind(null, record), 56 onClick: handleCreateOrEdit.bind(null, record),
57 ifShow: () => { 57 ifShow: () => {
58 - return record.state === 0; 58 + return record.state === 0 && record.creator === userId;
59 }, 59 },
60 }, 60 },
61 { 61 {
@@ -63,7 +63,7 @@ @@ -63,7 +63,7 @@
63 icon: 'ant-design:delete-outlined', 63 icon: 'ant-design:delete-outlined',
64 color: 'error', 64 color: 'error',
65 ifShow: () => { 65 ifShow: () => {
66 - return record.state === 0; 66 + return record.state === 0 && record.creator === userId;
67 }, 67 },
68 popConfirm: { 68 popConfirm: {
69 title: '是否确认删除', 69 title: '是否确认删除',
@@ -93,6 +93,12 @@ @@ -93,6 +93,12 @@
93 import { Popconfirm, Modal } from 'ant-design-vue'; 93 import { Popconfirm, Modal } from 'ant-design-vue';
94 import { JsonPreview } from '/@/components/CodeEditor'; 94 import { JsonPreview } from '/@/components/CodeEditor';
95 import { useMessage } from '/@/hooks/web/useMessage'; 95 import { useMessage } from '/@/hooks/web/useMessage';
  96 + import { USER_INFO_KEY } from '/@/enums/cacheEnum';
  97 + import { getAuthCache } from '/@/utils/auth';
  98 +
  99 + const userInfo = getAuthCache(USER_INFO_KEY) as any;
  100 +
  101 + const userId = ref(userInfo?.userId);
96 102
97 const [registerTable, { reload, clearSelectedRowKeys }] = useTable({ 103 const [registerTable, { reload, clearSelectedRowKeys }] = useTable({
98 api: getDataViewInterfacePage, 104 api: getDataViewInterfacePage,