diff --git a/env/.env b/env/.env index 51615b8..0517a4b 100644 --- a/env/.env +++ b/env/.env @@ -14,3 +14,7 @@ VITE_APP_PROXY_PREFIX='/api' VITE_SERVER_BASEURL='https://dev.work.star-lock.cn/api' VITE_APP_ENV='XHJ_DEV' + +VITE_APP_VERSION='1.0.0' +VITE_APP_BUILD_NUMBER=1 + diff --git a/src/interceptors/request.ts b/src/interceptors/request.ts index d24db1d..b1ef464 100644 --- a/src/interceptors/request.ts +++ b/src/interceptors/request.ts @@ -17,7 +17,6 @@ const baseUrl = getEnvBaseUrl() const httpInterceptor = { // 拦截前触发 invoke(options: CustomRequestOptions) { - // 接口请求支持通过 query 参数配置 queryString if (options.query) { const queryStr = qs.stringify(options.query) if (options.url.includes('?')) { @@ -26,7 +25,6 @@ const httpInterceptor = { options.url += `?${queryStr}` } } - // 非 http 开头需拼接地址 if (!options.url.startsWith('http')) { // #ifdef H5 // console.log(__VITE_APP_PROXY__) @@ -42,16 +40,13 @@ const httpInterceptor = { // #endif // TIPS: 如果需要对接多个后端服务,也可以在这里处理,拼接成所需要的地址 } - // 1. 请求超时 - options.timeout = 10000 // 10s - // 2. (可选)添加小程序端请求头标识 + options.timeout = 3000 options.header = { - platform, // 可选,与 uniapp 定义的平台一致,告诉后台来源 + platform, + version: import.meta.env.VITE_APP_VERSION + '+' + import.meta.env.VITE_APP_BUILD_NUMBER, ...options.header } - // 3. 添加 token 请求头标识 - const userStore = useUserStore() - const { token } = userStore.userInfo as unknown as IUserInfo + const token = uni.getStorageSync('token') if (token) { options.header.Authorization = `Bearer ${token}` } diff --git a/src/pages/code/code.vue b/src/pages/code/code.vue index 731d583..0b5e811 100644 --- a/src/pages/code/code.vue +++ b/src/pages/code/code.vue @@ -38,6 +38,13 @@ - - diff --git a/src/pages/home/home.vue b/src/pages/home/home.vue index 72aaa46..ff34a33 100644 --- a/src/pages/home/home.vue +++ b/src/pages/home/home.vue @@ -18,13 +18,14 @@