vite-uni-dev-tool 1.1.0 → 1.2.1
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.
- package/README.md +21 -1
- package/dist/const.cjs +1 -1
- package/dist/const.d.ts +2 -1
- package/dist/const.js +1 -1
- package/dist/core-shared.d.ts +2 -3
- package/dist/core.d.ts +8 -8
- package/dist/core.js +2 -2
- package/dist/i18n/index.d.ts +0 -1
- package/dist/i18n/instance.d.ts +0 -1
- package/dist/i18n/locales/en.cjs +1 -1
- package/dist/i18n/locales/en.d.ts +6 -1
- package/dist/i18n/locales/en.js +1 -1
- package/dist/i18n/locales/zh-Hans.cjs +1 -1
- package/dist/i18n/locales/zh-Hans.d.ts +6 -1
- package/dist/i18n/locales/zh-Hans.js +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/modules/devConsole/index.cjs +4 -4
- package/dist/modules/devConsole/index.d.ts +6 -107
- package/dist/modules/devConsole/index.js +4 -4
- package/dist/modules/devEvent/index.cjs +3 -3
- package/dist/modules/devEvent/index.d.ts +2 -3
- package/dist/modules/devEvent/index.js +3 -3
- package/dist/modules/devIntercept/index.cjs +14 -14
- package/dist/modules/devIntercept/index.d.ts +34 -6
- package/dist/modules/devIntercept/index.js +14 -14
- package/dist/modules/devStore/index.cjs +1 -1
- package/dist/modules/devStore/index.d.ts +48 -40
- package/dist/modules/devStore/index.js +1 -1
- package/dist/modules/devToolInfo/index.cjs +1 -1
- package/dist/modules/devToolInfo/index.d.ts +6 -25
- package/dist/modules/devToolInfo/index.js +1 -1
- package/dist/plugins/uniDevTool/transform/transformApp.d.ts +0 -1
- package/dist/plugins/uniDevTool/transform/transformMain.cjs +3 -3
- package/dist/plugins/uniDevTool/transform/transformMain.d.ts +2 -2
- package/dist/plugins/uniDevTool/transform/transformMain.js +3 -3
- package/dist/plugins/uniDevTool/transform/transformVue.cjs +31 -25
- package/dist/plugins/uniDevTool/transform/transformVue.d.ts +2 -2
- package/dist/plugins/uniDevTool/transform/transformVue.js +30 -24
- package/dist/plugins/uniDevTool/uniDevTool.cjs +3 -3
- package/dist/plugins/uniDevTool/uniDevTool.d.ts +3 -2
- package/dist/plugins/uniDevTool/uniDevTool.js +3 -3
- package/dist/plugins/uniGlobalComponents/uniGlobalComponents.d.ts +0 -1
- package/dist/plugins/utils/index.d.ts +0 -1
- package/dist/shims-uni.d.ts +26 -22
- package/dist/type.d.ts +47 -43
- package/dist/utils/array.d.ts +0 -1
- package/dist/utils/date.d.ts +0 -1
- package/dist/utils/file.d.ts +0 -1
- package/dist/utils/function.d.ts +0 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/ip.d.ts +0 -1
- package/dist/utils/language.d.ts +14 -15
- package/dist/utils/object.cjs +1 -1
- package/dist/utils/object.d.ts +7 -8
- package/dist/utils/object.js +1 -1
- package/dist/utils/openLink.d.ts +0 -1
- package/dist/utils/page.d.ts +0 -1
- package/dist/utils/platform.d.ts +0 -1
- package/dist/utils/string.d.ts +0 -1
- package/dist/utils/utils.d.ts +0 -1
- package/dist/v3/DevTool/components/BluetoothList/BluetoothItem.vue +199 -199
- package/dist/v3/DevTool/components/BluetoothList/BluetoothTool.vue +730 -730
- package/dist/v3/DevTool/components/BluetoothList/index.vue +167 -167
- package/dist/v3/DevTool/components/CaptureScreen/index.vue +109 -109
- package/dist/v3/DevTool/components/ConsoleList/ConsoleItem.vue +230 -225
- package/dist/v3/DevTool/components/ConsoleList/RunJSInput.vue +247 -247
- package/dist/v3/DevTool/components/ConsoleList/index.vue +171 -171
- package/dist/v3/DevTool/components/ConsoleList/staticTips.ts +1145 -1145
- package/dist/v3/DevTool/components/DevToolButton/index.vue +42 -6
- package/dist/v3/DevTool/components/DevToolTitle/index.vue +24 -24
- package/dist/v3/DevTool/components/DevToolWindow/DevToolOverlay.vue +197 -197
- package/dist/v3/DevTool/components/DevToolWindow/hooks/dataUtils.ts +48 -48
- package/dist/v3/DevTool/components/DevToolWindow/hooks/useDevToolData.ts +411 -387
- package/dist/v3/DevTool/components/DevToolWindow/hooks/useDevToolHandlers.ts +644 -629
- package/dist/v3/DevTool/components/DevToolWindow/hooks/useDevToolOverlay.ts +201 -197
- package/dist/v3/DevTool/components/DevToolWindow/index.vue +27 -64
- package/dist/v3/DevTool/components/ElEvent/ElEventItem.vue +105 -105
- package/dist/v3/DevTool/components/ElEvent/index.vue +106 -106
- package/dist/v3/DevTool/components/Instance/components/InstanceTreeNode.vue +265 -265
- package/dist/v3/DevTool/components/Instance/flatten.ts +226 -226
- package/dist/v3/DevTool/components/Instance/index.vue +94 -94
- package/dist/v3/DevTool/components/Instance/registry.ts +49 -49
- package/dist/v3/DevTool/components/Instance/transformTree.ts +393 -375
- package/dist/v3/DevTool/components/Instance/transformTreeCtx.ts +268 -268
- package/dist/v3/DevTool/components/Instance/typing.d.ts +43 -43
- package/dist/v3/DevTool/components/InstanceDetail/index.vue +485 -485
- package/dist/v3/DevTool/components/JsonDetail/index.vue +70 -70
- package/dist/v3/DevTool/components/NFCList/NFCItem.vue +112 -112
- package/dist/v3/DevTool/components/NFCList/NFCTool.vue +454 -454
- package/dist/v3/DevTool/components/NFCList/const.ts +56 -56
- package/dist/v3/DevTool/components/NFCList/index.vue +94 -94
- package/dist/v3/DevTool/components/NetworkList/InterceptConfig.vue +624 -624
- package/dist/v3/DevTool/components/NetworkList/InterceptItem.vue +140 -140
- package/dist/v3/DevTool/components/NetworkList/NetworkDetail.vue +287 -287
- package/dist/v3/DevTool/components/NetworkList/NetworkIntercept.vue +88 -88
- package/dist/v3/DevTool/components/NetworkList/NetworkItem.vue +163 -163
- package/dist/v3/DevTool/components/NetworkList/NetworkSend.vue +589 -589
- package/dist/v3/DevTool/components/NetworkList/const.ts +4 -4
- package/dist/v3/DevTool/components/NetworkList/hooks/useNetworkForm.ts +86 -86
- package/dist/v3/DevTool/components/NetworkList/index.vue +160 -160
- package/dist/v3/DevTool/components/NetworkList/utils.ts +101 -101
- package/dist/v3/DevTool/components/Performance/index.vue +498 -498
- package/dist/v3/DevTool/components/Performance/modules/PerformanceMetrics.vue +153 -153
- package/dist/v3/DevTool/components/Performance/modules/usePerformanceChart.ts +460 -460
- package/dist/v3/DevTool/components/Performance/modules/usePerformanceData.ts +258 -258
- package/dist/v3/DevTool/components/PiniaList/index.vue +93 -93
- package/dist/v3/DevTool/components/RunJS/index.vue +148 -148
- package/dist/v3/DevTool/components/ScanCodeList/ScanCodeItem.vue +97 -97
- package/dist/v3/DevTool/components/ScanCodeList/index.vue +100 -100
- package/dist/v3/DevTool/components/SettingButton/index.vue +45 -45
- package/dist/v3/DevTool/components/SettingList/index.vue +226 -218
- package/dist/v3/DevTool/components/SettingList/modules/SettingBarrage.vue +320 -304
- package/dist/v3/DevTool/components/SettingList/modules/SettingDevTool.vue +212 -212
- package/dist/v3/DevTool/components/SettingList/modules/SettingInfo.vue +157 -157
- package/dist/v3/DevTool/components/SettingList/modules/SettingLanguage.vue +74 -74
- package/dist/v3/DevTool/components/SettingList/modules/SettingLog.vue +230 -230
- package/dist/v3/DevTool/components/SettingList/typing.d.ts +2 -2
- package/dist/v3/DevTool/components/SourceCode/Line.vue +127 -127
- package/dist/v3/DevTool/components/SourceCode/parseCode.ts +609 -609
- package/dist/v3/DevTool/components/StorageList/index.vue +174 -174
- package/dist/v3/DevTool/components/TransferList/TransferDetail.vue +268 -268
- package/dist/v3/DevTool/components/VuexList/index.vue +84 -84
- package/dist/v3/DevTool/index.vue +85 -138
- package/dist/v3/components/AppTransition/index.vue +156 -176
- package/dist/v3/components/AutoSizer/index.vue +192 -192
- package/dist/v3/components/AutoSizer/index1.vue +184 -184
- package/dist/v3/components/AutoSizer/utils.ts +49 -49
- package/dist/v3/components/Barrage/BarrageItem.vue +194 -137
- package/dist/v3/components/Barrage/index.vue +205 -202
- package/dist/v3/components/CircularButton/index.vue +84 -84
- package/dist/v3/components/CustomSwiper/CustomSwiperItem.vue +49 -49
- package/dist/v3/components/CustomSwiper/index.vue +104 -104
- package/dist/v3/components/DevErrorBoundary/index.vue +388 -0
- package/dist/v3/components/DraggableContainer/index.vue +186 -73
- package/dist/v3/components/Empty/index.vue +29 -29
- package/dist/v3/components/FilterSelect/index.vue +179 -179
- package/dist/v3/components/JsonPretty/components/Brackets/index.vue +27 -27
- package/dist/v3/components/JsonPretty/components/Carets/index.vue +59 -59
- package/dist/v3/components/JsonPretty/components/CheckController/index.vue +136 -136
- package/dist/v3/components/JsonPretty/components/TreeNode/index.vue +387 -387
- package/dist/v3/components/JsonPretty/hooks/useClipboard.ts +21 -21
- package/dist/v3/components/JsonPretty/hooks/useError.ts +21 -21
- package/dist/v3/components/JsonPretty/type.ts +127 -127
- package/dist/v3/components/JsonPretty/utils/index.ts +169 -169
- package/dist/v3/components/MovableContainer/index.vue +10 -4
- package/dist/v3/components/Pick/index.vue +321 -322
- package/dist/v3/components/Tag/index.vue +113 -113
- package/dist/v3/components/VirtualList/AutoSize.vue +40 -40
- package/dist/v3/components/VirtualList/index.vue +416 -416
- package/dist/v3/hooks/useBluetooth/index.ts +561 -561
- package/dist/v3/hooks/useContainerStyle.ts +95 -153
- package/dist/v3/hooks/useNFC/index.ts +107 -107
- package/dist/v3/hooks/useNFC/typing.d.ts +396 -396
- package/dist/v3/hooks/useNFC/useNFCAndroid.ts +966 -966
- package/dist/v3/hooks/useNFC/useNFCMpWeiXin.ts +812 -812
- package/dist/v3/hooks/useNFC/utils.ts +754 -754
- package/dist/v3/hooks/useRequest/index.ts +586 -586
- package/dist/v3/hooks/useRequest/utils.ts +267 -267
- package/dist/v3/hooks/useScanCode/index.ts +206 -206
- package/dist/v3/hooks/useWebsocket/index.ts +253 -253
- package/dist/v3/styles/theme.ts +12 -12
- package/package.json +70 -59
- package/dist/const.d.ts.map +0 -1
- package/dist/core-shared.d.ts.map +0 -1
- package/dist/core.d.ts.map +0 -1
- package/dist/i18n/index.d.ts.map +0 -1
- package/dist/i18n/instance.d.ts.map +0 -1
- package/dist/i18n/locales/en.d.ts.map +0 -1
- package/dist/i18n/locales/zh-Hans.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/modules/devConsole/index.d.ts.map +0 -1
- package/dist/modules/devEvent/index.d.ts.map +0 -1
- package/dist/modules/devIntercept/index.d.ts.map +0 -1
- package/dist/modules/devStore/index.d.ts.map +0 -1
- package/dist/modules/devToolInfo/index.d.ts.map +0 -1
- package/dist/plugins/uniDevTool/transform/transformApp.d.ts.map +0 -1
- package/dist/plugins/uniDevTool/transform/transformMain.d.ts.map +0 -1
- package/dist/plugins/uniDevTool/transform/transformVue.d.ts.map +0 -1
- package/dist/plugins/uniDevTool/uniDevTool.d.ts.map +0 -1
- package/dist/plugins/uniGlobalComponents/uniGlobalComponents.d.ts.map +0 -1
- package/dist/plugins/utils/index.d.ts.map +0 -1
- package/dist/type.d.ts.map +0 -1
- package/dist/utils/array.d.ts.map +0 -1
- package/dist/utils/date.d.ts.map +0 -1
- package/dist/utils/file.d.ts.map +0 -1
- package/dist/utils/function.d.ts.map +0 -1
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/ip.d.ts.map +0 -1
- package/dist/utils/language.d.ts.map +0 -1
- package/dist/utils/object.d.ts.map +0 -1
- package/dist/utils/openLink.d.ts.map +0 -1
- package/dist/utils/page.d.ts.map +0 -1
- package/dist/utils/platform.d.ts.map +0 -1
- package/dist/utils/string.d.ts.map +0 -1
- package/dist/utils/utils.d.ts.map +0 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("../../core-shared.cjs"),
|
|
2
|
-
`).map(
|
|
3
|
-
`+
|
|
4
|
-
`))==null?void 0:
|
|
5
|
-
`),
|
|
6
|
-
`),r=((h=t==null?void 0:t.slice(2))==null?void 0:h[0])||"";d.backup.originalConsole.warn(e);const
|
|
7
|
-
`))==null?void 0:
|
|
8
|
-
`);this.reportError({type:"warn",msg:
|
|
9
|
-
`))==null?void 0:
|
|
10
|
-
`),
|
|
11
|
-
`),h=
|
|
12
|
-
`),h=
|
|
13
|
-
`),o=l==null?void 0:l[2];
|
|
14
|
-
`),s
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("../../core-shared.cjs"),_=require("../../const.cjs");require("../../utils/index.cjs");const I=require("../../utils/date.cjs"),w=require("../../utils/page.cjs"),C=require("../../utils/object.cjs"),E=require("../../utils/language.cjs"),M=require("../../utils/string.cjs");class N{constructor(e){this.preWarn="",this.initPinia=!1,this.isReporting=!1,this.lastReportMsg="",this.lastReportTime=0,this.captureScreen=t=>{if(!this.hooks.getDevToolDestroy()){const r=this.hooks.getScreenIndex(),s=this.hooks.setScreenIndex(r+1);this.hooks.updateScreen([{index:s,position:w.getCurrentPagePath(),startTime:I.getCurrentDate(),endTime:I.getCurrentDate(),type:"captureScreen",path:(t==null?void 0:t.path)??""}])}},this.hooks=e.hooks,typeof uni<"u"&&(uni.$on(_.DEV_TOOL_ON_INIT,t=>this.init(t)),uni.$on(_.DEV_TOOL_ON_DESTROY,()=>this.reset()))}safeDefineProperty(e,t,r){if(!e)return!1;try{const s=Object.getOwnPropertyDescriptor(e,t);return s&&s.configurable===!1?(console.warn(`[DevTool] ${t} 属性不可配置,已跳过拦截`),!1):(Object.defineProperty(e,t,{...r,configurable:!0}),!0)}catch(s){return console.warn(`[DevTool] 拦截 ${t} 失败,环境可能受限:`,s),!1}}formatStack(e){if(!e)return"";const t=e.split(`
|
|
2
|
+
`).map(s=>s.trim()).filter(Boolean);return t.find(s=>{const n=s.toLowerCase();return n.includes("at ")&&!n.includes("devintercept")&&!n.includes("devconsole")&&!n.includes("core-shared")&&!n.includes("core.ts")})||t[0]||""}reportError({type:e="error",msg:t="",stack:r="",source:s="System",itemType:n="string"}){if(this.hooks.getDevToolDestroy()||this.isReporting)return;const u=Date.now();if(t===this.lastReportMsg&&u-this.lastReportTime<100)return;this.lastReportMsg=t,this.lastReportTime=u;const h=this.formatStack(r);this.isReporting=!0;try{const c=[];if(n==="object"||n==="array"){const a=C.parseValue(t);c.push({type:n,value:a,shortValue:E.transformValueToShortString(a,n)})}else c.push({type:n,value:`[${s}] ${t}`});this.hooks.updateConsole([{type:e,args:c,position:w.getCurrentPagePath(),time:I.getCurrentDate(),stack:h}])}finally{this.isReporting=!1}}init({enableCaptureScreen:e,enableInterceptPromiseReject:t}){this.enableCaptureScreen=e,this.enableInterceptPromiseReject=t,this.interceptAppConsole(),this.interceptAppError(),this.interceptSetStorage(),this.interceptRemoveStorage(),this.interceptClearStorage(),this.interceptRequest(),this.interceptSocket(),this.interceptUploadFile(),this.interceptDownloadFile(),this.interceptSwitchTab(),this.interceptRedirectTo(),this.interceptReLaunch(),this.interceptNavigateBack(),this.interceptNavigateTo(),this.interceptUniEvent(),this.interceptScanCode(),this.enableCaptureScreen&&this.interceptCaptureScreen(),this.interceptScreenRecording(),this.enableInterceptPromiseReject&&this.interceptPromiseReject()}reset(){["InterceptAppConsole","InterceptErrorApp","InterceptPromiseReject","InterceptStorage","InterceptRemoveStorage","InterceptClearStorage","InterceptRequest","InterceptSocket","InterceptUploadFile","InterceptDownloadFile","InterceptSwitchTab","InterceptRedirectTo","InterceptReLaunch","InterceptNavigateBack","InterceptNavigateTo","UniEvent","InterceptScanCode","InterceptScreenRecording"].forEach(e=>{var t;return(t=this[`reset${e}`])==null?void 0:t.call(this)}),this.enableCaptureScreen&&this.resetInterceptCaptureScreen()}interceptAppConsole(){const e=this;uni.__log__&&this.safeDefineProperty(uni,"__log__",{writable:!1,value:function(r,s,...n){var h,c;(c=(h=d.backup).__log__)==null||c.call(h,r,s,...n);const u=w.getCurrentPagePath();e.hooks.updateConsole([{type:r,position:u,time:I.getCurrentDate(),args:n.map(a=>{const p=E.transformValueToView(a),l=C.parseValue(a),i=p==="object"||p==="array"?E.transformValueToShortString(l,p):"";return{type:p,value:l,shortValue:i}}),stack:s}])}}),["log","info","debug","error","warn","time","timeEnd","count","clear"].forEach(r=>{this.safeDefineProperty(console,r,{value:function(...s){var h,c;if(["time","timeEnd","count","clear"].includes(r)&&r in d.consoleProxy)return d.consoleProxy[r](...s);(c=(h=d.backup.originalConsole)[r])==null||c.call(h,...s);const n=s.map(a=>{const p=E.transformValueToView(a),l=C.parseValue(a),i=p==="object"||p==="array"?E.transformValueToShortString(l,p):"";return{type:p,value:l,shortValue:i}}),u=e.formatStack(new Error().stack||"");s.length>0&&e.hooks.updateConsole([{type:r,args:n,position:w.getCurrentPagePath(),time:I.getCurrentDate(),stack:u}])}})})}resetInterceptAppConsole(){uni.__log__&&this.safeDefineProperty(uni,"__log__",{writable:!0,value:d.backup.__log__}),["log","info","debug","error","warn","time","timeEnd","count","clear"].forEach(t=>{this.safeDefineProperty(console,t,{value:d.backup.originalConsole[t]})})}interceptVue(e){if(!e)return;const t=(s,n,u)=>{this.hooks.getDevToolDestroy()||this.interceptErrorVue(s,u)},r=(s,n,u)=>{this.hooks.getDevToolDestroy()||this.interceptWarnVue(s+`
|
|
3
|
+
`+u)};e.appContext?(e.appContext.config.errorHandler=t,e.appContext.config.warnHandler=r):(e.config.errorHandler=t,e.config.warnHandler=r)}interceptAppError(){if(this.onErrorHandler=e=>{var s;const t=typeof e=="string"?e:(e==null?void 0:e.message)||String(e)||"",r=(e==null?void 0:e.stack)||(typeof t=="string"?(s=t.split(`
|
|
4
|
+
`))==null?void 0:s[1]:"")||"";this.reportError({msg:t,stack:r,source:"AppError"})},this.onErrorHandler&&uni.onError(this.onErrorHandler),uni.onUnhandledRejection){this.onUnhandledRejectionHandler=t=>{var n;let r="Unhandled Promise Rejection",s="";t.reason&&(r=typeof t.reason=="string"?t.reason:t.reason.message||String(t.reason)||r,s=((n=t.reason)==null?void 0:n.stack)||""),this.reportError({msg:r,stack:s,source:"UnhandledRejection"})};const e=uni;this.onUnhandledRejectionHandler&&e.onUnhandledRejection&&e.onUnhandledRejection(this.onUnhandledRejectionHandler)}typeof window<"u"&&window.addEventListener&&(this.boundWindowError=e=>{var s,n;if(e.target!==window)return;const t=e.message||((s=e.error)==null?void 0:s.message)||String(e),r=((n=e.error)==null?void 0:n.stack)||"";this.reportError({msg:t,stack:r,source:"WindowError"})},this.boundWindowRejection=e=>{let t="Unhandled Promise Rejection",r="";e.reason&&(t=typeof e.reason=="string"?e.reason:e.reason.message||String(e.reason),r=e.reason.stack||""),this.reportError({msg:t,stack:r,source:"WindowRejection"})},this.resourceErrorHandler=e=>{if(e instanceof ErrorEvent&&e.target===window)return;const t=e.target;if(!t||t===window)return;const r=String(t.tagName||"").toUpperCase(),s=t.src||t.href||t.currentSrc||t.getAttribute&&t.getAttribute("src");(["IMG","SCRIPT","LINK","VIDEO","AUDIO","SOURCE","UNI-IMAGE"].includes(r)||s)&&this.reportError({type:"error",msg:`Resource Load Failed: ${s||"unknown source"}`,source:"Resource"})},window.addEventListener("error",this.boundWindowError),window.addEventListener("unhandledrejection",this.boundWindowRejection),window.addEventListener("error",this.resourceErrorHandler,!0))}resetInterceptErrorApp(){uni.offError&&this.onErrorHandler&&uni.offError(this.onErrorHandler);const e=uni;e.offUnhandledRejection&&this.onUnhandledRejectionHandler&&e.offUnhandledRejection(this.onUnhandledRejectionHandler),typeof window<"u"&&window.removeEventListener&&(this.boundWindowError&&window.removeEventListener("error",this.boundWindowError),this.boundWindowRejection&&window.removeEventListener("unhandledrejection",this.boundWindowRejection),this.resourceErrorHandler&&window.removeEventListener("error",this.resourceErrorHandler,!0))}interceptErrorVue(e,t){var u;const r=(u=e==null?void 0:e.stack)==null?void 0:u.split(`
|
|
5
|
+
`),s=(r==null?void 0:r[1])||(e==null?void 0:e.stack)||"",n=(e==null?void 0:e.message)||(e==null?void 0:e.toString())||"Unknown Error";d.backup.originalConsole.error(e),uni.$emit(_.DEV_ERROR_BOUNDARY_TRIGGER,{err:e,info:t}),this.reportError({msg:n,stack:s,source:"VueError"})}interceptWarnVue(e){var n,u,h,c;if(this.preWarn===e)return;this.preWarn=e;const t=(u=(n=new Error)==null?void 0:n.stack)==null?void 0:u.split(`
|
|
6
|
+
`),r=((h=t==null?void 0:t.slice(2))==null?void 0:h[0])||"";d.backup.originalConsole.warn(e);const s=(c=e.split(`
|
|
7
|
+
`))==null?void 0:c.map(a=>M.escapeHTML(a)).join(`
|
|
8
|
+
`);this.reportError({type:"warn",msg:s,stack:r,source:"VueWarn"})}interceptPromiseReject(){const e=this;this.safeDefineProperty(Promise,"reject",{configurable:!0,value:function(t){var n,u;const r=(t==null?void 0:t.toString())||"Promise Reject",s=((u=(n=t==null?void 0:t.stack)==null?void 0:n.split(`
|
|
9
|
+
`))==null?void 0:u[1])??"";return e.reportError({msg:r,stack:s,source:"Promise.reject"}),d.backup.reject.call(Promise,t)}})}resetInterceptPromiseReject(){this.safeDefineProperty(Promise,"reject",{configurable:!0,value:function(e){return d.backup.reject.call(Promise,e)}})}interceptSetStorage(){const e=this;this.safeDefineProperty(uni,"setStorageSync",{configurable:!0,value:function(t,r){d.backup.setStorageSync(t,r),e.hooks.updateStorage([{key:t.toString(),_oldKey:t.toString(),value:r}])}}),uni.addInterceptor("setStorage",{invoke(t){const r=t.complete;t.complete=function(s){var n,u;r&&r(s),e.hooks.updateStorage([{key:(n=t.key)==null?void 0:n.toString(),_oldKey:(u=t.key)==null?void 0:u.toString(),value:t.data}])}}})}resetInterceptStorage(){uni.removeInterceptor("setStorage"),this.safeDefineProperty(uni,"setStorageSync",{configurable:!0,value:d.backup.setStorageSync}),uni.removeInterceptor("clearStorage"),this.safeDefineProperty(uni,"clearStorageSync",{configurable:!0,value:d.backup.clearStorageSync}),uni.removeInterceptor("removeStorage"),this.safeDefineProperty(uni,"removeStorageSync",{configurable:!0,value:d.backup.removeStorageSync})}interceptClearStorage(){const e=this;this.safeDefineProperty(uni,"clearStorageSync",{configurable:!0,value:function(){d.backup.clearStorageSync(),e.hooks.clearStorage()}}),uni.addInterceptor("clearStorage",{invoke(){e.hooks.clearStorage()}})}resetInterceptClearStorage(){this.safeDefineProperty(uni,"clearStorageSync",{configurable:!0,value:d.backup.clearStorageSync}),uni.removeInterceptor("clearStorage")}interceptRemoveStorage(){const e=this;this.safeDefineProperty(uni,"removeStorageSync",{configurable:!0,value:function(t){d.backup.removeStorageSync(t),e.hooks.removeStorage(t)}}),uni.addInterceptor("removeStorage",{invoke(t){const r=t.complete;t.complete=function(s){r&&r(s),e.hooks.removeStorage(t.key)}}})}resetInterceptRemoveStorage(){this.safeDefineProperty(uni,"removeStorageSync",{configurable:!0,value:d.backup.removeStorageSync}),uni.removeInterceptor("removeStorage")}interceptVuexStorage(e){var r;this.hooks.getDevToolDestroy()||(this.hooks.setVuexList(e.state),this.hooks.setVueStore(e),(r=e==null?void 0:e.subscribe)==null||r.call(e,(s,n)=>{this.hooks.setVuexList(n)}))}interceptPiniaStore(e){var r;if(this.initPinia||(this.initPinia=!0,this.hooks.setPiniaStore(e.pinia)),this.hooks.setPiniaList(e.pinia.state.value),!this.hooks.getDevToolDestroy())return(r=e==null?void 0:e.store)==null||r.$subscribe(()=>{this.hooks.setPiniaList({[e.store.$id]:e.store.$state})}),e.pinia}interceptRequest(){const e=this;uni.addInterceptor("request",{invoke(t){var R,V,H,U,W,F,x;const r=e.hooks.getRequestIndex(),s=e.hooks.setRequestIndex(r+1),n=t.url,u=(R=n==null?void 0:n.split("?"))==null?void 0:R[0],h=u==null?void 0:u.lastIndexOf("/"),c=(u==null?void 0:u.slice(h+1))??"",a=(H=(V=new Error)==null?void 0:V.stack)==null?void 0:H.split(`
|
|
10
|
+
`),p=uni.__dev_tool_platform__==="app"?a==null?void 0:a[2]:a==null?void 0:a[5],l=e.hooks.getInterceptNetworkMap(),o=`${(U=t.method)==null?void 0:U.toUpperCase()}|${u}`,i=l==null?void 0:l.get(o),g=Object.keys(t.header??{}).includes("dev-tool-sponsor")?"dev_tool":"user";t.header={...C.omit(t.header,["dev-tool-sponsor"])};const f={index:s,stack:p,url:t.url,name:c,startTime:Date.now(),endTime:0,time:"-",headers:{requestHeader:Object.entries(t.header??{}).map(([m,k])=>({key:m,value:k})),responseHeader:[]},method:t.method||"GET",status:"pending",payload:t!=null&&t.data?JSON.stringify(t.data):"",response:{data:void 0,statusCode:0,header:{},cookies:[],errMsg:""},size:"",sponsor:g};i&&(f.headers.requestHeader=[...f.headers.requestHeader,...i.headers.requestHeader||[]],f.payload=i.payload,f.intercepted=!0,Object.assign(t,{timeout:i.timeout})),e.hooks.updateNetwork([f]);const S={errMsg:""};let b=!0;i&&(S.statusCode=i.status,(F=(W=i==null?void 0:i.status)==null?void 0:W.toString())!=null&&F.startsWith("2")?(b=!0,S.errMsg="request:ok",S.header=(x=i.headers.responseHeader)==null?void 0:x.reduce((m,k)=>({...m,[k.key]:k.value}),{}),S.data=i.response.data):(b=!1,S.errMsg="request:fail"));const y=t.fail,v=t.success,T=t.complete;t.fail=function(m){const k=()=>{i?b?v==null||v(S):y==null||y(S):y==null||y(m)};i&&i.delay&&i.delay>0?setTimeout(k,i.delay):k()},t.success=function(m){const k=P=>{i?b?v==null||v(S):y==null||y(S):v==null||v(P)};i&&i.delay?setTimeout(()=>k(m),Number(i.delay)):k(m)},t.complete=function(m){const k=()=>{const P=Date.now()-f.startTime;f.time=P<1e3?P+"ms":P/1e3+"s",f.endTime=Date.now();const D=m.header||{},q=(D==null?void 0:D["Content-Length"])||(D==null?void 0:D["content-length"])||"0",j=Number(q)||0;f.size=j>1024?(j/1024).toFixed(2)+"k":j+"b",i?(T==null||T(S),f.status=i.status,f.response=S,f.headers.responseHeader=i.headers.responseHeader):(T==null||T(m),f.status=m.statusCode??"error",f.response=m,f.headers.responseHeader=Object.entries(m.header??{}).map(([$,L])=>({key:$,value:L}))),e.hooks.updateNetwork([f],s)};i&&i.delay&&i.delay>0?setTimeout(k,i.delay):k()}}})}resetInterceptRequest(){uni.removeInterceptor("request")}interceptSocket(){const e=this,t=function(r){const s=r.url,n=Object.entries(r.header??{}).map(([o,i])=>({key:o,value:i})),u=(r.method??"GET").toLowerCase(),h=r.protocols??[];e.hooks.updateWs({url:s,headers:n,method:u,protocols:h,readyState:"connection",message:[]});const c=d.backup.connectSocket({...r,multiple:!0,complete:o=>{var i;(i=r==null?void 0:r.complete)==null||i.call(r,o)}});e.hooks.addWsTask(s,c);function a(o,i,g,f){let S=o;if(typeof o=="string")try{const R=JSON.parse(o);typeof R=="object"&&R!==null&&(S=R)}catch{}const b=E.transformValueToView(S),y=C.parseValue(S),T=b==="object"||b==="array"?E.transformValueToShortString(y,b):"";e.hooks.updateWs({url:s,readyState:g,headers:n,protocols:h,message:[{value:y,valueType:b,shortValue:T,status:f,time:Date.now(),type:i}]})}const p=c.send;c.send=o=>{let i=o.data;if(typeof i=="object"&&i!==null)try{i=JSON.stringify(i)}catch{}p.call(c,{...o,data:i,fail:g=>{var f;(f=o==null?void 0:o.fail)==null||f.call(o,g),a(o.data,"send","error","error")},success:g=>{var f;(f=o==null?void 0:o.success)==null||f.call(o,g),a(o.data,"send","open","success")},complete:g=>{var f;(f=o==null?void 0:o.complete)==null||f.call(o,g)}})};const l=c.close;return c.close=o=>{e.hooks.updateWs({url:s,readyState:"closing",headers:n,protocols:h,message:[]}),l.call(c,{...o,fail:i=>{var g;(g=o==null?void 0:o.fail)==null||g.call(o,i),a(i,"send","closing","error")},success:i=>{var g;(g=o==null?void 0:o.success)==null||g.call(o,i),a(i,"send","closed","success")},complete:i=>{var g;(g=o==null?void 0:o.complete)==null||g.call(o,i)}})},c.onOpen(()=>{e.hooks.updateWs({url:s,readyState:"open",headers:n,protocols:h,message:[]})}),c.onError(o=>{a(o,"receive","error","error")}),c.onMessage(o=>{a(o.data,"receive","open","success")}),c.onClose(o=>{a(o,"receive","closed","success"),e.hooks.removeWsTask(s)}),c};this.safeDefineProperty(uni,"connectSocket",{configurable:!0,value:t})}resetInterceptSocket(){this.safeDefineProperty(uni,"connectSocket",{configurable:!0,value:d.backup.connectSocket})}interceptUploadFile(){const e=this,t=r=>{var a,p;const s=e.hooks.getTransferIndex(),n=e.hooks.setTransferIndex(s+1),u=(p=(a=new Error)==null?void 0:a.stack)==null?void 0:p.split(`
|
|
11
|
+
`),h=u==null?void 0:u[2];e.hooks.updateTransfer([{index:n,type:"upload",stack:h,name:r.name,url:r.url,filePath:r.filePath,fileType:r.fileType,headers:{requestHeader:Object.entries(r.header||{}).map(([l,o])=>({key:l,value:o})),responseHeader:[]},formData:r.formData,status:"pending",progress:0,totalBytesSent:0,totalBytesExpectedToSend:0,startTime:Date.now()}],n);const c=d.backup.uploadFile({...r,success:l=>{var o;(o=r==null?void 0:r.success)==null||o.call(r,l),e.hooks.updateTransfer([{index:n,type:"upload",status:"success",endTime:Date.now(),response:{...l,data:JSON.parse(l.data)}}],n),e.hooks.removeTransferTask(n)},fail:l=>{var o;(o=r==null?void 0:r.fail)==null||o.call(r,l),e.hooks.updateTransfer([{index:n,type:"upload",status:"error",response:l,endTime:Date.now()}],n),e.hooks.removeTransferTask(n)}});return c.onProgressUpdate(l=>{e.hooks.updateTransfer([{index:n,type:"upload",progress:l.progress,totalBytesSent:l.totalBytesSent,totalBytesExpectedToSend:l.totalBytesExpectedToSend,status:"uploading"}],n)}),e.hooks.addTransferTask(n,c),c};this.safeDefineProperty(uni,"uploadFile",{configurable:!0,value:t})}resetInterceptUploadFile(){this.safeDefineProperty(uni,"uploadFile",{configurable:!0,value:d.backup.uploadFile})}interceptDownloadFile(){const e=this,t=r=>{var a,p;const s=e.hooks.getTransferIndex(),n=e.hooks.setTransferIndex(s+1),u=(p=(a=new Error)==null?void 0:a.stack)==null?void 0:p.split(`
|
|
12
|
+
`),h=u==null?void 0:u[2];e.hooks.updateTransfer([{index:n,type:"download",stack:h,url:r.url,filePath:r.filePath,headers:{requestHeader:Object.entries(r.header||{}).map(([l,o])=>({key:l,value:o})),responseHeader:[]},status:"pending",progress:0,totalBytesWritten:0,totalBytesExpectedToWrite:0,startTime:Date.now()}],n);const c=d.backup.downloadFile({...r,success:l=>{var o;(o=r==null?void 0:r.success)==null||o.call(r,l),e.hooks.updateTransfer([{index:n,type:"download",status:"success",endTime:Date.now(),response:{...l,statusCode:l.statusCode,tempFilePath:l.tempFilePath}}],n),e.hooks.removeTransferTask(n)},fail:l=>{var o;(o=r==null?void 0:r.fail)==null||o.call(r,l),e.hooks.updateTransfer([{index:n,type:"download",status:"error",response:l,endTime:Date.now()}],n),e.hooks.removeTransferTask(n)}});return c.onProgressUpdate(l=>{e.hooks.updateTransfer([{index:n,type:"download",progress:l.progress,totalBytesWritten:l.totalBytesWritten,totalBytesExpectedToWrite:l.totalBytesExpectedToWrite,status:"downloading"}],n)}),e.hooks.addTransferTask(n,c),c};this.safeDefineProperty(uni,"downloadFile",{configurable:!0,value:t})}resetInterceptDownloadFile(){this.safeDefineProperty(uni,"downloadFile",{configurable:!0,value:d.backup.downloadFile})}interceptRouterMethod(e){const t=this;uni.addInterceptor(e,{invoke(r){const s=r.complete;r.complete=function(n){var h,c,a;s==null||s(n);const u=((a=(c=(h=r.url)==null?void 0:h.slice(1))==null?void 0:c.split("?"))==null?void 0:a[0])||"/";t.hooks.updateRoute(u),t.hooks.closeWindow()}}})}interceptSwitchTab(){this.interceptRouterMethod("switchTab")}resetInterceptSwitchTab(){uni.removeInterceptor("switchTab")}interceptRedirectTo(){this.interceptRouterMethod("redirectTo")}resetInterceptRedirectTo(){uni.removeInterceptor("redirectTo")}interceptReLaunch(){this.interceptRouterMethod("reLaunch")}resetInterceptReLaunch(){uni.removeInterceptor("reLaunch")}interceptNavigateBack(){this.interceptRouterMethod("navigateBack")}resetInterceptNavigateBack(){uni.removeInterceptor("navigateBack")}interceptNavigateTo(){this.interceptRouterMethod("navigateTo")}resetInterceptNavigateTo(){uni.removeInterceptor("navigateTo")}uniEventFactory(e,t=!0){const r=`$${e}`,s=this;Object.defineProperty(uni,r,{configurable:!0,value:function(n,...u){var h,c,a,p;if((c=(h=d.backup)==null?void 0:h[r])==null||c.call(h,n,...u),t&&!n.startsWith("dev-")&&!n.startsWith("perf-")){const l=(p=(a=new Error)==null?void 0:a.stack)==null?void 0:p.split(`
|
|
13
|
+
`),o=l==null?void 0:l[2];s.hooks.updateUniEvent([{eventName:n,timer:I.getCurrentDate(),stack:o,type:e}]),s.hooks.updateUniEventCount(e)}}})}interceptUniEvent(){this.uniEventFactory("on"),this.uniEventFactory("once"),this.uniEventFactory("emit"),this.uniEventFactory("off")}resetUniEvent(){Object.defineProperty(uni,"$on",{configurable:!0,value:d.backup.$on}),Object.defineProperty(uni,"$once",{configurable:!0,value:d.backup.$once}),Object.defineProperty(uni,"$emit",{configurable:!0,value:d.backup.$emit}),Object.defineProperty(uni,"$off",{configurable:!0,value:d.backup.$off})}interceptScanCode(){const e=this;uni.addInterceptor("scanCode",{invoke(t){var u,h;const r=t.complete,s=(h=(u=new Error)==null?void 0:u.stack)==null?void 0:h.split(`
|
|
14
|
+
`),n=s==null?void 0:s[5];t.complete=function(c){r&&r(c);const a=c;let p={},l="";try{p=JSON.parse((a==null?void 0:a.result)||"{}"),l=E.transformValueToShortString(p,"object")}catch{p=a==null?void 0:a.result,l=String((a==null?void 0:a.result)||"")}e.hooks.updateScanCode([{timer:Date.now(),charSet:(a==null?void 0:a.charSet)||"",rawData:(c==null?void 0:c.rawData)||"",result:(a==null?void 0:a.result)||"",resultObject:p,scanType:(a==null?void 0:a.scanType)||"",errMsg:(c==null?void 0:c.errMsg)||"",path:w.getCurrentPagePath(),stack:n,shortValue:l}])}}})}resetInterceptScanCode(){uni.removeInterceptor("scanCode")}interceptCaptureScreen(){uni.__dev_tool_platform__!=="web"&&uni.onUserCaptureScreen(this.captureScreen)}resetInterceptCaptureScreen(){uni.__dev_tool_platform__!=="web"&&uni.offUserCaptureScreen(this.captureScreen)}listenerScreenRecording(e){const{state:t}=e,r=this.hooks.getScreenIndex(),s=this.hooks.setScreenIndex(r+1),n=I.getCurrentDate();this.hooks.updateScreen([{index:s,position:w.getCurrentPagePath(),startTime:n,endTime:n,type:"screenRecording:"+t}])}interceptScreenRecording(){uni.onScreenRecordingStateChanged&&(this.boundListenerScreenRecording=this.listenerScreenRecording.bind(this),uni.onScreenRecordingStateChanged(this.boundListenerScreenRecording))}resetInterceptScreenRecording(){uni.offScreenRecordingStateChanged&&this.boundListenerScreenRecording&&uni.offScreenRecordingStateChanged(this.boundListenerScreenRecording)}}exports.DevIntercept=N;
|
|
@@ -12,7 +12,7 @@ export declare class DevIntercept implements DevTool.DevInterceptInterface {
|
|
|
12
12
|
private enableInterceptPromiseReject;
|
|
13
13
|
private preWarn;
|
|
14
14
|
private initPinia;
|
|
15
|
-
private boundListenerScreenRecording
|
|
15
|
+
private boundListenerScreenRecording?;
|
|
16
16
|
private boundWindowError?;
|
|
17
17
|
private boundWindowRejection?;
|
|
18
18
|
private resourceErrorHandler?;
|
|
@@ -41,10 +41,21 @@ export declare class DevIntercept implements DevTool.DevInterceptInterface {
|
|
|
41
41
|
reset(): void;
|
|
42
42
|
interceptAppConsole(): void;
|
|
43
43
|
resetInterceptAppConsole(): void;
|
|
44
|
-
interceptVue(vueInstance:
|
|
44
|
+
interceptVue(vueInstance: {
|
|
45
|
+
appContext?: {
|
|
46
|
+
config: {
|
|
47
|
+
errorHandler?: (err: Error, vm: unknown, info: string) => void;
|
|
48
|
+
warnHandler?: (msg: string, vm: unknown, trace: string) => void;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
config: {
|
|
52
|
+
errorHandler?: (err: Error, vm: unknown, info: string) => void;
|
|
53
|
+
warnHandler?: (msg: string, vm: unknown, trace: string) => void;
|
|
54
|
+
};
|
|
55
|
+
}): void;
|
|
45
56
|
interceptAppError(): void;
|
|
46
57
|
resetInterceptErrorApp(): void;
|
|
47
|
-
interceptErrorVue(error: Error): void;
|
|
58
|
+
interceptErrorVue(error: Error, info?: string): void;
|
|
48
59
|
interceptWarnVue(warn: string): void;
|
|
49
60
|
interceptPromiseReject(): void;
|
|
50
61
|
resetInterceptPromiseReject(): void;
|
|
@@ -54,8 +65,26 @@ export declare class DevIntercept implements DevTool.DevInterceptInterface {
|
|
|
54
65
|
resetInterceptClearStorage(): void;
|
|
55
66
|
interceptRemoveStorage(): void;
|
|
56
67
|
resetInterceptRemoveStorage(): void;
|
|
57
|
-
interceptVuexStorage(store:
|
|
58
|
-
|
|
68
|
+
interceptVuexStorage(store: {
|
|
69
|
+
state: Record<string, unknown>;
|
|
70
|
+
subscribe?: (cb: (mutation: unknown, state: Record<string, unknown>) => void) => void;
|
|
71
|
+
}): void;
|
|
72
|
+
interceptPiniaStore(context: {
|
|
73
|
+
pinia: {
|
|
74
|
+
state: {
|
|
75
|
+
value: Record<string, unknown>;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
store: {
|
|
79
|
+
$id: string;
|
|
80
|
+
$state: Record<string, unknown>;
|
|
81
|
+
$subscribe: (cb: () => void) => void;
|
|
82
|
+
};
|
|
83
|
+
}): {
|
|
84
|
+
state: {
|
|
85
|
+
value: Record<string, unknown>;
|
|
86
|
+
};
|
|
87
|
+
} | undefined;
|
|
59
88
|
interceptRequest(): void;
|
|
60
89
|
resetInterceptRequest(): void;
|
|
61
90
|
interceptSocket(): void;
|
|
@@ -87,4 +116,3 @@ export declare class DevIntercept implements DevTool.DevInterceptInterface {
|
|
|
87
116
|
interceptScreenRecording(): void;
|
|
88
117
|
resetInterceptScreenRecording(): void;
|
|
89
118
|
}
|
|
90
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import{backup as
|
|
2
|
-
`).map(
|
|
3
|
-
`+
|
|
4
|
-
`))==null?void 0:
|
|
5
|
-
`),
|
|
6
|
-
`),r=((h=t==null?void 0:t.slice(2))==null?void 0:h[0])||"";
|
|
7
|
-
`))==null?void 0:
|
|
8
|
-
`);this.reportError({type:"warn",msg:
|
|
9
|
-
`))==null?void 0:
|
|
10
|
-
`),
|
|
11
|
-
`),h=
|
|
12
|
-
`),h=
|
|
13
|
-
`),o=l==null?void 0:l[2];
|
|
14
|
-
`),s
|
|
1
|
+
import{backup as p,consoleProxy as $}from"../../core-shared.js";import{DEV_TOOL_ON_INIT as B,DEV_TOOL_ON_DESTROY as q,DEV_ERROR_BOUNDARY_TRIGGER as A}from"../../const.js";import"../../utils/index.js";import{getCurrentDate as I}from"../../utils/date.js";import{getCurrentPagePath as w}from"../../utils/page.js";import{parseValue as C,omit as G}from"../../utils/object.js";import{transformValueToShortString as P,transformValueToView as _}from"../../utils/language.js";import{escapeHTML as J}from"../../utils/string.js";class re{constructor(e){this.preWarn="",this.initPinia=!1,this.isReporting=!1,this.lastReportMsg="",this.lastReportTime=0,this.captureScreen=t=>{if(!this.hooks.getDevToolDestroy()){const r=this.hooks.getScreenIndex(),s=this.hooks.setScreenIndex(r+1);this.hooks.updateScreen([{index:s,position:w(),startTime:I(),endTime:I(),type:"captureScreen",path:(t==null?void 0:t.path)??""}])}},this.hooks=e.hooks,typeof uni<"u"&&(uni.$on(B,t=>this.init(t)),uni.$on(q,()=>this.reset()))}safeDefineProperty(e,t,r){if(!e)return!1;try{const s=Object.getOwnPropertyDescriptor(e,t);return s&&s.configurable===!1?(console.warn(`[DevTool] ${t} 属性不可配置,已跳过拦截`),!1):(Object.defineProperty(e,t,{...r,configurable:!0}),!0)}catch(s){return console.warn(`[DevTool] 拦截 ${t} 失败,环境可能受限:`,s),!1}}formatStack(e){if(!e)return"";const t=e.split(`
|
|
2
|
+
`).map(s=>s.trim()).filter(Boolean);return t.find(s=>{const n=s.toLowerCase();return n.includes("at ")&&!n.includes("devintercept")&&!n.includes("devconsole")&&!n.includes("core-shared")&&!n.includes("core.ts")})||t[0]||""}reportError({type:e="error",msg:t="",stack:r="",source:s="System",itemType:n="string"}){if(this.hooks.getDevToolDestroy()||this.isReporting)return;const u=Date.now();if(t===this.lastReportMsg&&u-this.lastReportTime<100)return;this.lastReportMsg=t,this.lastReportTime=u;const h=this.formatStack(r);this.isReporting=!0;try{const c=[];if(n==="object"||n==="array"){const i=C(t);c.push({type:n,value:i,shortValue:P(i,n)})}else c.push({type:n,value:`[${s}] ${t}`});this.hooks.updateConsole([{type:e,args:c,position:w(),time:I(),stack:h}])}finally{this.isReporting=!1}}init({enableCaptureScreen:e,enableInterceptPromiseReject:t}){this.enableCaptureScreen=e,this.enableInterceptPromiseReject=t,this.interceptAppConsole(),this.interceptAppError(),this.interceptSetStorage(),this.interceptRemoveStorage(),this.interceptClearStorage(),this.interceptRequest(),this.interceptSocket(),this.interceptUploadFile(),this.interceptDownloadFile(),this.interceptSwitchTab(),this.interceptRedirectTo(),this.interceptReLaunch(),this.interceptNavigateBack(),this.interceptNavigateTo(),this.interceptUniEvent(),this.interceptScanCode(),this.enableCaptureScreen&&this.interceptCaptureScreen(),this.interceptScreenRecording(),this.enableInterceptPromiseReject&&this.interceptPromiseReject()}reset(){["InterceptAppConsole","InterceptErrorApp","InterceptPromiseReject","InterceptStorage","InterceptRemoveStorage","InterceptClearStorage","InterceptRequest","InterceptSocket","InterceptUploadFile","InterceptDownloadFile","InterceptSwitchTab","InterceptRedirectTo","InterceptReLaunch","InterceptNavigateBack","InterceptNavigateTo","UniEvent","InterceptScanCode","InterceptScreenRecording"].forEach(e=>{var t;return(t=this[`reset${e}`])==null?void 0:t.call(this)}),this.enableCaptureScreen&&this.resetInterceptCaptureScreen()}interceptAppConsole(){const e=this;uni.__log__&&this.safeDefineProperty(uni,"__log__",{writable:!1,value:function(r,s,...n){var h,c;(c=(h=p).__log__)==null||c.call(h,r,s,...n);const u=w();e.hooks.updateConsole([{type:r,position:u,time:I(),args:n.map(i=>{const d=_(i),l=C(i),a=d==="object"||d==="array"?P(l,d):"";return{type:d,value:l,shortValue:a}}),stack:s}])}}),["log","info","debug","error","warn","time","timeEnd","count","clear"].forEach(r=>{this.safeDefineProperty(console,r,{value:function(...s){var h,c;if(["time","timeEnd","count","clear"].includes(r)&&r in $)return $[r](...s);(c=(h=p.originalConsole)[r])==null||c.call(h,...s);const n=s.map(i=>{const d=_(i),l=C(i),a=d==="object"||d==="array"?P(l,d):"";return{type:d,value:l,shortValue:a}}),u=e.formatStack(new Error().stack||"");s.length>0&&e.hooks.updateConsole([{type:r,args:n,position:w(),time:I(),stack:u}])}})})}resetInterceptAppConsole(){uni.__log__&&this.safeDefineProperty(uni,"__log__",{writable:!0,value:p.__log__}),["log","info","debug","error","warn","time","timeEnd","count","clear"].forEach(t=>{this.safeDefineProperty(console,t,{value:p.originalConsole[t]})})}interceptVue(e){if(!e)return;const t=(s,n,u)=>{this.hooks.getDevToolDestroy()||this.interceptErrorVue(s,u)},r=(s,n,u)=>{this.hooks.getDevToolDestroy()||this.interceptWarnVue(s+`
|
|
3
|
+
`+u)};e.appContext?(e.appContext.config.errorHandler=t,e.appContext.config.warnHandler=r):(e.config.errorHandler=t,e.config.warnHandler=r)}interceptAppError(){if(this.onErrorHandler=e=>{var s;const t=typeof e=="string"?e:(e==null?void 0:e.message)||String(e)||"",r=(e==null?void 0:e.stack)||(typeof t=="string"?(s=t.split(`
|
|
4
|
+
`))==null?void 0:s[1]:"")||"";this.reportError({msg:t,stack:r,source:"AppError"})},this.onErrorHandler&&uni.onError(this.onErrorHandler),uni.onUnhandledRejection){this.onUnhandledRejectionHandler=t=>{var n;let r="Unhandled Promise Rejection",s="";t.reason&&(r=typeof t.reason=="string"?t.reason:t.reason.message||String(t.reason)||r,s=((n=t.reason)==null?void 0:n.stack)||""),this.reportError({msg:r,stack:s,source:"UnhandledRejection"})};const e=uni;this.onUnhandledRejectionHandler&&e.onUnhandledRejection&&e.onUnhandledRejection(this.onUnhandledRejectionHandler)}typeof window<"u"&&window.addEventListener&&(this.boundWindowError=e=>{var s,n;if(e.target!==window)return;const t=e.message||((s=e.error)==null?void 0:s.message)||String(e),r=((n=e.error)==null?void 0:n.stack)||"";this.reportError({msg:t,stack:r,source:"WindowError"})},this.boundWindowRejection=e=>{let t="Unhandled Promise Rejection",r="";e.reason&&(t=typeof e.reason=="string"?e.reason:e.reason.message||String(e.reason),r=e.reason.stack||""),this.reportError({msg:t,stack:r,source:"WindowRejection"})},this.resourceErrorHandler=e=>{if(e instanceof ErrorEvent&&e.target===window)return;const t=e.target;if(!t||t===window)return;const r=String(t.tagName||"").toUpperCase(),s=t.src||t.href||t.currentSrc||t.getAttribute&&t.getAttribute("src");(["IMG","SCRIPT","LINK","VIDEO","AUDIO","SOURCE","UNI-IMAGE"].includes(r)||s)&&this.reportError({type:"error",msg:`Resource Load Failed: ${s||"unknown source"}`,source:"Resource"})},window.addEventListener("error",this.boundWindowError),window.addEventListener("unhandledrejection",this.boundWindowRejection),window.addEventListener("error",this.resourceErrorHandler,!0))}resetInterceptErrorApp(){uni.offError&&this.onErrorHandler&&uni.offError(this.onErrorHandler);const e=uni;e.offUnhandledRejection&&this.onUnhandledRejectionHandler&&e.offUnhandledRejection(this.onUnhandledRejectionHandler),typeof window<"u"&&window.removeEventListener&&(this.boundWindowError&&window.removeEventListener("error",this.boundWindowError),this.boundWindowRejection&&window.removeEventListener("unhandledrejection",this.boundWindowRejection),this.resourceErrorHandler&&window.removeEventListener("error",this.resourceErrorHandler,!0))}interceptErrorVue(e,t){var u;const r=(u=e==null?void 0:e.stack)==null?void 0:u.split(`
|
|
5
|
+
`),s=(r==null?void 0:r[1])||(e==null?void 0:e.stack)||"",n=(e==null?void 0:e.message)||(e==null?void 0:e.toString())||"Unknown Error";p.originalConsole.error(e),uni.$emit(A,{err:e,info:t}),this.reportError({msg:n,stack:s,source:"VueError"})}interceptWarnVue(e){var n,u,h,c;if(this.preWarn===e)return;this.preWarn=e;const t=(u=(n=new Error)==null?void 0:n.stack)==null?void 0:u.split(`
|
|
6
|
+
`),r=((h=t==null?void 0:t.slice(2))==null?void 0:h[0])||"";p.originalConsole.warn(e);const s=(c=e.split(`
|
|
7
|
+
`))==null?void 0:c.map(i=>J(i)).join(`
|
|
8
|
+
`);this.reportError({type:"warn",msg:s,stack:r,source:"VueWarn"})}interceptPromiseReject(){const e=this;this.safeDefineProperty(Promise,"reject",{configurable:!0,value:function(t){var n,u;const r=(t==null?void 0:t.toString())||"Promise Reject",s=((u=(n=t==null?void 0:t.stack)==null?void 0:n.split(`
|
|
9
|
+
`))==null?void 0:u[1])??"";return e.reportError({msg:r,stack:s,source:"Promise.reject"}),p.reject.call(Promise,t)}})}resetInterceptPromiseReject(){this.safeDefineProperty(Promise,"reject",{configurable:!0,value:function(e){return p.reject.call(Promise,e)}})}interceptSetStorage(){const e=this;this.safeDefineProperty(uni,"setStorageSync",{configurable:!0,value:function(t,r){p.setStorageSync(t,r),e.hooks.updateStorage([{key:t.toString(),_oldKey:t.toString(),value:r}])}}),uni.addInterceptor("setStorage",{invoke(t){const r=t.complete;t.complete=function(s){var n,u;r&&r(s),e.hooks.updateStorage([{key:(n=t.key)==null?void 0:n.toString(),_oldKey:(u=t.key)==null?void 0:u.toString(),value:t.data}])}}})}resetInterceptStorage(){uni.removeInterceptor("setStorage"),this.safeDefineProperty(uni,"setStorageSync",{configurable:!0,value:p.setStorageSync}),uni.removeInterceptor("clearStorage"),this.safeDefineProperty(uni,"clearStorageSync",{configurable:!0,value:p.clearStorageSync}),uni.removeInterceptor("removeStorage"),this.safeDefineProperty(uni,"removeStorageSync",{configurable:!0,value:p.removeStorageSync})}interceptClearStorage(){const e=this;this.safeDefineProperty(uni,"clearStorageSync",{configurable:!0,value:function(){p.clearStorageSync(),e.hooks.clearStorage()}}),uni.addInterceptor("clearStorage",{invoke(){e.hooks.clearStorage()}})}resetInterceptClearStorage(){this.safeDefineProperty(uni,"clearStorageSync",{configurable:!0,value:p.clearStorageSync}),uni.removeInterceptor("clearStorage")}interceptRemoveStorage(){const e=this;this.safeDefineProperty(uni,"removeStorageSync",{configurable:!0,value:function(t){p.removeStorageSync(t),e.hooks.removeStorage(t)}}),uni.addInterceptor("removeStorage",{invoke(t){const r=t.complete;t.complete=function(s){r&&r(s),e.hooks.removeStorage(t.key)}}})}resetInterceptRemoveStorage(){this.safeDefineProperty(uni,"removeStorageSync",{configurable:!0,value:p.removeStorageSync}),uni.removeInterceptor("removeStorage")}interceptVuexStorage(e){var r;this.hooks.getDevToolDestroy()||(this.hooks.setVuexList(e.state),this.hooks.setVueStore(e),(r=e==null?void 0:e.subscribe)==null||r.call(e,(s,n)=>{this.hooks.setVuexList(n)}))}interceptPiniaStore(e){var r;if(this.initPinia||(this.initPinia=!0,this.hooks.setPiniaStore(e.pinia)),this.hooks.setPiniaList(e.pinia.state.value),!this.hooks.getDevToolDestroy())return(r=e==null?void 0:e.store)==null||r.$subscribe(()=>{this.hooks.setPiniaList({[e.store.$id]:e.store.$state})}),e.pinia}interceptRequest(){const e=this;uni.addInterceptor("request",{invoke(t){var R,H,U,W,F,x,V;const r=e.hooks.getRequestIndex(),s=e.hooks.setRequestIndex(r+1),n=t.url,u=(R=n==null?void 0:n.split("?"))==null?void 0:R[0],h=u==null?void 0:u.lastIndexOf("/"),c=(u==null?void 0:u.slice(h+1))??"",i=(U=(H=new Error)==null?void 0:H.stack)==null?void 0:U.split(`
|
|
10
|
+
`),d=uni.__dev_tool_platform__==="app"?i==null?void 0:i[2]:i==null?void 0:i[5],l=e.hooks.getInterceptNetworkMap(),o=`${(W=t.method)==null?void 0:W.toUpperCase()}|${u}`,a=l==null?void 0:l.get(o),g=Object.keys(t.header??{}).includes("dev-tool-sponsor")?"dev_tool":"user";t.header={...G(t.header,["dev-tool-sponsor"])};const f={index:s,stack:d,url:t.url,name:c,startTime:Date.now(),endTime:0,time:"-",headers:{requestHeader:Object.entries(t.header??{}).map(([S,k])=>({key:S,value:k})),responseHeader:[]},method:t.method||"GET",status:"pending",payload:t!=null&&t.data?JSON.stringify(t.data):"",response:{data:void 0,statusCode:0,header:{},cookies:[],errMsg:""},size:"",sponsor:g};a&&(f.headers.requestHeader=[...f.headers.requestHeader,...a.headers.requestHeader||[]],f.payload=a.payload,f.intercepted=!0,Object.assign(t,{timeout:a.timeout})),e.hooks.updateNetwork([f]);const m={errMsg:""};let T=!0;a&&(m.statusCode=a.status,(x=(F=a==null?void 0:a.status)==null?void 0:F.toString())!=null&&x.startsWith("2")?(T=!0,m.errMsg="request:ok",m.header=(V=a.headers.responseHeader)==null?void 0:V.reduce((S,k)=>({...S,[k.key]:k.value}),{}),m.data=a.response.data):(T=!1,m.errMsg="request:fail"));const y=t.fail,v=t.success,E=t.complete;t.fail=function(S){const k=()=>{a?T?v==null||v(m):y==null||y(m):y==null||y(S)};a&&a.delay&&a.delay>0?setTimeout(k,a.delay):k()},t.success=function(S){const k=D=>{a?T?v==null||v(m):y==null||y(m):v==null||v(D)};a&&a.delay?setTimeout(()=>k(S),Number(a.delay)):k(S)},t.complete=function(S){const k=()=>{const D=Date.now()-f.startTime;f.time=D<1e3?D+"ms":D/1e3+"s",f.endTime=Date.now();const b=S.header||{},L=(b==null?void 0:b["Content-Length"])||(b==null?void 0:b["content-length"])||"0",j=Number(L)||0;f.size=j>1024?(j/1024).toFixed(2)+"k":j+"b",a?(E==null||E(m),f.status=a.status,f.response=m,f.headers.responseHeader=a.headers.responseHeader):(E==null||E(S),f.status=S.statusCode??"error",f.response=S,f.headers.responseHeader=Object.entries(S.header??{}).map(([N,M])=>({key:N,value:M}))),e.hooks.updateNetwork([f],s)};a&&a.delay&&a.delay>0?setTimeout(k,a.delay):k()}}})}resetInterceptRequest(){uni.removeInterceptor("request")}interceptSocket(){const e=this,t=function(r){const s=r.url,n=Object.entries(r.header??{}).map(([o,a])=>({key:o,value:a})),u=(r.method??"GET").toLowerCase(),h=r.protocols??[];e.hooks.updateWs({url:s,headers:n,method:u,protocols:h,readyState:"connection",message:[]});const c=p.connectSocket({...r,multiple:!0,complete:o=>{var a;(a=r==null?void 0:r.complete)==null||a.call(r,o)}});e.hooks.addWsTask(s,c);function i(o,a,g,f){let m=o;if(typeof o=="string")try{const R=JSON.parse(o);typeof R=="object"&&R!==null&&(m=R)}catch{}const T=_(m),y=C(m),E=T==="object"||T==="array"?P(y,T):"";e.hooks.updateWs({url:s,readyState:g,headers:n,protocols:h,message:[{value:y,valueType:T,shortValue:E,status:f,time:Date.now(),type:a}]})}const d=c.send;c.send=o=>{let a=o.data;if(typeof a=="object"&&a!==null)try{a=JSON.stringify(a)}catch{}d.call(c,{...o,data:a,fail:g=>{var f;(f=o==null?void 0:o.fail)==null||f.call(o,g),i(o.data,"send","error","error")},success:g=>{var f;(f=o==null?void 0:o.success)==null||f.call(o,g),i(o.data,"send","open","success")},complete:g=>{var f;(f=o==null?void 0:o.complete)==null||f.call(o,g)}})};const l=c.close;return c.close=o=>{e.hooks.updateWs({url:s,readyState:"closing",headers:n,protocols:h,message:[]}),l.call(c,{...o,fail:a=>{var g;(g=o==null?void 0:o.fail)==null||g.call(o,a),i(a,"send","closing","error")},success:a=>{var g;(g=o==null?void 0:o.success)==null||g.call(o,a),i(a,"send","closed","success")},complete:a=>{var g;(g=o==null?void 0:o.complete)==null||g.call(o,a)}})},c.onOpen(()=>{e.hooks.updateWs({url:s,readyState:"open",headers:n,protocols:h,message:[]})}),c.onError(o=>{i(o,"receive","error","error")}),c.onMessage(o=>{i(o.data,"receive","open","success")}),c.onClose(o=>{i(o,"receive","closed","success"),e.hooks.removeWsTask(s)}),c};this.safeDefineProperty(uni,"connectSocket",{configurable:!0,value:t})}resetInterceptSocket(){this.safeDefineProperty(uni,"connectSocket",{configurable:!0,value:p.connectSocket})}interceptUploadFile(){const e=this,t=r=>{var i,d;const s=e.hooks.getTransferIndex(),n=e.hooks.setTransferIndex(s+1),u=(d=(i=new Error)==null?void 0:i.stack)==null?void 0:d.split(`
|
|
11
|
+
`),h=u==null?void 0:u[2];e.hooks.updateTransfer([{index:n,type:"upload",stack:h,name:r.name,url:r.url,filePath:r.filePath,fileType:r.fileType,headers:{requestHeader:Object.entries(r.header||{}).map(([l,o])=>({key:l,value:o})),responseHeader:[]},formData:r.formData,status:"pending",progress:0,totalBytesSent:0,totalBytesExpectedToSend:0,startTime:Date.now()}],n);const c=p.uploadFile({...r,success:l=>{var o;(o=r==null?void 0:r.success)==null||o.call(r,l),e.hooks.updateTransfer([{index:n,type:"upload",status:"success",endTime:Date.now(),response:{...l,data:JSON.parse(l.data)}}],n),e.hooks.removeTransferTask(n)},fail:l=>{var o;(o=r==null?void 0:r.fail)==null||o.call(r,l),e.hooks.updateTransfer([{index:n,type:"upload",status:"error",response:l,endTime:Date.now()}],n),e.hooks.removeTransferTask(n)}});return c.onProgressUpdate(l=>{e.hooks.updateTransfer([{index:n,type:"upload",progress:l.progress,totalBytesSent:l.totalBytesSent,totalBytesExpectedToSend:l.totalBytesExpectedToSend,status:"uploading"}],n)}),e.hooks.addTransferTask(n,c),c};this.safeDefineProperty(uni,"uploadFile",{configurable:!0,value:t})}resetInterceptUploadFile(){this.safeDefineProperty(uni,"uploadFile",{configurable:!0,value:p.uploadFile})}interceptDownloadFile(){const e=this,t=r=>{var i,d;const s=e.hooks.getTransferIndex(),n=e.hooks.setTransferIndex(s+1),u=(d=(i=new Error)==null?void 0:i.stack)==null?void 0:d.split(`
|
|
12
|
+
`),h=u==null?void 0:u[2];e.hooks.updateTransfer([{index:n,type:"download",stack:h,url:r.url,filePath:r.filePath,headers:{requestHeader:Object.entries(r.header||{}).map(([l,o])=>({key:l,value:o})),responseHeader:[]},status:"pending",progress:0,totalBytesWritten:0,totalBytesExpectedToWrite:0,startTime:Date.now()}],n);const c=p.downloadFile({...r,success:l=>{var o;(o=r==null?void 0:r.success)==null||o.call(r,l),e.hooks.updateTransfer([{index:n,type:"download",status:"success",endTime:Date.now(),response:{...l,statusCode:l.statusCode,tempFilePath:l.tempFilePath}}],n),e.hooks.removeTransferTask(n)},fail:l=>{var o;(o=r==null?void 0:r.fail)==null||o.call(r,l),e.hooks.updateTransfer([{index:n,type:"download",status:"error",response:l,endTime:Date.now()}],n),e.hooks.removeTransferTask(n)}});return c.onProgressUpdate(l=>{e.hooks.updateTransfer([{index:n,type:"download",progress:l.progress,totalBytesWritten:l.totalBytesWritten,totalBytesExpectedToWrite:l.totalBytesExpectedToWrite,status:"downloading"}],n)}),e.hooks.addTransferTask(n,c),c};this.safeDefineProperty(uni,"downloadFile",{configurable:!0,value:t})}resetInterceptDownloadFile(){this.safeDefineProperty(uni,"downloadFile",{configurable:!0,value:p.downloadFile})}interceptRouterMethod(e){const t=this;uni.addInterceptor(e,{invoke(r){const s=r.complete;r.complete=function(n){var h,c,i;s==null||s(n);const u=((i=(c=(h=r.url)==null?void 0:h.slice(1))==null?void 0:c.split("?"))==null?void 0:i[0])||"/";t.hooks.updateRoute(u),t.hooks.closeWindow()}}})}interceptSwitchTab(){this.interceptRouterMethod("switchTab")}resetInterceptSwitchTab(){uni.removeInterceptor("switchTab")}interceptRedirectTo(){this.interceptRouterMethod("redirectTo")}resetInterceptRedirectTo(){uni.removeInterceptor("redirectTo")}interceptReLaunch(){this.interceptRouterMethod("reLaunch")}resetInterceptReLaunch(){uni.removeInterceptor("reLaunch")}interceptNavigateBack(){this.interceptRouterMethod("navigateBack")}resetInterceptNavigateBack(){uni.removeInterceptor("navigateBack")}interceptNavigateTo(){this.interceptRouterMethod("navigateTo")}resetInterceptNavigateTo(){uni.removeInterceptor("navigateTo")}uniEventFactory(e,t=!0){const r=`$${e}`,s=this;Object.defineProperty(uni,r,{configurable:!0,value:function(n,...u){var h,c,i,d;if((c=(h=p)==null?void 0:h[r])==null||c.call(h,n,...u),t&&!n.startsWith("dev-")&&!n.startsWith("perf-")){const l=(d=(i=new Error)==null?void 0:i.stack)==null?void 0:d.split(`
|
|
13
|
+
`),o=l==null?void 0:l[2];s.hooks.updateUniEvent([{eventName:n,timer:I(),stack:o,type:e}]),s.hooks.updateUniEventCount(e)}}})}interceptUniEvent(){this.uniEventFactory("on"),this.uniEventFactory("once"),this.uniEventFactory("emit"),this.uniEventFactory("off")}resetUniEvent(){Object.defineProperty(uni,"$on",{configurable:!0,value:p.$on}),Object.defineProperty(uni,"$once",{configurable:!0,value:p.$once}),Object.defineProperty(uni,"$emit",{configurable:!0,value:p.$emit}),Object.defineProperty(uni,"$off",{configurable:!0,value:p.$off})}interceptScanCode(){const e=this;uni.addInterceptor("scanCode",{invoke(t){var u,h;const r=t.complete,s=(h=(u=new Error)==null?void 0:u.stack)==null?void 0:h.split(`
|
|
14
|
+
`),n=s==null?void 0:s[5];t.complete=function(c){r&&r(c);const i=c;let d={},l="";try{d=JSON.parse((i==null?void 0:i.result)||"{}"),l=P(d,"object")}catch{d=i==null?void 0:i.result,l=String((i==null?void 0:i.result)||"")}e.hooks.updateScanCode([{timer:Date.now(),charSet:(i==null?void 0:i.charSet)||"",rawData:(c==null?void 0:c.rawData)||"",result:(i==null?void 0:i.result)||"",resultObject:d,scanType:(i==null?void 0:i.scanType)||"",errMsg:(c==null?void 0:c.errMsg)||"",path:w(),stack:n,shortValue:l}])}}})}resetInterceptScanCode(){uni.removeInterceptor("scanCode")}interceptCaptureScreen(){uni.__dev_tool_platform__!=="web"&&uni.onUserCaptureScreen(this.captureScreen)}resetInterceptCaptureScreen(){uni.__dev_tool_platform__!=="web"&&uni.offUserCaptureScreen(this.captureScreen)}listenerScreenRecording(e){const{state:t}=e,r=this.hooks.getScreenIndex(),s=this.hooks.setScreenIndex(r+1),n=I();this.hooks.updateScreen([{index:s,position:w(),startTime:n,endTime:n,type:"screenRecording:"+t}])}interceptScreenRecording(){uni.onScreenRecordingStateChanged&&(this.boundListenerScreenRecording=this.listenerScreenRecording.bind(this),uni.onScreenRecordingStateChanged(this.boundListenerScreenRecording))}resetInterceptScreenRecording(){uni.offScreenRecordingStateChanged&&this.boundListenerScreenRecording&&uni.offScreenRecordingStateChanged(this.boundListenerScreenRecording)}}export{re as DevIntercept};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("../../const.cjs");require("../../utils/index.cjs");const o=require("../devToolInfo/index.cjs"),C=require("../../utils/function.cjs"),D=require("../../utils/language.cjs"),y=require("../../utils/object.cjs"),b=require("../../utils/page.cjs"),x=require("../../utils/ip.cjs");class z{constructor(){if(this.consoleList=[],this.consoleMaxSize=1e3,this.totalConsoleCount=0,this.networkList=[],this.networkMaxSize=1e3,this.totalNetworkCount=0,this.interceptNetworkMap=new Map,this.requestIndex=-1,this.storageList=[],this.vuexList={},this.piniaList={},this.routeList=[],this.prePath="",this.wsList=[],this.wsDataMaxSize=1e3,this.wsTaskMap=new Map,this.transferList=[],this.transferMaxSize=1e3,this.transferIndex=-1,this.transferTaskMap=new Map,this.elEventList=[],this.uniEventList=[],this.eventCount={on:0,once:0,emit:0,off:0},this.elEventListMaxSize=1e3,this.uniEventListMaxSize=1e3,this.screenList=[],this.scanCodeList=[],this.nfcList=[],this.bluetoothList=[],this.screenIndex=-1,this.screenMaxSize=1e3,this.scanCodeListMaxSize=1e3,this.nfcListMaxSize=1e3,this.systemInfo={},this.deviceInfo={},this.windowInfo={},this.netWorkStatus={},this.devToolVersion="0.0.0",this.devToolBuildTime="",this.devToolGit="",this.devToolVisible=!1,this.devToolDestroy=!1,this.cacheInterceptConfig=!0,this.useTransition=!0,this.cacheNetworkLog=!1,this.cacheConsoleLog=!1,this.baseFontSize=12,this.tagFontSize=10,this.tipsFontSize=10,this.fontFamily="",this.fontWeight="normal",this.barrageVisible=!0,this.barrageMaxTracks=10,this.barrageTrackHeight=36,this.barrageStartTop=40,this.barrageDuration=6,this.barrageMaxLength=100,this.barrageTypes=["log","info","warn","error","network","transfer","websocket"],this.barrageShowWhenOpen=!1,this.saveConsoleLogThrottled=C.throttle(()=>{this.cacheConsoleLog&&o.setDevToolConsoleList(this.consoleList)},1e3),this.saveNetworkLogThrottled=C.throttle(()=>{this.cacheNetworkLog&&o.setDevToolNetworkList(this.networkList)},1e3),this.cacheMaxSize=8*1024*1024*10,typeof uni<"u"){const{devToolDestroy:t=!1,devToolButtonVisible:e=!1,cacheInterceptConfig:s=!0,cacheNetworkLog:n=!1,cacheConsoleLog:i=!1,useTransition:l=!0,baseFontSize:r=12,tagFontSize:L=10,tipsFontSize:p=10,fontFamily:a="",fontWeight:c="normal",barrageVisible:v=!0,barrageMaxTracks:d=10,barrageTrackHeight:h=36,barrageStartTop:f=40,barrageDuration:g=6,barrageMaxLength:S=100,barrageTypes:u=["log","info","warn","error","network","transfer","websocket"],barrageShowWhenOpen:T=!1,interceptNetworkList:w=[]}=uni.getStorageSync(M.DEV_TOOL_INFO)||{};this.devToolDestroy=t,this.devToolVisible=e,this.cacheInterceptConfig=s,this.cacheNetworkLog=n,this.cacheConsoleLog=i,this.useTransition=l,this.baseFontSize=r,this.tagFontSize=L,this.tipsFontSize=p,this.fontFamily=a,this.fontWeight=c,this.barrageVisible=v,this.barrageMaxTracks=d,this.barrageTrackHeight=h,this.barrageStartTop=f,this.barrageDuration=g,this.barrageMaxLength=S,this.barrageTypes=u,this.barrageShowWhenOpen=T,this.updateInterceptNetworkList(w),this.cacheNetworkLog&&(this.networkList=o.getDevToolNetworkList(),this.requestIndex=Math.max(...this.networkList.map(k=>k.index??-1),-1)),this.cacheConsoleLog&&(this.consoleList=o.getDevToolConsoleList()),this.totalConsoleCount=this.consoleList.length,this.totalNetworkCount=this.networkList.length}}updateHasUpload(){this.consoleList=this.consoleList.map(t=>({...t,hasUpload:!0})),this.networkList=this.networkList.map(t=>({...t,hasUpload:!0})),this.transferList=this.transferList.map(t=>({...t,hasUpload:!0})),this.elEventList=this.elEventList.map(t=>({...t,hasUpload:!0})),this.uniEventList=this.uniEventList.map(t=>({...t,hasUpload:!0})),this.screenList=this.screenList.map(t=>({...t,hasUpload:!0}))}setDevToolVisible(t){this.devToolVisible=t,o.setDevToolInfo({devToolButtonVisible:t})}getDevToolVisible(){return this.devToolVisible}setDevToolDestroy(t){this.devToolDestroy=t,o.setDevToolInfo({devToolDestroy:t})}getDevToolDestroy(){return this.devToolDestroy}setCacheInterceptConfig(t){this.cacheInterceptConfig=t,o.setDevToolInfo({cacheInterceptConfig:t})}getCacheNetworkLog(){return this.cacheNetworkLog}setUseTransition(t){this.useTransition=t,o.setDevToolInfo({useTransition:t})}setBaseFontSize(t){this.baseFontSize=t,o.setDevToolInfo({baseFontSize:t})}setTagFontSize(t){this.tagFontSize=t,o.setDevToolInfo({tagFontSize:t})}setTipsFontSize(t){this.tipsFontSize=t,o.setDevToolInfo({tipsFontSize:t})}setFontFamily(t){this.fontFamily=t,o.setDevToolInfo({fontFamily:t})}setFontWeight(t){this.fontWeight=t,o.setDevToolInfo({fontWeight:t})}setBarrageVisible(t){this.barrageVisible=t,o.setDevToolInfo({barrageVisible:t})}setBarrageMaxTracks(t){this.barrageMaxTracks=t,o.setDevToolInfo({barrageMaxTracks:t})}setBarrageTrackHeight(t){this.barrageTrackHeight=t,o.setDevToolInfo({barrageTrackHeight:t})}setBarrageStartTop(t){this.barrageStartTop=t,o.setDevToolInfo({barrageStartTop:t})}setBarrageDuration(t){this.barrageDuration=t,o.setDevToolInfo({barrageDuration:t})}setBarrageMaxLength(t){this.barrageMaxLength=t,o.setDevToolInfo({barrageMaxLength:t})}setBarrageTypes(t){this.barrageTypes=t,o.setDevToolInfo({barrageTypes:t})}setBarrageShowWhenOpen(t){this.barrageShowWhenOpen=t,o.setDevToolInfo({barrageShowWhenOpen:t})}setCacheConsoleLog(t){this.cacheConsoleLog=t,o.setDevToolInfo({cacheConsoleLog:t}),t?o.setDevToolConsoleList(this.consoleList):o.setDevToolConsoleList([])}setCacheNetworkLog(t){this.cacheNetworkLog=t,o.setDevToolInfo({cacheNetworkLog:t}),t?o.setDevToolNetworkList(this.networkList):o.setDevToolNetworkList([])}getConsoleList(){return this.consoleList}updateConsoleList(t,e){typeof e=="number"&&e>-1&&t.length===1?this.consoleList[e]&&(this.consoleList[e]=t[0]):(this.consoleList.push(...t),this.totalConsoleCount+=t.length,this.consoleList.length>this.consoleMaxSize&&(this.consoleList=this.consoleList.slice(-this.consoleMaxSize))),this.saveConsoleLogThrottled()}clearConsoleList(){this.consoleList=[],this.totalConsoleCount=0,this.cacheConsoleLog&&o.setDevToolConsoleList([])}getNetworkList(){return this.networkList}updateNetworkList(t,e){typeof e=="number"&&e>-1&&t.length===1?this.networkList[e]&&(this.networkList[e]=t[0]):(this.networkList.push(...t),this.totalNetworkCount+=t.length,this.networkList.length>this.networkMaxSize&&(this.networkList=this.networkList.slice(-this.networkMaxSize))),this.saveNetworkLogThrottled()}clearNetworkList(){this.networkList=[],this.totalNetworkCount=0,this.cacheNetworkLog&&o.setDevToolNetworkList([])}getInterceptNetworkMap(){return this.interceptNetworkMap}getRequestIndex(){return this.requestIndex}setRequestIndex(t){return this.requestIndex=t,this.requestIndex}updateInterceptNetworkList(t){this.interceptNetworkMap.clear(),t.forEach(e=>{var n;const s=`${(n=e.method)==null?void 0:n.toUpperCase()}|${e.url}`;this.interceptNetworkMap.set(s,e)})}clearInterceptNetworkList(){this.clearNetworkList()}getStorageList(){return this.storageList}setStorageList(t){return this.storageList=t,this.storageList}getVuexList(){return this.vuexList}getPiniaList(){return this.piniaList}setVuexStore(t){this.vuexStore=t}setVuexList(t){this.vuexList=t}setPiniaStore(t){this.piniaStore=t}setPiniaList(t){this.piniaList={...this.piniaList||{},...t}}updateStore(t){const{key:e,_oldKey:s,value:n}=t;return s===e&&(uni.removeStorageSync(s),this.storageList=this.storageList.filter(i=>i.key!==s)),uni.setStorageSync(e,n),this.storageList}updateVuexStore(t){var e,s;try{Object.assign(((e=this.vuexStore)==null?void 0:e.state)??{},t)}catch(n){console.error("[DevTool] updateVuexStore error",n)}return this.setVuexList({...((s=this.vuexStore)==null?void 0:s.state)??{}}),this.vuexList}updatePiniaStore(t){try{if(!this.piniaStore)return{};const[e,s]=Object.entries(t)[0];if(D.isNil(e))return{};y.setValueByPath(this.piniaStore.state.value,e,s),this.setPiniaList({...this.piniaStore.state.value??{}})}catch(e){console.error("[DevTool] updatePiniaStore error",e)}return this.piniaList}clearStorageList(t){return this.storageList=[],t&&uni.clearStorage(),this.storageList}removeStorage(t,e){return this.storageList=this.storageList.filter(s=>s.key!==t),e&&uni.removeStorageSync(t),this.storageList}addStorage(t,e){const{key:s,value:n}=t;return this.storageList.unshift({key:s,_oldKey:s,value:n}),e&&uni.setStorageSync(s,n),this.storageList}refreshStore(){const{keys:t}=uni.getStorageInfoSync();return this.storageList=t.map(e=>{const s=uni.getStorageSync(e);return{key:e,_oldKey:e,value:s}}),this.storageList}updateStoreList(t){const e=t[0],s=this.storageList.findIndex(n=>n.key===e._oldKey);return s>-1&&t.length===1?this.storageList[s]=t[0]:this.storageList.push(...t),this.storageList}getRouteList(){return this.routeList}setRouteList(t,e){var n;const s=e||((n=t==null?void 0:t[0])==null?void 0:n.path)||"";return this.routeList=t.map((i,l)=>({...i,name:i.style.navigationBarTitleText||"无名",uvList:[],index:i.path===s&&l===0?4:i.path===s?3:l===0?2:1})),this.routeList}updateRouteList(t){const e=t?t==="/"?b.getCurrentPagePath():t:b.getCurrentPagePath(),s=this.prePath;this.routeList=this.routeList.map((r,L)=>({...r,index:r.path===e&&L===0?4:r.path===e?3:L===0?2:1}));const n=(r,L,p)=>{var v,d;if(!r[L])return r;r[L].uvList||(r[L].uvList=[]);const a=r[L],c=a.uvList??[];if(c.length){const h=c.length-1,f=c[h];if(f&&f.inTime&&!f.outTime){const g=Date.now();a.outTime=g,c[h].outTime=g,c[h].duration=g-f.inTime,a.duration=c[h].duration,a.totalDuration=c.reduce((S,u)=>S+(u.duration||0),0),p&&(a.visitTimes=c.length)}else{const g=Date.now();a.inTime=g,a.outTime=0,a.duration=0,(v=a.uvList)==null||v.push({index:h+1,inTime:g,outTime:0,duration:0}),p&&(a.visitTimes=(d=a.uvList)==null?void 0:d.length)}}else{const h=Date.now();a.inTime=h,a.outTime=0,a.duration=0,a.totalDuration=0,a.visitTimes=1,a.uvList=[{index:0,inTime:h,outTime:0,duration:0}]}return r},i=this.routeList.findIndex(r=>r.path===s),l=this.routeList.findIndex(r=>r.path===e);return i>-1&&n(this.routeList,i),l>-1&&n(this.routeList,l,!0),this.prePath=e,this.routeList}getWsList(){return this.wsList}updateWsList(t){var s,n;const e=this.wsList.findIndex(i=>i.url===t.url);if(e>-1){const i=this.wsList[e];i.headers=t.headers??i.headers,i.readyState=t.readyState??i.readyState,i.method=t.method??i.method,i.protocols=t.protocols??i.protocols,i.message=[...i.message??[],...t.message??[]];const l=this.wsDataMaxSize,r=((s=i.message)==null?void 0:s.length)??0;r>l&&((n=i.message)==null||n.splice(0,r-l))}else this.wsList.push(t);return this.wsList}clearWsList(){this.wsList=[]}clearWsMessage(t){const e=this.wsList.findIndex(s=>s.url===t);e>-1&&(this.wsList[e].message=[])}addWsTask(t,e){this.wsTaskMap.set(t,e)}removeWsTask(t){this.wsTaskMap.delete(t)}getWsTask(t){const e=this.wsTaskMap.get(t);if(e)return e;if(!t)return;let s;return this.wsTaskMap.forEach((n,i)=>{s||i&&(i.includes(t)||t.includes(i))&&(s=n)}),s}getTransferList(){return this.transferList}updateTransferList(t,e){if(typeof e=="number"&&e>-1&&t.length===1){const s=t[0],n=this.transferList.findIndex(i=>i.index===e);n>-1?this.transferList[n]={...this.transferList[n],...s}:this.transferList.push(s)}else this.transferList.length+t.length>this.transferMaxSize&&(this.transferList=[]),this.transferList.push(...t)}getTransferIndex(){return this.transferIndex}setTransferIndex(t){return this.transferIndex=t,this.transferIndex}addTransferTask(t,e){this.transferTaskMap.set(t,e)}removeTransferTask(t){this.transferTaskMap.delete(t)}clearTransferTask(){this.transferTaskMap.clear()}getElEventList(){return this.elEventList}getUniEventList(){return this.uniEventList}getEventCount(){return this.eventCount}addElEvent(t){this.elEventList.length>=this.elEventListMaxSize&&this.elEventList.shift(),this.elEventList.push(t)}clearElEventList(){this.elEventList=[]}updateUniEventList(t){this.uniEventList.length+t.length>this.uniEventListMaxSize&&(this.uniEventList=[]),this.uniEventList.push(...t)}updateUniEventCount(t){this.eventCount[t]++}clearUniEventList(){this.uniEventList=[],this.eventCount={on:0,once:0,emit:0,off:0}}getScreenList(){return this.screenList}getScanCodeList(){return this.scanCodeList}getNfcList(){return this.nfcList}getScreenIndex(){return this.screenIndex}setScreenIndex(t){return this.screenIndex=t,this.screenIndex}getSystemInfo(){return this.systemInfo}getDeviceInfo(){return this.deviceInfo}getWindowInfo(){return this.windowInfo}setSystemInfo(t){this.systemInfo=t}setDeviceInfo(t){this.deviceInfo=t}setWindowInfo(t){this.windowInfo=t}setNetWorkStatus(t){this.netWorkStatus=t}updateScreenList(t,e){typeof e=="number"&&e>-1&&t.length===1?this.screenList[e]&&(this.screenList[e]=t[0]):(this.screenList.length+t.length>this.screenMaxSize&&(this.screenList=[]),this.screenList.push(...t))}updateScanCodeList(t){this.scanCodeList.length+t.length>this.scanCodeListMaxSize&&(this.scanCodeList=[]),this.scanCodeList.push(...t)}updateNfcList(t){this.nfcList.length+t.length>this.nfcListMaxSize&&(this.nfcList=[]),this.nfcList.push(...t)}updateBluetoothList(t){this.bluetoothList=t}clearScanCodeList(){this.scanCodeList=[]}clearNfcList(){this.nfcList=[]}clearBluetoothList(){this.bluetoothList=[]}getDevToolOptions(){return this.devToolOptions}setDevToolOptions(t){var f,g,S;this.devToolOptions=t,this.transferMaxSize=t.uploadMaxSize||1e3,this.consoleMaxSize=t.consoleMaxSize||1e3,this.networkMaxSize=t.networkMaxSize||1e3,this.wsDataMaxSize=t.wsDataMaxSize||1e3,this.elEventListMaxSize=t.elEventListMaxSize||1e3,this.uniEventListMaxSize=t.uniEventListMaxSize||1e3,this.screenMaxSize=t.screenMaxSize||1e3,this.scanCodeListMaxSize=t.scanCodeListMaxSize||1e3,this.nfcListMaxSize=t.nfcListMaxSize||1e3,this.devToolVersion=t.devToolVersion??"0.0.0",this.devToolBuildTime=t.devToolBuildTime??"",this.devToolGit=t.devToolGit??"";const{devToolButtonVisible:e,useTransition:s=!0,baseFontSize:n=12,tagFontSize:i=10,tipsFontSize:l=10,fontFamily:r="",fontWeight:L="normal",cacheInterceptConfig:p=!0,cacheNetworkLog:a=!1,cacheConsoleLog:c=!1,barrageVisible:v=!0,barrageShowWhenOpen:d=!1}=o.getDevToolInfo();this.devToolVisible=D.isBoolean(e)?e:t.initShowDevTool??!0,this.useTransition=s,this.baseFontSize=n,this.tagFontSize=i,this.tipsFontSize=l,this.fontFamily=r,this.fontWeight=L,this.cacheInterceptConfig=p,this.cacheNetworkLog=a,this.cacheConsoleLog=c,this.barrageVisible=v,this.barrageShowWhenOpen=d,this.cacheNetworkLog&&(this.networkList=o.getDevToolNetworkList(),this.requestIndex=Math.max(...this.networkList.map(u=>u.index??-1),-1)),this.cacheConsoleLog&&(this.consoleList=o.getDevToolConsoleList()),this.setDevToolVisible(this.devToolVisible),this.setDevToolDestroy(!this.devToolVisible);const h=((f=t.pagesJson)==null?void 0:f.pages.map(u=>{var T,w,k;return{...u,type:(k=(w=(T=t.pagesJson)==null?void 0:T.tabBar)==null?void 0:w.list)!=null&&k.some(I=>I.pagePath===u.path)?"nav":"main"}}))??[];(S=(g=t.pagesJson)==null?void 0:g.subPackages)==null||S.forEach(u=>{u.pages.forEach(T=>{h.push({...T,path:`${u.root}/${T.path}`,type:"sub",uvList:[]})})}),this.setRouteList(h)}async getDevData(){const t=await uni.getNetworkType()||{};this.setNetWorkStatus(t);let e="0.0.0.0";try{uni.__dev_tool_platform__==="app"?e=x.getWifiIp()||x.getLanIp()||"0.0.0.0":uni.__dev_tool_platform__==="mp-weixin"&&(e=await x.getMicroAppIp())}catch(s){console.error("[DevTool] Get IP error",s)}return{consoleList:this.consoleList,networkList:this.networkList,storageList:this.storageList,routeList:this.routeList,vuexList:this.vuexList,piniaList:this.piniaList,wsList:this.wsList,transferList:this.transferList,elEventList:this.elEventList,uniEventList:this.uniEventList,eventCount:this.eventCount,screenList:this.screenList,scanCodeList:this.scanCodeList,nfcList:this.nfcList,bluetoothList:this.bluetoothList,systemInfo:this.systemInfo,deviceInfo:this.deviceInfo,windowInfo:this.windowInfo,netWorkStatus:{ip:e,...t,isConnected:t.networkType!=="none"},devToolVisible:this.getDevToolVisible(),cacheInterceptConfig:this.cacheInterceptConfig,cacheNetworkLog:this.cacheNetworkLog,cacheConsoleLog:this.cacheConsoleLog,useTransition:this.useTransition,baseFontSize:this.baseFontSize,tagFontSize:this.tagFontSize,tipsFontSize:this.tipsFontSize,fontFamily:this.fontFamily,fontWeight:this.fontWeight,barrageVisible:this.barrageVisible,barrageMaxTracks:this.barrageMaxTracks,barrageTrackHeight:this.barrageTrackHeight,barrageStartTop:this.barrageStartTop,barrageDuration:this.barrageDuration,barrageMaxLength:this.barrageMaxLength,barrageTypes:[...this.barrageTypes],barrageShowWhenOpen:this.barrageShowWhenOpen,devToolVersion:this.devToolVersion,devToolBuildTime:this.devToolBuildTime,devToolGit:this.devToolGit,totalConsoleCount:this.totalConsoleCount,totalNetworkCount:this.totalNetworkCount}}getExportData(t){const e={};return t.exportLog&&(e.consoleList=this.consoleList),t.exportNetwork&&(e.networkList=this.networkList),t.exportStorage&&(e.storageList=this.storageList,e.vuexList=this.vuexList,e.piniaList=this.piniaList),t.exportTransfer&&(e.transferList=this.transferList),t.exportWebSocket&&(e.wsList=this.wsList),t.exportWindow&&(e.windowInfo=uni.getWindowInfo?uni.getWindowInfo():{errMsg:"not supported"}),t.exportDevice&&(e.deviceInfo=uni.getDeviceInfo?uni.getDeviceInfo():{errMsg:"not supported"}),t.exportSystem&&(e.systemInfo=uni.getSystemInfo?uni.getSystemInfo():{errMsg:"not supported"}),t.exportUniEvent&&(e.uniEventList=this.uniEventList),t.exportElEvent&&(e.elEventList=this.elEventList),t.exportScanCodeList&&(e.scanCodeList=this.scanCodeList),t.exportNfcList&&(e.nfcList=this.nfcList),e}clearDevCache(){this.consoleList=[],this.networkList=[],this.wsList=[],this.transferList=[],this.elEventList=[],this.uniEventList=[],this.screenList=[],this.scanCodeList=[],this.nfcList=[],this.bluetoothList=[],this.cacheConsoleLog&&o.setDevToolConsoleList([]),this.cacheNetworkLog&&o.setDevToolNetworkList([])}clearAll(){this.clearDevCache(),this.storageList=[],this.routeList=[],this.interceptNetworkMap.clear()}getCurrentPagePath(){return b.getCurrentPagePath()}}exports.DevStore=z;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("../../const.cjs");require("../../utils/index.cjs");const h=require("../devToolInfo/index.cjs"),C=require("../../utils/function.cjs"),y=require("../../utils/language.cjs"),I=require("../../utils/object.cjs"),w=require("../../utils/page.cjs"),k=require("../../utils/ip.cjs");class z{constructor(){if(this.consoleList=[],this.consoleMaxSize=1e3,this.totalConsoleCount=0,this.networkList=[],this.networkMaxSize=1e3,this.totalNetworkCount=0,this.interceptNetworkMap=new Map,this.requestIndex=-1,this.storageList=[],this.vuexList={},this.piniaList={},this.routeList=[],this.prePath="",this.wsList=[],this.wsDataMaxSize=1e3,this.wsTaskMap=new Map,this.transferList=[],this.transferMaxSize=1e3,this.transferIndex=-1,this.transferTaskMap=new Map,this.elEventList=[],this.uniEventList=[],this.eventCount={on:0,once:0,emit:0,off:0},this.elEventListMaxSize=1e3,this.uniEventListMaxSize=1e3,this.screenList=[],this.scanCodeList=[],this.nfcList=[],this.bluetoothList=[],this.screenIndex=-1,this.screenMaxSize=1e3,this.scanCodeListMaxSize=1e3,this.nfcListMaxSize=1e3,this.systemInfo={},this.deviceInfo={},this.windowInfo={},this.netWorkStatus={},this.devToolVersion="0.0.0",this.devToolBuildTime="",this.devToolGit="",this.devToolButtonVisible=!1,this.devToolDestroy=!1,this.cacheInterceptConfig=!0,this.useTransition=!0,this.cacheNetworkLog=!1,this.cacheConsoleLog=!1,this.baseFontSize=12,this.tagFontSize=10,this.tipsFontSize=10,this.fontFamily="",this.fontWeight="normal",this.barrageVisible=!0,this.barrageMaxTracks=10,this.barrageTrackHeight=36,this.barrageStartTop=40,this.barrageDuration=6,this.barrageMaxLength=100,this.barrageAllowDrag=!0,this.barrageTypes=["log","info","warn","error","network","transfer","websocket"],this.barrageShowWhenOpen=!1,this.saveConsoleLogThrottled=C.throttle(()=>{this.cacheConsoleLog&&h.setDevToolConsoleList(this.consoleList)},1e3),this.saveNetworkLogThrottled=C.throttle(()=>{this.cacheNetworkLog&&h.setDevToolNetworkList(this.networkList)},1e3),this.cacheMaxSize=8*1024*1024*10,typeof uni>"u")return;const t=uni.getStorageSync(D.DEV_TOOL_INFO)||{};Object.assign(this,t),this.devToolButtonVisible=t.devToolButtonVisible??!1,t.interceptNetworkList&&this.updateInterceptNetworkList(t.interceptNetworkList),this.cacheNetworkLog&&(this.networkList=h.getDevToolNetworkList(),this.requestIndex=Math.max(...this.networkList.map(e=>e.index??-1),-1)),this.cacheConsoleLog&&(this.consoleList=h.getDevToolConsoleList()),this.totalConsoleCount=this.consoleList.length,this.totalNetworkCount=this.networkList.length}updateHasUpload(){[this.consoleList,this.networkList,this.transferList,this.elEventList,this.uniEventList,this.screenList].forEach(e=>e.forEach(s=>s.hasUpload=!0))}setAndSync(t,e,s){this[t]=e,h.setDevToolInfo({[s||t]:e})}setDevToolButtonVisible(t){this.setAndSync("devToolButtonVisible",t)}getDevToolButtonVisible(){return this.devToolButtonVisible}setDevToolDestroy(t){this.setAndSync("devToolDestroy",t)}getDevToolDestroy(){return this.devToolDestroy}setCacheInterceptConfig(t){this.setAndSync("cacheInterceptConfig",t)}getCacheNetworkLog(){return this.cacheNetworkLog}setUseTransition(t){this.setAndSync("useTransition",t)}setBaseFontSize(t){this.setAndSync("baseFontSize",t)}setTagFontSize(t){this.setAndSync("tagFontSize",t)}setTipsFontSize(t){this.setAndSync("tipsFontSize",t)}setFontFamily(t){this.setAndSync("fontFamily",t)}setFontWeight(t){this.setAndSync("fontWeight",t)}setBarrageVisible(t){this.setAndSync("barrageVisible",t)}setBarrageMaxTracks(t){this.setAndSync("barrageMaxTracks",t)}setBarrageTrackHeight(t){this.setAndSync("barrageTrackHeight",t)}setBarrageStartTop(t){this.setAndSync("barrageStartTop",t)}setBarrageDuration(t){this.setAndSync("barrageDuration",t)}setBarrageMaxLength(t){this.setAndSync("barrageMaxLength",t)}setBarrageAllowDrag(t){this.setAndSync("barrageAllowDrag",t)}setBarrageTypes(t){this.setAndSync("barrageTypes",t)}setBarrageShowWhenOpen(t){this.setAndSync("barrageShowWhenOpen",t)}setCacheConsoleLog(t){this.cacheConsoleLog=t,h.setDevToolInfo({cacheConsoleLog:t}),h.setDevToolConsoleList(t?this.consoleList:[])}setCacheNetworkLog(t){this.cacheNetworkLog=t,h.setDevToolInfo({cacheNetworkLog:t}),h.setDevToolNetworkList(t?this.networkList:[])}getConsoleList(){return this.consoleList}updateConsoleList(t,e){typeof e=="number"&&e>-1&&t.length===1?this.consoleList[e]&&(this.consoleList[e]=t[0]):(this.consoleList.push(...t),this.totalConsoleCount+=t.length,this.consoleList.length>this.consoleMaxSize&&(this.consoleList=this.consoleList.slice(-this.consoleMaxSize))),this.saveConsoleLogThrottled()}clearConsoleList(){this.consoleList=[],this.totalConsoleCount=0,this.cacheConsoleLog&&h.setDevToolConsoleList([])}getNetworkList(){return this.networkList}updateNetworkList(t,e){typeof e=="number"&&e>-1&&t.length===1?this.networkList[e]&&(this.networkList[e]=t[0]):(this.networkList.push(...t),this.totalNetworkCount+=t.length,this.networkList.length>this.networkMaxSize&&(this.networkList=this.networkList.slice(-this.networkMaxSize))),this.saveNetworkLogThrottled()}clearNetworkList(){this.networkList=[],this.totalNetworkCount=0,this.cacheNetworkLog&&h.setDevToolNetworkList([])}getInterceptNetworkMap(){return this.interceptNetworkMap}getRequestIndex(){return this.requestIndex}setRequestIndex(t){return this.requestIndex=t,this.requestIndex}updateInterceptNetworkList(t){this.interceptNetworkMap.clear(),t.forEach(e=>{var o;const s=`${(o=e.method)==null?void 0:o.toUpperCase()}|${e.url}`;this.interceptNetworkMap.set(s,e)})}clearInterceptNetworkList(){this.clearNetworkList()}getStorageList(){return this.storageList}setStorageList(t){return this.storageList=t,this.storageList}getVuexList(){return this.vuexList}getPiniaList(){return this.piniaList}setVuexStore(t){this.vuexStore=t}setVuexList(t){this.vuexList=t}setPiniaStore(t){this.piniaStore=t}setPiniaList(t){this.piniaList={...this.piniaList||{},...t}}updateStore(t){const{key:e,_oldKey:s,value:o}=t;return s===e&&(uni.removeStorageSync(s),this.storageList=this.storageList.filter(i=>i.key!==s)),uni.setStorageSync(e,o),this.storageList}updateVuexStore(t){var e,s;try{Object.assign(((e=this.vuexStore)==null?void 0:e.state)??{},t)}catch(o){console.error("[DevTool] updateVuexStore error",o)}return this.setVuexList({...((s=this.vuexStore)==null?void 0:s.state)??{}}),this.vuexList}updatePiniaStore(t){try{if(!this.piniaStore)return{};const[e,s]=Object.entries(t)[0];if(y.isNil(e))return{};I.setValueByPath(this.piniaStore.state.value,e,s),this.setPiniaList({...this.piniaStore.state.value??{}})}catch(e){console.error("[DevTool] updatePiniaStore error",e)}return this.piniaList}clearStorageList(t){return this.storageList=[],t&&uni.clearStorage(),this.storageList}removeStorage(t,e){return this.storageList=this.storageList.filter(s=>s.key!==t),e&&uni.removeStorageSync(t),this.storageList}addStorage(t,e){const{key:s,value:o}=t;return this.storageList.unshift({key:s,_oldKey:s,value:o}),e&&uni.setStorageSync(s,o),this.storageList}refreshStore(){const{keys:t}=uni.getStorageInfoSync();return this.storageList=t.map(e=>{const s=uni.getStorageSync(e);return{key:e,_oldKey:e,value:s}}),this.storageList}updateStoreList(t){const e=t[0],s=this.storageList.findIndex(o=>o.key===e._oldKey);return s>-1&&t.length===1?this.storageList[s]=t[0]:this.storageList.push(...t),this.storageList}getRouteList(){return this.routeList}setRouteList(t,e){var o;const s=e||((o=t==null?void 0:t[0])==null?void 0:o.path)||"";return this.routeList=t.map((i,a)=>({...i,name:i.style.navigationBarTitleText||"无名",uvList:[],index:i.path===s&&a===0?4:i.path===s?3:a===0?2:1})),this.routeList}updateRouteList(t){const e=t?t==="/"?w.getCurrentPagePath():t:w.getCurrentPagePath(),s=this.prePath;this.routeList=this.routeList.map((n,u)=>({...n,index:n.path===e&&u===0?4:n.path===e?3:u===0?2:1}));const o=(n,u,p)=>{var v,S;if(!n[u])return n;n[u].uvList||(n[u].uvList=[]);const r=n[u],l=r.uvList??[];if(l.length){const c=l.length-1,f=l[c];if(f&&f.inTime&&!f.outTime){const L=Date.now();r.outTime=L,l[c].outTime=L,l[c].duration=L-f.inTime,r.duration=l[c].duration,r.totalDuration=l.reduce((T,g)=>T+(g.duration||0),0),p&&(r.visitTimes=l.length)}else{const L=Date.now();r.inTime=L,r.outTime=0,r.duration=0,(v=r.uvList)==null||v.push({index:c+1,inTime:L,outTime:0,duration:0}),p&&(r.visitTimes=(S=r.uvList)==null?void 0:S.length)}}else{const c=Date.now();r.inTime=c,r.outTime=0,r.duration=0,r.totalDuration=0,r.visitTimes=1,r.uvList=[{index:0,inTime:c,outTime:0,duration:0}]}return n},i=this.routeList.findIndex(n=>n.path===s),a=this.routeList.findIndex(n=>n.path===e);return i>-1&&o(this.routeList,i),a>-1&&o(this.routeList,a,!0),this.prePath=e,this.routeList}getWsList(){return this.wsList}updateWsList(t){var s,o;const e=this.wsList.findIndex(i=>i.url===t.url);if(e>-1){const i=this.wsList[e];i.headers=t.headers??i.headers,i.readyState=t.readyState??i.readyState,i.method=t.method??i.method,i.protocols=t.protocols??i.protocols,i.message=[...i.message??[],...t.message??[]];const a=this.wsDataMaxSize,n=((s=i.message)==null?void 0:s.length)??0;n>a&&((o=i.message)==null||o.splice(0,n-a))}else this.wsList.push(t);return this.wsList}clearWsList(){this.wsList=[]}clearWsMessage(t){const e=this.wsList.findIndex(s=>s.url===t);e>-1&&(this.wsList[e].message=[])}addWsTask(t,e){this.wsTaskMap.set(t,e)}removeWsTask(t){this.wsTaskMap.delete(t)}getWsTask(t){const e=this.wsTaskMap.get(t);if(e)return e;if(!t)return;let s;return this.wsTaskMap.forEach((o,i)=>{s||i&&(i.includes(t)||t.includes(i))&&(s=o)}),s}getTransferList(){return this.transferList}updateTransferList(t,e){if(typeof e=="number"&&e>-1&&t.length===1){const s=t[0],o=this.transferList.findIndex(i=>i.index===e);o>-1?this.transferList[o]={...this.transferList[o],...s}:this.transferList.push(s)}else this.transferList.length+t.length>this.transferMaxSize&&(this.transferList=[]),this.transferList.push(...t)}getTransferIndex(){return this.transferIndex}setTransferIndex(t){return this.transferIndex=t,this.transferIndex}addTransferTask(t,e){this.transferTaskMap.set(t,e)}removeTransferTask(t){this.transferTaskMap.delete(t)}clearTransferTask(){this.transferTaskMap.clear()}getElEventList(){return this.elEventList}getUniEventList(){return this.uniEventList}getEventCount(){return this.eventCount}addElEvent(t){this.elEventList.length>=this.elEventListMaxSize&&this.elEventList.shift(),this.elEventList.push(t)}clearElEventList(){this.elEventList=[]}updateUniEventList(t){this.uniEventList.length+t.length>this.uniEventListMaxSize&&(this.uniEventList=[]),this.uniEventList.push(...t)}updateUniEventCount(t){this.eventCount[t]++}clearUniEventList(){this.uniEventList=[],this.eventCount={on:0,once:0,emit:0,off:0}}getScreenList(){return this.screenList}getScanCodeList(){return this.scanCodeList}getNfcList(){return this.nfcList}getScreenIndex(){return this.screenIndex}setScreenIndex(t){return this.screenIndex=t,this.screenIndex}getSystemInfo(){return this.systemInfo}getDeviceInfo(){return this.deviceInfo}getWindowInfo(){return this.windowInfo}setSystemInfo(t){this.systemInfo=t}setDeviceInfo(t){this.deviceInfo=t}setWindowInfo(t){this.windowInfo=t}setNetWorkStatus(t){this.netWorkStatus=t}updateScreenList(t,e){typeof e=="number"&&e>-1&&t.length===1?this.screenList[e]&&(this.screenList[e]=t[0]):(this.screenList.length+t.length>this.screenMaxSize&&(this.screenList=[]),this.screenList.push(...t))}updateScanCodeList(t){this.scanCodeList.length+t.length>this.scanCodeListMaxSize&&(this.scanCodeList=[]),this.scanCodeList.push(...t)}updateNfcList(t){this.nfcList.length+t.length>this.nfcListMaxSize&&(this.nfcList=[]),this.nfcList.push(...t)}updateBluetoothList(t){this.bluetoothList=t}clearScanCodeList(){this.scanCodeList=[]}clearNfcList(){this.nfcList=[]}clearBluetoothList(){this.bluetoothList=[]}getDevToolOptions(){return this.devToolOptions}setDevToolOptions(t){var f,L,T;this.devToolOptions=t,this.transferMaxSize=t.uploadMaxSize||1e3,this.consoleMaxSize=t.consoleMaxSize||1e3,this.networkMaxSize=t.networkMaxSize||1e3,this.wsDataMaxSize=t.wsDataMaxSize||1e3,this.elEventListMaxSize=t.elEventListMaxSize||1e3,this.uniEventListMaxSize=t.uniEventListMaxSize||1e3,this.screenMaxSize=t.screenMaxSize||1e3,this.scanCodeListMaxSize=t.scanCodeListMaxSize||1e3,this.nfcListMaxSize=t.nfcListMaxSize||1e3,this.devToolVersion=t.devToolVersion??"0.0.0",this.devToolBuildTime=t.devToolBuildTime??"",this.devToolGit=t.devToolGit??"";const{devToolButtonVisible:e,useTransition:s=!0,baseFontSize:o=12,tagFontSize:i=10,tipsFontSize:a=10,fontFamily:n="",fontWeight:u="normal",cacheInterceptConfig:p=!0,cacheNetworkLog:r=!1,cacheConsoleLog:l=!1,barrageVisible:v=!0,barrageShowWhenOpen:S=!1}=h.getDevToolInfo();this.devToolButtonVisible=y.isBoolean(e)?e:t.initShowDevTool??!0,this.useTransition=s,this.baseFontSize=o,this.tagFontSize=i,this.tipsFontSize=a,this.fontFamily=n,this.fontWeight=u,this.cacheInterceptConfig=p,this.cacheNetworkLog=r,this.cacheConsoleLog=l,this.barrageVisible=v,this.barrageShowWhenOpen=S,this.cacheNetworkLog&&(this.networkList=h.getDevToolNetworkList(),this.requestIndex=Math.max(...this.networkList.map(g=>g.index??-1),-1)),this.cacheConsoleLog&&(this.consoleList=h.getDevToolConsoleList()),this.setDevToolButtonVisible(this.devToolButtonVisible),this.setDevToolDestroy(!this.devToolButtonVisible);const c=((f=t.pagesJson)==null?void 0:f.pages.map(g=>{var d,x,b;return{...g,type:(b=(x=(d=t.pagesJson)==null?void 0:d.tabBar)==null?void 0:x.list)!=null&&b.some(M=>M.pagePath===g.path)?"nav":"main"}}))??[];(T=(L=t.pagesJson)==null?void 0:L.subPackages)==null||T.forEach(g=>{g.pages.forEach(d=>{c.push({...d,path:`${g.root}/${d.path}`,type:"sub",uvList:[]})})}),this.setRouteList(c)}async getDevData(){var s,o,i,a;const t=await uni.getNetworkType()||{};this.setNetWorkStatus(t);let e="0.0.0.0";try{uni.__dev_tool_platform__==="app"?e=k.getWifiIp()||k.getLanIp()||"0.0.0.0":uni.__dev_tool_platform__==="mp-weixin"&&(e=await k.getMicroAppIp())}catch(n){console.error("[DevTool] Get IP error",n)}return{consoleList:this.consoleList,networkList:this.networkList,storageList:this.storageList,routeList:this.routeList,vuexList:this.vuexList,piniaList:this.piniaList,wsList:this.wsList,transferList:this.transferList,elEventList:this.elEventList,uniEventList:this.uniEventList,eventCount:this.eventCount,screenList:this.screenList,scanCodeList:this.scanCodeList,nfcList:this.nfcList,bluetoothList:this.bluetoothList,systemInfo:this.systemInfo,deviceInfo:this.deviceInfo,windowInfo:this.windowInfo,netWorkStatus:{ip:e,...t,isConnected:t.networkType!=="none"},devToolVisible:this.getDevToolButtonVisible(),cacheInterceptConfig:this.cacheInterceptConfig,cacheNetworkLog:this.cacheNetworkLog,cacheConsoleLog:this.cacheConsoleLog,useTransition:this.useTransition,baseFontSize:this.baseFontSize,tagFontSize:this.tagFontSize,tipsFontSize:this.tipsFontSize,fontFamily:this.fontFamily,fontWeight:this.fontWeight,barrageVisible:this.barrageVisible,barrageMaxTracks:this.barrageMaxTracks,barrageTrackHeight:this.barrageTrackHeight,barrageStartTop:this.barrageStartTop,barrageDuration:this.barrageDuration,barrageMaxLength:this.barrageMaxLength,barrageAllowDrag:this.barrageAllowDrag,barrageTypes:[...this.barrageTypes],barrageShowWhenOpen:this.barrageShowWhenOpen,devToolVersion:this.devToolVersion,devToolBuildTime:this.devToolBuildTime,devToolGit:this.devToolGit,sourceFileServers:(s=this.devToolOptions)==null?void 0:s.sourceFileServers,mode:(o=this.devToolOptions)==null?void 0:o.mode,useDevSource:(i=this.devToolOptions)==null?void 0:i.useDevSource,zIndex:(a=this.devToolOptions)==null?void 0:a.zIndex,totalConsoleCount:this.totalConsoleCount,totalNetworkCount:this.totalNetworkCount}}getExportData(t){const e={};return Object.entries({exportLog:["consoleList"],exportNetwork:["networkList"],exportTransfer:["transferList"],exportWebSocket:["wsList"],exportUniEvent:["uniEventList"],exportElEvent:["elEventList"],exportScanCodeList:["scanCodeList"],exportNfcList:["nfcList"],exportStorage:["storageList","vuexList","piniaList"]}).forEach(([i,a])=>{t[i]&&a.forEach(n=>{e[n]=this[n]})}),Object.entries({Window:"windowInfo",Device:"deviceInfo",System:"systemInfo"}).forEach(([i,a])=>{var n;t[`export${i}`]&&(e[a]=((n=uni[`get${i}Info`])==null?void 0:n.call(uni))||{errMsg:"not supported"})}),e}clearDevCache(){["consoleList","networkList","wsList","transferList","elEventList","uniEventList","screenList","scanCodeList","nfcList","bluetoothList"].forEach(e=>{this[e]=[]}),this.cacheConsoleLog&&h.setDevToolConsoleList([]),this.cacheNetworkLog&&h.setDevToolNetworkList([])}clearAll(){this.clearDevCache(),this.storageList=[],this.routeList=[],this.interceptNetworkMap.clear()}getCurrentPagePath(){return w.getCurrentPagePath()}}exports.DevStore=z;
|