Commit 9c49f5159fecdf7e08d5f5d251f71f74fd72eabd

Authored by fengwotao
1 parent 20c33e78

perf: 公共接口管理代码优化

@@ -38,7 +38,7 @@ @@ -38,7 +38,7 @@
38 </template> 38 </template>
39 <script lang="ts" setup name="body"> 39 <script lang="ts" setup name="body">
40 import { reactive, ref, nextTick } from 'vue'; 40 import { reactive, ref, nextTick } from 'vue';
41 - import { RequestBodyTypeEnum } from '../../../enum/index'; 41 + import { RequestBodyTypeEnum } from '../../../config/enum';
42 import BodyTable from './bodyTable.vue'; 42 import BodyTable from './bodyTable.vue';
43 import { isEmpty } from '/@/utils/is'; 43 import { isEmpty } from '/@/utils/is';
44 import { useUtils } from '../../../hooks/useUtils'; 44 import { useUtils } from '../../../hooks/useUtils';
@@ -59,8 +59,8 @@ @@ -59,8 +59,8 @@
59 import { Select, Button } from 'ant-design-vue'; 59 import { Select, Button } from 'ant-design-vue';
60 import { findDictItemByCode } from '/@/api/system/dict'; 60 import { findDictItemByCode } from '/@/api/system/dict';
61 import { PlusOutlined, MinusOutlined } from '@ant-design/icons-vue'; 61 import { PlusOutlined, MinusOutlined } from '@ant-design/icons-vue';
62 - import { editCellTableTHeadConfig } from '../../../config';  
63 - import { selectType, tableItems } from '../../../types'; 62 + import { editCellTableTHeadConfig } from '../../../config/config';
  63 + import { selectType, tableItems } from '../../../config/types';
64 64
65 defineProps({ 65 defineProps({
66 method: { 66 method: {
@@ -40,9 +40,8 @@ @@ -40,9 +40,8 @@
40 import { reactive, nextTick } from 'vue'; 40 import { reactive, nextTick } from 'vue';
41 import { Button } from 'ant-design-vue'; 41 import { Button } from 'ant-design-vue';
42 import { PlusOutlined, MinusOutlined } from '@ant-design/icons-vue'; 42 import { PlusOutlined, MinusOutlined } from '@ant-design/icons-vue';
43 - import { editTestCellTableTHeaderConfig } from '../../../config';  
44 - import { tableItems } from '../../../types';  
45 - 43 + import { editTestCellTableTHeaderConfig } from '../../../config/config';
  44 + import { tableItems } from '../../../config/types';
46 defineProps({ 45 defineProps({
47 method: { 46 method: {
48 type: String, 47 type: String,
@@ -78,8 +78,8 @@ @@ -78,8 +78,8 @@
78 import { Select, Button } from 'ant-design-vue'; 78 import { Select, Button } from 'ant-design-vue';
79 import { findDictItemByCode } from '/@/api/system/dict'; 79 import { findDictItemByCode } from '/@/api/system/dict';
80 import { PlusOutlined, MinusOutlined } from '@ant-design/icons-vue'; 80 import { PlusOutlined, MinusOutlined } from '@ant-design/icons-vue';
81 - import { editCellTableTHeadConfig } from '../../../config';  
82 - import { selectType, tableItems } from '../../../types'; 81 + import { editCellTableTHeadConfig } from '../../../config/config';
  82 + import { selectType, tableItems } from '../../../config/types';
83 import { useModal, BasicModal } from '/@/components/Modal'; 83 import { useModal, BasicModal } from '/@/components/Modal';
84 import DateRangeSelect from './DateRangeSelect/index.vue'; 84 import DateRangeSelect from './DateRangeSelect/index.vue';
85 85
@@ -58,7 +58,7 @@ @@ -58,7 +58,7 @@
58 import JsonEditor from '../../SimpleRequest/components/jsonEditor.vue'; 58 import JsonEditor from '../../SimpleRequest/components/jsonEditor.vue';
59 import { useMessage } from '/@/hooks/web/useMessage'; 59 import { useMessage } from '/@/hooks/web/useMessage';
60 import { getTenantAllPageLists, getTenantPageList } from '/@/api/tenant/tenantApi'; 60 import { getTenantAllPageLists, getTenantPageList } from '/@/api/tenant/tenantApi';
61 - import { selectType } from '../../../types'; 61 + import { selectType } from '../../../config/types';
62 import { Select } from 'ant-design-vue'; 62 import { Select } from 'ant-design-vue';
63 import { getUserToken } from '/@/api/sys/user'; 63 import { getUserToken } from '/@/api/sys/user';
64 import { USER_INFO_KEY } from '/@/enums/cacheEnum'; 64 import { USER_INFO_KEY } from '/@/enums/cacheEnum';
@@ -133,8 +133,8 @@ @@ -133,8 +133,8 @@
133 import { useApi } from '../../../hooks/useApi'; 133 import { useApi } from '../../../hooks/useApi';
134 import { useUtils } from '../../../hooks/useUtils'; 134 import { useUtils } from '../../../hooks/useUtils';
135 import { cloneDeep } from 'lodash-es'; 135 import { cloneDeep } from 'lodash-es';
136 - import { tableItems, selectType } from '../../../types';  
137 - import { editTestCellTableTHeadConfig } from '../../../config'; 136 + import { tableItems, selectType } from '../../../config/types';
  137 + import { editTestCellTableTHeadConfig } from '../../../config/config';
138 import { QuestionCircleOutlined } from '@ant-design/icons-vue'; 138 import { QuestionCircleOutlined } from '@ant-design/icons-vue';
139 139
140 const props = defineProps({ 140 const props = defineProps({
@@ -46,7 +46,7 @@ @@ -46,7 +46,7 @@
46 import { Button } from 'ant-design-vue'; 46 import { Button } from 'ant-design-vue';
47 import TestHeaderEditCellTable from './testEditHeaderCellTable.vue'; 47 import TestHeaderEditCellTable from './testEditHeaderCellTable.vue';
48 import { useMessage } from '/@/hooks/web/useMessage'; 48 import { useMessage } from '/@/hooks/web/useMessage';
49 - import { selectType } from '../../../types'; 49 + import { selectType } from '../../../config/types';
50 import { Select } from 'ant-design-vue'; 50 import { Select } from 'ant-design-vue';
51 import { getUserToken } from '/@/api/sys/user'; 51 import { getUserToken } from '/@/api/sys/user';
52 import { USER_INFO_KEY } from '/@/enums/cacheEnum'; 52 import { USER_INFO_KEY } from '/@/enums/cacheEnum';
@@ -24,8 +24,8 @@ @@ -24,8 +24,8 @@
24 <script lang="ts" setup name="editCellTable"> 24 <script lang="ts" setup name="editCellTable">
25 import { reactive } from 'vue'; 25 import { reactive } from 'vue';
26 import { cloneDeep } from 'lodash-es'; 26 import { cloneDeep } from 'lodash-es';
27 - import { tableItems } from '../../../types';  
28 - import { editTestCellTableTHeadConfig } from '../../../config'; 27 + import { tableItems } from '../../../config/types';
  28 + import { editTestCellTableTHeadConfig } from '../../../config/config';
29 29
30 defineProps({ 30 defineProps({
31 method: { 31 method: {
@@ -49,7 +49,7 @@ @@ -49,7 +49,7 @@
49 import { useUtils } from '../../../hooks/useUtils'; 49 import { useUtils } from '../../../hooks/useUtils';
50 import { useMessage } from '/@/hooks/web/useMessage'; 50 import { useMessage } from '/@/hooks/web/useMessage';
51 import { getTenantAllPageLists, getTenantPageList } from '/@/api/tenant/tenantApi'; 51 import { getTenantAllPageLists, getTenantPageList } from '/@/api/tenant/tenantApi';
52 - import { selectType } from '../../../types'; 52 + import { selectType } from '../../../config/types';
53 import { Select } from 'ant-design-vue'; 53 import { Select } from 'ant-design-vue';
54 import { getUserToken } from '/@/api/sys/user'; 54 import { getUserToken } from '/@/api/sys/user';
55 import { USER_INFO_KEY } from '/@/enums/cacheEnum'; 55 import { USER_INFO_KEY } from '/@/enums/cacheEnum';
@@ -174,8 +174,8 @@ @@ -174,8 +174,8 @@
174 import { useApi } from '../../../hooks/useApi'; 174 import { useApi } from '../../../hooks/useApi';
175 import { useUtils } from '../../../hooks/useUtils'; 175 import { useUtils } from '../../../hooks/useUtils';
176 import { cloneDeep } from 'lodash-es'; 176 import { cloneDeep } from 'lodash-es';
177 - import { tableItems, selectType } from '../../../types';  
178 - import { editTestCellTableTHeadConfig } from '../../../config'; 177 + import { tableItems, selectType } from '../../../config/types';
  178 + import { editTestCellTableTHeadConfig } from '../../../config/config';
179 import { QuestionCircleOutlined } from '@ant-design/icons-vue'; 179 import { QuestionCircleOutlined } from '@ant-design/icons-vue';
180 import moment from 'moment'; 180 import moment from 'moment';
181 import { AggregateDataEnum } from '/@/views/report/config/timeConfig'; 181 import { AggregateDataEnum } from '/@/views/report/config/timeConfig';
src/views/dataview/publicApi/config/config.ts renamed from src/views/dataview/publicApi/config.ts
@@ -5,6 +5,8 @@ import { findDictItemByCode } from '/@/api/system/dict'; @@ -5,6 +5,8 @@ import { findDictItemByCode } from '/@/api/system/dict';
5 import { USER_INFO_KEY } from '/@/enums/cacheEnum'; 5 import { USER_INFO_KEY } from '/@/enums/cacheEnum';
6 import { getAuthCache } from '/@/utils/auth'; 6 import { getAuthCache } from '/@/utils/auth';
7 import { isAdmin } from '/@/enums/roleEnum'; 7 import { isAdmin } from '/@/enums/roleEnum';
  8 +import { defaultField } from './constants';
  9 +import { useUtils } from '../hooks/useUtils';
8 10
9 // 表格配置 11 // 表格配置
10 export const columns: BasicColumn[] = [ 12 export const columns: BasicColumn[] = [
@@ -116,24 +118,6 @@ export const schemas: FormSchema[] = [ @@ -116,24 +118,6 @@ export const schemas: FormSchema[] = [
116 placeholder: '请输入接口名称', 118 placeholder: '请输入接口名称',
117 }, 119 },
118 }, 120 },
119 - // {  
120 - // field: 'interfaceType',  
121 - // component: 'ApiRadioGroup',  
122 - // label: '接口类型',  
123 - // required: true,  
124 - // colProps: {  
125 - // span: 8,  
126 - // },  
127 - // defaultValue: 'SYSTEM',  
128 - // componentProps: {  
129 - // api: findDictItemByCode,  
130 - // params: {  
131 - // dictCode: 'interface_Type',  
132 - // },  
133 - // labelField: 'itemText',  
134 - // valueField: 'itemValue',  
135 - // },  
136 - // },  
137 { 121 {
138 field: 'interfaceType', 122 field: 'interfaceType',
139 component: 'ApiRadioGroup', 123 component: 'ApiRadioGroup',
@@ -142,21 +126,17 @@ export const schemas: FormSchema[] = [ @@ -142,21 +126,17 @@ export const schemas: FormSchema[] = [
142 colProps: { 126 colProps: {
143 span: 8, 127 span: 8,
144 }, 128 },
145 - defaultValue: 'CUSTOM', 129 + defaultValue: 'SYSTEM',
146 componentProps: { 130 componentProps: {
147 - options: [  
148 - {  
149 - label: '系统默认',  
150 - value: 'SYSTEM',  
151 - },  
152 - {  
153 - label: '自定义',  
154 - value: 'CUSTOM',  
155 - },  
156 - ], 131 + api: findDictItemByCode,
  132 + params: {
  133 + dictCode: 'interface_Type',
  134 + },
  135 + labelField: 'itemText',
  136 + valueField: 'itemValue',
157 }, 137 },
158 ifShow: ({}) => { 138 ifShow: ({}) => {
159 - const userInfo: any = getAuthCache(USER_INFO_KEY); 139 + const userInfo = getAuthCache(USER_INFO_KEY) as any;
160 const role: string = userInfo?.roles[0]; 140 const role: string = userInfo?.roles[0];
161 if (isAdmin(role)) return true; 141 if (isAdmin(role)) return true;
162 else return false; 142 else return false;
@@ -180,14 +160,11 @@ export const schemas: FormSchema[] = [ @@ -180,14 +160,11 @@ export const schemas: FormSchema[] = [
180 labelField: 'itemText', 160 labelField: 'itemText',
181 valueField: 'itemValue', 161 valueField: 'itemValue',
182 getPopupContainer: () => document.body, 162 getPopupContainer: () => document.body,
183 - async onChange(e) {  
184 - setFieldsValue({  
185 - requestOriginUrl: '',  
186 - requestHttpTypeAndUrl: {  
187 - requestHttpType: undefined,  
188 - requestUrl: '',  
189 - },  
190 - }); 163 + onChange(e) {
  164 + if (!e) return;
  165 + const { usePlaceholder } = useUtils();
  166 + const setDefaultPlaceholder = usePlaceholder(e);
  167 + setFieldsValue(defaultField);
191 updateSchema({ 168 updateSchema({
192 field: 'requestHttpTypeAndUrl', 169 field: 'requestHttpTypeAndUrl',
193 componentProps: { 170 componentProps: {
@@ -197,9 +174,7 @@ export const schemas: FormSchema[] = [ @@ -197,9 +174,7 @@ export const schemas: FormSchema[] = [
197 updateSchema({ 174 updateSchema({
198 field: 'requestOriginUrl', 175 field: 'requestOriginUrl',
199 componentProps: { 176 componentProps: {
200 - placeholder: `${  
201 - e === '0' ? '示例:http://127.0.0.1' : e === '2' ? '示例:ws://127.0.0.1' : ''  
202 - }`, 177 + placeholder: setDefaultPlaceholder,
203 }, 178 },
204 }); 179 });
205 }, 180 },
@@ -224,11 +199,10 @@ export const schemas: FormSchema[] = [ @@ -224,11 +199,10 @@ export const schemas: FormSchema[] = [
224 labelField: 'itemText', 199 labelField: 'itemText',
225 valueField: 'itemValue', 200 valueField: 'itemValue',
226 onChange: (e) => { 201 onChange: (e) => {
227 - if (e) {  
228 - setFieldsValue({  
229 - requestOriginUrl: '',  
230 - });  
231 - } 202 + if (!e) return;
  203 + setFieldsValue({
  204 + requestOriginUrl: '',
  205 + });
232 }, 206 },
233 }; 207 };
234 }, 208 },
@@ -242,10 +216,9 @@ export const schemas: FormSchema[] = [ @@ -242,10 +216,9 @@ export const schemas: FormSchema[] = [
242 componentProps: ({ formActionType }) => { 216 componentProps: ({ formActionType }) => {
243 const { getFieldsValue } = formActionType; 217 const { getFieldsValue } = formActionType;
244 const type = getFieldsValue()?.requestContentType; 218 const type = getFieldsValue()?.requestContentType;
  219 + const { usePlaceholder } = useUtils();
245 return { 220 return {
246 - placeholder: `${  
247 - type === '0' ? '示例:http://127.0.0.1' : type === '2' ? '示例:ws://127.0.0.1' : ''  
248 - }`, 221 + placeholder: usePlaceholder(type),
249 }; 222 };
250 }, 223 },
251 ifShow: ({ values }) => values['originUrlType'] === 'custom_url', 224 ifShow: ({ values }) => values['originUrlType'] === 'custom_url',
  1 +///公共接口管理所需常量值
  2 +
  3 +import { RequestOriginTypeEnum } from './enum';
  4 +
  5 +export const commonHttpPlaceHolder = '示例:http://127.0.0.1';
  6 +
  7 +export const websocketPlaceHolder = '示例:ws://127.0.0.1';
  8 +
  9 +export const defaultField = {
  10 + originUrlType: RequestOriginTypeEnum.SERVER_URL,
  11 + requestOriginUrl: '',
  12 + requestHttpTypeAndUrl: {
  13 + requestHttpType: undefined,
  14 + requestUrl: '',
  15 + },
  16 +};
src/views/dataview/publicApi/config/enum/index.ts renamed from src/views/dataview/publicApi/enum/index.ts
  1 +///公共接口管理所需枚举值
  2 +
1 /** 3 /**
2 * @description: 请求体类型 4 * @description: 请求体类型
3 */ 5 */
@@ -8,3 +10,20 @@ export enum RequestBodyTypeEnum { @@ -8,3 +10,20 @@ export enum RequestBodyTypeEnum {
8 JSON = 'json', 10 JSON = 'json',
9 XML = 'xml', 11 XML = 'xml',
10 } 12 }
  13 +
  14 +/**
  15 + * @description: 请求方式
  16 + */
  17 +export enum RequestMethodTypeEnum {
  18 + COMMOM = '0',
  19 + WEBSOCKET = '2',
  20 + SQL = '1',
  21 +}
  22 +
  23 +/**
  24 + * @description: 源地址类型
  25 + */
  26 +export enum RequestOriginTypeEnum {
  27 + CUSTOM_URL = 'custom_url',
  28 + SERVER_URL = 'server_url',
  29 +}
src/views/dataview/publicApi/config/types/index.ts renamed from src/views/dataview/publicApi/types/index.ts
@@ -69,7 +69,7 @@ @@ -69,7 +69,7 @@
69 import { ref, nextTick, watch } from 'vue'; 69 import { ref, nextTick, watch } from 'vue';
70 import { BasicDrawer, useDrawerInner } from '/@/components/Drawer'; 70 import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
71 import { BasicForm, useForm } from '/@/components/Form'; 71 import { BasicForm, useForm } from '/@/components/Form';
72 - import { schemas } from './config'; 72 + import { schemas } from './config/config';
73 import SimpleRequest from './components/SimpleRequest/index.vue'; 73 import SimpleRequest from './components/SimpleRequest/index.vue';
74 import { TestSql } from './components/TestSql/index'; 74 import { TestSql } from './components/TestSql/index';
75 import { 75 import {
  1 +import { commonHttpPlaceHolder, websocketPlaceHolder } from '../config/constants';
  2 +import { RequestMethodTypeEnum } from '../config/enum';
1 import { otherHttp } from '/@/utils/http/axios'; 3 import { otherHttp } from '/@/utils/http/axios';
2 4
3 export const useUtils = () => { 5 export const useUtils = () => {
@@ -16,6 +18,7 @@ export const useUtils = () => { @@ -16,6 +18,7 @@ export const useUtils = () => {
16 }); 18 });
17 return temps; 19 return temps;
18 }; 20 };
  21 +
19 //默认push一个 22 //默认push一个
20 const pushObj = { 23 const pushObj = {
21 key: undefined, 24 key: undefined,
@@ -25,6 +28,7 @@ export const useUtils = () => { @@ -25,6 +28,7 @@ export const useUtils = () => {
25 date1: '', 28 date1: '',
26 date2: '', 29 date2: '',
27 }; 30 };
  31 +
28 //新增时置空特定数据 32 //新增时置空特定数据
29 const resetReqHttpType = { 33 const resetReqHttpType = {
30 requestHttpTypeAndUrl: { 34 requestHttpTypeAndUrl: {
@@ -38,6 +42,7 @@ export const useUtils = () => { @@ -38,6 +42,7 @@ export const useUtils = () => {
38 type: '0', 42 type: '0',
39 }, 43 },
40 }; 44 };
  45 +
41 //对象转get params参数 46 //对象转get params参数
42 const convertObj = (data: object) => { 47 const convertObj = (data: object) => {
43 const _result: any = []; 48 const _result: any = [];
@@ -53,6 +58,7 @@ export const useUtils = () => { @@ -53,6 +58,7 @@ export const useUtils = () => {
53 } 58 }
54 return _result.join('&'); 59 return _result.join('&');
55 }; 60 };
  61 +
56 //判断服务器地址是否为http/https ws/wss 62 //判断服务器地址是否为http/https ws/wss
57 const isServerUrl = (method, type) => { 63 const isServerUrl = (method, type) => {
58 const pathUrl = window.location.host; 64 const pathUrl = window.location.host;
@@ -69,6 +75,7 @@ export const useUtils = () => { @@ -69,6 +75,7 @@ export const useUtils = () => {
69 } 75 }
70 return url; 76 return url;
71 }; 77 };
  78 +
72 //TODO:待优化自定义请求 79 //TODO:待优化自定义请求
73 const isOtherHttp = async (url, token, params) => { 80 const isOtherHttp = async (url, token, params) => {
74 return await otherHttp.get( 81 return await otherHttp.get(
@@ -84,6 +91,17 @@ export const useUtils = () => { @@ -84,6 +91,17 @@ export const useUtils = () => {
84 } 91 }
85 ); 92 );
86 }; 93 };
  94 +
  95 + //请求方式切换动态更新源地址placeholder
  96 + const usePlaceholder = (type) =>
  97 + `${
  98 + type === RequestMethodTypeEnum.COMMOM
  99 + ? commonHttpPlaceHolder
  100 + : type === RequestMethodTypeEnum.WEBSOCKET
  101 + ? websocketPlaceHolder
  102 + : ''
  103 + }`;
  104 +
87 return { 105 return {
88 getMultipleKeys, 106 getMultipleKeys,
89 pushObj, 107 pushObj,
@@ -92,5 +110,6 @@ export const useUtils = () => { @@ -92,5 +110,6 @@ export const useUtils = () => {
92 isServerUrl, 110 isServerUrl,
93 convertObj, 111 convertObj,
94 isOtherHttp, 112 isOtherHttp,
  113 + usePlaceholder,
95 }; 114 };
96 }; 115 };
@@ -85,7 +85,7 @@ @@ -85,7 +85,7 @@
85 import { h, ref } from 'vue'; 85 import { h, ref } from 'vue';
86 import { BasicTable, useTable, TableAction } from '/@/components/Table'; 86 import { BasicTable, useTable, TableAction } from '/@/components/Table';
87 import { useDrawer } from '/@/components/Drawer'; 87 import { useDrawer } from '/@/components/Drawer';
88 - import { columns, searchFormSchema } from './config'; 88 + import { columns, searchFormSchema } from './config/config';
89 import { PublicApiForm } from './index'; 89 import { PublicApiForm } from './index';
90 import { 90 import {
91 getDataViewInterfacePage, 91 getDataViewInterfacePage,