Commit 1065207808220bee12a85971f9f61de179c76c34

Authored by xp.Huang
2 parents be4155d1 ecbfc6c3

Merge branch 'ft' into 'main_dev'

fix:修改Teambition上的问题

See merge request yunteng/thingskit-front!543
@@ -34,6 +34,8 @@ enum Api { @@ -34,6 +34,8 @@ enum Api {
34 getTenantProfile = '/tenant_profiles', 34 getTenantProfile = '/tenant_profiles',
35 deleteTenantProfile = '/tenantProfile', 35 deleteTenantProfile = '/tenantProfile',
36 setTenantProfile = '/tenantProfile', 36 setTenantProfile = '/tenantProfile',
  37 + getTenantPageList = '/admin/all/tenants',
  38 + getTenantAllPageList = '/admin/',
37 } 39 }
38 40
39 export async function deleteTenantProfileApi(ids: string) { 41 export async function deleteTenantProfileApi(ids: string) {
@@ -155,3 +157,15 @@ export function getTenantRoles(tenantCode: string) { @@ -155,3 +157,15 @@ export function getTenantRoles(tenantCode: string) {
155 url: Api.getTenantRoles, 157 url: Api.getTenantRoles,
156 }); 158 });
157 } 159 }
  160 +
  161 +export function getTenantPageList() {
  162 + return defHttp.get({
  163 + url: Api.getTenantPageList,
  164 + });
  165 +}
  166 +
  167 +export function getTenantAllPageLists(tenantId) {
  168 + return defHttp.get({
  169 + url: `${Api.getTenantAllPageList}${tenantId}/all/tenant_admin`,
  170 + });
  171 +}
@@ -39,6 +39,7 @@ export interface TenantPageRequestParams extends BaseQueryParams { @@ -39,6 +39,7 @@ export interface TenantPageRequestParams extends BaseQueryParams {
39 } 39 }
40 40
41 export interface TenantAdminPageRequestParams extends BaseQueryParams { 41 export interface TenantAdminPageRequestParams extends BaseQueryParams {
  42 + [x: string]: any;
42 realName?: string; 43 realName?: string;
43 tenantId?: string; 44 tenantId?: string;
44 items?: string[]; 45 items?: string[];
@@ -67,8 +67,8 @@ @@ -67,8 +67,8 @@
67 initVal(); 67 initVal();
68 }); 68 });
69 69
70 - function initVal() {  
71 - if (props?.type) getOptions(props?.type); 70 + async function initVal() {
  71 + if (props?.type) await getOptions(props?.type);
72 if (props?.value) for (let i in props.value) Reflect.set(valueObj, i, props.value[i]); 72 if (props?.value) for (let i in props.value) Reflect.set(valueObj, i, props.value[i]);
73 } 73 }
74 74
@@ -42,8 +42,6 @@ @@ -42,8 +42,6 @@
42 42
43 const role: string = userInfo?.roles[0]; 43 const role: string = userInfo?.roles[0];
44 44
45 - console.log({ role });  
46 -  
47 const loading = ref(true); 45 const loading = ref(true);
48 46
49 setTimeout(() => { 47 setTimeout(() => {
@@ -22,6 +22,7 @@ @@ -22,6 +22,7 @@
22 v-show="getRequestBody.content.requestParamsBodyType === 'x-www-form-urlencoded'" 22 v-show="getRequestBody.content.requestParamsBodyType === 'x-www-form-urlencoded'"
23 /> 23 />
24 <JsonEditor 24 <JsonEditor
  25 + style="width: 35vw; height: 30vh"
25 v-show="getRequestBody.content.requestParamsBodyType === 'json'" 26 v-show="getRequestBody.content.requestParamsBodyType === 'json'"
26 ref="jsonEditorRef" 27 ref="jsonEditorRef"
27 /> 28 />
@@ -20,7 +20,7 @@ @@ -20,7 +20,7 @@
20 mode: 'code', 20 mode: 'code',
21 mainMenuBar: false, 21 mainMenuBar: false,
22 statusBar: false, 22 statusBar: false,
23 - }; 23 + } as object;
24 let editor = new jsoneditor(jsoneditorRef.value, options); 24 let editor = new jsoneditor(jsoneditorRef.value, options);
25 editor.set(jsonValue.value); 25 editor.set(jsonValue.value);
26 jsonInstance.value = editor; 26 jsonInstance.value = editor;
@@ -163,6 +163,7 @@ @@ -163,6 +163,7 @@
163 163
164 const handleTestParamsInterface = () => { 164 const handleTestParamsInterface = () => {
165 excuteTestRef.value?.showTest(); 165 excuteTestRef.value?.showTest();
  166 + excuteTestRef.value?.resetValue(false);
166 let value = getValue(false) as any; 167 let value = getValue(false) as any;
167 dataMap.mapParamsObj = { 168 dataMap.mapParamsObj = {
168 list: value?.Params, 169 list: value?.Params,
@@ -174,6 +175,7 @@ @@ -174,6 +175,7 @@
174 let value = getValue(false) as any; 175 let value = getValue(false) as any;
175 const type = value?.Body?.requestParamsBodyType; 176 const type = value?.Body?.requestParamsBodyType;
176 excuteTestRef.value?.showTest(); 177 excuteTestRef.value?.showTest();
  178 + excuteTestRef.value?.resetValue(false);
177 let values = []; 179 let values = [];
178 for (let i in value?.Body) if (i === type) values = value?.Body[i]; 180 for (let i in value?.Body) if (i === type) values = value?.Body[i];
179 dataMap.mapBodyObj = { 181 dataMap.mapBodyObj = {
@@ -185,6 +187,7 @@ @@ -185,6 +187,7 @@
185 187
186 const handleTestHeaderInterface = () => { 188 const handleTestHeaderInterface = () => {
187 excuteTestRef.value?.showTest(); 189 excuteTestRef.value?.showTest();
  190 + excuteTestRef.value?.resetValue(false);
188 let value = getValue(false) as any; 191 let value = getValue(false) as any;
189 dataMap.mapHeaderObj = { 192 dataMap.mapHeaderObj = {
190 list: value?.Header, 193 list: value?.Header,
@@ -207,14 +210,20 @@ @@ -207,14 +210,20 @@
207 }; 210 };
208 211
209 //设置数据 212 //设置数据
210 - const setValue = (data) => {  
211 - nextTick(() => {  
212 - const Objects = JSON.parse(data?.requestParams);  
213 - if (!Objects) return;  
214 - dataForTypeMap[0][1](isEmpty(Objects?.Params) ? [pushObj] : Objects?.Params);  
215 - dataForTypeMap[1][1](isEmpty(Objects?.Body) ? {} : Objects?.Body);  
216 - dataForTypeMap[2][1](isEmpty(Objects?.Header) ? [pushObj] : Objects?.Header);  
217 - }); 213 + const setValue = (data, flag, defaultValue) => {
  214 + if (!flag) {
  215 + nextTick(() => {
  216 + const Objects = JSON.parse(data?.requestParams);
  217 + if (!Objects) return;
  218 + dataForTypeMap[0][1](isEmpty(Objects?.Params) ? [pushObj] : Objects?.Params);
  219 + dataForTypeMap[1][1](isEmpty(Objects?.Body) ? {} : Objects?.Body);
  220 + dataForTypeMap[2][1](isEmpty(Objects?.Header) ? [pushObj] : Objects?.Header);
  221 + });
  222 + } else {
  223 + nextTick(() => {
  224 + dataForTypeMap[0][1](defaultValue);
  225 + });
  226 + }
218 }; 227 };
219 228
220 //重置数据 229 //重置数据
@@ -2,18 +2,52 @@ @@ -2,18 +2,52 @@
2 <div> 2 <div>
3 <div class="mt-8"> 3 <div class="mt-8">
4 <div class="flex"> 4 <div class="flex">
5 - <Button @click="handleTest" type="primary"> 打开测试接口 </Button>  
6 - <Button class="ml-2" @click="onCloseTest" type="primary"> 关闭测试接口 </Button> 5 + <div class="flex" v-if="isAdmin(role)">
  6 + <Select
  7 + v-model:value="selectTenant"
  8 + allowClear
  9 + @change="onSelect"
  10 + style="width: 150px"
  11 + :getPopupContainer="
  12 + (triggerNode) => {
  13 + return triggerNode.parentNode;
  14 + }
  15 + "
  16 + placeholder="请选择租户"
  17 + :options="selectOptions"
  18 + />
  19 + <Select
  20 + v-model:value="selectSysTenant"
  21 + allowClear
  22 + @change="onSelctTenant"
  23 + style="width: 150px; margin-left: 10px"
  24 + v-if="selectTenantOptions.length > 0"
  25 + :getPopupContainer="
  26 + (triggerNode) => {
  27 + return triggerNode.parentNode;
  28 + }
  29 + "
  30 + placeholder="请选择租户"
  31 + :options="selectTenantOptions"
  32 + />
  33 + </div>
  34 + <Button
  35 + :disabled="testDisabled"
  36 + class="ml-2"
  37 + @click="handleTest(isSingleClickText)"
  38 + type="primary"
  39 + >{{ `${isSingleClickText === 'open' ? '打开' : '关闭'}测试接口` }}
  40 + </Button>
7 </div> 41 </div>
8 <div v-if="showTestEditCell" class="mt-8"> 42 <div v-if="showTestEditCell" class="mt-8">
9 <a-row type="flex" justify="center"> 43 <a-row type="flex" justify="center">
10 <a-col :span="3"> 参数设置 </a-col> 44 <a-col :span="3"> 参数设置 </a-col>
11 <a-col :span="21"> 45 <a-col :span="21">
12 <div v-if="data?.type === 'x-www-form-urlencoded' || data?.type === 'form-data'"> 46 <div v-if="data?.type === 'x-www-form-urlencoded' || data?.type === 'form-data'">
13 - <TestBodyCellTable ref="testEditCellTableRef" /> 47 + <TestBodyCellTable :token="getToken" ref="testEditCellTableRef" />
14 </div> 48 </div>
15 <div style="width: 30vw" v-else-if="data?.type === 'json'"> 49 <div style="width: 30vw" v-else-if="data?.type === 'json'">
16 - <JsonEditor ref="jsonEditorRef" /> 50 + <JsonEditor style="width: 35vw; height: 30vh" ref="jsonEditorRef" />
17 </div> 51 </div>
18 <div style="width: 30vw" v-else-if="data?.type === 'xml'"> 52 <div style="width: 30vw" v-else-if="data?.type === 'xml'">
19 <a-textarea v-model:value="xmlContent" placeholder="请输入xml" :rows="6" /> 53 <a-textarea v-model:value="xmlContent" placeholder="请输入xml" :rows="6" />
@@ -26,13 +60,24 @@ @@ -26,13 +60,24 @@
26 </div> 60 </div>
27 </template> 61 </template>
28 <script lang="ts" setup name="testRequest"> 62 <script lang="ts" setup name="testRequest">
29 - import { ref, nextTick } from 'vue'; 63 + import { ref, nextTick, onMounted } from 'vue';
30 import { Button } from 'ant-design-vue'; 64 import { Button } from 'ant-design-vue';
31 import TestBodyCellTable from './testEditBodyCellTable.vue'; 65 import TestBodyCellTable from './testEditBodyCellTable.vue';
32 import moment from 'moment'; 66 import moment from 'moment';
33 import { useUtils } from '../../../hooks/useUtils'; 67 import { useUtils } from '../../../hooks/useUtils';
34 import JsonEditor from '../../SimpleRequest/components/jsonEditor.vue'; 68 import JsonEditor from '../../SimpleRequest/components/jsonEditor.vue';
35 import { useMessage } from '/@/hooks/web/useMessage'; 69 import { useMessage } from '/@/hooks/web/useMessage';
  70 + import { getTenantAllPageLists, getTenantPageList } from '/@/api/tenant/tenantApi';
  71 + import { selectType } from '../../../types';
  72 + import { Select } from 'ant-design-vue';
  73 + import { getUserToken } from '/@/api/sys/user';
  74 + import { USER_INFO_KEY } from '/@/enums/cacheEnum';
  75 + import { getAuthCache } from '/@/utils/auth';
  76 + import { isAdmin } from '/@/enums/roleEnum';
  77 +
  78 + const userInfo: any = getAuthCache(USER_INFO_KEY);
  79 +
  80 + const role: string = userInfo?.roles[0];
36 81
37 const emits = defineEmits(['testBodyInterface', 'closeTest']); 82 const emits = defineEmits(['testBodyInterface', 'closeTest']);
38 83
@@ -42,12 +87,33 @@ @@ -42,12 +87,33 @@
42 }, 87 },
43 }); 88 });
44 89
  90 + onMounted(async () => {
  91 + if (isAdmin(role)) {
  92 + const res = await getTenantPageList();
  93 + selectOptions.value = res.map((m) => ({ label: m.name, value: m.tenantId }));
  94 + } else {
  95 + //租户
  96 + const { token } = await getUserToken(userInfo?.userId);
  97 + getToken.value = token;
  98 + }
  99 + });
  100 +
  101 + const selectOptions = ref<selectType[]>([]);
  102 +
  103 + const selectTenantOptions = ref<selectType[]>([]);
  104 +
45 const { createMessage } = useMessage(); 105 const { createMessage } = useMessage();
46 106
47 const showTestEditCell = ref(false); 107 const showTestEditCell = ref(false);
48 108
  109 + const testDisabled = ref(true);
  110 +
49 const excuteData = ref({}); 111 const excuteData = ref({});
50 112
  113 + const selectTenant = ref(undefined);
  114 +
  115 + const selectSysTenant = ref(undefined);
  116 +
51 const xmlContent = ref(''); 117 const xmlContent = ref('');
52 118
53 const testEditCellTableRef = ref<InstanceType<typeof TestBodyCellTable>>(); 119 const testEditCellTableRef = ref<InstanceType<typeof TestBodyCellTable>>();
@@ -58,10 +124,47 @@ @@ -58,10 +124,47 @@
58 124
59 const { getMultipleKeys } = useUtils(); 125 const { getMultipleKeys } = useUtils();
60 126
61 - const handleTest = () => {  
62 - showTestEditCell.value = true;  
63 - emits('testBodyInterface');  
64 - getValue(); 127 + const getToken = ref('');
  128 +
  129 + const onSelect = async (e) => {
  130 + if (e) {
  131 + testDisabled.value = false;
  132 + } else {
  133 + testDisabled.value = true;
  134 + }
  135 + selectSysTenant.value = undefined;
  136 + const rest = (await getTenantAllPageLists(e)) as any;
  137 + selectTenantOptions.value = rest?.map((m) => ({ label: m.realName, value: m.id }));
  138 + };
  139 +
  140 + const onSelctTenant = async (e) => {
  141 + if (e) {
  142 + testDisabled.value = false;
  143 + } else {
  144 + testDisabled.value = true;
  145 + }
  146 + const { token } = await getUserToken(e);
  147 + getToken.value = token;
  148 + };
  149 +
  150 + const isSingleClickText = ref('open');
  151 +
  152 + const handleTest = (o) => {
  153 + if (isAdmin(role)) {
  154 + if (!selectTenant.value || !selectSysTenant.value) {
  155 + createMessage.error('请选择租户或者租户管理员');
  156 + throw Error('请选择租户或者租户管理员');
  157 + }
  158 + }
  159 + if (o === 'open') {
  160 + showTestEditCell.value = true;
  161 + emits('testBodyInterface');
  162 + getValue();
  163 + isSingleClickText.value = 'close';
  164 + } else {
  165 + isSingleClickText.value = 'open';
  166 + onCloseTest();
  167 + }
65 }; 168 };
66 169
67 const getValue = async () => { 170 const getValue = async () => {
@@ -141,6 +244,7 @@ @@ -141,6 +244,7 @@
141 } 244 }
142 excuteData.value = { 245 excuteData.value = {
143 params, 246 params,
  247 + token: getToken.value,
144 }; 248 };
145 return excuteData.value; 249 return excuteData.value;
146 }; 250 };
@@ -149,6 +253,9 @@ @@ -149,6 +253,9 @@
149 const setValue = () => { 253 const setValue = () => {
150 showTestEditCell.value = false; 254 showTestEditCell.value = false;
151 testResult.value = ''; 255 testResult.value = '';
  256 + selectTenant.value = undefined;
  257 + selectSysTenant.value = undefined;
  258 + selectTenantOptions.value = [];
152 }; 259 };
153 260
154 const onCloseTest = () => { 261 const onCloseTest = () => {
@@ -130,9 +130,8 @@ @@ -130,9 +130,8 @@
130 import { reactive, ref, onMounted } from 'vue'; 130 import { reactive, ref, onMounted } from 'vue';
131 import { Select } from 'ant-design-vue'; 131 import { Select } from 'ant-design-vue';
132 import { findDictItemByCode } from '/@/api/system/dict'; 132 import { findDictItemByCode } from '/@/api/system/dict';
133 - import { getAllDeviceByOrg } from '/@/api/dataBoard';  
134 - import { getDeviceAttributes } from '/@/api/dataBoard';  
135 import { useApi } from '../../../hooks/useApi'; 133 import { useApi } from '../../../hooks/useApi';
  134 + import { useUtils } from '../../../hooks/useUtils';
136 import { cloneDeep } from 'lodash-es'; 135 import { cloneDeep } from 'lodash-es';
137 import { tableItems, selectType } from '../../../types'; 136 import { tableItems, selectType } from '../../../types';
138 import { editTestCellTableTHeadConfig } from '../../../config'; 137 import { editTestCellTableTHeadConfig } from '../../../config';
@@ -142,6 +141,9 @@ @@ -142,6 +141,9 @@
142 method: { 141 method: {
143 type: String, 142 type: String,
144 }, 143 },
  144 + token: {
  145 + type: String,
  146 + },
145 }); 147 });
146 148
147 onMounted(async () => { 149 onMounted(async () => {
@@ -155,6 +157,8 @@ @@ -155,6 +157,8 @@
155 selectOptions.value = selectOptions.value.filter((f) => f.value !== 'scope'); 157 selectOptions.value = selectOptions.value.filter((f) => f.value !== 'scope');
156 }); 158 });
157 159
  160 + const { isOtherHttp } = useUtils();
  161 +
158 const selectOptions = ref<selectType[]>([]); 162 const selectOptions = ref<selectType[]>([]);
159 163
160 const valueOptions = ref<selectType[]>([]); 164 const valueOptions = ref<selectType[]>([]);
@@ -199,10 +203,10 @@ @@ -199,10 +203,10 @@
199 const getApi = (list) => { 203 const getApi = (list) => {
200 list?.forEach(async (it) => { 204 list?.forEach(async (it) => {
201 if (it.key === 'deviceProfileId') { 205 if (it.key === 'deviceProfileId') {
202 - const { options } = await useApi(it.key); 206 + const { options } = await useApi(it.key, props.token);
203 valueOptions.value = options; 207 valueOptions.value = options;
204 } else if (it.key === 'organizationId') { 208 } else if (it.key === 'organizationId') {
205 - const { options } = await useApi(it.key); 209 + const { options } = await useApi(it.key, props.token);
206 treeData.value = options as any; 210 treeData.value = options as any;
207 } 211 }
208 }); 212 });
@@ -220,7 +224,10 @@ @@ -220,7 +224,10 @@
220 }; 224 };
221 225
222 const getEntityOptions = async (organizationId: string, deviceProfileId?: string) => { 226 const getEntityOptions = async (organizationId: string, deviceProfileId?: string) => {
223 - const res = await getAllDeviceByOrg(organizationId, deviceProfileId); 227 + const res = await isOtherHttp('api/yt/device/list', props.token, {
  228 + organizationId,
  229 + deviceProfileId,
  230 + });
224 entityOptions.value = res.map((item) => ({ 231 entityOptions.value = res.map((item) => ({
225 label: item.name, 232 label: item.name,
226 value: item.tbDeviceId, 233 value: item.tbDeviceId,
@@ -228,7 +235,10 @@ @@ -228,7 +235,10 @@
228 }; 235 };
229 236
230 const getAttributeOptions = async (params) => { 237 const getAttributeOptions = async (params) => {
231 - const res = await getDeviceAttributes(params); 238 + const { deviceProfileId, dataType } = params;
  239 + const res = await isOtherHttp(`api/yt/device/attributes/${deviceProfileId}`, props.token, {
  240 + dataType,
  241 + });
232 if (Object.keys(res).length === 0) return (attributeOptions.value.length = 0); 242 if (Object.keys(res).length === 0) return (attributeOptions.value.length = 0);
233 attributeOptions.value = res?.map((item) => ({ label: item.name, value: item.identifier })); 243 attributeOptions.value = res?.map((item) => ({ label: item.name, value: item.identifier }));
234 }; 244 };
1 <template> 1 <template>
2 <div v-if="showTestFlag" class="mt-8"> 2 <div v-if="showTestFlag" class="mt-8">
3 <div> 3 <div>
4 - <Button @click="handleExcute" type="primary"> 执行测试请求 </Button> 4 + <a-row>
  5 + <Button @click="handleExcute" type="primary"> 执行测试请求 </Button>
  6 + </a-row>
  7 + <a-row class="mt-8" type="flex" justify="center" align="middle">
  8 + <a-col :span="2"> 测试地址 </a-col>
  9 + <a-col :span="22">
  10 + <Tag color="blue" style="width: 31.6vw; white-space: normal; height: auto">
  11 + {{ apiUrl?.split('{?')[0] }}
  12 + </Tag>
  13 + </a-col>
  14 + </a-row>
5 </div> 15 </div>
6 <div class="mt-8"> 16 <div class="mt-8">
7 <a-row type="flex" justify="center"> 17 <a-row type="flex" justify="center">
8 <a-col :span="24"> 18 <a-col :span="24">
9 - <a-textarea  
10 - disabled 19 + <JsonEditor
11 v-if="isWebSocketType === '2'" 20 v-if="isWebSocketType === '2'"
12 - allow-clear  
13 - show-count  
14 - v-model:value="testResult"  
15 - placeholder="测试结果为:"  
16 - :rows="8"  
17 - />  
18 - <a-textarea  
19 - disabled  
20 - v-else  
21 - allow-clear  
22 - show-count  
23 - v-model:value="httpResult"  
24 - placeholder="测试结果为:"  
25 - :rows="8" 21 + style="width: 35vw; height: 40vh"
  22 + ref="jsonWebsocketEditorRef"
26 /> 23 />
  24 + <JsonEditor v-else style="width: 35vw; height: 40vh" ref="jsonEditorRef" />
27 </a-col> 25 </a-col>
28 </a-row> 26 </a-row>
29 </div> 27 </div>
@@ -34,9 +32,9 @@ @@ -34,9 +32,9 @@
34 import { Button } from 'ant-design-vue'; 32 import { Button } from 'ant-design-vue';
35 import { otherHttp } from '/@/utils/http/axios'; 33 import { otherHttp } from '/@/utils/http/axios';
36 import { useWebSocket } from '@vueuse/core'; 34 import { useWebSocket } from '@vueuse/core';
37 - import { JWT_TOKEN_KEY } from '/@/enums/cacheEnum';  
38 - import { getAuthCache } from '/@/utils/auth';  
39 import { useUtils } from '../../../hooks/useUtils'; 35 import { useUtils } from '../../../hooks/useUtils';
  36 + import JsonEditor from '../../SimpleRequest/components/jsonEditor.vue';
  37 + import { Tag } from 'ant-design-vue';
40 38
41 const emits = defineEmits(['emitExcute']); 39 const emits = defineEmits(['emitExcute']);
42 40
@@ -48,7 +46,9 @@ @@ -48,7 +46,9 @@
48 46
49 const showTestFlag = ref(false); 47 const showTestFlag = ref(false);
50 48
51 - const token = getAuthCache(JWT_TOKEN_KEY); 49 + const jsonEditorRef = ref<InstanceType<typeof JsonEditor>>();
  50 +
  51 + const jsonWebsocketEditorRef = ref<InstanceType<typeof JsonEditor>>();
52 52
53 const socketUrls = ref(''); 53 const socketUrls = ref('');
54 54
@@ -79,11 +79,13 @@ @@ -79,11 +79,13 @@
79 return formatString(this, replacements); 79 return formatString(this, replacements);
80 }; 80 };
81 81
82 - const testResult = ref(''); 82 + const isWebSocketType = ref('');
  83 +
  84 + const isToken = ref('');
83 85
84 - const httpResult = ref(''); 86 + const apiUrl = ref('');
85 87
86 - const isWebSocketType = ref(''); 88 + const isPostToken = ref('');
87 89
88 //执行测试接口 90 //执行测试接口
89 const handleExcute = () => { 91 const handleExcute = () => {
@@ -100,11 +102,13 @@ @@ -100,11 +102,13 @@
100 const url = Objects?.apiGetUrl; 102 const url = Objects?.apiGetUrl;
101 const headers = Objects?.Header?.params; 103 const headers = Objects?.Header?.params;
102 const params = Objects?.Params?.params; 104 const params = Objects?.Params?.params;
  105 + isToken.value = Objects?.Params?.token;
103 const body = Objects?.Body?.params; 106 const body = Objects?.Body?.params;
104 - const apiUrl = url?.restfulFormat(params); 107 + isPostToken.value = Objects?.Body?.token;
  108 + apiUrl.value = url?.restfulFormat(params);
105 if (isWebSocketType.value === '2') { 109 if (isWebSocketType.value === '2') {
106 socketUrls.value = url; 110 socketUrls.value = url;
107 - socketMessage.server = `${socketUrls.value}?token=${token}`; 111 + socketMessage.server = `${socketUrls.value}?token=${isToken.value}`;
108 const list = Object.values(params); 112 const list = Object.values(params);
109 const isEmpty = list.some((it) => it === '' || null || undefined); 113 const isEmpty = list.some((it) => it === '' || null || undefined);
110 if (!isEmpty) { 114 if (!isEmpty) {
@@ -113,20 +117,46 @@ @@ -113,20 +117,46 @@
113 resetValue(false); 117 resetValue(false);
114 } 118 }
115 } else { 119 } else {
116 - const resp = await otherHttpRequest(apiType, apiUrl?.split('{?')[0], headers, params, body);  
117 - if (!resp) return;  
118 - httpResult.value = JSON.stringify(resp); 120 + try {
  121 + const resp = await otherHttpRequest(
  122 + apiType,
  123 + apiUrl.value?.split('{?')[0],
  124 + headers,
  125 + params,
  126 + body,
  127 + isToken.value,
  128 + isPostToken.value
  129 + );
  130 + if (!resp) return;
  131 + if (Object.prototype.toString.call(resp) === '[object Object]') {
  132 + jsonEditorRef.value?.setJsonValue(resp);
  133 + } else if (typeof resp === 'string') {
  134 + jsonEditorRef.value?.setJsonValue(resp);
  135 + } else if (Array.isArray(resp)) {
  136 + jsonEditorRef.value?.setJsonValue(JSON.stringify(resp));
  137 + } else {
  138 + jsonEditorRef.value?.setJsonValue(JSON.stringify(resp));
  139 + }
  140 + } catch (e) {
  141 + if (Object.prototype.toString.call(e) === '[object Object]') {
  142 + jsonEditorRef.value?.setJsonValue(e);
  143 + } else {
  144 + jsonEditorRef.value?.setJsonValue(JSON.stringify(e));
  145 + }
  146 + }
119 } 147 }
120 }; 148 };
121 149
122 //websocket请求 150 //websocket请求
123 const websocketRequest = (params, destroy = false) => { 151 const websocketRequest = (params, destroy = false) => {
124 //websocket请求 152 //websocket请求
125 - Reflect.deleteProperty(params, 'deviceProfileId');  
126 - Reflect.deleteProperty(params, 'organizationId');  
127 - Reflect.set(params, 'cmdId', 1);  
128 - Reflect.set(params, 'scope', 'LATEST_TELEMETRY');  
129 - Reflect.set(params, 'entityType', 'DEVICE'); 153 + if (Object.prototype.toString.call(params) === '[object Object]') {
  154 + Reflect.deleteProperty(params, 'deviceProfileId');
  155 + Reflect.deleteProperty(params, 'organizationId');
  156 + Reflect.set(params, 'cmdId', 1);
  157 + Reflect.set(params, 'scope', 'LATEST_TELEMETRY');
  158 + Reflect.set(params, 'entityType', 'DEVICE');
  159 + }
130 socketMessage.sendValue.tsSubCmds.push(params); 160 socketMessage.sendValue.tsSubCmds.push(params);
131 const { send, close } = useWebSocket(socketMessage.server, { 161 const { send, close } = useWebSocket(socketMessage.server, {
132 onConnected() { 162 onConnected() {
@@ -135,7 +165,15 @@ @@ -135,7 +165,15 @@
135 }, 165 },
136 onMessage(_, e) { 166 onMessage(_, e) {
137 const { data } = JSON.parse(e.data); 167 const { data } = JSON.parse(e.data);
138 - testResult.value = JSON.stringify(data); 168 + if (Object.prototype.toString.call(data) === '[object Object]') {
  169 + jsonWebsocketEditorRef.value?.setJsonValue(data);
  170 + } else if (typeof data === 'string') {
  171 + jsonWebsocketEditorRef.value?.setJsonValue(data);
  172 + } else if (Array.isArray(data)) {
  173 + jsonWebsocketEditorRef.value?.setJsonValue(JSON.stringify(data));
  174 + } else {
  175 + jsonEditorRef.value?.setJsonValue(JSON.stringify(data));
  176 + }
139 }, 177 },
140 onDisconnected() { 178 onDisconnected() {
141 console.log('断开连接了'); 179 console.log('断开连接了');
@@ -159,32 +197,49 @@ @@ -159,32 +197,49 @@
159 headers = {}, 197 headers = {},
160 params = {}, 198 params = {},
161 body, 199 body,
  200 + token,
  201 + postToken,
162 joinPrefix = false 202 joinPrefix = false
163 ) => { 203 ) => {
  204 + const { convertObj } = useUtils();
164 switch (apiType) { 205 switch (apiType) {
165 case 'GET': 206 case 'GET':
  207 + const objGet = Object.assign({}, headers, {
  208 + 'X-Authorization': `Bearer ${!token ? postToken : token}`,
  209 + });
166 return await otherHttp.get( 210 return await otherHttp.get(
167 - { url: apiUrl, params, headers }, 211 + { url: apiUrl, params, headers: objGet },
168 { 212 {
169 apiUrl: '', 213 apiUrl: '',
170 joinPrefix, 214 joinPrefix,
  215 + withToken: false,
  216 + errorMessageMode: 'none',
171 } 217 }
172 ); 218 );
173 case 'POST': 219 case 'POST':
174 - const { convertObj } = useUtils(); 220 + const objPost = Object.assign({}, headers, {
  221 + 'X-Authorization': `Bearer ${!postToken ? token : postToken}`,
  222 + });
175 return await otherHttp.post( 223 return await otherHttp.post(
176 - { url: `${apiUrl}?${convertObj(params)}`, data: body, headers }, 224 + { url: `${apiUrl}?${convertObj(params)}`, data: body, headers: objPost },
177 { 225 {
178 apiUrl: '', 226 apiUrl: '',
179 joinPrefix, 227 joinPrefix,
  228 + withToken: false,
  229 + errorMessageMode: 'none',
180 } 230 }
181 ); 231 );
182 case 'PUT': 232 case 'PUT':
  233 + const objPut = Object.assign({}, headers, {
  234 + 'X-Authorization': `Bearer ${!postToken ? token : postToken}`,
  235 + });
183 return await otherHttp.put( 236 return await otherHttp.put(
184 - { url: apiUrl, data: body, headers, params }, 237 + { url: `${apiUrl}?${convertObj(params)}`, data: body, headers: objPut, params },
185 { 238 {
186 apiUrl: '', 239 apiUrl: '',
187 joinPrefix, 240 joinPrefix,
  241 + withToken: false,
  242 + errorMessageMode: 'none',
188 } 243 }
189 ); 244 );
190 } 245 }
@@ -194,8 +249,10 @@ @@ -194,8 +249,10 @@
194 if (flag) { 249 if (flag) {
195 showTestFlag.value = false; 250 showTestFlag.value = false;
196 } 251 }
197 - httpResult.value = '测试结果为:';  
198 - testResult.value = '测试结果为:'; 252 + nextTick(() => {
  253 + jsonEditorRef.value?.setJsonValue('执行测试结果为:');
  254 + jsonWebsocketEditorRef.value?.setJsonValue('执行测试结果为:');
  255 + });
199 isWebSocketType.value = '0'; 256 isWebSocketType.value = '0';
200 }; 257 };
201 258
@@ -2,8 +2,42 @@ @@ -2,8 +2,42 @@
2 <div> 2 <div>
3 <div class="mt-8"> 3 <div class="mt-8">
4 <div class="flex"> 4 <div class="flex">
5 - <Button @click="handleTest" type="primary"> 打开测试接口 </Button>  
6 - <Button class="ml-2" @click="onCloseTest" type="primary"> 关闭测试接口 </Button> 5 + <div class="flex" v-if="isAdmin(role)">
  6 + <Select
  7 + allowClear
  8 + v-model:value="selectTenant"
  9 + @change="onSelect"
  10 + style="width: 150px"
  11 + :getPopupContainer="
  12 + (triggerNode) => {
  13 + return triggerNode.parentNode;
  14 + }
  15 + "
  16 + placeholder="请选择租户"
  17 + :options="selectOptions"
  18 + />
  19 + <Select
  20 + v-model:value="selectSysTenant"
  21 + allowClear
  22 + @change="onSelctTenant"
  23 + style="width: 150px; margin-left: 10px"
  24 + v-if="selectTenantOptions.length > 0"
  25 + :getPopupContainer="
  26 + (triggerNode) => {
  27 + return triggerNode.parentNode;
  28 + }
  29 + "
  30 + placeholder="请选择租户"
  31 + :options="selectTenantOptions"
  32 + />
  33 + </div>
  34 + <Button
  35 + :disabled="testDisabled"
  36 + class="ml-2"
  37 + @click="handleTest(isSingleClickText)"
  38 + type="primary"
  39 + >{{ `${isSingleClickText === 'open' ? '打开' : '关闭'}测试接口` }}
  40 + </Button>
7 </div> 41 </div>
8 <div v-if="showTestEditCell" class="mt-8"> 42 <div v-if="showTestEditCell" class="mt-8">
9 <a-row type="flex" justify="center"> 43 <a-row type="flex" justify="center">
@@ -18,33 +52,102 @@ @@ -18,33 +52,102 @@
18 </div> 52 </div>
19 </template> 53 </template>
20 <script lang="ts" setup name="testRequest"> 54 <script lang="ts" setup name="testRequest">
21 - import { ref, nextTick } from 'vue'; 55 + import { ref, nextTick, onMounted } from 'vue';
22 import { Button } from 'ant-design-vue'; 56 import { Button } from 'ant-design-vue';
23 import TestHeaderEditCellTable from './testEditHeaderCellTable.vue'; 57 import TestHeaderEditCellTable from './testEditHeaderCellTable.vue';
24 import { useMessage } from '/@/hooks/web/useMessage'; 58 import { useMessage } from '/@/hooks/web/useMessage';
  59 + import { selectType } from '../../../types';
  60 + import { Select } from 'ant-design-vue';
  61 + import { getUserToken } from '/@/api/sys/user';
  62 + import { USER_INFO_KEY } from '/@/enums/cacheEnum';
  63 + import { getTenantAllPageLists, getTenantPageList } from '/@/api/tenant/tenantApi';
  64 + import { getAuthCache } from '/@/utils/auth';
  65 + import { isAdmin } from '/@/enums/roleEnum';
25 66
26 const emits = defineEmits(['testHeaderInterface', 'closeTest']); 67 const emits = defineEmits(['testHeaderInterface', 'closeTest']);
27 68
  69 + const userInfo: any = getAuthCache(USER_INFO_KEY);
  70 +
  71 + const role: string = userInfo?.roles[0];
  72 +
28 const props = defineProps({ 73 const props = defineProps({
29 data: { 74 data: {
30 type: Object, 75 type: Object,
31 }, 76 },
32 }); 77 });
33 78
  79 + onMounted(async () => {
  80 + if (isAdmin(role)) {
  81 + const res = await getTenantPageList();
  82 + selectOptions.value = res.map((m) => ({ label: m.name, value: m.tenantId }));
  83 + } else {
  84 + //租户
  85 + const { token } = await getUserToken(userInfo?.userId);
  86 + getToken.value = token;
  87 + }
  88 + });
  89 +
  90 + const selectOptions = ref<selectType[]>([]);
  91 +
  92 + const selectTenantOptions = ref<selectType[]>([]);
  93 +
  94 + const testDisabled = ref(true);
  95 +
34 const { createMessage } = useMessage(); 96 const { createMessage } = useMessage();
35 97
36 const showTestEditCell = ref(false); 98 const showTestEditCell = ref(false);
37 99
38 const excuteData = ref({}); 100 const excuteData = ref({});
39 101
  102 + const selectTenant = ref(undefined);
  103 +
  104 + const selectSysTenant = ref(undefined);
  105 +
40 const testEditCellTableRef = ref<InstanceType<typeof TestHeaderEditCellTable>>(); 106 const testEditCellTableRef = ref<InstanceType<typeof TestHeaderEditCellTable>>();
41 107
42 const testResult = ref(''); 108 const testResult = ref('');
43 109
44 - const handleTest = () => {  
45 - showTestEditCell.value = true;  
46 - emits('testHeaderInterface');  
47 - getValue(); 110 + const getToken = ref('');
  111 +
  112 + const onSelect = async (e) => {
  113 + if (e) {
  114 + testDisabled.value = false;
  115 + } else {
  116 + testDisabled.value = true;
  117 + }
  118 + selectSysTenant.value = undefined;
  119 + const rest = (await getTenantAllPageLists(e)) as any;
  120 + selectTenantOptions.value = rest?.map((m) => ({ label: m.realName, value: m.id }));
  121 + };
  122 +
  123 + const onSelctTenant = async (e) => {
  124 + if (e) {
  125 + testDisabled.value = false;
  126 + } else {
  127 + testDisabled.value = true;
  128 + }
  129 + const { token } = await getUserToken(e);
  130 + getToken.value = token;
  131 + };
  132 +
  133 + const isSingleClickText = ref('open');
  134 +
  135 + const handleTest = (o) => {
  136 + if (isAdmin(role)) {
  137 + if (!selectTenant.value || !selectSysTenant.value) {
  138 + createMessage.error('请选择租户或者租户管理员');
  139 + throw Error('请选择租户或者租户管理员');
  140 + }
  141 + }
  142 + if (o === 'open') {
  143 + showTestEditCell.value = true;
  144 + emits('testHeaderInterface');
  145 + getValue();
  146 + isSingleClickText.value = 'close';
  147 + } else {
  148 + isSingleClickText.value = 'open';
  149 + onCloseTest();
  150 + }
48 }; 151 };
49 152
50 const getValue = async () => { 153 const getValue = async () => {
@@ -72,6 +175,7 @@ @@ -72,6 +175,7 @@
72 getTable?.map((it: any) => (params[it.key!] = it.value!)); 175 getTable?.map((it: any) => (params[it.key!] = it.value!));
73 excuteData.value = { 176 excuteData.value = {
74 params, 177 params,
  178 + token: getToken.value,
75 }; 179 };
76 return excuteData.value; 180 return excuteData.value;
77 }; 181 };
@@ -80,6 +184,9 @@ @@ -80,6 +184,9 @@
80 const setValue = () => { 184 const setValue = () => {
81 showTestEditCell.value = false; 185 showTestEditCell.value = false;
82 testResult.value = ''; 186 testResult.value = '';
  187 + selectTenant.value = undefined;
  188 + selectSysTenant.value = undefined;
  189 + selectTenantOptions.value = [];
83 }; 190 };
84 191
85 const onCloseTest = () => { 192 const onCloseTest = () => {
@@ -2,14 +2,38 @@ @@ -2,14 +2,38 @@
2 <div> 2 <div>
3 <div class="mt-8"> 3 <div class="mt-8">
4 <div class="flex"> 4 <div class="flex">
5 - <Button @click="handleTest" type="primary"> 打开测试接口 </Button>  
6 - <Button class="ml-2" @click="onCloseTest" type="primary"> 关闭测试接口 </Button> 5 + <div class="flex" v-if="isAdmin(role)">
  6 + <Select
  7 + allowClear
  8 + v-model:value="selectTenant"
  9 + @change="onSelect"
  10 + style="width: 150px"
  11 + placeholder="请选择租户"
  12 + :options="selectOptions"
  13 + />
  14 + <Select
  15 + v-model:value="selectSysTenant"
  16 + allowClear
  17 + @change="onSelctTenant"
  18 + style="width: 150px; margin-left: 10px"
  19 + v-if="selectTenantOptions.length > 0"
  20 + placeholder="请选择租户"
  21 + :options="selectTenantOptions"
  22 + />
  23 + </div>
  24 + <Button
  25 + :disabled="isAdmin(role) ? testDisabled : false"
  26 + class="ml-2"
  27 + @click="handleTest(isSingleClickText)"
  28 + type="primary"
  29 + >{{ `${isSingleClickText === 'open' ? '打开' : '关闭'}测试接口` }}
  30 + </Button>
7 </div> 31 </div>
8 <div v-if="showTestEditCell" class="mt-8"> 32 <div v-if="showTestEditCell" class="mt-8">
9 <a-row type="flex" justify="center"> 33 <a-row type="flex" justify="center">
10 <a-col :span="3"> 参数设置 </a-col> 34 <a-col :span="3"> 参数设置 </a-col>
11 <a-col :span="21"> 35 <a-col :span="21">
12 - <TestParamsCellTable ref="testEditCellTableRef" /> 36 + <TestParamsCellTable :token="getToken" ref="testEditCellTableRef" />
13 </a-col> 37 </a-col>
14 </a-row> 38 </a-row>
15 </div> 39 </div>
@@ -18,12 +42,23 @@ @@ -18,12 +42,23 @@
18 </div> 42 </div>
19 </template> 43 </template>
20 <script lang="ts" setup name="testRequest"> 44 <script lang="ts" setup name="testRequest">
21 - import { ref, nextTick } from 'vue'; 45 + import { ref, nextTick, onMounted } from 'vue';
22 import { Button } from 'ant-design-vue'; 46 import { Button } from 'ant-design-vue';
23 import TestParamsCellTable from './testEditParamsCellTable.vue'; 47 import TestParamsCellTable from './testEditParamsCellTable.vue';
24 import moment from 'moment'; 48 import moment from 'moment';
25 import { useUtils } from '../../../hooks/useUtils'; 49 import { useUtils } from '../../../hooks/useUtils';
26 import { useMessage } from '/@/hooks/web/useMessage'; 50 import { useMessage } from '/@/hooks/web/useMessage';
  51 + import { getTenantAllPageLists, getTenantPageList } from '/@/api/tenant/tenantApi';
  52 + import { selectType } from '../../../types';
  53 + import { Select } from 'ant-design-vue';
  54 + import { getUserToken } from '/@/api/sys/user';
  55 + import { USER_INFO_KEY } from '/@/enums/cacheEnum';
  56 + import { getAuthCache } from '/@/utils/auth';
  57 + import { isAdmin } from '/@/enums/roleEnum';
  58 +
  59 + const userInfo: any = getAuthCache(USER_INFO_KEY);
  60 +
  61 + const role: string = userInfo?.roles[0];
27 62
28 const emits = defineEmits(['testParamsInterface', 'closeTest']); 63 const emits = defineEmits(['testParamsInterface', 'closeTest']);
29 64
@@ -33,22 +68,73 @@ @@ -33,22 +68,73 @@
33 }, 68 },
34 }); 69 });
35 70
  71 + onMounted(async () => {
  72 + if (isAdmin(role)) {
  73 + const res = await getTenantPageList();
  74 + selectOptions.value = res.map((m) => ({ label: m.name, value: m.tenantId }));
  75 + } else {
  76 + //租户
  77 + const { token } = await getUserToken(userInfo?.userId);
  78 + getToken.value = token;
  79 + }
  80 + });
  81 +
  82 + const selectOptions = ref<selectType[]>([]);
  83 +
  84 + const testDisabled = ref(true);
  85 +
  86 + const selectTenantOptions = ref<selectType[]>([]);
  87 +
36 const { createMessage } = useMessage(); 88 const { createMessage } = useMessage();
37 89
38 const showTestEditCell = ref(false); 90 const showTestEditCell = ref(false);
39 91
40 const excuteData = ref({}); 92 const excuteData = ref({});
41 93
  94 + const selectTenant = ref(undefined);
  95 +
  96 + const selectSysTenant = ref(undefined);
  97 +
42 const testEditCellTableRef = ref<InstanceType<typeof TestParamsCellTable>>(); 98 const testEditCellTableRef = ref<InstanceType<typeof TestParamsCellTable>>();
43 99
44 const testResult = ref(''); 100 const testResult = ref('');
45 101
46 const { getMultipleKeys } = useUtils(); 102 const { getMultipleKeys } = useUtils();
47 103
48 - const handleTest = () => {  
49 - showTestEditCell.value = true;  
50 - emits('testParamsInterface');  
51 - getValue(); 104 + const getToken = ref('');
  105 +
  106 + const onSelect = async (e) => {
  107 + if (e) {
  108 + testDisabled.value = false;
  109 + } else {
  110 + testDisabled.value = true;
  111 + }
  112 + selectSysTenant.value = undefined;
  113 + const rest = (await getTenantAllPageLists(e)) as any;
  114 + selectTenantOptions.value = rest?.map((m) => ({ label: m.realName, value: m.id }));
  115 + };
  116 +
  117 + const onSelctTenant = async (e) => {
  118 + if (e) {
  119 + testDisabled.value = false;
  120 + } else {
  121 + testDisabled.value = true;
  122 + }
  123 + const { token } = await getUserToken(e);
  124 + getToken.value = token;
  125 + };
  126 + const isSingleClickText = ref('open');
  127 +
  128 + const handleTest = (o) => {
  129 + if (o === 'open') {
  130 + showTestEditCell.value = true;
  131 + emits('testParamsInterface');
  132 + getValue();
  133 + isSingleClickText.value = 'close';
  134 + } else {
  135 + isSingleClickText.value = 'open';
  136 + onCloseTest();
  137 + }
52 }; 138 };
53 139
54 const getValue = async () => { 140 const getValue = async () => {
@@ -116,6 +202,7 @@ @@ -116,6 +202,7 @@
116 } 202 }
117 excuteData.value = { 203 excuteData.value = {
118 params, 204 params,
  205 + token: getToken.value,
119 }; 206 };
120 return excuteData.value; 207 return excuteData.value;
121 }; 208 };
@@ -124,6 +211,9 @@ @@ -124,6 +211,9 @@
124 const setValue = () => { 211 const setValue = () => {
125 showTestEditCell.value = false; 212 showTestEditCell.value = false;
126 testResult.value = ''; 213 testResult.value = '';
  214 + selectTenant.value = undefined;
  215 + selectSysTenant.value = undefined;
  216 + selectTenantOptions.value = [];
127 }; 217 };
128 218
129 const onCloseTest = () => { 219 const onCloseTest = () => {
@@ -130,9 +130,8 @@ @@ -130,9 +130,8 @@
130 import { reactive, ref, onMounted } from 'vue'; 130 import { reactive, ref, onMounted } from 'vue';
131 import { Select } from 'ant-design-vue'; 131 import { Select } from 'ant-design-vue';
132 import { findDictItemByCode } from '/@/api/system/dict'; 132 import { findDictItemByCode } from '/@/api/system/dict';
133 - import { getAllDeviceByOrg } from '/@/api/dataBoard';  
134 - import { getDeviceAttributes } from '/@/api/dataBoard';  
135 import { useApi } from '../../../hooks/useApi'; 133 import { useApi } from '../../../hooks/useApi';
  134 + import { useUtils } from '../../../hooks/useUtils';
136 import { cloneDeep } from 'lodash-es'; 135 import { cloneDeep } from 'lodash-es';
137 import { tableItems, selectType } from '../../../types'; 136 import { tableItems, selectType } from '../../../types';
138 import { editTestCellTableTHeadConfig } from '../../../config'; 137 import { editTestCellTableTHeadConfig } from '../../../config';
@@ -142,6 +141,9 @@ @@ -142,6 +141,9 @@
142 method: { 141 method: {
143 type: String, 142 type: String,
144 }, 143 },
  144 + token: {
  145 + type: String,
  146 + },
145 }); 147 });
146 148
147 onMounted(async () => { 149 onMounted(async () => {
@@ -155,6 +157,8 @@ @@ -155,6 +157,8 @@
155 selectOptions.value = selectOptions.value.filter((f) => f.value !== 'scope'); 157 selectOptions.value = selectOptions.value.filter((f) => f.value !== 'scope');
156 }); 158 });
157 159
  160 + const { isOtherHttp } = useUtils();
  161 +
158 const selectOptions = ref<selectType[]>([]); 162 const selectOptions = ref<selectType[]>([]);
159 163
160 const valueOptions = ref<selectType[]>([]); 164 const valueOptions = ref<selectType[]>([]);
@@ -191,10 +195,10 @@ @@ -191,10 +195,10 @@
191 const getApi = (list) => { 195 const getApi = (list) => {
192 list?.forEach(async (it) => { 196 list?.forEach(async (it) => {
193 if (it.key === 'deviceProfileId') { 197 if (it.key === 'deviceProfileId') {
194 - const { options } = await useApi(it.key); 198 + const { options } = await useApi(it.key, props.token);
195 valueOptions.value = options; 199 valueOptions.value = options;
196 } else if (it.key === 'organizationId') { 200 } else if (it.key === 'organizationId') {
197 - const { options } = await useApi(it.key); 201 + const { options } = await useApi(it.key, props.token);
198 treeData.value = options as any; 202 treeData.value = options as any;
199 } 203 }
200 }); 204 });
@@ -212,7 +216,10 @@ @@ -212,7 +216,10 @@
212 }; 216 };
213 217
214 const getEntityOptions = async (organizationId: string, deviceProfileId?: string) => { 218 const getEntityOptions = async (organizationId: string, deviceProfileId?: string) => {
215 - const res = await getAllDeviceByOrg(organizationId, deviceProfileId); 219 + const res = await isOtherHttp('api/yt/device/list', props.token, {
  220 + organizationId,
  221 + deviceProfileId,
  222 + });
216 entityOptions.value = res.map((item) => ({ 223 entityOptions.value = res.map((item) => ({
217 label: item.name, 224 label: item.name,
218 value: item.tbDeviceId, 225 value: item.tbDeviceId,
@@ -220,7 +227,10 @@ @@ -220,7 +227,10 @@
220 }; 227 };
221 228
222 const getAttributeOptions = async (params) => { 229 const getAttributeOptions = async (params) => {
223 - const res = await getDeviceAttributes(params); 230 + const { deviceProfileId, dataType } = params;
  231 + const res = await isOtherHttp(`api/yt/device/attributes/${deviceProfileId}`, props.token, {
  232 + dataType,
  233 + });
224 if (Object.keys(res).length === 0) return (attributeOptions.value.length = 0); 234 if (Object.keys(res).length === 0) return (attributeOptions.value.length = 0);
225 attributeOptions.value = res?.map((item) => ({ label: item.name, value: item.identifier })); 235 attributeOptions.value = res?.map((item) => ({ label: item.name, value: item.identifier }));
226 }; 236 };
@@ -102,6 +102,7 @@ export const schemas: FormSchema[] = [ @@ -102,6 +102,7 @@ export const schemas: FormSchema[] = [
102 getPopupContainer: () => document.body, 102 getPopupContainer: () => document.body,
103 async onChange(e) { 103 async onChange(e) {
104 setFieldsValue({ 104 setFieldsValue({
  105 + requestOriginUrl: '',
105 requestHttpTypeAndUrl: { 106 requestHttpTypeAndUrl: {
106 requestHttpType: undefined, 107 requestHttpType: undefined,
107 requestUrl: '', 108 requestUrl: '',
@@ -113,6 +114,14 @@ export const schemas: FormSchema[] = [ @@ -113,6 +114,14 @@ export const schemas: FormSchema[] = [
113 type: e, 114 type: e,
114 }, 115 },
115 }); 116 });
  117 + updateSchema({
  118 + field: 'requestOriginUrl',
  119 + componentProps: {
  120 + placeholder: `${
  121 + e === '0' ? '示例:http://127.0.0.1' : e === '2' ? '示例:ws://127.0.0.1' : ''
  122 + }`,
  123 + },
  124 + });
116 }, 125 },
117 }; 126 };
118 }, 127 },
@@ -124,14 +133,24 @@ export const schemas: FormSchema[] = [ @@ -124,14 +133,24 @@ export const schemas: FormSchema[] = [
124 required: true, 133 required: true,
125 colProps: { span: 24 }, 134 colProps: { span: 24 },
126 defaultValue: 'server_url', 135 defaultValue: 'server_url',
127 - componentProps: {  
128 - placeholder: '请选择地址类型',  
129 - api: findDictItemByCode,  
130 - params: {  
131 - dictCode: 'dataview_select_origin_type',  
132 - },  
133 - labelField: 'itemText',  
134 - valueField: 'itemValue', 136 + componentProps: ({ formActionType }) => {
  137 + const { setFieldsValue } = formActionType;
  138 + return {
  139 + placeholder: '请选择地址类型',
  140 + api: findDictItemByCode,
  141 + params: {
  142 + dictCode: 'dataview_select_origin_type',
  143 + },
  144 + labelField: 'itemText',
  145 + valueField: 'itemValue',
  146 + onChange: (e) => {
  147 + if (e) {
  148 + setFieldsValue({
  149 + requestOriginUrl: '',
  150 + });
  151 + }
  152 + },
  153 + };
135 }, 154 },
136 }, 155 },
137 { 156 {
@@ -140,9 +159,14 @@ export const schemas: FormSchema[] = [ @@ -140,9 +159,14 @@ export const schemas: FormSchema[] = [
140 colProps: { span: 24 }, 159 colProps: { span: 24 },
141 required: true, 160 required: true,
142 component: 'Input', 161 component: 'Input',
143 - componentProps: {  
144 - maxLength: 255,  
145 - placeholder: '请输入地址', 162 + componentProps: ({ formActionType }) => {
  163 + const { getFieldsValue } = formActionType;
  164 + const type = getFieldsValue()?.requestContentType;
  165 + return {
  166 + placeholder: `${
  167 + type === '0' ? '示例:http://127.0.0.1' : type === '2' ? '示例:ws://127.0.0.1' : ''
  168 + }`,
  169 + };
146 }, 170 },
147 ifShow: ({ values }) => values['originUrlType'] === 'custom_url', 171 ifShow: ({ values }) => values['originUrlType'] === 'custom_url',
148 }, 172 },
@@ -160,6 +184,13 @@ export const schemas: FormSchema[] = [ @@ -160,6 +184,13 @@ export const schemas: FormSchema[] = [
160 }, 184 },
161 }, 185 },
162 { 186 {
  187 + field: 'fillAddress',
  188 + label: '完整地址',
  189 + component: 'Input',
  190 + slot: 'slotFillAddress',
  191 + colProps: { span: 24 },
  192 + },
  193 + {
163 field: 'requestSQLKey', 194 field: 'requestSQLKey',
164 label: '键名', 195 label: '键名',
165 colProps: { span: 6 }, 196 colProps: { span: 6 },
1 <template> 1 <template>
2 <div> 2 <div>
3 <BasicDrawer 3 <BasicDrawer
  4 + destroyOnClose
4 showFooter 5 showFooter
5 v-bind="$attrs" 6 v-bind="$attrs"
6 @register="registerDrawer" 7 @register="registerDrawer"
@@ -9,6 +10,9 @@ @@ -9,6 +10,9 @@
9 > 10 >
10 <BasicForm @register="registerForm"> 11 <BasicForm @register="registerForm">
11 <template #selectMethods="{ model }"> 12 <template #selectMethods="{ model }">
  13 + <p style="display: none">{{
  14 + watchRequestHttpTypeAndUrl(model['requestHttpTypeAndUrl'])
  15 + }}</p>
12 <SimpleRequest 16 <SimpleRequest
13 ref="simpleRequestRef" 17 ref="simpleRequestRef"
14 v-if="model['requestContentType'] === '0' || model['requestContentType'] === '2'" 18 v-if="model['requestContentType'] === '0' || model['requestContentType'] === '2'"
@@ -27,12 +31,30 @@ @@ -27,12 +31,30 @@
27 /> 31 />
28 </div> 32 </div>
29 </template> 33 </template>
  34 + <template #slotFillAddress="{ model }">
  35 + <div>
  36 + <Tag color="blue" style="width: 35vw; white-space: normal; height: auto">
  37 + {{
  38 + ` ${
  39 + model['originUrlType'] !== 'server_url'
  40 + ? !model['requestOriginUrl']
  41 + ? ''
  42 + : model['requestOriginUrl'] + model['requestHttpTypeAndUrl']?.requestUrl
  43 + : `${templateFillAddress(model['requestContentType'], model['originUrlType'])}${
  44 + model['requestHttpTypeAndUrl']?.requestUrl
  45 + }`
  46 + }
  47 + `
  48 + }}
  49 + </Tag>
  50 + </div>
  51 + </template>
30 </BasicForm> 52 </BasicForm>
31 </BasicDrawer> 53 </BasicDrawer>
32 </div> 54 </div>
33 </template> 55 </template>
34 <script lang="ts" setup name="publicApi"> 56 <script lang="ts" setup name="publicApi">
35 - import { ref, nextTick } from 'vue'; 57 + import { ref, nextTick, watch } from 'vue';
36 import { BasicDrawer, useDrawerInner } from '/@/components/Drawer'; 58 import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
37 import { BasicForm, useForm } from '/@/components/Form'; 59 import { BasicForm, useForm } from '/@/components/Form';
38 import { schemas } from './config'; 60 import { schemas } from './config';
@@ -45,8 +67,9 @@ @@ -45,8 +67,9 @@
45 67
46 import { useMessage } from '/@/hooks/web/useMessage'; 68 import { useMessage } from '/@/hooks/web/useMessage';
47 import { useUtils } from './hooks/useUtils'; 69 import { useUtils } from './hooks/useUtils';
  70 + import { Tag } from 'ant-design-vue';
48 71
49 - const { resetReqHttpType } = useUtils(); 72 + const { resetReqHttpType, isServerUrl } = useUtils();
50 73
51 const emits = defineEmits(['success', 'register']); 74 const emits = defineEmits(['success', 'register']);
52 75
@@ -60,6 +83,35 @@ @@ -60,6 +83,35 @@
60 83
61 const testSqlRef = ref<InstanceType<typeof TestSql>>(); 84 const testSqlRef = ref<InstanceType<typeof TestSql>>();
62 85
  86 + const templateFillAddress = (method, type) => {
  87 + return isServerUrl(method, type);
  88 + };
  89 +
  90 + const watchRequestHttpTypeAndUrlStr = ref('');
  91 +
  92 + const watchRequestHttpTypeAndUrl = (o) => {
  93 + watchRequestHttpTypeAndUrlStr.value = o;
  94 + };
  95 +
  96 + watch(
  97 + () => watchRequestHttpTypeAndUrlStr.value,
  98 + (newValue: any) => {
  99 + if (!newValue?.requestUrl) return;
  100 + if (newValue?.requestUrl.includes('{entityType}')) {
  101 + simpleRequestRef.value?.setValue(null, true, [
  102 + {
  103 + key: 'scope',
  104 + value: 'entityType',
  105 + required: true,
  106 + },
  107 + ]);
  108 + }
  109 + },
  110 + {
  111 + deep: true,
  112 + }
  113 + );
  114 +
63 const [registerForm, { resetFields, validate, setFieldsValue, updateSchema }] = useForm({ 115 const [registerForm, { resetFields, validate, setFieldsValue, updateSchema }] = useForm({
64 labelWidth: 120, 116 labelWidth: 120,
65 schemas, 117 schemas,
@@ -94,7 +146,7 @@ @@ -94,7 +146,7 @@
94 requestUrl: data.record?.requestUrl, 146 requestUrl: data.record?.requestUrl,
95 }, 147 },
96 }); 148 });
97 - await nextTick(() => simpleRequestRef.value?.setValue(data.record)); 149 + await nextTick(() => simpleRequestRef.value?.setValue(data.record, false, []));
98 updateSchema({ 150 updateSchema({
99 field: 'requestHttpTypeAndUrl', 151 field: 'requestHttpTypeAndUrl',
100 componentProps: { 152 componentProps: {
@@ -110,12 +162,19 @@ @@ -110,12 +162,19 @@
110 const values = await validate(); 162 const values = await validate();
111 if (!values) return; 163 if (!values) return;
112 const isRequestHttpTypeAndUrlEmpty = values?.requestHttpTypeAndUrl; 164 const isRequestHttpTypeAndUrlEmpty = values?.requestHttpTypeAndUrl;
113 - if (  
114 - !Reflect.get(isRequestHttpTypeAndUrlEmpty, 'requestHttpType') ||  
115 - !Reflect.get(isRequestHttpTypeAndUrlEmpty, 'requestUrl')  
116 - ) {  
117 - createMessage.error('请填写请求类型&地址');  
118 - throw Error('请填写请求类型&地址'); 165 + if (values.requestContentType === '0') {
  166 + if (
  167 + !Reflect.get(isRequestHttpTypeAndUrlEmpty, 'requestHttpType') ||
  168 + !Reflect.get(isRequestHttpTypeAndUrlEmpty, 'requestUrl')
  169 + ) {
  170 + createMessage.error('请填写请求类型&地址');
  171 + throw Error('请填写请求类型&地址');
  172 + }
  173 + } else if (values.requestContentType === '2') {
  174 + if (!Reflect.get(isRequestHttpTypeAndUrlEmpty, 'requestUrl')) {
  175 + createMessage.error('请填写请求类型&地址');
  176 + throw Error('请填写请求类型&地址');
  177 + }
119 } 178 }
120 const Objects = simpleRequestRef.value?.getValue(true); 179 const Objects = simpleRequestRef.value?.getValue(true);
121 const requestOriginUrl = 180 const requestOriginUrl =
1 import { ref } from 'vue'; 1 import { ref } from 'vue';
2 -import { deviceProfile } from '/@/api/device/deviceManager';  
3 -import { getOrganizationList } from '/@/api/system/system';  
4 -// import { copyTransFun } from '/@/utils/fnUtils';  
5 -// import { getAllDeviceByOrg } from '/@/api/dataBoard';  
6 -// import { getDeviceAttributes } from '/@/api/dataBoard';  
7 import { copyTransFun } from '/@/utils/fnUtils'; 2 import { copyTransFun } from '/@/utils/fnUtils';
  3 +import { useUtils } from './useUtils';
8 4
9 -export const useApi = async (key) => { 5 +export const useApi = async (key, token) => {
  6 + const { isOtherHttp } = useUtils();
10 const options = ref<{ label: string; value: string; disabled?: boolean }[]>([]); 7 const options = ref<{ label: string; value: string; disabled?: boolean }[]>([]);
11 switch (key) { 8 switch (key) {
12 case 'deviceProfileId': 9 case 'deviceProfileId':
13 - const res = await deviceProfile(); 10 + const res = (await isOtherHttp('/api/yt/device_profile/me/list', token, {})) as any;
14 options.value = res?.map((m) => ({ label: m.name, value: m.id })); 11 options.value = res?.map((m) => ({ label: m.name, value: m.id }));
15 break; 12 break;
16 case 'organizationId': 13 case 'organizationId':
17 - const data = await getOrganizationList(); 14 + const data = await isOtherHttp('/api/yt/organization/me/list', token, {});
18 copyTransFun(data as never as any); 15 copyTransFun(data as never as any);
19 options.value = data as any; 16 options.value = data as any;
20 } 17 }
  1 +import { otherHttp } from '/@/utils/http/axios';
  2 +
1 export const useUtils = () => { 3 export const useUtils = () => {
2 //获取多个key 4 //获取多个key
3 const getMultipleKeys = (list) => { 5 const getMultipleKeys = (list) => {
@@ -51,5 +53,44 @@ export const useUtils = () => { @@ -51,5 +53,44 @@ export const useUtils = () => {
51 } 53 }
52 return _result.join('&'); 54 return _result.join('&');
53 }; 55 };
54 - return { getMultipleKeys, pushObj, resetReqHttpType, resetUpdateSchema, convertObj }; 56 + //判断服务器地址是否为http/https ws/wss
  57 + const isServerUrl = (method, type) => {
  58 + const pathUrl = window.location.host;
  59 + const protocol = window.location.protocol;
  60 + let url = '';
  61 + if (method === '2') {
  62 + if (type === 'server_url') {
  63 + url = `${protocol === 'http' ? 'ws:' : protocol === 'https' ? 'wss:' : 'ws:'}//${pathUrl}`;
  64 + }
  65 + } else if (method === '0') {
  66 + if (type === 'server_url') {
  67 + url = `${protocol}//${pathUrl}`;
  68 + }
  69 + }
  70 + return url;
  71 + };
  72 + //TODO:待优化自定义请求
  73 + const isOtherHttp = async (url, token, params) => {
  74 + return await otherHttp.get(
  75 + {
  76 + url,
  77 + headers: { 'X-Authorization': `Bearer ${token}` },
  78 + params,
  79 + },
  80 + {
  81 + apiUrl: '',
  82 + withToken: false,
  83 + joinPrefix: false,
  84 + }
  85 + );
  86 + };
  87 + return {
  88 + getMultipleKeys,
  89 + pushObj,
  90 + resetReqHttpType,
  91 + resetUpdateSchema,
  92 + isServerUrl,
  93 + convertObj,
  94 + isOtherHttp,
  95 + };
55 }; 96 };
@@ -152,7 +152,7 @@ @@ -152,7 +152,7 @@
152 else setStatusIsTrue(); 152 else setStatusIsTrue();
153 }, 153 },
154 getCheckboxProps: (record) => ({ 154 getCheckboxProps: (record) => ({
155 - disabled: record.state === 1, 155 + disabled: record.creator !== userId.value || record.state === 1,
156 }), 156 }),
157 }; 157 };
158 158
@@ -174,21 +174,30 @@ @@ -174,21 +174,30 @@
174 }; 174 };
175 175
176 const handlePublish = async (type, record) => { 176 const handlePublish = async (type, record) => {
177 - type === 'publish' ? await getPublish(record.id) : await getCancelPublish(record.id);  
178 - createMessage.success(`${type === 'publish' ? '发布' : '取消发布'}成功`);  
179 - handleSuccess(); 177 + try {
  178 + type === 'publish' ? await getPublish(record.id) : await getCancelPublish(record.id);
  179 + createMessage.success(`${type === 'publish' ? '发布' : '取消发布'}成功`);
  180 + } finally {
  181 + handleSuccess();
  182 + }
180 }; 183 };
181 184
182 const handleBatchPublish = async (type) => { 185 const handleBatchPublish = async (type) => {
183 - await putPublishOrCancelPublish(type, batchDeleteIds.value);  
184 - createMessage.success(`${type === 'batchPublish' ? '批量发布' : '批量取消发布'}成功`);  
185 - handleSuccess(); 186 + try {
  187 + await putPublishOrCancelPublish(type, batchDeleteIds.value);
  188 + createMessage.success(`${type === 'batchPublish' ? '批量发布' : '批量取消发布'}成功`);
  189 + } finally {
  190 + handleSuccess();
  191 + }
186 }; 192 };
187 193
188 const handleDeleteOrBatchDelete = async (record) => { 194 const handleDeleteOrBatchDelete = async (record) => {
189 - const ids = record === null ? batchDeleteIds.value : [record.id];  
190 - await deleteBigViewInterface(ids);  
191 - createMessage.success(`${record === null ? '批量删除' : '删除'}成功`);  
192 - handleSuccess(); 195 + try {
  196 + const ids = record === null ? batchDeleteIds.value : [record.id];
  197 + await deleteBigViewInterface(ids);
  198 + createMessage.success(`${record === null ? '批量删除' : '删除'}成功`);
  199 + } finally {
  200 + handleSuccess();
  201 + }
193 }; 202 };
194 </script> 203 </script>
1 import { FormSchema } from '/@/components/Form'; 1 import { FormSchema } from '/@/components/Form';
2 import { findDictItemByCode } from '/@/api/system/dict'; 2 import { findDictItemByCode } from '/@/api/system/dict';
3 import { deviceProfile, getGatewayDevice } from '/@/api/device/deviceManager'; 3 import { deviceProfile, getGatewayDevice } from '/@/api/device/deviceManager';
4 -import { DeviceTypeEnum } from '/@/api/device/model/deviceModel';  
5 import { TransportTypeEnum } from '../../profiles/components/TransportDescript/const'; 4 import { TransportTypeEnum } from '../../profiles/components/TransportDescript/const';
6 5
7 export enum TypeEnum { 6 export enum TypeEnum {
@@ -114,20 +113,6 @@ export const step1Schemas: FormSchema[] = [ @@ -114,20 +113,6 @@ export const step1Schemas: FormSchema[] = [
114 }, 113 },
115 }, 114 },
116 { 115 {
117 - field: 'code',  
118 - label: '地址码',  
119 - component: 'Input',  
120 - ifShow: ({ model }) => {  
121 - return (  
122 - model['transportType'] === TransportTypeEnum.TCP &&  
123 - model['deviceType'] === DeviceTypeEnum.SENSOR  
124 - );  
125 - },  
126 - dynamicRules: ({ model }) => {  
127 - return [{ required: model['transportType'] === 'TCP', message: '地址码为必填项' }];  
128 - },  
129 - },  
130 - {  
131 field: 'brand', 116 field: 'brand',
132 component: 'ApiRadioGroup', 117 component: 'ApiRadioGroup',
133 label: '选择厂家', 118 label: '选择厂家',