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