Commit 6fb946eaedd5641b8fcfccae6f9a7f4512724f19

Authored by xp.Huang
2 parents ea4342aa 40c29078

Merge branch 'main_dev' into 'main'

Main dev merge

See merge request yunteng/thingskit-front!723
... ... @@ -68,7 +68,7 @@
68 68 </div>
69 69 </template>
70 70 <script lang="ts" setup name="testRequest">
71   - import { nextTick, ref, reactive, onUnmounted } from 'vue';
  71 + import { nextTick, ref, reactive, onUnmounted, unref } from 'vue';
72 72 import { Button } from 'ant-design-vue';
73 73 import { otherHttp } from '/@/utils/http/axios';
74 74 import { useWebSocket } from '@vueuse/core';
... ... @@ -153,6 +153,9 @@
153 153
154 154 const postBodyType = ref('');
155 155
  156 + //定义一个全局的关闭websocket变量 fix: 修复切换产品切换属性websocket又新建连接,造成上一个ws和这一个ws交替接受信息问题
  157 + const closeSocket = ref<Nullable<Fn>>(null);
  158 +
156 159 //执行测试接口
157 160 const handleExcute = () => {
158 161 emits('emitExcute');
... ... @@ -188,6 +191,8 @@
188 191 const list = Object.values(params);
189 192 const isEmpty = list.some((it) => it === '' || null || undefined);
190 193 if (!isEmpty) {
  194 + //执行ws close方法 关闭上一个
  195 + unref(closeSocket)?.();
191 196 websocketRequest(params);
192 197 } else {
193 198 resetValue(false);
... ... @@ -245,6 +250,7 @@
245 250 },
246 251 onError() {},
247 252 });
  253 + closeSocket.value = close;
248 254 if (destroy) close();
249 255 } finally {
250 256 }
... ...
1 1 import { BasicColumn, FormSchema } from '/@/components/Table';
2   -import { h } from 'vue';
  2 +import { h, unref } from 'vue';
3 3 import { Tag } from 'ant-design-vue';
4 4 import { findDictItemByCode } from '/@/api/system/dict';
5 5 import { USER_INFO_KEY } from '/@/enums/cacheEnum';
... ... @@ -7,6 +7,7 @@ import { getAuthCache } from '/@/utils/auth';
7 7 import { isAdmin } from '/@/enums/roleEnum';
8 8 import { defaultField } from './constants';
9 9 import { useUtils } from '../hooks/useUtils';
  10 +import { useRole } from '/@/hooks/business/useRole';
10 11
11 12 // 表格配置
12 13 export const columns: BasicColumn[] = [
... ... @@ -106,189 +107,192 @@ export const searchFormSchema: FormSchema[] = [
106 107 ];
107 108
108 109 //表单配置
109   -export const schemas: FormSchema[] = [
110   - {
111   - field: 'interfaceName',
112   - label: '接口名称',
113   - colProps: { span: 24 },
114   - required: true,
115   - component: 'Input',
116   - componentProps: {
117   - maxLength: 255,
118   - placeholder: '请输入接口名称',
119   - },
120   - },
121   - {
122   - field: 'interfaceType',
123   - component: 'ApiRadioGroup',
124   - label: '接口类型',
125   - required: true,
126   - colProps: {
127   - span: 8,
128   - },
129   - defaultValue: 'CUSTOM',
130   - componentProps: {
131   - api: findDictItemByCode,
132   - params: {
133   - dictCode: 'interface_Type',
  110 +export const schemas = (): FormSchema[] => {
  111 + const { isPlatformAdmin, isSysadmin } = useRole();
  112 + return [
  113 + {
  114 + field: 'interfaceName',
  115 + label: '接口名称',
  116 + colProps: { span: 24 },
  117 + required: true,
  118 + component: 'Input',
  119 + componentProps: {
  120 + maxLength: 255,
  121 + placeholder: '请输入接口名称',
134 122 },
135   - labelField: 'itemText',
136   - valueField: 'itemValue',
137   - },
138   - ifShow: ({}) => {
139   - const userInfo = getAuthCache(USER_INFO_KEY) as any;
140   - const role: string = userInfo?.roles[0];
141   - if (isAdmin(role)) return true;
142   - else return false;
143 123 },
144   - },
145   - {
146   - field: 'requestContentType',
147   - label: '请求方式',
148   - component: 'ApiSelect',
149   - required: true,
150   - colProps: { span: 24 },
151   - defaultValue: '0',
152   - componentProps: ({ formActionType }) => {
153   - const { updateSchema, setFieldsValue } = formActionType;
154   - return {
  124 + {
  125 + field: 'interfaceType',
  126 + component: 'ApiRadioGroup',
  127 + label: '接口类型',
  128 + required: true,
  129 + colProps: {
  130 + span: 8,
  131 + },
  132 + defaultValue: unref(isPlatformAdmin) || unref(isSysadmin) ? 'SYSTEM' : null,
  133 + componentProps: {
155 134 api: findDictItemByCode,
156 135 params: {
157   - dictCode: 'dataview_select_methods',
  136 + dictCode: 'interface_Type',
158 137 },
159   - placeholder: '请选择请求方式',
160 138 labelField: 'itemText',
161 139 valueField: 'itemValue',
162   - getPopupContainer: () => document.body,
163   - onChange(e) {
164   - if (!e) return;
165   - const { usePlaceholder } = useUtils();
166   - const setDefaultPlaceholder = usePlaceholder(e);
167   - setFieldsValue(defaultField);
168   - updateSchema({
169   - field: 'requestHttpTypeAndUrl',
170   - componentProps: {
171   - type: e,
172   - },
173   - });
174   - updateSchema({
175   - field: 'requestOriginUrl',
176   - componentProps: {
177   - placeholder: setDefaultPlaceholder,
178   - },
179   - });
180   - },
181   - };
  140 + },
  141 + ifShow: ({}) => {
  142 + const userInfo = getAuthCache(USER_INFO_KEY) as any;
  143 + const role: string = userInfo?.roles[0];
  144 + if (isAdmin(role)) return true;
  145 + else return false;
  146 + },
182 147 },
183   - },
184   - {
185   - field: 'originUrlType',
186   - label: '地址类型',
187   - component: 'ApiSelect',
188   - required: true,
189   - colProps: { span: 24 },
190   - defaultValue: 'server_url',
191   - componentProps: ({ formActionType }) => {
192   - const { setFieldsValue } = formActionType;
193   - return {
194   - placeholder: '请选择地址类型',
195   - api: findDictItemByCode,
196   - params: {
197   - dictCode: 'dataview_select_origin_type',
198   - },
199   - labelField: 'itemText',
200   - valueField: 'itemValue',
201   - onChange: (e) => {
202   - if (!e) return;
203   - setFieldsValue({
204   - requestOriginUrl: '',
205   - });
206   - },
207   - };
  148 + {
  149 + field: 'requestContentType',
  150 + label: '请求方式',
  151 + component: 'ApiSelect',
  152 + required: true,
  153 + colProps: { span: 24 },
  154 + defaultValue: '0',
  155 + componentProps: ({ formActionType }) => {
  156 + const { updateSchema, setFieldsValue } = formActionType;
  157 + return {
  158 + api: findDictItemByCode,
  159 + params: {
  160 + dictCode: 'dataview_select_methods',
  161 + },
  162 + placeholder: '请选择请求方式',
  163 + labelField: 'itemText',
  164 + valueField: 'itemValue',
  165 + getPopupContainer: () => document.body,
  166 + onChange(e) {
  167 + if (!e) return;
  168 + const { usePlaceholder } = useUtils();
  169 + const setDefaultPlaceholder = usePlaceholder(e);
  170 + setFieldsValue(defaultField);
  171 + updateSchema({
  172 + field: 'requestHttpTypeAndUrl',
  173 + componentProps: {
  174 + type: e,
  175 + },
  176 + });
  177 + updateSchema({
  178 + field: 'requestOriginUrl',
  179 + componentProps: {
  180 + placeholder: setDefaultPlaceholder,
  181 + },
  182 + });
  183 + },
  184 + };
  185 + },
208 186 },
209   - },
210   - {
211   - field: 'requestOriginUrl',
212   - label: '源地址',
213   - colProps: { span: 24 },
214   - required: true,
215   - component: 'Input',
216   - componentProps: ({ formActionType }) => {
217   - const { getFieldsValue } = formActionType;
218   - const type = getFieldsValue()?.requestContentType;
219   - const { usePlaceholder } = useUtils();
220   - return {
221   - placeholder: usePlaceholder(type),
222   - };
  187 + {
  188 + field: 'originUrlType',
  189 + label: '地址类型',
  190 + component: 'ApiSelect',
  191 + required: true,
  192 + colProps: { span: 24 },
  193 + defaultValue: 'server_url',
  194 + componentProps: ({ formActionType }) => {
  195 + const { setFieldsValue } = formActionType;
  196 + return {
  197 + placeholder: '请选择地址类型',
  198 + api: findDictItemByCode,
  199 + params: {
  200 + dictCode: 'dataview_select_origin_type',
  201 + },
  202 + labelField: 'itemText',
  203 + valueField: 'itemValue',
  204 + onChange: (e) => {
  205 + if (!e) return;
  206 + setFieldsValue({
  207 + requestOriginUrl: '',
  208 + });
  209 + },
  210 + };
  211 + },
223 212 },
224   - ifShow: ({ values }) => values['originUrlType'] === 'custom_url',
225   - },
226   - {
227   - field: 'requestHttpTypeAndUrl',
228   - label: '请求类型&地址',
229   - component: 'InputGroup',
230   - required: true,
231   - colProps: { span: 24 },
232   - componentProps: ({ formActionType }) => {
233   - const { getFieldsValue } = formActionType;
234   - return {
235   - type: getFieldsValue().requestContentType,
236   - };
  213 + {
  214 + field: 'requestOriginUrl',
  215 + label: '源地址',
  216 + colProps: { span: 24 },
  217 + required: true,
  218 + component: 'Input',
  219 + componentProps: ({ formActionType }) => {
  220 + const { getFieldsValue } = formActionType;
  221 + const type = getFieldsValue()?.requestContentType;
  222 + const { usePlaceholder } = useUtils();
  223 + return {
  224 + placeholder: usePlaceholder(type),
  225 + };
  226 + },
  227 + ifShow: ({ values }) => values['originUrlType'] === 'custom_url',
237 228 },
238   - },
239   - {
240   - field: 'fillAddress',
241   - label: '完整地址',
242   - component: 'Input',
243   - slot: 'slotFillAddress',
244   - colProps: { span: 24 },
245   - ifShow: ({ values }) => {
246   - return values['originUrlType'] === 'custom_url' && values['requestOriginUrl'];
  229 + {
  230 + field: 'requestHttpTypeAndUrl',
  231 + label: '请求类型&地址',
  232 + component: 'InputGroup',
  233 + required: true,
  234 + colProps: { span: 24 },
  235 + componentProps: ({ formActionType }) => {
  236 + const { getFieldsValue } = formActionType;
  237 + return {
  238 + type: getFieldsValue().requestContentType,
  239 + };
  240 + },
247 241 },
248   - },
249   - {
250   - field: 'slotServerAddress',
251   - label: '完整地址',
252   - component: 'Input',
253   - slot: 'slotServerAddress',
254   - colProps: { span: 24 },
255   - ifShow: ({ values }) => {
256   - return values['originUrlType'] === 'server_url';
  242 + {
  243 + field: 'fillAddress',
  244 + label: '完整地址',
  245 + component: 'Input',
  246 + slot: 'slotFillAddress',
  247 + colProps: { span: 24 },
  248 + ifShow: ({ values }) => {
  249 + return values['originUrlType'] === 'custom_url' && values['requestOriginUrl'];
  250 + },
257 251 },
258   - },
259   - {
260   - field: 'requestSQLKey',
261   - label: '键名',
262   - colProps: { span: 6 },
263   - component: 'Input',
264   - defaultValue: 'sql',
265   - componentProps: {
266   - disabled: true,
  252 + {
  253 + field: 'slotServerAddress',
  254 + label: '完整地址',
  255 + component: 'Input',
  256 + slot: 'slotServerAddress',
  257 + colProps: { span: 24 },
  258 + ifShow: ({ values }) => {
  259 + return values['originUrlType'] === 'server_url';
  260 + },
267 261 },
268   - ifShow: ({ values }) => values['requestContentType'] === '1',
269   - },
270   - {
271   - field: 'requestSQLContent',
272   - label: '键值',
273   - colProps: { span: 24 },
274   - component: 'InputTextArea',
275   - defaultValue: 'select * from where',
276   - componentProps: {
277   - maxLength: 255,
278   - placeholder: '请输入键值',
279   - rows: 6,
  262 + {
  263 + field: 'requestSQLKey',
  264 + label: '键名',
  265 + colProps: { span: 6 },
  266 + component: 'Input',
  267 + defaultValue: 'sql',
  268 + componentProps: {
  269 + disabled: true,
  270 + },
  271 + ifShow: ({ values }) => values['requestContentType'] === '1',
280 272 },
281   - ifShow: ({ values }) => values['requestContentType'] === '1',
282   - },
283   - {
284   - field: 'slot',
285   - label: '参数设置',
286   - component: 'Input',
287   - slot: 'selectMethods',
288   - colProps: { span: 24 },
289   - ifShow: ({ values }) => values['requestContentType'] !== '1',
290   - },
291   -];
  273 + {
  274 + field: 'requestSQLContent',
  275 + label: '键值',
  276 + colProps: { span: 24 },
  277 + component: 'InputTextArea',
  278 + defaultValue: 'select * from where',
  279 + componentProps: {
  280 + maxLength: 255,
  281 + placeholder: '请输入键值',
  282 + rows: 6,
  283 + },
  284 + ifShow: ({ values }) => values['requestContentType'] === '1',
  285 + },
  286 + {
  287 + field: 'slot',
  288 + label: '参数设置',
  289 + component: 'Input',
  290 + slot: 'selectMethods',
  291 + colProps: { span: 24 },
  292 + ifShow: ({ values }) => values['requestContentType'] !== '1',
  293 + },
  294 + ];
  295 +};
292 296
293 297 //表格表头配置
294 298 export const editCellTableTHeadConfig = ['序号', '内置参数', '参数名', '是否必须', '操作'];
... ...
... ... @@ -123,7 +123,7 @@
123 123
124 124 const [registerForm, { resetFields, validate, setFieldsValue, updateSchema }] = useForm({
125 125 labelWidth: 120,
126   - schemas,
  126 + schemas: schemas(),
127 127 showActionButtonGroup: false,
128 128 });
129 129
... ... @@ -172,7 +172,6 @@
172 172 const filter = simpleRequestRef.value?.getFilterValue();
173 173 const requestOriginUrl = getOriginUrlType(values);
174 174 const params = (Objects as Recordable)?.Params?.filter((item) => item.key);
175   -
176 175 (Objects as Recordable).Params = params;
177 176 const data = {
178 177 ...values,
... ...