Commit 1d60a05b3c433ce98e47dae49a74ccc9539d8941

Authored by xp.Huang
2 parents 623e2620 bda264ea

Merge branch 'ft' into 'main_dev'

pref: 公共接口管理 调整接口类型根据不同管理员显示

See merge request yunteng/thingskit-front!550
... ... @@ -16,6 +16,8 @@ export enum ConfigurationPermission {
16 16 SHARE = 'api:yt:dataview:center:share',
17 17 DESIGN = 'api:yt:dataview:center:get_configuration_info:design',
18 18 PREVIEW = 'api:yt:dataview:center:get_configuration_info:preview',
  19 + PUBLISH = 'api:yt:dataview:center:publish',
  20 + CANCEL_PUBLISH = 'api:yt:dataview:center:cancel_publish',
19 21 }
20 22
21 23 // 查询字段
... ...
... ... @@ -301,7 +301,7 @@
301 301 },
302 302 {
303 303 text: '发布',
304   - auth: ConfigurationPermission.UPDATE,
  304 + auth: ConfigurationPermission.PUBLISH,
305 305 icon: 'ant-design:node-expand-outlined',
306 306 event: '',
307 307 onClick: handlePublish.bind(null, item),
... ... @@ -309,6 +309,7 @@
309 309 },
310 310 {
311 311 text: '取消发布',
  312 + auth: ConfigurationPermission.CANCEL_PUBLISH,
312 313 icon: 'ant-design:node-collapse-outlined',
313 314 event: '',
314 315 onClick: handleCancelPublish.bind(null, item),
... ...
1 1 <template>
2   - <div class="flex" style="justify-content: space-between; align-content: center">
  2 + <div class="flex flex-col justify-between">
3 3 <div ref="jsoneditorRef" style="height: 100%; width: 100%"></div>
4 4 <div class="ml-2 -mt-1.5">
5   - <Button v-if="showBtn" @click="onHandleCopy" type="text"> 复制测试结果 </Button>
  5 + <Button v-if="showBtn" @click="onHandleCopy" class="mt-8 -ml-2">
  6 + <template #icon>
  7 + <CopyOutlined />
  8 + </template>
  9 + copy
  10 + </Button>
6 11 </div>
7 12 </div>
8 13 </template>
... ... @@ -13,6 +18,7 @@
13 18 import 'jsoneditor/dist/jsoneditor.min.css';
14 19 import { Button } from 'ant-design-vue';
15 20 import { useMessage } from '/@/hooks/web/useMessage';
  21 + import { CopyOutlined } from '@ant-design/icons-vue';
16 22
17 23 const props = defineProps({
18 24 showBtn: {
... ... @@ -36,11 +42,7 @@
36 42 mode: 'code',
37 43 mainMenuBar: false,
38 44 statusBar: false,
39   - onFocus: () => {
40   - if (props.showBtn) {
41   - setJsonValue('测试结果为');
42   - }
43   - },
  45 + onFocus: () => {},
44 46 onBlur: () => {},
45 47 onChangeText: (e) => {
46 48 if (props.showBtn) {
... ...
... ... @@ -9,6 +9,7 @@
9 9 @closeTest="onCloseTest"
10 10 ref="testParamsRequestRef"
11 11 :data="dataMap.mapParamsObj"
  12 + :interfaceType="interfaceType"
12 13 />
13 14 </TabPane>
14 15 <TabPane
... ... @@ -24,6 +25,7 @@
24 25 @testBodyInterface="handleTestBodyInterface"
25 26 @closeTest="onCloseTest"
26 27 ref="testBodyRequestRef"
  28 + :interfaceType="interfaceType"
27 29 :data="dataMap.mapBodyObj"
28 30 />
29 31 </TabPane>
... ... @@ -33,6 +35,7 @@
33 35 @testHeaderInterface="handleTestHeaderInterface"
34 36 @closeTest="onCloseTest"
35 37 ref="testHeaderRequestRef"
  38 + :interfaceType="interfaceType"
36 39 :data="dataMap.mapHeaderObj"
37 40 />
38 41 </TabPane>
... ... @@ -64,6 +67,9 @@
64 67 originUrlType: {
65 68 type: String,
66 69 },
  70 + interfaceType: {
  71 + type: String,
  72 + },
67 73 });
68 74
69 75 const emits = defineEmits(['activeKey']);
... ...
... ... @@ -2,7 +2,7 @@
2 2 <div>
3 3 <div class="mt-8">
4 4 <div class="flex">
5   - <div class="flex" v-if="isAdmin(role)">
  5 + <div class="flex" v-if="interfaceType === 'SYSTEM' && isAdmin(role)">
6 6 <Select
7 7 v-model:value="selectTenant"
8 8 allowClear
... ... @@ -22,7 +22,7 @@
22 22 />
23 23 </div>
24 24 <Button
25   - :disabled="isAdmin(role) ? testDisabled : false"
  25 + :disabled="interfaceType === 'SYSTEM' && isAdmin(role) ? testDisabled : false"
26 26 class="ml-2"
27 27 @click="handleTest(isSingleClickText)"
28 28 type="primary"
... ... @@ -75,6 +75,9 @@
75 75 data: {
76 76 type: Object,
77 77 },
  78 + interfaceType: {
  79 + type: String,
  80 + },
78 81 });
79 82
80 83 onMounted(async () => {
... ... @@ -235,6 +238,7 @@
235 238 excuteData.value = {
236 239 params,
237 240 token: getToken.value,
  241 + type: props.data?.type,
238 242 };
239 243 return excuteData.value;
240 244 };
... ...
... ... @@ -100,6 +100,8 @@
100 100
101 101 const isShowTestResult = ref(false);
102 102
  103 + const postBodyType = ref('');
  104 +
103 105 //执行测试接口
104 106 const handleExcute = () => {
105 107 emits('emitExcute');
... ... @@ -123,6 +125,7 @@
123 125 isToken.value = Objects?.Params?.token;
124 126 const body = Objects?.Body?.params;
125 127 isPostToken.value = Objects?.Body?.token;
  128 + postBodyType.value = Objects?.Body?.type;
126 129 apiUrl.value = url?.restfulFormat(params);
127 130 if (isWebSocketType.value === '2') {
128 131 socketUrls.value = url;
... ... @@ -143,7 +146,8 @@
143 146 params,
144 147 body,
145 148 isToken.value,
146   - isPostToken.value
  149 + isPostToken.value,
  150 + postBodyType.value
147 151 );
148 152 if (!resp) return;
149 153 if (Object.prototype.toString.call(resp) === '[object Object]') {
... ... @@ -151,7 +155,10 @@
151 155 } else if (typeof resp === 'string') {
152 156 jsonEditorRef.value?.setJsonValue(resp);
153 157 } else if (Array.isArray(resp)) {
154   - jsonEditorRef.value?.setJsonValue(JSON.stringify(resp));
  158 + const temp = {
  159 + data: resp,
  160 + };
  161 + jsonEditorRef.value?.setJsonValue(temp);
155 162 } else {
156 163 jsonEditorRef.value?.setJsonValue(JSON.stringify(resp));
157 164 }
... ... @@ -217,14 +224,19 @@
217 224 body,
218 225 token,
219 226 postToken,
  227 + postBodyType,
220 228 joinPrefix = false
221 229 ) => {
222 230 const { convertObj } = useUtils();
223 231 switch (apiType) {
224 232 case 'GET':
225   - const objGet = Object.assign({}, headers, {
226   - 'X-Authorization': `Bearer ${!token ? postToken : token}`,
227   - });
  233 + const objGet = Object.assign(
  234 + {},
  235 + {
  236 + 'X-Authorization': `Bearer ${!token ? postToken : token}`,
  237 + },
  238 + headers
  239 + );
228 240 return await otherHttp.get(
229 241 { url: apiUrl, params, headers: objGet },
230 242 {
... ... @@ -235,9 +247,26 @@
235 247 }
236 248 );
237 249 case 'POST':
238   - const objPost = Object.assign({}, headers, {
239   - 'X-Authorization': `Bearer ${!postToken ? token : postToken}`,
240   - });
  250 + console.log(postBodyType);
  251 + const objPost = Object.assign(
  252 + {},
  253 + {
  254 + 'X-Authorization': `Bearer ${!postToken ? token : postToken}`,
  255 + },
  256 + {
  257 + 'Content-Type':
  258 + postBodyType === 'xml'
  259 + ? 'text/xml'
  260 + : postBodyType === 'form-data'
  261 + ? 'multipart/form-data'
  262 + : postBodyType === 'x-www-form-urlencoded'
  263 + ? 'application/x-www-form-urlencoded'
  264 + : postBodyType === 'json'
  265 + ? 'application/json'
  266 + : 'application/json',
  267 + },
  268 + headers
  269 + );
241 270 return await otherHttp.post(
242 271 { url: `${apiUrl}?${convertObj(params)}`, data: body, headers: objPost },
243 272 {
... ...
... ... @@ -2,7 +2,7 @@
2 2 <div>
3 3 <div class="mt-8">
4 4 <div class="flex">
5   - <div class="flex" v-if="isAdmin(role)">
  5 + <div class="flex" v-if="interfaceType === 'SYSTEM' && isAdmin(role)">
6 6 <Select
7 7 allowClear
8 8 v-model:value="selectTenant"
... ... @@ -22,7 +22,7 @@
22 22 />
23 23 </div>
24 24 <Button
25   - :disabled="isAdmin(role) ? testDisabled : false"
  25 + :disabled="interfaceType === 'SYSTEM' && isAdmin(role) ? testDisabled : false"
26 26 class="ml-2"
27 27 @click="handleTest(isSingleClickText)"
28 28 type="primary"
... ... @@ -64,6 +64,9 @@
64 64 data: {
65 65 type: Object,
66 66 },
  67 + interfaceType: {
  68 + type: String,
  69 + },
67 70 });
68 71
69 72 onMounted(async () => {
... ...
... ... @@ -2,7 +2,7 @@
2 2 <div>
3 3 <div class="mt-8">
4 4 <div class="flex">
5   - <div class="flex" v-if="isAdmin(role)">
  5 + <div class="flex" v-if="interfaceType === 'SYSTEM' && isAdmin(role)">
6 6 <Select
7 7 allowClear
8 8 v-model:value="selectTenant"
... ... @@ -22,7 +22,7 @@
22 22 />
23 23 </div>
24 24 <Button
25   - :disabled="isAdmin(role) ? testDisabled : false"
  25 + :disabled="interfaceType === 'SYSTEM' && isAdmin(role) ? testDisabled : false"
26 26 class="ml-2"
27 27 @click="handleTest(isSingleClickText)"
28 28 type="primary"
... ... @@ -66,6 +66,9 @@
66 66 data: {
67 67 type: Object,
68 68 },
  69 + interfaceType: {
  70 + type: String,
  71 + },
69 72 });
70 73
71 74 onMounted(async () => {
... ...
... ... @@ -2,6 +2,9 @@ import { BasicColumn, FormSchema } from '/@/components/Table';
2 2 import { h } from 'vue';
3 3 import { Tag } from 'ant-design-vue';
4 4 import { findDictItemByCode } from '/@/api/system/dict';
  5 +import { USER_INFO_KEY } from '/@/enums/cacheEnum';
  6 +import { getAuthCache } from '/@/utils/auth';
  7 +import { isAdmin } from '/@/enums/roleEnum';
5 8
6 9 // 表格配置
7 10 export const columns: BasicColumn[] = [
... ... @@ -11,6 +14,14 @@ export const columns: BasicColumn[] = [
11 14 width: 150,
12 15 },
13 16 {
  17 + title: '接口类型',
  18 + dataIndex: 'interfaceType',
  19 + width: 80,
  20 + format(text) {
  21 + return text === 'SYSTEM' ? '系统默认' : '自定义';
  22 + },
  23 + },
  24 + {
14 25 title: '请求方式',
15 26 dataIndex: 'requestContentType',
16 27 width: 90,
... ... @@ -42,7 +53,7 @@ export const searchFormSchema: FormSchema[] = [
42 53 field: 'name',
43 54 label: '接口名称',
44 55 component: 'Input',
45   - colProps: { span: 9 },
  56 + colProps: { span: 7 },
46 57 componentProps: {
47 58 maxLength: 36,
48 59 placeholder: '请输入接口名称',
... ... @@ -52,7 +63,7 @@ export const searchFormSchema: FormSchema[] = [
52 63 field: 'state',
53 64 label: '发布状态',
54 65 component: 'Select',
55   - colProps: { span: 9 },
  66 + colProps: { span: 7 },
56 67 componentProps: {
57 68 options: [
58 69 {
... ... @@ -67,6 +78,31 @@ export const searchFormSchema: FormSchema[] = [
67 78 placeholder: '请选择发布状态',
68 79 },
69 80 },
  81 + {
  82 + field: 'interfaceType',
  83 + label: '接口类型',
  84 + component: 'Select',
  85 + colProps: { span: 7 },
  86 + componentProps: {
  87 + options: [
  88 + {
  89 + label: '系统默认',
  90 + value: 'SYSTEM',
  91 + },
  92 + {
  93 + label: '自定义',
  94 + value: 'CUSTOM',
  95 + },
  96 + ],
  97 + placeholder: '请选择接口类型',
  98 + },
  99 + ifShow: ({}) => {
  100 + const userInfo: any = getAuthCache(USER_INFO_KEY);
  101 + const role: string = userInfo?.roles[0];
  102 + if (isAdmin(role)) return true;
  103 + else return false;
  104 + },
  105 + },
70 106 ];
71 107
72 108 //表单配置
... ... @@ -82,6 +118,52 @@ export const schemas: FormSchema[] = [
82 118 placeholder: '请输入接口名称',
83 119 },
84 120 },
  121 + // {
  122 + // field: 'interfaceType',
  123 + // component: 'ApiRadioGroup',
  124 + // label: '接口类型',
  125 + // required: true,
  126 + // colProps: {
  127 + // span: 8,
  128 + // },
  129 + // defaultValue: 'SYSTEM',
  130 + // componentProps: {
  131 + // api: findDictItemByCode,
  132 + // params: {
  133 + // dictCode: 'interface_Type',
  134 + // },
  135 + // labelField: 'itemText',
  136 + // valueField: 'itemValue',
  137 + // },
  138 + // },
  139 + {
  140 + field: 'interfaceType',
  141 + component: 'ApiRadioGroup',
  142 + label: '接口类型',
  143 + required: true,
  144 + colProps: {
  145 + span: 8,
  146 + },
  147 + defaultValue: 'CUSTOM',
  148 + componentProps: {
  149 + options: [
  150 + {
  151 + label: '系统默认',
  152 + value: 'SYSTEM',
  153 + },
  154 + {
  155 + label: '自定义',
  156 + value: 'CUSTOM',
  157 + },
  158 + ],
  159 + },
  160 + ifShow: ({}) => {
  161 + const userInfo: any = getAuthCache(USER_INFO_KEY);
  162 + const role: string = userInfo?.roles[0];
  163 + if (isAdmin(role)) return true;
  164 + else return false;
  165 + },
  166 + },
85 167 {
86 168 field: 'requestContentType',
87 169 label: '请求方式',
... ... @@ -190,9 +272,17 @@ export const schemas: FormSchema[] = [
190 272 slot: 'slotFillAddress',
191 273 colProps: { span: 24 },
192 274 ifShow: ({ values }) => {
193   - if (values['requestOriginUrl']) {
194   - return true;
195   - } else return false;
  275 + return values['originUrlType'] === 'custom_url' && values['requestOriginUrl'];
  276 + },
  277 + },
  278 + {
  279 + field: 'slotServerAddress',
  280 + label: '完整地址',
  281 + component: 'Input',
  282 + slot: 'slotServerAddress',
  283 + colProps: { span: 24 },
  284 + ifShow: ({ values }) => {
  285 + return values['originUrlType'] === 'server_url';
196 286 },
197 287 },
198 288 {
... ...
... ... @@ -20,6 +20,7 @@
20 20 :method="model['requestContentType']"
21 21 :requestOriginUrl="model['requestOriginUrl']"
22 22 :originUrlType="model['originUrlType']"
  23 + :interfaceType="model['interfaceType']"
23 24 />
24 25 </template>
25 26 <template #testSql="{ model }">
... ... @@ -33,6 +34,19 @@
33 34 </template>
34 35 <template #slotFillAddress="{ model }">
35 36 <div>
  37 + <template v-if="model['originUrlType'] === 'custom_url'">
  38 + <Tag
  39 + v-if="model['requestOriginUrl']"
  40 + color="blue"
  41 + style="width: 35vw; white-space: normal; height: auto"
  42 + >
  43 + {{ ` ${model['requestOriginUrl'] + model['requestHttpTypeAndUrl']?.requestUrl}` }}
  44 + </Tag>
  45 + </template>
  46 + </div>
  47 + </template>
  48 + <template #slotServerAddress="{ model }">
  49 + <div>
36 50 <Tag
37 51 v-if="model['originUrlType'] === 'server_url'"
38 52 color="blue"
... ... @@ -45,15 +59,6 @@
45 59 `
46 60 }}
47 61 </Tag>
48   - <template v-else>
49   - <Tag
50   - v-if="model['requestOriginUrl']"
51   - color="blue"
52   - style="width: 35vw; white-space: normal; height: auto"
53   - >
54   - {{ ` ${model['requestOriginUrl'] + model['requestHttpTypeAndUrl']?.requestUrl}` }}
55   - </Tag>
56   - </template>
57 62 </div>
58 63 </template>
59 64 </BasicForm>
... ...
... ... @@ -12,7 +12,12 @@
12 12 </template>
13 13 </BasicTable>
14 14 <div style="margin-left: 0.44rem">
15   - <a-button type="primary" class="mr-4" :disabled="disabled" @click="handleFrpRemote"
  15 + <a-button
  16 + v-if="isAdmin !== 'CUSTOMER_USER'"
  17 + type="primary"
  18 + class="mr-4"
  19 + :disabled="disabled"
  20 + @click="handleFrpRemote"
16 21 >远程连接</a-button
17 22 >
18 23 </div>
... ... @@ -20,13 +25,15 @@
20 25 </template>
21 26
22 27 <script setup lang="ts">
23   - import { ref, nextTick } from 'vue';
  28 + import { ref, nextTick, computed } from 'vue';
24 29 import { BasicTable, useTable, BasicColumn } from '/@/components/Table';
25 30 import { Switch } from 'ant-design-vue';
26 31 import { h } from 'vue';
27 32 import { Tag } from 'ant-design-vue';
28 33 import { frpGetInfoApi, frpPutInfoApi } from '/@/api/device/deviceConfigApi';
29 34 import { useMessage } from '/@/hooks/web/useMessage';
  35 + import { USER_INFO_KEY } from '/@/enums/cacheEnum';
  36 + import { getAuthCache } from '/@/utils/auth';
30 37
31 38 const props = defineProps({
32 39 deviceDetail: {
... ... @@ -35,6 +42,18 @@
35 42 },
36 43 });
37 44
  45 + const userInfo = getAuthCache(USER_INFO_KEY) as unknown as any;
  46 +
  47 + const isAdmin = computed(() => {
  48 + if (userInfo.roles.includes('TENANT_ADMIN')) {
  49 + return 'TENANT_ADMIN';
  50 + } else if (userInfo.roles.includes('CUSTOMER_USER')) {
  51 + return 'CUSTOMER_USER';
  52 + } else {
  53 + return 'SYS_ADMIN';
  54 + }
  55 + });
  56 +
38 57 const { createMessage } = useMessage();
39 58 const tableData: any = ref([]);
40 59 const checked = ref<boolean>(false);
... ...