vite-uni-dev-tool 1.0.0 → 1.1.0

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 (168) hide show
  1. package/README.md +46 -0
  2. package/dist/const.cjs +1 -1
  3. package/dist/const.d.ts +12 -0
  4. package/dist/const.d.ts.map +1 -1
  5. package/dist/const.js +1 -1
  6. package/dist/core-shared.d.ts +1 -1
  7. package/dist/core-shared.d.ts.map +1 -1
  8. package/dist/core-shared.js +1 -1
  9. package/dist/core.d.ts +10 -3
  10. package/dist/core.d.ts.map +1 -1
  11. package/dist/core.js +2 -2
  12. package/dist/i18n/locales/en.cjs +1 -1
  13. package/dist/i18n/locales/en.d.ts +81 -0
  14. package/dist/i18n/locales/en.d.ts.map +1 -1
  15. package/dist/i18n/locales/en.js +1 -1
  16. package/dist/i18n/locales/zh-Hans.cjs +1 -1
  17. package/dist/i18n/locales/zh-Hans.d.ts +82 -1
  18. package/dist/i18n/locales/zh-Hans.d.ts.map +1 -1
  19. package/dist/i18n/locales/zh-Hans.js +1 -1
  20. package/dist/modules/devConsole/index.cjs +1 -1
  21. package/dist/modules/devConsole/index.js +3 -3
  22. package/dist/modules/devEvent/index.cjs +3 -3
  23. package/dist/modules/devEvent/index.d.ts +1 -0
  24. package/dist/modules/devEvent/index.d.ts.map +1 -1
  25. package/dist/modules/devEvent/index.js +3 -3
  26. package/dist/modules/devIntercept/index.cjs +14 -13
  27. package/dist/modules/devIntercept/index.d.ts +19 -0
  28. package/dist/modules/devIntercept/index.d.ts.map +1 -1
  29. package/dist/modules/devIntercept/index.js +14 -13
  30. package/dist/modules/devStore/index.cjs +1 -1
  31. package/dist/modules/devStore/index.d.ts +21 -0
  32. package/dist/modules/devStore/index.d.ts.map +1 -1
  33. package/dist/modules/devStore/index.js +1 -1
  34. package/dist/plugins/uniDevTool/transform/transformMain.cjs +1 -1
  35. package/dist/plugins/uniDevTool/transform/transformMain.js +1 -1
  36. package/dist/type.d.ts +47 -2
  37. package/dist/type.d.ts.map +1 -1
  38. package/dist/utils/language.cjs +1 -1
  39. package/dist/utils/language.d.ts.map +1 -1
  40. package/dist/utils/language.js +1 -1
  41. package/dist/utils/object.cjs +1 -1
  42. package/dist/utils/object.d.ts.map +1 -1
  43. package/dist/utils/object.js +1 -1
  44. package/dist/v3/DevTool/components/BluetoothList/BluetoothItem.vue +199 -0
  45. package/dist/v3/DevTool/components/BluetoothList/BluetoothTool.vue +730 -0
  46. package/dist/v3/DevTool/components/BluetoothList/index.vue +167 -0
  47. package/dist/v3/{CaptureScreen → DevTool/components/CaptureScreen}/index.vue +109 -109
  48. package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/ConsoleItem.vue +225 -224
  49. package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/RunJSInput.vue +247 -249
  50. package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/index.vue +171 -160
  51. package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/staticTips.ts +1145 -1145
  52. package/dist/v3/{DevToolButton → DevTool/components/DevToolButton}/index.vue +7 -4
  53. package/dist/v3/{DevToolTitle → DevTool/components/DevToolTitle}/index.vue +24 -24
  54. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/DevToolOverlay.vue +197 -182
  55. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/const.ts +28 -5
  56. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/dataUtils.ts +48 -48
  57. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/useDevToolData.ts +387 -338
  58. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/useDevToolHandlers.ts +629 -549
  59. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/useDevToolOverlay.ts +197 -184
  60. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/index.vue +67 -16
  61. package/dist/v3/{ElEvent → DevTool/components/ElEvent}/ElEventItem.vue +105 -105
  62. package/dist/v3/{ElEvent → DevTool/components/ElEvent}/index.vue +106 -109
  63. package/dist/v3/{Instance → DevTool/components/Instance}/components/InstanceTreeNode.vue +265 -265
  64. package/dist/v3/{Instance → DevTool/components/Instance}/flatten.ts +226 -226
  65. package/dist/v3/{Instance → DevTool/components/Instance}/index.vue +94 -94
  66. package/dist/v3/{Instance → DevTool/components/Instance}/registry.ts +49 -49
  67. package/dist/v3/{Instance → DevTool/components/Instance}/transformTree.ts +375 -375
  68. package/dist/v3/{Instance → DevTool/components/Instance}/transformTreeCtx.ts +268 -268
  69. package/dist/v3/{Instance → DevTool/components/Instance}/typing.d.ts +43 -43
  70. package/dist/v3/{InstanceDetail → DevTool/components/InstanceDetail}/index.vue +485 -485
  71. package/dist/v3/{JsonDetail → DevTool/components/JsonDetail}/index.vue +70 -70
  72. package/dist/v3/{NFCList → DevTool/components/NFCList}/NFCItem.vue +112 -113
  73. package/dist/v3/{NFCList → DevTool/components/NFCList}/NFCTool.vue +454 -478
  74. package/dist/v3/{NFCList → DevTool/components/NFCList}/const.ts +56 -56
  75. package/dist/v3/{NFCList → DevTool/components/NFCList}/index.vue +94 -98
  76. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/InterceptConfig.vue +624 -608
  77. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/InterceptItem.vue +140 -140
  78. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkDetail.vue +287 -296
  79. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkIntercept.vue +88 -93
  80. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkItem.vue +163 -167
  81. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkSend.vue +589 -556
  82. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/const.ts +4 -4
  83. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/hooks/useNetworkForm.ts +86 -86
  84. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/index.vue +160 -160
  85. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/utils.ts +101 -101
  86. package/dist/v3/{Performance → DevTool/components/Performance}/index.vue +498 -495
  87. package/dist/v3/{Performance → DevTool/components/Performance}/modules/PerformanceMetrics.vue +153 -153
  88. package/dist/v3/{Performance → DevTool/components/Performance}/modules/PerformanceWidget.vue +12 -9
  89. package/dist/v3/{Performance → DevTool/components/Performance}/modules/usePerformanceChart.ts +460 -460
  90. package/dist/v3/{Performance → DevTool/components/Performance}/modules/usePerformanceData.ts +258 -258
  91. package/dist/v3/{PiniaList → DevTool/components/PiniaList}/index.vue +93 -94
  92. package/dist/v3/{RouteList → DevTool/components/RouteList}/index.vue +21 -24
  93. package/dist/v3/{RunJS → DevTool/components/RunJS}/index.vue +148 -148
  94. package/dist/v3/{ScanCodeList → DevTool/components/ScanCodeList}/ScanCodeItem.vue +97 -98
  95. package/dist/v3/{ScanCodeList → DevTool/components/ScanCodeList}/index.vue +100 -104
  96. package/dist/v3/{SettingButton → DevTool/components/SettingButton}/index.vue +45 -45
  97. package/dist/v3/{SettingList → DevTool/components/SettingList}/index.vue +218 -150
  98. package/dist/v3/DevTool/components/SettingList/modules/SettingBarrage.vue +304 -0
  99. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingDevTool.vue +212 -208
  100. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingInfo.vue +157 -119
  101. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingLanguage.vue +74 -74
  102. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingLog.vue +230 -230
  103. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingNetwork.vue +3 -3
  104. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingTheme.vue +37 -7
  105. package/dist/v3/{SettingList → DevTool/components/SettingList}/typing.d.ts +2 -2
  106. package/dist/v3/{SourceCode → DevTool/components/SourceCode}/Line.vue +127 -116
  107. package/dist/v3/{SourceCode → DevTool/components/SourceCode}/index.vue +8 -8
  108. package/dist/v3/{SourceCode → DevTool/components/SourceCode}/parseCode.ts +609 -701
  109. package/dist/v3/{StorageList → DevTool/components/StorageList}/index.vue +174 -174
  110. package/dist/v3/{TransferList → DevTool/components/TransferList}/TransferDetail.vue +268 -268
  111. package/dist/v3/{TransferList → DevTool/components/TransferList}/TransferItem.vue +4 -4
  112. package/dist/v3/{TransferList → DevTool/components/TransferList}/index.vue +8 -8
  113. package/dist/v3/{UniEvent → DevTool/components/UniEvent}/UniEventItem.vue +6 -7
  114. package/dist/v3/{UniEvent → DevTool/components/UniEvent}/index.vue +6 -6
  115. package/dist/v3/{VuexList → DevTool/components/VuexList}/index.vue +84 -84
  116. package/dist/v3/{WebSocket → DevTool/components/WebSocket}/WebSocketDetail.vue +8 -8
  117. package/dist/v3/{WebSocket → DevTool/components/WebSocket}/WebSocketItem.vue +4 -4
  118. package/dist/v3/{WebSocket → DevTool/components/WebSocket}/index.vue +8 -8
  119. package/dist/v3/DevTool/index.vue +179 -5
  120. package/dist/v3/{AppTransition → components/AppTransition}/index.vue +176 -170
  121. package/dist/v3/{AutoSizer → components/AutoSizer}/index.vue +192 -192
  122. package/dist/v3/{AutoSizer → components/AutoSizer}/index1.vue +184 -184
  123. package/dist/v3/{AutoSizer → components/AutoSizer}/utils.ts +49 -49
  124. package/dist/v3/components/Barrage/BarrageItem.vue +137 -0
  125. package/dist/v3/components/Barrage/index.vue +202 -0
  126. package/dist/v3/{CircularButton → components/CircularButton}/index.vue +84 -84
  127. package/dist/v3/{CustomSwiper → components/CustomSwiper}/CustomSwiperItem.vue +49 -49
  128. package/dist/v3/{CustomSwiper → components/CustomSwiper}/index.vue +104 -104
  129. package/dist/v3/{DraggableContainer → components/DraggableContainer}/index.vue +1 -1
  130. package/dist/v3/{Empty → components/Empty}/index.vue +29 -29
  131. package/dist/v3/{FilterInput → components/FilterInput}/index.vue +1 -1
  132. package/dist/v3/{FilterSelect → components/FilterSelect}/index.vue +179 -179
  133. package/dist/v3/{JsonPretty → components/JsonPretty}/components/Brackets/index.vue +27 -27
  134. package/dist/v3/{JsonPretty → components/JsonPretty}/components/Carets/index.vue +59 -59
  135. package/dist/v3/{JsonPretty → components/JsonPretty}/components/CheckController/index.vue +136 -136
  136. package/dist/v3/{JsonPretty → components/JsonPretty}/components/TreeNode/index.vue +387 -381
  137. package/dist/v3/{JsonPretty → components/JsonPretty}/hooks/useClipboard.ts +21 -21
  138. package/dist/v3/{JsonPretty → components/JsonPretty}/hooks/useError.ts +21 -21
  139. package/dist/v3/{JsonPretty → components/JsonPretty}/index.vue +16 -13
  140. package/dist/v3/{JsonPretty → components/JsonPretty}/type.ts +127 -126
  141. package/dist/v3/{JsonPretty → components/JsonPretty}/utils/index.ts +169 -169
  142. package/dist/v3/{MovableContainer → components/MovableContainer}/index.vue +1 -1
  143. package/dist/v3/{Pick → components/Pick}/index.vue +322 -322
  144. package/dist/v3/{Tabs → components/Tabs}/index.vue +30 -4
  145. package/dist/v3/{Tag → components/Tag}/index.vue +113 -113
  146. package/dist/v3/{VirtualList → components/VirtualList}/AutoSize.vue +40 -40
  147. package/dist/v3/{VirtualList → components/VirtualList}/index.vue +416 -412
  148. package/dist/v3/hooks/useBluetooth/index.ts +561 -0
  149. package/dist/v3/hooks/useContainerStyle.ts +153 -153
  150. package/dist/v3/hooks/useNFC/index.ts +107 -107
  151. package/dist/v3/hooks/useNFC/typing.d.ts +396 -396
  152. package/dist/v3/hooks/useNFC/useNFCAndroid.ts +966 -966
  153. package/dist/v3/hooks/useNFC/useNFCMpWeiXin.ts +812 -812
  154. package/dist/v3/hooks/useNFC/utils.ts +754 -754
  155. package/dist/v3/hooks/useRequest/index.ts +586 -573
  156. package/dist/v3/hooks/useRequest/utils.ts +267 -267
  157. package/dist/v3/hooks/useScanCode/index.ts +206 -206
  158. package/dist/v3/hooks/useWebsocket/README.md +79 -0
  159. package/dist/v3/hooks/useWebsocket/index.ts +253 -0
  160. package/dist/v3/styles/theme.css +17 -10
  161. package/dist/v3/styles/theme.ts +12 -12
  162. package/package.json +59 -64
  163. package/dist/plugins/uniParseStock/index.d.ts +0 -10
  164. package/dist/plugins/uniParseStock/index.d.ts.map +0 -1
  165. /package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/index.css +0 -0
  166. /package/dist/v3/{SettingList → DevTool/components/SettingList}/index.css +0 -0
  167. /package/dist/v3/{Empty → components/Empty}/empty.png +0 -0
  168. /package/dist/v3/{VirtualList → components/VirtualList}/readme.md +0 -0
@@ -1,608 +1,624 @@
1
- <template>
2
- <view class="intercept-config" :style="customStyle">
3
- <view class="intercept-config-control">
4
- <DevToolTitle>{{ t('network.interceptConfig') }}</DevToolTitle>
5
- <CircularButton style="margin-left: auto" text="×" @click="onClose" />
6
- </view>
7
-
8
- <scroll-view scroll-y class="intercept-config-form">
9
- <view class="intercept-config-tip">
10
- {{ t('network.tipsIntercept') }}
11
- </view>
12
- <view class="intercept-config-control">
13
- <DevToolTitle>{{ t('network.timeout') }}</DevToolTitle>
14
- </view>
15
- <input
16
- class="intercept-input"
17
- :value="state.timeout"
18
- @input="onChangeState($event, 'timeout')" />
19
- <view class="intercept-config-tip">
20
- {{ t('network.tipsTimeout') }}
21
- </view>
22
- <view class="intercept-config-control">
23
- <DevToolTitle>{{ t('network.responseStatus') }}</DevToolTitle>
24
- </view>
25
- <input
26
- class="intercept-input"
27
- :value="state.status"
28
- @input="onChangeState($event, 'status')" />
29
- <view class="intercept-config-control">
30
- <DevToolTitle>{{ t('network.requestMethod') }}</DevToolTitle>
31
- </view>
32
- <radio-group class="radio-group" @change="onChangeRequestMethod">
33
- <label
34
- class="radio-group-item"
35
- v-for="item in requestMethods"
36
- :key="item.value">
37
- <radio
38
- size
39
- style="transform: scale(0.8)"
40
- :color="themeColor"
41
- :value="item.value"
42
- :checked="item.value === state.method" />
43
-
44
- <view>{{ item.name }}</view>
45
- </label>
46
- </radio-group>
47
-
48
- <view class="intercept-config-control">
49
- <DevToolTitle>{{ t('network.requestHeaders') }}</DevToolTitle>
50
- <CircularButton
51
- style="margin-left: auto"
52
- text=""
53
- @click="onAddRequestHeader" />
54
- </view>
55
-
56
- <view class="intercept-header-list">
57
- <checkbox-group
58
- v-if="requestHeaderList.length > 0"
59
- key="requestHeaderList"
60
- @change="onChangeRequestHeaderChecked">
61
- <view
62
- class="intercept-header-item"
63
- v-for="(item, index) in requestHeaderList"
64
- :key="item.id">
65
- <checkbox
66
- :color="themeColor"
67
- :value="item.id"
68
- :checked="item.checked" />
69
- <input
70
- class="intercept-input"
71
- :placeholder="t('network.placeholderHeaderName')"
72
- :value="item.key"
73
- @input="onChangeRequestHeader($event, 'key', index)" />
74
- <input
75
- class="intercept-input"
76
- :placeholder="t('network.placeholderHeaderValue')"
77
- :value="item.value"
78
- @input="onChangeRequestHeader($event, 'value', index)" />
79
- <CircularButton
80
- style="margin-left: 6px"
81
- text="一"
82
- @click="onDeleteRequestHeader(item)" />
83
- </view>
84
- </checkbox-group>
85
-
86
- <view class="intercept-empty" v-else>
87
- {{ t('network.noRequestHeaders') }}
88
- </view>
89
- </view>
90
-
91
- <view class="intercept-config-control">
92
- <DevToolTitle>{{ t('network.responseHeaders') }}</DevToolTitle>
93
- <CircularButton
94
- style="margin-left: auto"
95
- text="+"
96
- @click="onAddResponseHeader" />
97
- </view>
98
-
99
- <view class="intercept-header-list">
100
- <checkbox-group
101
- v-if="responseHeaderList.length > 0"
102
- key="responseHeaderList"
103
- @change="onChangeResponseHeaderChecked">
104
- <view
105
- class="intercept-header-item"
106
- v-for="(item, index) in responseHeaderList"
107
- :key="item.id">
108
- <checkbox
109
- :color="themeColor"
110
- :value="item.id"
111
- :checked="item.checked" />
112
- <input
113
- class="intercept-input"
114
- :placeholder="t('network.placeholderRespHeaderName')"
115
- :value="item.key"
116
- @input="onChangeResponseHeader($event, 'key', index)" />
117
- <input
118
- class="intercept-input"
119
- :placeholder="t('network.placeholderRespHeaderValue')"
120
- :value="item.value"
121
- @input="onChangeResponseHeader($event, 'value', index)" />
122
- <CircularButton
123
- style="margin-left: 6px"
124
- text="一"
125
- @click="onDeleteResponseHeader(item)" />
126
- </view>
127
- </checkbox-group>
128
-
129
- <view class="intercept-empty" v-else>
130
- {{ t('network.noResponseHeaders') }}
131
- </view>
132
- </view>
133
- <DevToolTitle>{{ t('network.requestUrl') }}</DevToolTitle>
134
- <textarea
135
- :placeholder="t('network.placeholderUrl')"
136
- class="intercept-textarea"
137
- :value="state.url"
138
- @input="onChangeUrl" />
139
- <view class="form-error-message">
140
- {{ hasUrl ? '' : t('network.toastEnterUrl') }}
141
- </view>
142
-
143
- <view class="intercept-config-control">
144
- <DevToolTitle>{{ t('network.requestParams') }}</DevToolTitle>
145
- <CircularButton
146
- style="margin-left: auto"
147
- text=""
148
- @click="onAddQuery" />
149
- </view>
150
- <view class="intercept-param-list">
151
- <checkbox-group
152
- v-if="queryList.length > 0"
153
- @change="handleQueryCheckedChange">
154
- <view
155
- class="intercept-param-item"
156
- v-for="(item, index) in queryList"
157
- :key="item.id">
158
- <checkbox
159
- :color="themeColor"
160
- :checked="item.checked"
161
- :value="item.id" />
162
- <input
163
- class="intercept-input"
164
- :placeholder="t('network.placeholderParamName')"
165
- :value="item.key"
166
- @input="onChangeQuery($event, 'key', index)" />
167
- <input
168
- class="intercept-input"
169
- :placeholder="t('network.placeholderParamValue')"
170
- :value="item.value"
171
- @input="onChangeQuery($event, 'value', index)" />
172
- <CircularButton
173
- text=""
174
- style="margin-left: 6px"
175
- @click="onDeleteQuery(item)" />
176
- </view>
177
- </checkbox-group>
178
-
179
- <view class="intercept-empty" v-else>
180
- {{ t('network.emptyParams') }}
181
- </view>
182
- </view>
183
-
184
- <template v-if="!noBodyRequestMethods.includes(state.method)">
185
- <view class="intercept-config-control">
186
- <DevToolTitle>{{ t('network.requestBody') }}</DevToolTitle>
187
- </view>
188
-
189
- <textarea
190
- :placeholder="t('network.placeholderBody')"
191
- class="intercept-textarea"
192
- :value="state.bodyText"
193
- @input="onChangeState($event, 'bodyText')" />
194
- </template>
195
-
196
- <view class="intercept-config-control">
197
- <DevToolTitle>{{ t('network.responseBody') }}</DevToolTitle>
198
- </view>
199
- <textarea
200
- :placeholder="t('network.placeholderRespBody')"
201
- class="intercept-textarea"
202
- :value="state.responseText"
203
- @input="onChangeState($event, 'responseText')" />
204
- </scroll-view>
205
- <view class="intercept-config-buttons">
206
- <SettingButton @click="onConfirm">
207
- {{ t('network.saveConfig') }}
208
- </SettingButton>
209
- </view>
210
- </view>
211
- </template>
212
- <script lang="ts" setup>
213
- import { computed, ref, onMounted } from 'vue';
214
- import CircularButton from '../CircularButton/index.vue';
215
- import DevToolTitle from '../DevToolTitle/index.vue';
216
- import type { DevTool } from '../../type';
217
- import SettingButton from '../SettingButton/index.vue';
218
- import { useI18n } from '../../i18n';
219
- import { getThemeMainColor } from '../styles/theme';
220
- const { t } = useI18n();
221
- const themeColor = computed(() => getThemeMainColor(props.theme));
222
-
223
- const props = defineProps<{
224
- theme?: string;
225
- network: DevTool.NetworkItem;
226
- zIndex?: number;
227
- customStyle?: Record<string, any>;
228
- }>();
229
-
230
- const emit = defineEmits<{
231
- (e: 'close'): void;
232
- (e: 'openDetail', v: DevTool.NetworkItem): void;
233
- (e: 'confirm', v: DevTool.NetworkItem): void;
234
- }>();
235
-
236
- import {
237
- requestMethods,
238
- noBodyRequestMethods,
239
- defaultHeader,
240
- arrayToObject,
241
- objectToArray,
242
- arrayToUrlParams,
243
- urlParamsToObject,
244
- unionArrayByKey,
245
- } from './utils';
246
- import { useKeyValueList, useNetworkState } from './hooks/useNetworkForm';
247
-
248
- const { state, hasUrl, onChangeState, parseUrlToList, parseListToUrl } =
249
- useNetworkState({
250
- method: 'GET',
251
- url: 'http://mock.view-uni-dev-tool/a?a=123',
252
- status: 200,
253
- bodyText: '',
254
- responseText: '',
255
- timeout: 3 * 1000,
256
- });
257
-
258
- const {
259
- list: requestHeaderList,
260
- onAdd: onAddRequestHeader,
261
- onDelete: onDeleteRequestHeader,
262
- onChangeChecked: onChangeRequestHeaderChecked,
263
- onChangeValue: onChangeRequestHeaderItem,
264
- setList: setRequestHeaderList,
265
- } = useKeyValueList(defaultHeader);
266
-
267
- const {
268
- list: responseHeaderList,
269
- onAdd: onAddResponseHeader,
270
- onDelete: onDeleteResponseHeader,
271
- onChangeChecked: onChangeResponseHeaderChecked,
272
- onChangeValue: onChangeResponseHeaderItem,
273
- setList: setResponseHeaderList,
274
- } = useKeyValueList(defaultHeader);
275
-
276
- const {
277
- list: queryList,
278
- onAdd: onAddQuery,
279
- onDelete: onDeleteQuery,
280
- onChangeChecked: onChangeQueryChecked,
281
- onChangeValue: onChangeQueryItem,
282
- setList: setQueryList,
283
- } = useKeyValueList([
284
- {
285
- id: '1',
286
- key: 'a',
287
- value: '123',
288
- checked: true,
289
- },
290
- ]);
291
-
292
- const isFinished = ref(false);
293
-
294
- function onChangeUrl(e: any) {
295
- const url = e.detail.value;
296
- state.url = url;
297
- const list = parseUrlToList(url);
298
- setQueryList(list);
299
- }
300
-
301
- function onReset() {
302
- isFinished.value = false;
303
- hasUrl.value = true;
304
- state.method = 'GET';
305
- state.url = '';
306
- state.bodyText = '';
307
- setResponseHeaderList(defaultHeader);
308
- setQueryList([]);
309
- }
310
-
311
- function onClose() {
312
- emit('close');
313
- onReset();
314
- }
315
-
316
- function onConfirm() {
317
- if (!state.url) {
318
- hasUrl.value = false;
319
- uni.showToast({
320
- title: t('network.toastEnterUrl'),
321
- icon: 'none',
322
- });
323
- return;
324
- }
325
- hasUrl.value = true;
326
-
327
- const responseHeader = arrayToObject(responseHeaderList);
328
- const query = arrayToUrlParams(queryList.filter((q) => q.checked));
329
-
330
- const baseUrl = state.url?.split('?')[0] || '';
331
- const lastSlashIndex = baseUrl.lastIndexOf('/');
332
- const name = lastSlashIndex !== -1 ? baseUrl.slice(lastSlashIndex + 1) : '';
333
-
334
- const interceptConfig: DevTool.NetworkItem = {
335
- index: 0,
336
-
337
- name,
338
- url: state.url,
339
- method: state.method,
340
- timeout: state.timeout,
341
- status: state.status as string,
342
- time: '',
343
- startTime: 0,
344
- endTime: 0,
345
- size: '',
346
- headers: {
347
- requestHeader: requestHeaderList,
348
- responseHeader: responseHeaderList,
349
- },
350
- response: {
351
- data: '',
352
- statusCode: Number(state.status),
353
- header: responseHeader,
354
- cookies: [],
355
- errMsg: 'request:ok',
356
- },
357
- payload: {},
358
- };
359
-
360
- if (noBodyRequestMethods.includes(state.method)) {
361
- // 不支持携带 body 参数
362
-
363
- interceptConfig.payload = {};
364
- } else {
365
- // 支持 url 中携带参数
366
-
367
- if (state.url.includes('?')) {
368
- interceptConfig.url = state.url + '&' + query;
369
- } else {
370
- interceptConfig.url = state.url + '?' + query;
371
- }
372
-
373
- // 支持携带 body 参数
374
- if (state.bodyText?.trim()) {
375
- try {
376
- const bodyJson = JSON.parse(state.bodyText);
377
- interceptConfig.payload = bodyJson;
378
- } catch (_error) {
379
- uni.showToast({
380
- title: t('network.toastBodyJson'),
381
- icon: 'none',
382
- });
383
- return;
384
- }
385
- }
386
- }
387
-
388
- if (state.responseText?.trim()) {
389
- try {
390
- const bodyJson = JSON.parse(state.responseText);
391
- interceptConfig.response.data = bodyJson;
392
- } catch (_error) {
393
- uni.showToast({
394
- title: t('network.toastRespJson'),
395
- icon: 'none',
396
- });
397
- return;
398
- }
399
- }
400
-
401
- uni.showToast({
402
- icon: 'none',
403
- title: t('network.toastSaveSuccess'),
404
- });
405
-
406
- emit('confirm', interceptConfig);
407
- emit('close');
408
- }
409
-
410
- function onChangeRequestMethod(e: any) {
411
- const method = e.detail.value;
412
- state.method = method;
413
- }
414
-
415
- function onChangeRequestHeader(e: any, key: 'key' | 'value', index: number) {
416
- onChangeRequestHeaderItem(index, key, e.detail.value);
417
- }
418
-
419
- function onChangeResponseHeader(e: any, key: 'key' | 'value', index: number) {
420
- onChangeResponseHeaderItem(index, key, e.detail.value);
421
- }
422
-
423
- function handleQueryCheckedChange(e: any) {
424
- onChangeQueryChecked(e);
425
- state.url = parseListToUrl(state.url, queryList);
426
- }
427
-
428
- function onChangeQuery(e: any, key: 'key' | 'value', index: number) {
429
- onChangeQueryItem(index, key, e.detail.value);
430
- state.url = parseListToUrl(state.url, queryList);
431
- }
432
-
433
- /**
434
- * 处理规格
435
- */
436
- function handleInterceptConfig() {
437
- // 如果没有网络数据或尚未开始,则直接返回
438
- if (!props.network || !props.network.url) return;
439
-
440
- // 设置基础请求信息
441
- state.url = props.network.url;
442
- state.method = props.network.method?.toUpperCase() ?? 'GET';
443
- state.status = props.network.status as string;
444
-
445
- // 初始化请求头
446
- const requestHeaders =
447
- props.network.headers?.requestHeader?.map((item, index) => {
448
- return {
449
- ...item,
450
- id: index.toString(),
451
- checked: true,
452
- };
453
- }) ?? [];
454
-
455
- setRequestHeaderList(requestHeaders);
456
-
457
- const responseHeaders =
458
- props.network.headers?.responseHeader?.map((item, index) => {
459
- return {
460
- ...item,
461
- id: index.toString(),
462
- checked: true,
463
- };
464
- }) ?? [];
465
-
466
- setResponseHeaderList(responseHeaders);
467
-
468
- setQueryList([]);
469
-
470
- // 解析参数
471
- if (noBodyRequestMethods.includes(state.method)) {
472
- // 参数在 query 中
473
- if (props.network.url.includes('?')) {
474
- const urlParams = objectToArray(
475
- urlParamsToObject(props.network.url.split('?')?.[1] ?? ''),
476
- );
477
- const payloadParams = objectToArray(props.network.payload);
478
-
479
- const list = unionArrayByKey(urlParams, payloadParams, 'key');
480
-
481
- setQueryList(list);
482
- }
483
- } else {
484
- // 参数在 query 中
485
- if (props.network.url.includes('?')) {
486
- const urlParams = objectToArray(
487
- urlParamsToObject(props.network.url.split('?')?.[1] ?? ''),
488
- );
489
- setQueryList(urlParams);
490
- }
491
- state.bodyText = JSON.stringify(props.network.payload);
492
- }
493
-
494
- if (props.network.response?.data) {
495
- try {
496
- state.responseText = JSON.stringify(props.network.response.data);
497
- } catch (_error) {
498
- state.responseText = props.network.response.data as string;
499
- }
500
- }
501
- }
502
-
503
- onMounted(() => {
504
- handleInterceptConfig();
505
- });
506
- </script>
507
-
508
- <style scoped>
509
- .intercept-config {
510
- position: fixed;
511
- width: 100vw;
512
- height: 100%;
513
- z-index: 5;
514
- top: 0;
515
- left: 0;
516
- padding: 0 16px;
517
-
518
- /* #ifdef H5 || APP-PLUS */
519
- padding: 50px 16px;
520
-
521
- /* #endif */
522
- overflow: auto;
523
- background-color: var(--dev-tool-bg3-color);
524
- box-sizing: border-box;
525
- }
526
-
527
- .intercept-config-tip {
528
- font-size: var(--dev-tool-tips-font-size);
529
- color: var(--dev-tool-info-color);
530
- }
531
-
532
- .intercept-config-form {
533
- height: calc(100% - 32px - 42px);
534
- overflow: auto;
535
- }
536
-
537
- .intercept-config-control {
538
- display: flex;
539
- align-items: center;
540
- gap: 12px;
541
- height: 32px;
542
- border-bottom: 1px solid transparent;
543
- box-sizing: border-box;
544
- }
545
-
546
- .radio-group {
547
- display: flex;
548
- flex-wrap: wrap;
549
- }
550
-
551
- .radio-group-item {
552
- display: flex;
553
- align-items: center;
554
- width: 25%;
555
- margin-bottom: 6px;
556
- }
557
-
558
- .intercept-input {
559
- padding: 0 6px;
560
- height: 24px;
561
- border: 1px solid var(--dev-tool-border-color);
562
- }
563
-
564
- .intercept-textarea {
565
- padding: 6px;
566
- width: 100%;
567
- box-sizing: border-box;
568
- border: 1px solid var(--dev-tool-border-color);
569
- }
570
-
571
- .form-error-message {
572
- padding: 0 6px;
573
- height: 24px;
574
- line-height: 24px;
575
- color: red;
576
- }
577
-
578
- .intercept-header-item {
579
- display: flex;
580
- align-items: center;
581
- }
582
-
583
- .intercept-empty {
584
- color: var(--dev-tool-info-color);
585
- text-align: center;
586
- }
587
-
588
- .intercept-param-item {
589
- display: flex;
590
- align-items: center;
591
- }
592
-
593
- .intercept-body-data-item {
594
- display: flex;
595
- align-items: center;
596
- }
597
-
598
- .intercept-config-buttons {
599
- position: sticky;
600
- display: flex;
601
- justify-content: space-between;
602
-
603
- /* gap: 6px; */
604
- width: 100%;
605
- margin-top: 12px;
606
- background-color: var(--dev-tool-bg3-color);
607
- }
608
- </style>
1
+ <template>
2
+ <view class="intercept-config" :style="customStyle">
3
+ <view class="intercept-config-control">
4
+ <DevToolTitle>{{ t('network.interceptConfig') }}</DevToolTitle>
5
+ <CircularButton style="margin-left: auto" text="×" @click="onClose" />
6
+ </view>
7
+
8
+ <scroll-view scroll-y class="intercept-config-form">
9
+ <view class="intercept-config-tip">
10
+ {{ t('network.tipsIntercept') }}
11
+ </view>
12
+ <view class="intercept-config-control">
13
+ <DevToolTitle>{{ t('network.timeout') }}</DevToolTitle>
14
+ </view>
15
+ <input
16
+ class="intercept-input"
17
+ :value="state.timeout"
18
+ @input="onChangeState($event, 'timeout')" />
19
+ <view class="intercept-config-tip">
20
+ {{ t('network.tipsTimeout') }}
21
+ </view>
22
+ <view class="intercept-config-control">
23
+ <DevToolTitle>
24
+ {{ t('network.delay') }}
25
+ </DevToolTitle>
26
+ </view>
27
+ <input
28
+ class="intercept-input"
29
+ :value="state.delay"
30
+ @input="onChangeState($event, 'delay')" />
31
+ <view class="intercept-config-tip">
32
+ {{ t('network.tipsDelay') }}
33
+ </view>
34
+ <view class="intercept-config-control">
35
+ <DevToolTitle>{{ t('network.responseStatus') }}</DevToolTitle>
36
+ </view>
37
+ <input
38
+ class="intercept-input"
39
+ :value="state.status"
40
+ @input="onChangeState($event, 'status')" />
41
+ <view class="intercept-config-control">
42
+ <DevToolTitle>{{ t('network.requestMethod') }}</DevToolTitle>
43
+ </view>
44
+ <radio-group class="radio-group" @change="onChangeRequestMethod">
45
+ <label
46
+ class="radio-group-item"
47
+ v-for="item in requestMethods"
48
+ :key="item.value">
49
+ <radio
50
+ size
51
+ style="transform: scale(0.8)"
52
+ :color="themeColor"
53
+ :value="item.value"
54
+ :checked="item.value === state.method" />
55
+
56
+ <view>{{ item.name }}</view>
57
+ </label>
58
+ </radio-group>
59
+
60
+ <view class="intercept-config-control">
61
+ <DevToolTitle>{{ t('network.requestHeaders') }}</DevToolTitle>
62
+ <CircularButton
63
+ style="margin-left: auto"
64
+ text=""
65
+ @click="onAddRequestHeader" />
66
+ </view>
67
+
68
+ <view class="intercept-header-list">
69
+ <checkbox-group
70
+ v-if="requestHeaderList.length > 0"
71
+ key="requestHeaderList"
72
+ @change="onChangeRequestHeaderChecked">
73
+ <view
74
+ class="intercept-header-item"
75
+ v-for="(item, index) in requestHeaderList"
76
+ :key="item.id">
77
+ <checkbox
78
+ :color="themeColor"
79
+ :value="item.id"
80
+ :checked="item.checked" />
81
+ <input
82
+ class="intercept-input"
83
+ :placeholder="t('network.placeholderHeaderName')"
84
+ :value="item.key"
85
+ @input="onChangeRequestHeader($event, 'key', index)" />
86
+ <input
87
+ class="intercept-input"
88
+ :placeholder="t('network.placeholderHeaderValue')"
89
+ :value="item.value"
90
+ @input="onChangeRequestHeader($event, 'value', index)" />
91
+ <CircularButton
92
+ style="margin-left: 6px"
93
+ text="一"
94
+ @click="onDeleteRequestHeader(item)" />
95
+ </view>
96
+ </checkbox-group>
97
+
98
+ <view class="intercept-empty" v-else>
99
+ {{ t('network.noRequestHeaders') }}
100
+ </view>
101
+ </view>
102
+
103
+ <view class="intercept-config-control">
104
+ <DevToolTitle>{{ t('network.responseHeaders') }}</DevToolTitle>
105
+ <CircularButton
106
+ style="margin-left: auto"
107
+ text=""
108
+ @click="onAddResponseHeader" />
109
+ </view>
110
+
111
+ <view class="intercept-header-list">
112
+ <checkbox-group
113
+ v-if="responseHeaderList.length > 0"
114
+ key="responseHeaderList"
115
+ @change="onChangeResponseHeaderChecked">
116
+ <view
117
+ class="intercept-header-item"
118
+ v-for="(item, index) in responseHeaderList"
119
+ :key="item.id">
120
+ <checkbox
121
+ :color="themeColor"
122
+ :value="item.id"
123
+ :checked="item.checked" />
124
+ <input
125
+ class="intercept-input"
126
+ :placeholder="t('network.placeholderRespHeaderName')"
127
+ :value="item.key"
128
+ @input="onChangeResponseHeader($event, 'key', index)" />
129
+ <input
130
+ class="intercept-input"
131
+ :placeholder="t('network.placeholderRespHeaderValue')"
132
+ :value="item.value"
133
+ @input="onChangeResponseHeader($event, 'value', index)" />
134
+ <CircularButton
135
+ style="margin-left: 6px"
136
+ text=""
137
+ @click="onDeleteResponseHeader(item)" />
138
+ </view>
139
+ </checkbox-group>
140
+
141
+ <view class="intercept-empty" v-else>
142
+ {{ t('network.noResponseHeaders') }}
143
+ </view>
144
+ </view>
145
+ <DevToolTitle>{{ t('network.requestUrl') }}</DevToolTitle>
146
+ <textarea
147
+ :placeholder="t('network.placeholderUrl')"
148
+ class="intercept-textarea"
149
+ :value="state.url"
150
+ @input="onChangeUrl" />
151
+ <view class="form-error-message">
152
+ {{ hasUrl ? '' : t('network.toastEnterUrl') }}
153
+ </view>
154
+
155
+ <view class="intercept-config-control">
156
+ <DevToolTitle>{{ t('network.requestParams') }}</DevToolTitle>
157
+ <CircularButton
158
+ style="margin-left: auto"
159
+ text=""
160
+ @click="onAddQuery" />
161
+ </view>
162
+ <view class="intercept-param-list">
163
+ <checkbox-group
164
+ v-if="queryList.length > 0"
165
+ @change="handleQueryCheckedChange">
166
+ <view
167
+ class="intercept-param-item"
168
+ v-for="(item, index) in queryList"
169
+ :key="item.id">
170
+ <checkbox
171
+ :color="themeColor"
172
+ :checked="item.checked"
173
+ :value="item.id" />
174
+ <input
175
+ class="intercept-input"
176
+ :placeholder="t('network.placeholderParamName')"
177
+ :value="item.key"
178
+ @input="onChangeQuery($event, 'key', index)" />
179
+ <input
180
+ class="intercept-input"
181
+ :placeholder="t('network.placeholderParamValue')"
182
+ :value="item.value"
183
+ @input="onChangeQuery($event, 'value', index)" />
184
+ <CircularButton
185
+ text=""
186
+ style="margin-left: 6px"
187
+ @click="onDeleteQuery(item)" />
188
+ </view>
189
+ </checkbox-group>
190
+
191
+ <view class="intercept-empty" v-else>
192
+ {{ t('network.emptyParams') }}
193
+ </view>
194
+ </view>
195
+
196
+ <template v-if="!noBodyRequestMethods.includes(state.method)">
197
+ <view class="intercept-config-control">
198
+ <DevToolTitle>{{ t('network.requestBody') }}</DevToolTitle>
199
+ </view>
200
+
201
+ <textarea
202
+ :placeholder="t('network.placeholderBody')"
203
+ class="intercept-textarea"
204
+ :value="state.bodyText"
205
+ @input="onChangeState($event, 'bodyText')" />
206
+ </template>
207
+
208
+ <view class="intercept-config-control">
209
+ <DevToolTitle>{{ t('network.responseBody') }}</DevToolTitle>
210
+ </view>
211
+ <textarea
212
+ :placeholder="t('network.placeholderRespBody')"
213
+ class="intercept-textarea"
214
+ :value="state.responseText"
215
+ @input="onChangeState($event, 'responseText')" />
216
+ </scroll-view>
217
+ <view class="intercept-config-buttons">
218
+ <SettingButton @click="onConfirm">
219
+ {{ t('network.saveConfig') }}
220
+ </SettingButton>
221
+ </view>
222
+ </view>
223
+ </template>
224
+ <script lang="ts" setup>
225
+ import { computed, ref, onMounted } from 'vue';
226
+ import CircularButton from '../../../components/CircularButton/index.vue';
227
+ import DevToolTitle from '../DevToolTitle/index.vue';
228
+ import type { DevTool } from '../../../../type';
229
+ import SettingButton from '../SettingButton/index.vue';
230
+ import { useI18n } from '../../../../i18n';
231
+ import { getThemeMainColor } from '../../../styles/theme';
232
+ const { t } = useI18n();
233
+
234
+ const themeColor = computed(() => getThemeMainColor(props.theme));
235
+
236
+ const props = defineProps<{
237
+ theme?: string;
238
+ network: DevTool.NetworkItem;
239
+ zIndex?: number;
240
+ customStyle?: Record<string, any>;
241
+ }>();
242
+
243
+ const emit = defineEmits<{
244
+ (e: 'close'): void;
245
+ (e: 'openDetail', v: DevTool.NetworkItem): void;
246
+ (e: 'confirm', v: DevTool.NetworkItem): void;
247
+ }>();
248
+
249
+ import {
250
+ requestMethods,
251
+ noBodyRequestMethods,
252
+ defaultHeader,
253
+ arrayToObject,
254
+ objectToArray,
255
+ arrayToUrlParams,
256
+ urlParamsToObject,
257
+ unionArrayByKey,
258
+ } from './utils';
259
+ import { useKeyValueList, useNetworkState } from './hooks/useNetworkForm';
260
+
261
+ const { state, hasUrl, onChangeState, parseUrlToList, parseListToUrl } =
262
+ useNetworkState({
263
+ method: 'GET',
264
+ url: 'http://mock.view-uni-dev-tool/a?a=123',
265
+ status: 200,
266
+ bodyText: '',
267
+ responseText: '',
268
+ timeout: 3 * 1000,
269
+ delay: 0,
270
+ });
271
+
272
+ const {
273
+ list: requestHeaderList,
274
+ onAdd: onAddRequestHeader,
275
+ onDelete: onDeleteRequestHeader,
276
+ onChangeChecked: onChangeRequestHeaderChecked,
277
+ onChangeValue: onChangeRequestHeaderItem,
278
+ setList: setRequestHeaderList,
279
+ } = useKeyValueList(defaultHeader);
280
+
281
+ const {
282
+ list: responseHeaderList,
283
+ onAdd: onAddResponseHeader,
284
+ onDelete: onDeleteResponseHeader,
285
+ onChangeChecked: onChangeResponseHeaderChecked,
286
+ onChangeValue: onChangeResponseHeaderItem,
287
+ setList: setResponseHeaderList,
288
+ } = useKeyValueList(defaultHeader);
289
+
290
+ const {
291
+ list: queryList,
292
+ onAdd: onAddQuery,
293
+ onDelete: onDeleteQuery,
294
+ onChangeChecked: onChangeQueryChecked,
295
+ onChangeValue: onChangeQueryItem,
296
+ setList: setQueryList,
297
+ } = useKeyValueList([
298
+ {
299
+ id: '1',
300
+ key: 'a',
301
+ value: '123',
302
+ checked: true,
303
+ },
304
+ ]);
305
+
306
+ const isFinished = ref(false);
307
+
308
+ function onChangeUrl(e: any) {
309
+ const url = e.detail.value;
310
+ state.url = url;
311
+ const list = parseUrlToList(url);
312
+ setQueryList(list);
313
+ }
314
+
315
+ function onReset() {
316
+ isFinished.value = false;
317
+ hasUrl.value = true;
318
+ state.method = 'GET';
319
+ state.url = '';
320
+ state.bodyText = '';
321
+ setResponseHeaderList(defaultHeader);
322
+ setQueryList([]);
323
+ }
324
+
325
+ function onClose() {
326
+ emit('close');
327
+ onReset();
328
+ }
329
+
330
+ function onConfirm() {
331
+ if (!state.url) {
332
+ hasUrl.value = false;
333
+ uni.showToast({
334
+ title: t('network.toastEnterUrl'),
335
+ icon: 'none',
336
+ });
337
+ return;
338
+ }
339
+ hasUrl.value = true;
340
+
341
+ const responseHeader = arrayToObject(responseHeaderList);
342
+ const query = arrayToUrlParams(queryList.filter((q) => q.checked));
343
+
344
+ const baseUrl = state.url?.split('?')[0] || '';
345
+ const lastSlashIndex = baseUrl.lastIndexOf('/');
346
+ const name = lastSlashIndex !== -1 ? baseUrl.slice(lastSlashIndex + 1) : '';
347
+
348
+ const interceptConfig: DevTool.NetworkItem = {
349
+ index: 0,
350
+
351
+ name,
352
+ url: state.url,
353
+ method: state.method,
354
+ timeout: state.timeout,
355
+ delay: state.delay,
356
+ status: state.status as string,
357
+ time: '',
358
+ startTime: 0,
359
+ endTime: 0,
360
+ size: '',
361
+ headers: {
362
+ requestHeader: requestHeaderList,
363
+ responseHeader: responseHeaderList,
364
+ },
365
+ response: {
366
+ data: '',
367
+ statusCode: Number(state.status),
368
+ header: responseHeader,
369
+ cookies: [],
370
+ errMsg: 'request:ok',
371
+ },
372
+ payload: {},
373
+ };
374
+
375
+ if (noBodyRequestMethods.includes(state.method)) {
376
+ // 不支持携带 body 参数
377
+
378
+ interceptConfig.payload = {};
379
+ } else {
380
+ // 支持 url 中携带参数
381
+
382
+ if (state.url.includes('?')) {
383
+ interceptConfig.url = state.url + '&' + query;
384
+ } else {
385
+ interceptConfig.url = state.url + '?' + query;
386
+ }
387
+
388
+ // 支持携带 body 参数
389
+ if (state.bodyText?.trim()) {
390
+ try {
391
+ const bodyJson = JSON.parse(state.bodyText);
392
+ interceptConfig.payload = bodyJson;
393
+ } catch (_error) {
394
+ uni.showToast({
395
+ title: t('network.toastBodyJson'),
396
+ icon: 'none',
397
+ });
398
+ return;
399
+ }
400
+ }
401
+ }
402
+
403
+ if (state.responseText?.trim()) {
404
+ try {
405
+ const bodyJson = JSON.parse(state.responseText);
406
+ interceptConfig.response.data = bodyJson;
407
+ } catch (_error) {
408
+ uni.showToast({
409
+ title: t('network.toastRespJson'),
410
+ icon: 'none',
411
+ });
412
+ return;
413
+ }
414
+ }
415
+
416
+ uni.showToast({
417
+ icon: 'none',
418
+ title: t('network.toastSaveSuccess'),
419
+ });
420
+
421
+ emit('confirm', interceptConfig);
422
+ emit('close');
423
+ }
424
+
425
+ function onChangeRequestMethod(e: any) {
426
+ const method = e.detail.value;
427
+ state.method = method;
428
+ }
429
+
430
+ function onChangeRequestHeader(e: any, key: 'key' | 'value', index: number) {
431
+ onChangeRequestHeaderItem(index, key, e.detail.value);
432
+ }
433
+
434
+ function onChangeResponseHeader(e: any, key: 'key' | 'value', index: number) {
435
+ onChangeResponseHeaderItem(index, key, e.detail.value);
436
+ }
437
+
438
+ function handleQueryCheckedChange(e: any) {
439
+ onChangeQueryChecked(e);
440
+ state.url = parseListToUrl(state.url, queryList);
441
+ }
442
+
443
+ function onChangeQuery(e: any, key: 'key' | 'value', index: number) {
444
+ onChangeQueryItem(index, key, e.detail.value);
445
+ state.url = parseListToUrl(state.url, queryList);
446
+ }
447
+
448
+ /**
449
+ * 处理规格
450
+ */
451
+ function handleInterceptConfig() {
452
+ // 如果没有网络数据或尚未开始,则直接返回
453
+ if (!props.network || !props.network.url) return;
454
+
455
+ // 设置基础请求信息
456
+ state.url = props.network.url;
457
+ state.method = props.network.method?.toUpperCase() ?? 'GET';
458
+ state.status = props.network.status as string;
459
+ state.delay = props.network.delay ?? 0;
460
+
461
+ // 初始化请求头
462
+ const requestHeaders =
463
+ props.network.headers?.requestHeader?.map((item, index) => {
464
+ return {
465
+ ...item,
466
+ id: index.toString(),
467
+ checked: true,
468
+ };
469
+ }) ?? [];
470
+
471
+ setRequestHeaderList(requestHeaders);
472
+
473
+ const responseHeaders =
474
+ props.network.headers?.responseHeader?.map((item, index) => {
475
+ return {
476
+ ...item,
477
+ id: index.toString(),
478
+ checked: true,
479
+ };
480
+ }) ?? [];
481
+
482
+ setResponseHeaderList(responseHeaders);
483
+
484
+ setQueryList([]);
485
+
486
+ // 解析参数
487
+ if (noBodyRequestMethods.includes(state.method)) {
488
+ // 参数在 query 中
489
+ if (props.network.url.includes('?')) {
490
+ const urlParams = objectToArray(
491
+ urlParamsToObject(props.network.url.split('?')?.[1] ?? ''),
492
+ );
493
+ const payloadParams = objectToArray(props.network.payload);
494
+
495
+ const list = unionArrayByKey(urlParams, payloadParams, 'key');
496
+
497
+ setQueryList(list);
498
+ }
499
+ } else {
500
+ // 参数在 query 中
501
+ if (props.network.url.includes('?')) {
502
+ const urlParams = objectToArray(
503
+ urlParamsToObject(props.network.url.split('?')?.[1] ?? ''),
504
+ );
505
+ setQueryList(urlParams);
506
+ }
507
+ state.bodyText = JSON.stringify(props.network.payload);
508
+ }
509
+
510
+ if (props.network.response?.data) {
511
+ try {
512
+ state.responseText = JSON.stringify(props.network.response.data);
513
+ } catch (_error) {
514
+ state.responseText = props.network.response.data as string;
515
+ }
516
+ }
517
+ }
518
+
519
+ onMounted(() => {
520
+ handleInterceptConfig();
521
+ });
522
+ </script>
523
+
524
+ <style scoped>
525
+ .intercept-config {
526
+ position: fixed;
527
+ width: 100vw;
528
+ height: 100%;
529
+ z-index: 5;
530
+ top: 0;
531
+ left: 0;
532
+ padding: 0 16px;
533
+
534
+ /* #ifdef H5 || APP-PLUS */
535
+ padding: 50px 16px;
536
+
537
+ /* #endif */
538
+ overflow: auto;
539
+ background-color: var(--dev-tool-bg3-color);
540
+ box-sizing: border-box;
541
+ }
542
+
543
+ .intercept-config-tip {
544
+ font-size: var(--dev-tool-tips-font-size);
545
+ color: var(--dev-tool-info-color);
546
+ }
547
+
548
+ .intercept-config-form {
549
+ height: calc(100% - 32px - 42px);
550
+ overflow: auto;
551
+ }
552
+
553
+ .intercept-config-control {
554
+ display: flex;
555
+ align-items: center;
556
+ gap: 12px;
557
+ height: 32px;
558
+ border-bottom: 1px solid transparent;
559
+ box-sizing: border-box;
560
+ }
561
+
562
+ .radio-group {
563
+ display: flex;
564
+ flex-wrap: wrap;
565
+ }
566
+
567
+ .radio-group-item {
568
+ display: flex;
569
+ align-items: center;
570
+ width: 25%;
571
+ margin-bottom: 6px;
572
+ }
573
+
574
+ .intercept-input {
575
+ padding: 0 6px;
576
+ height: 24px;
577
+ border: 1px solid var(--dev-tool-border-color);
578
+ }
579
+
580
+ .intercept-textarea {
581
+ padding: 6px;
582
+ width: 100%;
583
+ box-sizing: border-box;
584
+ border: 1px solid var(--dev-tool-border-color);
585
+ }
586
+
587
+ .form-error-message {
588
+ padding: 0 6px;
589
+ height: 24px;
590
+ line-height: 24px;
591
+ color: red;
592
+ }
593
+
594
+ .intercept-header-item {
595
+ display: flex;
596
+ align-items: center;
597
+ }
598
+
599
+ .intercept-empty {
600
+ color: var(--dev-tool-info-color);
601
+ text-align: center;
602
+ }
603
+
604
+ .intercept-param-item {
605
+ display: flex;
606
+ align-items: center;
607
+ }
608
+
609
+ .intercept-body-data-item {
610
+ display: flex;
611
+ align-items: center;
612
+ }
613
+
614
+ .intercept-config-buttons {
615
+ position: sticky;
616
+ display: flex;
617
+ justify-content: space-between;
618
+
619
+ /* gap: 6px; */
620
+ width: 100%;
621
+ margin-top: 12px;
622
+ background-color: var(--dev-tool-bg3-color);
623
+ }
624
+ </style>