vite-uni-dev-tool 0.0.20 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +14 -3
  2. package/dist/const.d.ts +12 -0
  3. package/dist/const.d.ts.map +1 -1
  4. package/dist/const.js +23 -20
  5. package/dist/core.d.ts +3 -3
  6. package/dist/core.d.ts.map +1 -1
  7. package/dist/core.js +89 -49
  8. package/dist/devEvent/index.d.ts +34 -0
  9. package/dist/devEvent/index.d.ts.map +1 -1
  10. package/dist/devEvent/index.js +71 -27
  11. package/dist/devIntercept/index.d.ts.map +1 -1
  12. package/dist/devIntercept/index.js +171 -145
  13. package/dist/devStore/index.d.ts +9 -0
  14. package/dist/devStore/index.d.ts.map +1 -1
  15. package/dist/devStore/index.js +54 -20
  16. package/dist/plugins/uniDevTool/uniDevTool.d.ts +1 -1
  17. package/dist/plugins/uniDevTool/uniDevTool.d.ts.map +1 -1
  18. package/dist/type.d.ts +18 -1
  19. package/dist/type.d.ts.map +1 -1
  20. package/dist/v2/DevTool/index.vue +8 -8
  21. package/dist/v3/DevTool/index.vue +13 -12
  22. package/dist/v3/DevToolWindow/const.d.ts +30 -0
  23. package/dist/v3/DevToolWindow/const.d.ts.map +1 -0
  24. package/dist/v3/DevToolWindow/const.ts +123 -0
  25. package/dist/v3/DevToolWindow/index.vue +186 -107
  26. package/dist/v3/NetworkList/InterceptConfig.vue +835 -0
  27. package/dist/v3/NetworkList/InterceptItem.vue +132 -0
  28. package/dist/v3/NetworkList/NetworkDetail.vue +86 -31
  29. package/dist/v3/NetworkList/NetworkIntercept.vue +85 -0
  30. package/dist/v3/NetworkList/NetworkItem.vue +18 -18
  31. package/dist/v3/NetworkList/NetworkSend.vue +61 -45
  32. package/dist/v3/NetworkList/index.vue +11 -67
  33. package/dist/v3/SettingList/index.vue +23 -2
  34. package/dist/v3/SourceCode/Line.vue +101 -0
  35. package/dist/v3/SourceCode/index.vue +35 -62
  36. package/dist/v3/SourceCode/parseCode.d.ts +27 -0
  37. package/dist/v3/SourceCode/parseCode.d.ts.map +1 -0
  38. package/dist/v3/SourceCode/parseCode.ts +643 -0
  39. package/dist/v3/Tag/index.vue +1 -0
  40. package/package.json +1 -1
@@ -0,0 +1,835 @@
1
+ <template>
2
+ <view class="intercept-config" :style="{ zIndex: zIndex }">
3
+ <view class="intercept-config-control">
4
+ <DevToolTitle>拦截规则配置</DevToolTitle>
5
+ <CircularButton style="margin-left: auto" text="×" @click="onClose" />
6
+ </view>
7
+
8
+ <view class="intercept-config-form">
9
+ <view class="intercept-config-tip">
10
+ tips:
11
+ 拦截请求,发送请求之前将采用输入的请求头和请求参数,返回响应头和响应参数。会真实发起一次请求(真实请求可能失败),更改最后的响应结果。
12
+ </view>
13
+ <view class="intercept-config-control">
14
+ <DevToolTitle>超时时间(ms)</DevToolTitle>
15
+ </view>
16
+ <input
17
+ class="intercept-input"
18
+ :value="state.timeout"
19
+ @input="onChangeState($event, 'timeout')"
20
+ />
21
+ <view class="intercept-config-tip">
22
+ tips: 防止请求不存在,请求时长异常
23
+ </view>
24
+ <view class="intercept-config-control">
25
+ <DevToolTitle>响应状态</DevToolTitle>
26
+ </view>
27
+ <input
28
+ class="intercept-input"
29
+ :value="state.status"
30
+ @input="onChangeState($event, 'status')"
31
+ />
32
+ <view class="intercept-config-control">
33
+ <DevToolTitle>请求方式</DevToolTitle>
34
+ </view>
35
+ <radio-group class="radio-group" @change="onChangeRequestMethod">
36
+ <label
37
+ class="radio-group-item"
38
+ v-for="item in requestMethods"
39
+ :key="item.value"
40
+ >
41
+ <radio
42
+ size
43
+ style="transform: scale(0.8)"
44
+ color="#9254de"
45
+ :value="item.value"
46
+ :checked="item.value === state.method"
47
+ />
48
+
49
+ <view>{{ item.name }}</view>
50
+ </label>
51
+ </radio-group>
52
+
53
+ <view class="intercept-config-control">
54
+ <DevToolTitle>请求头</DevToolTitle>
55
+ <CircularButton
56
+ style="margin-left: auto"
57
+ text="+"
58
+ @click="onAddRequestHeader"
59
+ />
60
+ </view>
61
+
62
+ <view class="intercept-header-list">
63
+ <checkbox-group
64
+ v-if="requestHeaderList.length > 0"
65
+ key="requestHeaderList"
66
+ @change="onChangeRequestHeaderChecked"
67
+ >
68
+ <view
69
+ class="intercept-header-item"
70
+ v-for="(item, index) in requestHeaderList"
71
+ :key="item.id"
72
+ >
73
+ <checkbox
74
+ color="#9254de"
75
+ :value="item.id"
76
+ :checked="item.checked"
77
+ />
78
+ <input
79
+ class="intercept-input"
80
+ placeholder="请输入请求头名称"
81
+ placeholderStyle="font-size: 12px"
82
+ :value="item.key"
83
+ @input="onChangeRequestHeader($event, 'key', index)"
84
+ />
85
+ <input
86
+ class="intercept-input"
87
+ placeholder="请输入请求头值"
88
+ placeholderStyle="font-size: 12px"
89
+ :value="item.value"
90
+ @input="onChangeRequestHeader($event, 'value', index)"
91
+ />
92
+ <CircularButton
93
+ style="margin-left: 6px"
94
+ text="一"
95
+ @click="onDeleteRequestHeader(item)"
96
+ />
97
+ </view>
98
+ </checkbox-group>
99
+
100
+ <view class="intercept-empty" v-else> 暂无请求头 </view>
101
+ </view>
102
+
103
+ <view class="intercept-config-control">
104
+ <DevToolTitle>响应头</DevToolTitle>
105
+ <CircularButton
106
+ style="margin-left: auto"
107
+ text="+"
108
+ @click="onAddResponseHeader"
109
+ />
110
+ </view>
111
+
112
+ <view class="intercept-header-list">
113
+ <checkbox-group
114
+ v-if="responseHeaderList.length > 0"
115
+ key="responseHeaderList"
116
+ @change="onChangeResponseHeaderChecked"
117
+ >
118
+ <view
119
+ class="intercept-header-item"
120
+ v-for="(item, index) in responseHeaderList"
121
+ :key="item.id"
122
+ >
123
+ <checkbox
124
+ color="#9254de"
125
+ :value="item.id"
126
+ :checked="item.checked"
127
+ />
128
+ <input
129
+ class="intercept-input"
130
+ placeholder="请输入响应头名称"
131
+ placeholderStyle="font-size: 12px"
132
+ :value="item.key"
133
+ @input="onChangeResponseHeader($event, 'key', index)"
134
+ />
135
+ <input
136
+ class="intercept-input"
137
+ placeholder="请输入响应头值"
138
+ placeholderStyle="font-size: 12px"
139
+ :value="item.value"
140
+ @input="onChangeResponseHeader($event, 'value', index)"
141
+ />
142
+ <CircularButton
143
+ style="margin-left: 6px"
144
+ text="一"
145
+ @click="onDeleteResponseHeader(item)"
146
+ />
147
+ </view>
148
+ </checkbox-group>
149
+
150
+ <view class="intercept-empty" v-else> 暂无响应头 </view>
151
+ </view>
152
+ <DevToolTitle>请求地址</DevToolTitle>
153
+ <textarea
154
+ placeholder="请输入请求地址"
155
+ placeholderStyle="font-size: 12px"
156
+ class="intercept-textarea"
157
+ :value="state.url"
158
+ @input="onChangeUrl"
159
+ />
160
+ <view class="form-error-message">
161
+ {{ hasUrl ? '' : '请输入请求地址' }}
162
+ </view>
163
+
164
+ <view class="intercept-config-control">
165
+ <DevToolTitle>请求参数(query)</DevToolTitle>
166
+ <CircularButton
167
+ style="margin-left: auto"
168
+ text="+"
169
+ @click="onAddQuery"
170
+ />
171
+ </view>
172
+ <view class="intercept-param-list">
173
+ <checkbox-group
174
+ v-if="queryList.length > 0"
175
+ @change="onChangeQueryChecked"
176
+ >
177
+ <view
178
+ class="intercept-param-item"
179
+ v-for="(item, index) in queryList"
180
+ :key="item.id"
181
+ >
182
+ <checkbox
183
+ color="#9254de"
184
+ :checked="item.checked"
185
+ :value="item.id"
186
+ />
187
+ <input
188
+ class="intercept-input"
189
+ placeholder="请输入参数名称"
190
+ placeholderStyle="font-size: 12px"
191
+ :value="item.key"
192
+ @input="onChangeQuery($event, 'key', index)"
193
+ />
194
+ <input
195
+ class="intercept-input"
196
+ placeholder="请输入参数值"
197
+ placeholderStyle="font-size: 12px"
198
+ :value="item.value"
199
+ @input="onChangeQuery($event, 'value', index)"
200
+ />
201
+ <CircularButton
202
+ text="一"
203
+ style="margin-left: 6px"
204
+ @click="onDeleteQuery(item)"
205
+ />
206
+ </view>
207
+ </checkbox-group>
208
+
209
+ <view class="intercept-empty" v-else> 暂无请求参数 </view>
210
+ </view>
211
+
212
+ <template v-if="!noBodyRequestMethods.includes(state.method)">
213
+ <view class="intercept-config-control">
214
+ <DevToolTitle>请求体(request body)</DevToolTitle>
215
+ </view>
216
+
217
+ <textarea
218
+ placeholder="请输入请求体"
219
+ class="intercept-textarea"
220
+ placeholderStyle="font-size: 12px"
221
+ :value="state.bodyText"
222
+ @input="onChangeState($event, 'bodyText')"
223
+ />
224
+ </template>
225
+
226
+ <view class="intercept-config-control">
227
+ <DevToolTitle>响应体(response body)</DevToolTitle>
228
+ </view>
229
+ <textarea
230
+ placeholder="请输入响应体"
231
+ class="intercept-textarea"
232
+ placeholderStyle="font-size: 12px"
233
+ :value="state.responseText"
234
+ @input="onChangeState($event, 'responseText')"
235
+ />
236
+ </view>
237
+ <view class="intercept-config-buttons">
238
+ <!-- <button
239
+ size="mini"
240
+ :disabled="!isFinished"
241
+ @click="emit('openDetail', network)"
242
+ >
243
+ 详情
244
+ </button>
245
+ <button size="mini" @click="onReset">重置</button>
246
+ <button size="mini" @click="onSend">发送</button> -->
247
+ <button
248
+ size="mini"
249
+ style="background-color: #9254de; color: #fff"
250
+ @click="onConfirm"
251
+ >
252
+ 保存配置
253
+ </button>
254
+ </view>
255
+ </view>
256
+ </template>
257
+ <script lang="ts" setup>
258
+ import { ref, reactive, onMounted } from 'vue';
259
+ import CircularButton from '../CircularButton/index.vue';
260
+ import DevToolTitle from '../DevToolTitle/index.vue';
261
+ import type { DevTool } from '../../type';
262
+
263
+ const props = defineProps<{ network: DevTool.NetworkItem; zIndex?: number }>();
264
+
265
+ const emit = defineEmits<{
266
+ (e: 'close'): void;
267
+ (e: 'openDetail', v: DevTool.NetworkItem): void;
268
+ (e: 'confirm', v: DevTool.NetworkItem): void;
269
+ }>();
270
+
271
+ const requestMethods = [
272
+ { name: 'GET', value: 'GET' },
273
+ { name: 'POST', value: 'POST' },
274
+ { name: 'PUT', value: 'PUT' },
275
+ { name: 'DELETE', value: 'DELETE' },
276
+ { name: 'PATCH', value: 'PATCH' },
277
+ { name: 'OPTIONS', value: 'OPTIONS' },
278
+ { name: 'HEAD', value: 'HEAD' },
279
+ ];
280
+
281
+ const hasUrl = ref(true);
282
+
283
+ const state = reactive<{
284
+ method: any;
285
+ url: string;
286
+ status: number | string;
287
+ bodyText: string;
288
+ responseText: string;
289
+ timeout: number;
290
+ }>({
291
+ method: 'GET',
292
+ url: 'http://mock.view-uni-dev-tool/a?a=123',
293
+ status: 200,
294
+ bodyText: '',
295
+ responseText: '',
296
+ timeout: 10 * 1000,
297
+ });
298
+
299
+ const defaultHeader = [
300
+ {
301
+ id: 1,
302
+ key: 'Accept',
303
+ value: '*/*',
304
+ checked: false,
305
+ },
306
+ {
307
+ id: 2,
308
+ key: 'Accept-Language',
309
+ value: 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
310
+ checked: false,
311
+ },
312
+ {
313
+ id: 3,
314
+ key: 'Cache-Control',
315
+ value: 'no-cache',
316
+ checked: false,
317
+ },
318
+ {
319
+ id: 4,
320
+ key: 'Content-Type',
321
+ value: 'application/json; charset=utf-8',
322
+ checked: true,
323
+ },
324
+ ];
325
+
326
+ type PB = {
327
+ id: number;
328
+ key: string;
329
+ value: string;
330
+ checked: boolean;
331
+ };
332
+
333
+ const requestHeaderList = reactive([...defaultHeader]);
334
+
335
+ const responseHeaderList = reactive([...defaultHeader]);
336
+
337
+ const queryList = reactive<PB[]>([
338
+ {
339
+ id: 1,
340
+ key: 'a',
341
+ value: '123',
342
+ checked: true,
343
+ },
344
+ ]);
345
+
346
+ const isFinished = ref(false);
347
+
348
+ const noBodyRequestMethods = ['GET', 'HEAD', 'PATCH', 'OPTIONS'];
349
+
350
+ function onChangeState(e: any, key: keyof typeof state) {
351
+ state[key] = e.detail.value as never;
352
+ }
353
+
354
+ function parseUrlToList(url: string) {
355
+ if (url.includes('?')) {
356
+ const query = url.split('?')[1];
357
+ const queryObject = urlParamsToObject(query);
358
+ const list = objectToArray(queryObject);
359
+
360
+ return list;
361
+ }
362
+ return [];
363
+ }
364
+
365
+ function parseListToUrl(list: PB[]) {
366
+ const baseUrl = state.url.split('?')[0] || '';
367
+ if (list.length === 0) {
368
+ return baseUrl;
369
+ } else {
370
+ return (
371
+ baseUrl + '?' + arrayToUrlParams(queryList?.filter((q) => q.checked))
372
+ );
373
+ }
374
+ }
375
+
376
+ function onChangeUrl(e: any) {
377
+ const url = e.detail.value;
378
+ state.url = url;
379
+ const list = parseUrlToList(url);
380
+ queryList.splice(0, queryList.length, ...list);
381
+ }
382
+
383
+ function onReset() {
384
+ isFinished.value = false;
385
+ hasUrl.value = true;
386
+ state.method = 'GET';
387
+ state.url = '';
388
+ state.bodyText = '';
389
+ responseHeaderList.splice(0, responseHeaderList.length, ...defaultHeader);
390
+ queryList.splice(0, queryList.length);
391
+ }
392
+
393
+ function onClose() {
394
+ emit('close');
395
+ onReset();
396
+ }
397
+
398
+ function onConfirm() {
399
+ if (!state.url) {
400
+ hasUrl.value = false;
401
+ uni.showToast({
402
+ title: '请输入请求地址',
403
+ icon: 'none',
404
+ });
405
+ return;
406
+ }
407
+ hasUrl.value = true;
408
+
409
+ const responseHeader = arrayToObject(responseHeaderList);
410
+ const query = arrayToUrlParams(queryList);
411
+
412
+ const baseUrl = state.url?.split('?')[0] || '';
413
+ const lastSlashIndex = baseUrl.lastIndexOf('/');
414
+ const name = lastSlashIndex !== -1 ? baseUrl.slice(lastSlashIndex + 1) : '';
415
+
416
+ const interceptConfig: DevTool.NetworkItem = {
417
+ index: 0,
418
+
419
+ name,
420
+ url: state.url,
421
+ method: state.method,
422
+ timeout: state.timeout,
423
+ status: state.status,
424
+ time: '',
425
+ startTime: 0,
426
+ endTime: 0,
427
+ size: '',
428
+ headers: {
429
+ requestHeader: requestHeaderList,
430
+ responseHeader: responseHeaderList,
431
+ },
432
+ response: {
433
+ data: '',
434
+ statusCode: state.status,
435
+ header: responseHeader,
436
+ cookies: [],
437
+ errMsg: 'request:ok',
438
+ },
439
+ payload: {},
440
+ };
441
+
442
+ if (noBodyRequestMethods.includes(state.method)) {
443
+ // 不支持携带 body 参数
444
+
445
+ interceptConfig.payload = {};
446
+ } else {
447
+ // 支持 url 中携带参数
448
+
449
+ if (state.url.includes('?')) {
450
+ interceptConfig.url = state.url + '&' + query;
451
+ } else {
452
+ interceptConfig.url = state.url + '?' + query;
453
+ }
454
+
455
+ // 支持携带 body 参数
456
+ if (state.bodyText?.trim()) {
457
+ try {
458
+ const bodyJson = JSON.parse(state.bodyText);
459
+ interceptConfig.payload = bodyJson;
460
+ } catch (error) {
461
+ uni.showToast({
462
+ title: '请求体请输入正确的JSON格式',
463
+ icon: 'none',
464
+ });
465
+ return;
466
+ }
467
+ }
468
+ }
469
+
470
+ if (state.responseText?.trim()) {
471
+ try {
472
+ const bodyJson = JSON.parse(state.responseText);
473
+ interceptConfig.response.data = bodyJson;
474
+ } catch (error) {
475
+ uni.showToast({
476
+ title: '响应体请输入正确的JSON格式',
477
+ icon: 'none',
478
+ });
479
+ return;
480
+ }
481
+ }
482
+
483
+ uni.showToast({
484
+ icon: 'none',
485
+ title: '保存成功',
486
+ });
487
+
488
+ emit('confirm', interceptConfig);
489
+ emit('close');
490
+ }
491
+
492
+ function onChangeRequestMethod(e: any) {
493
+ const method = e.detail.value;
494
+ state.method = method;
495
+ }
496
+
497
+ function onDeleteResponseHeader(item: any) {
498
+ const index = responseHeaderList.findIndex((i) => i.id === item.id);
499
+ responseHeaderList.splice(index, 1);
500
+ }
501
+
502
+ function onDeleteRequestHeader(item: any) {
503
+ const index = requestHeaderList.findIndex((i) => i.id === item.id);
504
+ requestHeaderList.splice(index, 1);
505
+ }
506
+
507
+ function onAddRequestHeader() {
508
+ const id = Date.now();
509
+ requestHeaderList.push({
510
+ id,
511
+ key: '',
512
+ value: '',
513
+ checked: false,
514
+ });
515
+ }
516
+ function onChangeRequestHeaderChecked(e: any) {
517
+ const list = e.detail?.value ?? [];
518
+
519
+ Object.assign(
520
+ requestHeaderList,
521
+ requestHeaderList.map((item) => {
522
+ return { ...item, checked: list?.includes(item.id) };
523
+ }),
524
+ );
525
+ }
526
+
527
+ function onChangeRequestHeader(e: any, key: 'key' | 'value', index: number) {
528
+ requestHeaderList[index][key] = e.detail.value;
529
+ }
530
+
531
+ function onAddResponseHeader() {
532
+ const id = Date.now();
533
+ responseHeaderList.push({
534
+ id,
535
+ key: '',
536
+ value: '',
537
+ checked: false,
538
+ });
539
+ }
540
+
541
+ function onChangeResponseHeaderChecked(e: any) {
542
+ const list = e.detail?.value ?? [];
543
+
544
+ Object.assign(
545
+ responseHeaderList,
546
+ responseHeaderList.map((item) => {
547
+ return { ...item, checked: list?.includes(item.id) };
548
+ }),
549
+ );
550
+ }
551
+
552
+ function onChangeResponseHeader(e: any, key: 'key' | 'value', index: number) {
553
+ responseHeaderList[index][key] = e.detail.value;
554
+ }
555
+
556
+ function onDeleteQuery(item: any) {
557
+ const index = queryList.findIndex((i) => i.id === item.id);
558
+ queryList.splice(index, 1);
559
+ }
560
+ function onAddQuery() {
561
+ const id = Date.now();
562
+ queryList.push({
563
+ id,
564
+ key: '',
565
+ value: '',
566
+ checked: false,
567
+ });
568
+ }
569
+ function onChangeQueryChecked(e: any) {
570
+ const list = e.detail?.value ?? [];
571
+ queryList.forEach((q) => {
572
+ q.checked = list?.includes(q.id);
573
+ });
574
+
575
+ state.url = parseListToUrl(queryList);
576
+ }
577
+
578
+ function onChangeQuery(e: any, key: 'key' | 'value', index: number) {
579
+ queryList[index][key] = e.detail.value;
580
+
581
+ state.url = parseListToUrl(queryList);
582
+ }
583
+
584
+ function arrayToObject(arr: any[]) {
585
+ return arr.reduce((acc, cur) => {
586
+ if (cur.checked) {
587
+ acc[cur.key] = cur.value;
588
+ }
589
+ return acc;
590
+ }, {});
591
+ }
592
+
593
+ function objectToArray<T extends Record<string, any>>(obj: T) {
594
+ return Object.entries(obj).map(([key, value]) => ({
595
+ id: Date.now(),
596
+ key,
597
+ value,
598
+ checked: true,
599
+ }));
600
+ }
601
+
602
+ function objectToUrlParams(obj: any) {
603
+ return Object.keys(obj)
604
+ .map((key) => `${key}=${encodeURIComponent(obj[key])}`)
605
+ .join('&');
606
+ }
607
+
608
+ function arrayToUrlParams(arr: any[]) {
609
+ return arr
610
+ .map((item) => `${item.key}=${encodeURIComponent(item.value)}`)
611
+ ?.join('&');
612
+ }
613
+
614
+ function unionArrayByKey<T>(arr1: T[], arr2: T[], key: keyof T): T[] {
615
+ const map = new Map();
616
+ arr1.forEach((item) => {
617
+ map.set(item?.[key], item);
618
+ });
619
+ arr2.forEach((item) => {
620
+ if (map.has(item?.[key])) {
621
+ map.set(item?.[key], { ...map.get(item?.[key]), ...item });
622
+ } else {
623
+ map.set(item?.[key], item);
624
+ }
625
+ });
626
+ return Array.from(map.values());
627
+ }
628
+
629
+ function urlParamsToObject(urlParams: string) {
630
+ return urlParams.split('&').reduce(
631
+ (acc, cur) => {
632
+ const [key, value] = cur.split('=');
633
+ acc[key] = value;
634
+ return acc;
635
+ },
636
+ {} as Record<string, any>,
637
+ );
638
+ }
639
+
640
+ /**
641
+ * 处理规格
642
+ */
643
+ function handleInterceptConfig() {
644
+ // 如果没有网络数据或尚未开始,则直接返回
645
+ if (!props.network || !props.network.url) return;
646
+
647
+ // 设置基础请求信息
648
+ state.url = props.network.url;
649
+ state.method = props.network.method?.toUpperCase() ?? 'GET';
650
+ state.status = props.network.status;
651
+
652
+ // 初始化请求头
653
+ const requestHeaders =
654
+ props.network.headers?.requestHeader?.map((item, index) => {
655
+ return {
656
+ ...item,
657
+ id: index,
658
+ checked: true,
659
+ };
660
+ }) ?? [];
661
+
662
+ requestHeaderList.splice(0, requestHeaderList.length, ...requestHeaders);
663
+
664
+ const responseHeaders =
665
+ props.network.headers?.responseHeader?.map((item, index) => {
666
+ return {
667
+ ...item,
668
+ id: index,
669
+ checked: true,
670
+ };
671
+ }) ?? [];
672
+
673
+ responseHeaderList.splice(0, responseHeaderList.length, ...responseHeaders);
674
+
675
+ queryList.splice(0, queryList.length);
676
+
677
+ // 解析参数
678
+ if (noBodyRequestMethods.includes(state.method)) {
679
+ // 参数在 query 中
680
+ if (props.network.url.includes('?')) {
681
+ const urlParams = objectToArray(
682
+ urlParamsToObject(props.network.url.split('?')?.[1] ?? ''),
683
+ );
684
+ const payloadParams = objectToArray(props.network.payload);
685
+
686
+ const list = unionArrayByKey(urlParams, payloadParams, 'key');
687
+
688
+ queryList.splice(0, queryList.length, ...list);
689
+ }
690
+ } else {
691
+ // 参数在 query 中
692
+ if (props.network.url.includes('?')) {
693
+ const urlParams = objectToArray(
694
+ urlParamsToObject(props.network.url.split('?')?.[1] ?? ''),
695
+ );
696
+ queryList.splice(0, queryList.length, ...urlParams);
697
+ }
698
+ state.bodyText = JSON.stringify(props.network.payload);
699
+ }
700
+
701
+ if (props.network.response?.data) {
702
+ try {
703
+ state.responseText = JSON.stringify(props.network.response.data);
704
+ } catch (error) {
705
+ state.responseText = props.network.response.data;
706
+ }
707
+ }
708
+ }
709
+
710
+ onMounted(() => {
711
+ handleInterceptConfig();
712
+ });
713
+ </script>
714
+
715
+ <style scoped>
716
+ .intercept-config {
717
+ position: fixed;
718
+ width: 100vw;
719
+ height: 100%;
720
+ z-index: 5;
721
+ top: 0;
722
+ left: 0;
723
+ padding: 0 16px;
724
+ /* #ifdef H5 */
725
+ padding: 50px 16px;
726
+ /* #endif */
727
+ overflow: auto;
728
+
729
+ background-color: var(--dev-tool-bg3-color);
730
+ box-sizing: border-box;
731
+ }
732
+
733
+ .intercept-config-tip {
734
+ font-size: 12px;
735
+ color: var(--dev-tool-info-color);
736
+ }
737
+ .intercept-config-form {
738
+ height: calc(100% - 32px - 42px);
739
+ overflow: auto;
740
+ }
741
+
742
+ .intercept-config-control {
743
+ display: flex;
744
+ align-items: center;
745
+ gap: 12px;
746
+ height: 32px;
747
+ border-bottom: 1px solid transparent;
748
+ box-sizing: border-box;
749
+ }
750
+
751
+ .intercept-config-control :deep(.tag) {
752
+ margin-right: 16px;
753
+ }
754
+ .intercept-config-control :deep(.tag):last-child {
755
+ margin-right: 0;
756
+ }
757
+
758
+ .radio-group {
759
+ display: flex;
760
+ flex-wrap: wrap;
761
+ }
762
+
763
+ .radio-group-item {
764
+ display: flex;
765
+ align-items: center;
766
+ width: 25%;
767
+ margin-bottom: 6px;
768
+
769
+ font-size: 12px;
770
+ }
771
+
772
+ .intercept-input {
773
+ padding: 0 6px;
774
+ height: 24px;
775
+ font-size: 12px;
776
+ border: 1px solid var(--dev-tool-border-color);
777
+ }
778
+ .intercept-textarea {
779
+ padding: 6px;
780
+ width: 100%;
781
+ box-sizing: border-box;
782
+ font-size: 12px;
783
+ border: 1px solid var(--dev-tool-border-color);
784
+ }
785
+ .form-error-message {
786
+ padding: 0 6px;
787
+ height: 24px;
788
+ line-height: 24px;
789
+ color: red;
790
+ }
791
+
792
+ .intercept-header-list {
793
+ }
794
+
795
+ .intercept-header-item {
796
+ display: flex;
797
+ align-items: center;
798
+ }
799
+
800
+ .intercept-empty {
801
+ color: var(--dev-tool-info-color);
802
+ text-align: center;
803
+ }
804
+
805
+ .intercept-param-list {
806
+ }
807
+ .intercept-param-item {
808
+ display: flex;
809
+ align-items: center;
810
+ }
811
+
812
+ .intercept-body-data {
813
+ }
814
+ .intercept-body-data-item {
815
+ display: flex;
816
+ align-items: center;
817
+ }
818
+
819
+ .intercept-config-buttons {
820
+ position: sticky;
821
+ display: flex;
822
+ justify-content: space-between;
823
+ /* gap: 6px; */
824
+ width: 100%;
825
+ margin-top: 12px;
826
+ background-color: var(--dev-tool-bg3-color);
827
+ }
828
+ .intercept-config-buttons button {
829
+ width: 100%;
830
+ margin-right: 6px;
831
+ }
832
+ .intercept-config-buttons button:last-child {
833
+ margin: 0;
834
+ }
835
+ </style>