From 55261a17eb65148af8abb292866e89c33bfbe372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=A8=E6=A0=88=E5=B0=8F=E5=AD=A6=E7=94=9F?= <1518079521@qq.com> Date: Fri, 15 Sep 2023 18:44:30 +0800 Subject: [PATCH] update uni-app --- uni-app/package-lock.json | 86 +++-- uni-app/package.json | 3 +- .../app/locale/zh-Hans/pages.index.index.json | 1 + .../app/locale/zh-Hans/pages.pay.result.json | 1 + .../components/pretty-times/pretty-times.vue | 10 +- uni-app/src/locale/language.ts | 7 +- uni-app/src/styles/common.scss | 10 - uni-app/src/styles/iconfont.css | 30 +- uni-app/src/styles/index.scss | 12 + uni-app/src/utils/interceptor.ts | 2 - uni-app/src/utils/request.ts | 295 +++++++++--------- 11 files changed, 267 insertions(+), 190 deletions(-) create mode 100644 uni-app/src/app/locale/zh-Hans/pages.index.index.json create mode 100644 uni-app/src/app/locale/zh-Hans/pages.pay.result.json diff --git a/uni-app/package-lock.json b/uni-app/package-lock.json index a7ac3737d..a00993234 100644 --- a/uni-app/package-lock.json +++ b/uni-app/package-lock.json @@ -26,6 +26,7 @@ "lodash-es": "^4.17.21", "pinia": "^2.0.36", "qrcode": "^1.5.1", + "qs": "^6.11.2", "sortablejs": "^1.15.0", "uview-plus": "^3.1.29", "vue": "^3.3.0", @@ -5235,6 +5236,21 @@ "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "dev": true }, + "node_modules/body-parser/node_modules/qs": { + "version": "6.11.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", + "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "dev": true, + "dependencies": { + "side-channel": "^1.0.4" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/brace-expansion": { "version": "2.0.1", "resolved": "https://registry.npmmirror.com/brace-expansion/-/brace-expansion-2.0.1.tgz", @@ -5334,7 +5350,6 @@ "version": "1.0.2", "resolved": "https://registry.npmmirror.com/call-bind/-/call-bind-1.0.2.tgz", "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", - "dev": true, "dependencies": { "function-bind": "^1.1.1", "get-intrinsic": "^1.0.2" @@ -6155,6 +6170,21 @@ "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "dev": true }, + "node_modules/express/node_modules/qs": { + "version": "6.11.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", + "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "dev": true, + "dependencies": { + "side-channel": "^1.0.4" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/fast-glob": { "version": "3.3.1", "resolved": "https://registry.npmmirror.com/fast-glob/-/fast-glob-3.3.1.tgz", @@ -6365,7 +6395,6 @@ "version": "1.2.1", "resolved": "https://registry.npmmirror.com/get-intrinsic/-/get-intrinsic-1.2.1.tgz", "integrity": "sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==", - "dev": true, "dependencies": { "function-bind": "^1.1.1", "has": "^1.0.3", @@ -6481,7 +6510,6 @@ "version": "1.0.1", "resolved": "https://registry.npmmirror.com/has-proto/-/has-proto-1.0.1.tgz", "integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==", - "dev": true, "engines": { "node": ">= 0.4" } @@ -6490,7 +6518,6 @@ "version": "1.0.3", "resolved": "https://registry.npmmirror.com/has-symbols/-/has-symbols-1.0.3.tgz", "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", - "dev": true, "engines": { "node": ">= 0.4" } @@ -9319,8 +9346,7 @@ "node_modules/object-inspect": { "version": "1.12.3", "resolved": "https://registry.npmmirror.com/object-inspect/-/object-inspect-1.12.3.tgz", - "integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==", - "dev": true + "integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==" }, "node_modules/omggif": { "version": "1.0.10", @@ -9988,15 +10014,17 @@ } }, "node_modules/qs": { - "version": "6.11.0", - "resolved": "https://registry.npmmirror.com/qs/-/qs-6.11.0.tgz", - "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", - "dev": true, + "version": "6.11.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.2.tgz", + "integrity": "sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==", "dependencies": { "side-channel": "^1.0.4" }, "engines": { "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" } }, "node_modules/querystringify": { @@ -10457,7 +10485,6 @@ "version": "1.0.4", "resolved": "https://registry.npmmirror.com/side-channel/-/side-channel-1.0.4.tgz", "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", - "dev": true, "dependencies": { "call-bind": "^1.0.0", "get-intrinsic": "^1.0.2", @@ -16164,6 +16191,15 @@ "resolved": "https://registry.npmmirror.com/ms/-/ms-2.0.0.tgz", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "dev": true + }, + "qs": { + "version": "6.11.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", + "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "dev": true, + "requires": { + "side-channel": "^1.0.4" + } } } }, @@ -16248,7 +16284,6 @@ "version": "1.0.2", "resolved": "https://registry.npmmirror.com/call-bind/-/call-bind-1.0.2.tgz", "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", - "dev": true, "requires": { "function-bind": "^1.1.1", "get-intrinsic": "^1.0.2" @@ -16913,6 +16948,15 @@ "resolved": "https://registry.npmmirror.com/ms/-/ms-2.0.0.tgz", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "dev": true + }, + "qs": { + "version": "6.11.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", + "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "dev": true, + "requires": { + "side-channel": "^1.0.4" + } } } }, @@ -17085,7 +17129,6 @@ "version": "1.2.1", "resolved": "https://registry.npmmirror.com/get-intrinsic/-/get-intrinsic-1.2.1.tgz", "integrity": "sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==", - "dev": true, "requires": { "function-bind": "^1.1.1", "has": "^1.0.3", @@ -17176,14 +17219,12 @@ "has-proto": { "version": "1.0.1", "resolved": "https://registry.npmmirror.com/has-proto/-/has-proto-1.0.1.tgz", - "integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==", - "dev": true + "integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==" }, "has-symbols": { "version": "1.0.3", "resolved": "https://registry.npmmirror.com/has-symbols/-/has-symbols-1.0.3.tgz", - "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", - "dev": true + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==" }, "hash-sum": { "version": "2.0.0", @@ -19444,8 +19485,7 @@ "object-inspect": { "version": "1.12.3", "resolved": "https://registry.npmmirror.com/object-inspect/-/object-inspect-1.12.3.tgz", - "integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==", - "dev": true + "integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==" }, "omggif": { "version": "1.0.10", @@ -19937,10 +19977,9 @@ "integrity": "sha512-EXtzRZmC+YGmGlDFbXKxQiMZNwCLEO6BANKXG4iCtSIM0yqc/pappSx3RIKr4r0uh5JsBckOXeKrB3Iz7mdQpQ==" }, "qs": { - "version": "6.11.0", - "resolved": "https://registry.npmmirror.com/qs/-/qs-6.11.0.tgz", - "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", - "dev": true, + "version": "6.11.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.2.tgz", + "integrity": "sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==", "requires": { "side-channel": "^1.0.4" } @@ -20325,7 +20364,6 @@ "version": "1.0.4", "resolved": "https://registry.npmmirror.com/side-channel/-/side-channel-1.0.4.tgz", "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", - "dev": true, "requires": { "call-bind": "^1.0.0", "get-intrinsic": "^1.0.2", diff --git a/uni-app/package.json b/uni-app/package.json index d0ec06f4c..802f73caa 100644 --- a/uni-app/package.json +++ b/uni-app/package.json @@ -57,6 +57,7 @@ "lodash-es": "^4.17.21", "pinia": "^2.0.36", "qrcode": "^1.5.1", + "qs": "^6.11.2", "sortablejs": "^1.15.0", "uview-plus": "^3.1.29", "vue": "^3.3.0", @@ -81,4 +82,4 @@ "vue-tsc": "^1.0.24", "windicss": "^3.5.6" } -} \ No newline at end of file +} diff --git a/uni-app/src/app/locale/zh-Hans/pages.index.index.json b/uni-app/src/app/locale/zh-Hans/pages.index.index.json new file mode 100644 index 000000000..9e26dfeeb --- /dev/null +++ b/uni-app/src/app/locale/zh-Hans/pages.index.index.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/uni-app/src/app/locale/zh-Hans/pages.pay.result.json b/uni-app/src/app/locale/zh-Hans/pages.pay.result.json new file mode 100644 index 000000000..9e26dfeeb --- /dev/null +++ b/uni-app/src/app/locale/zh-Hans/pages.pay.result.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/uni-app/src/components/pretty-times/pretty-times.vue b/uni-app/src/components/pretty-times/pretty-times.vue index e76c97b7a..7298818e2 100644 --- a/uni-app/src/components/pretty-times/pretty-times.vue +++ b/uni-app/src/components/pretty-times/pretty-times.vue @@ -4,7 +4,7 @@ -
+
{{item.week}} {{item.date}} @@ -19,7 +19,7 @@ + :_index==timeActive?selectedItemColor:'#333', borderColor:(isMultiple?item.isActive:_index==timeActive? selectedBorderColor:'')}" @click="selectTimeEvent(_index,item)"> {{item.begin}}~{{item.end}} {{item.time}} {{item.disable?disableText:undisableText}} @@ -104,6 +104,10 @@ type: String, default: "#FB4B5C" }, + selectedBorderColor: { // 时间选中border的颜色 + type: String, + default: "#FB4B5C" + }, beginTime: { type: String, default: "09:00:00" @@ -415,6 +419,6 @@ } .borderb { - border-bottom: 2px solid #FB4B5C; + border-bottom: 2px solid; } \ No newline at end of file diff --git a/uni-app/src/locale/language.ts b/uni-app/src/locale/language.ts index 132976f2a..849e6b33e 100644 --- a/uni-app/src/locale/language.ts +++ b/uni-app/src/locale/language.ts @@ -7,7 +7,7 @@ class Language { constructor(i18n: any) { this.i18n = i18n } - + /** * * @param locale 设置语言 @@ -29,7 +29,6 @@ class Language { */ public async loadLocaleMessages(path: string, locale: string) { try { - let route = 'app'; // 默认系统 // 检测当前访问的是系统(app)还是插件 @@ -42,11 +41,11 @@ class Language { else file = file.split('.').splice(1).join('.') // 是否已加载 - if (this.loadLocale.includes(`${locale}/${file}`)) { + if (this.loadLocale.includes(`${route}/${locale}/${file}`)) { this.setI18nLanguage(locale, file) return nextTick() } - this.loadLocale.push(`${locale}/${file}`) + this.loadLocale.push(`${route}/${locale}/${file}`) // 引入语言包文件 const messages = await import(`../${route}/locale/${locale}/${file}.json`) diff --git a/uni-app/src/styles/common.scss b/uni-app/src/styles/common.scss index 23faa062f..7ff5c28b3 100644 --- a/uni-app/src/styles/common.scss +++ b/uni-app/src/styles/common.scss @@ -4,14 +4,4 @@ --primary-color-disabled: #9acafc; --primary-color-light: #ecf5ff; --page-bg-color: #f7f7f7; -} - -/* 多行超出隐藏 */ -.multi-hidden { - word-break: break-all; - text-overflow: ellipsis; - overflow: hidden; - display: -webkit-box; - -webkit-line-clamp: 2; - -webkit-box-orient: vertical; } \ No newline at end of file diff --git a/uni-app/src/styles/iconfont.css b/uni-app/src/styles/iconfont.css index f06c476d4..1802384bc 100644 --- a/uni-app/src/styles/iconfont.css +++ b/uni-app/src/styles/iconfont.css @@ -1,8 +1,8 @@ @font-face { font-family: "iconfont"; /* Project id 3952239 */ - src: url('//at.alicdn.com/t/c/font_3952239_d5svxl1mnu5.woff2?t=1693022806663') format('woff2'), - url('//at.alicdn.com/t/c/font_3952239_d5svxl1mnu5.woff?t=1693022806663') format('woff'), - url('//at.alicdn.com/t/c/font_3952239_d5svxl1mnu5.ttf?t=1693022806663') format('truetype'); + src: url('//at.alicdn.com/t/c/font_3952239_8vg0d3zzqa7.woff2?t=1694674505913') format('woff2'), + url('//at.alicdn.com/t/c/font_3952239_8vg0d3zzqa7.woff?t=1694674505913') format('woff'), + url('//at.alicdn.com/t/c/font_3952239_8vg0d3zzqa7.ttf?t=1694674505913') format('truetype'); } .iconfont { @@ -13,6 +13,30 @@ -moz-osx-font-smoothing: grayscale; } +.iconkaidian:before { + content: "\e6fb"; +} + +.icongouwuche:before { + content: "\e699"; +} + +.iconliebiaoxingshi:before { + content: "\e742"; +} + +.iconshangpinliebiao:before { + content: "\e61c"; +} + +.iconjiahao1:before { + content: "\e84f"; +} + +.iconjianhao:before { + content: "\e850"; +} + .iconfenxiang1:before { content: "\e64d"; } diff --git a/uni-app/src/styles/index.scss b/uni-app/src/styles/index.scss index 599c2d2c9..55466c5b7 100644 --- a/uni-app/src/styles/index.scss +++ b/uni-app/src/styles/index.scss @@ -1,3 +1,15 @@ @import 'uview-plus/index.scss'; @import 'common.scss'; @import 'iconfont.css'; + + + +/* 多行超出隐藏 */ +.multi-hidden { + word-break: break-all; + text-overflow: ellipsis; + overflow: hidden; + display: -webkit-box; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; +} diff --git a/uni-app/src/utils/interceptor.ts b/uni-app/src/utils/interceptor.ts index 23fa6e3ac..95e70cd10 100644 --- a/uni-app/src/utils/interceptor.ts +++ b/uni-app/src/utils/interceptor.ts @@ -13,7 +13,6 @@ export const redirectInterceptor = () => { uni.addInterceptor(name, { invoke(args) { const route = urlDeconstruction(args.url) - // 加载语言包 language.loadLocaleMessages(route.path, uni.getLocale()) @@ -34,7 +33,6 @@ export const redirectInterceptor = () => { export const launchInterceptor = () => { const launch = uni.getLaunchOptionsSync() launch.path = `/${launch.path}` - // 加载语言包 language.loadLocaleMessages(launch.path, uni.getLocale()) diff --git a/uni-app/src/utils/request.ts b/uni-app/src/utils/request.ts index 94d8d6339..63206f390 100644 --- a/uni-app/src/utils/request.ts +++ b/uni-app/src/utils/request.ts @@ -1,171 +1,180 @@ import useMemberStore from '@/stores/member' -import { t } from '@/locale' -import { getToken, getAppChannel } from './common' +import {t} from '@/locale' +import {getToken, getAppChannel} from './common' +import qs from 'qs'; + interface RequestConfig { - showSuccessMessage ?: boolean + showSuccessMessage?: boolean } -interface RequestOptions extends UniNamespace.RequestOptions, RequestOptions { } +interface RequestOptions extends UniNamespace.RequestOptions, RequestOptions { +} class Request { - private baseUrl : string + private baseUrl: string - private config : RequestOptions = { - url: '', - header: {} - } + private config: RequestOptions = { + url: '', + header: {} + } - constructor() { - // #ifdef H5 - this.baseUrl = import.meta.env.VITE_APP_BASE_URL || `${location.origin}/api/` - // #endif - // #ifndef H5 - this.baseUrl = import.meta.env.VITE_APP_BASE_URL - // #endif - this.baseUrl.substr(-1) != '/' && (this.baseUrl += '/') + constructor() { + // #ifdef H5 + this.baseUrl = import.meta.env.VITE_APP_BASE_URL || `${location.origin}/api/` + // #endif + // #ifndef H5 + this.baseUrl = import.meta.env.VITE_APP_BASE_URL + // #endif + this.baseUrl.substr(-1) != '/' && (this.baseUrl += '/') - try { - this.config.header[import.meta.env.VITE_REQUEST_HEADER_CHANNEL_KEY] = getAppChannel() - } catch (e) { - } + try { + this.config.header[import.meta.env.VITE_REQUEST_HEADER_CHANNEL_KEY] = getAppChannel() + } catch (e) { + } - } + } - /** - * 请求拦截器 - */ - private requestInterceptors() { - // 携带token - try { - getToken() && (this.config.header[import.meta.env.VITE_REQUEST_HEADER_TOKEN_KEY] = getToken()) - this.config.header[import.meta.env.VITE_REQUEST_HEADER_CHANNEL_KEY] = getAppChannel() - } catch (e) { - } - } + /** + * 请求拦截器 + */ + private requestInterceptors() { + // 携带token + try { + getToken() && (this.config.header[import.meta.env.VITE_REQUEST_HEADER_TOKEN_KEY] = getToken()) + this.config.header[import.meta.env.VITE_REQUEST_HEADER_CHANNEL_KEY] = getAppChannel() + } catch (e) { + } + } - public get(url : string, data : AnyObject = {}, config : RequestConfig = {}) { - config.showSuccessMessage == undefined && (config.showSuccessMessage = false) - Object.assign(this.config, config) - return this.request('GET', url, data) - } + public get(url: string, data: AnyObject = {}, config: RequestConfig = {}) { + config.showSuccessMessage == undefined && (config.showSuccessMessage = false) + Object.assign(this.config, config) + console.log('get request', url, data) + return this.request('GET', url, data) + } - public post(url : string, data : AnyObject = {}, config : RequestConfig = {}) { - config.showSuccessMessage == undefined && (config.showSuccessMessage = false) - Object.assign(this.config, config) - return this.request('POST', url, data) - } + public post(url: string, data: AnyObject = {}, config: RequestConfig = {}) { + config.showSuccessMessage == undefined && (config.showSuccessMessage = false) + Object.assign(this.config, config) + return this.request('POST', url, data) + } - public put(url : string, data : AnyObject = {}, config : RequestConfig = {}) { - config.showSuccessMessage == undefined && (config.showSuccessMessage = false) - Object.assign(this.config, config) - return this.request('PUT', url, data) - } + public put(url: string, data: AnyObject = {}, config: RequestConfig = {}) { + config.showSuccessMessage == undefined && (config.showSuccessMessage = false) + Object.assign(this.config, config) + return this.request('PUT', url, data) + } - public delete(url : string, config : RequestConfig = {}) { - config.showSuccessMessage == undefined && (config.showSuccessMessage = false) - Object.assign(this.config, config) - return this.request('DELETE', url) - } + public delete(url: string, config: RequestConfig = {}) { + config.showSuccessMessage == undefined && (config.showSuccessMessage = false) + Object.assign(this.config, config) + return this.request('DELETE', url) + } - /** - * 发送上传请求 - */ - public upload(url : string, data : AnyObject = {}, config : RequestConfig = {}) { - this.requestInterceptors() + /** + * 发送上传请求 + */ + public upload(url: string, data: AnyObject = {}, config: RequestConfig = {}) { + this.requestInterceptors() - const params = Object.assign(uni.$u.deepClone(this.config), { - url: this.baseUrl + url, - ...data - }) + const params = Object.assign(uni.$u.deepClone(this.config), { + url: this.baseUrl + url, + ...data + }) - return new Promise((resolve, reject) => { - uni.uploadFile({ - ...params, - success: res => { - const data = JSON.parse(res.data) - if (data.code == 1) { - this.config.showSuccessMessage && uni.showToast({ title: data.msg, icon: 'none' }) - resolve(data) - } else { - if (data.code == 0) { - uni.showToast({ title: data.msg, icon: 'none' }) - } else { - this.handleAuthError(data.code) - } - reject(data) - } - }, - fail: res => { - reject(res) - } - }) - }) - } - - /** - * 发送请求 - */ - private request(method : string, url : string, data ?: AnyObject) { - this.requestInterceptors() - - const params = Object.assign(uni.$u.deepClone(this.config), { - url: this.baseUrl + url, - method, - data - }) - - return new Promise((resolve, reject) => { - uni.request({ - ...params, - success: res => { - const data = res.data - if (data.code == 1) { - this.config.showSuccessMessage && uni.showToast({ title: data.msg, icon: 'none' }) - resolve(data) - } else { + return new Promise((resolve, reject) => { + uni.uploadFile({ + ...params, + success: res => { + const data = JSON.parse(res.data) + if (data.code == 1) { + this.config.showSuccessMessage && uni.showToast({title: data.msg, icon: 'none'}) + resolve(data) + } else { if (data.code == 0) { - uni.showToast({ title: data.msg, icon: 'none' }) + uni.showToast({title: data.msg, icon: 'none'}) } else { this.handleAuthError(data.code) } - reject(data) - } - }, - fail: res => { - reject(res) - }, - complete: (res) => { - this.handleRequestFail(res) - } - }) - }) - } + reject(data) + } + }, + fail: res => { + reject(res) + } + }) + }) + } - private handleAuthError(code : number) { - switch (code) { - case 401: - useMemberStore().logout() - break; - } - } + /** + * 发送请求 + */ + private request(method: string, url: string, data ?: AnyObject) { + this.requestInterceptors() - private handleRequestFail(res) { - if (res.errMsg && res.errMsg == "request:ok") { - if (typeof res.data == 'string') { - uni.showToast({ icon: 'none', title: this.baseUrl + t('requestFail') }) - return - } - } - if (res.errMsg == 'request:fail') { - uni.showToast({ icon: 'none', title: this.baseUrl + t('requestFail') }) - return - } - if (res.errMsg && res.errMsg == 'request:fail url not in domain list') { - uni.showToast({ icon: 'none', title: this.baseUrl + t('notInDomainList') }); - return - } - } + let source = { + url: this.baseUrl + url, + method, + }; + if (source.method.toUpperCase() == 'GET') { + source.url += '?' + qs.stringify(data); + } else { + source.data = data; + } + const params = Object.assign(uni.$u.deepClone(this.config), source) + + return new Promise((resolve, reject) => { + uni.request({ + ...params, + success: res => { + const data = res.data + if (data.code == 1) { + this.config.showSuccessMessage && uni.showToast({title: data.msg, icon: 'none'}) + resolve(data) + } else { + if (data.code == 0) { + uni.showToast({title: data.msg, icon: 'none'}) + } else { + this.handleAuthError(data.code) + } + reject(data) + } + }, + fail: res => { + reject(res) + }, + complete: (res) => { + this.handleRequestFail(res) + } + }) + }) + } + + private handleAuthError(code: number) { + switch (code) { + case 401: + useMemberStore().logout() + break; + } + } + + private handleRequestFail(res) { + if (res.errMsg && res.errMsg == "request:ok") { + if (typeof res.data == 'string') { + uni.showToast({icon: 'none', title: this.baseUrl + t('requestFail')}) + return + } + } + if (res.errMsg == 'request:fail') { + uni.showToast({icon: 'none', title: this.baseUrl + t('requestFail')}) + return + } + if (res.errMsg && res.errMsg == 'request:fail url not in domain list') { + uni.showToast({icon: 'none', title: this.baseUrl + t('notInDomainList')}); + return + } + } } export default new Request()