modify
This commit is contained in:
parent
b68a1ed70a
commit
bc8ea41ef7
|
|
@ -0,0 +1,3 @@
|
|||
# 公共配置
|
||||
VITE_APP_NAME = GroupBuying
|
||||
VITE_APP_VERSION = 1.0.0
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
NODE_ENV = development
|
||||
VITE_API_BASE = http://dev-api.example.com
|
||||
VITE_DEBUG_MODE = true
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
NODE_ENV = production
|
||||
VITE_API_BASE = https://api.example.com
|
||||
VITE_DEBUG_MODE = false
|
||||
File diff suppressed because it is too large
Load Diff
31
package.json
31
package.json
|
|
@ -1,35 +1,36 @@
|
|||
{
|
||||
"name": "uni-preset-vue",
|
||||
"version": "0.0.0",
|
||||
"name": "group-buying",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"dev:custom": "uni -p",
|
||||
"dev:h5": "uni",
|
||||
"dev:custom": "uni -p --mode development",
|
||||
"dev:h5": "uni --mode development",
|
||||
"dev:h5:ssr": "uni --ssr",
|
||||
"dev:mp-alipay": "uni -p mp-alipay",
|
||||
"dev:mp-baidu": "uni -p mp-baidu",
|
||||
"dev:mp-alipay": "uni -p mp-alipay --mode development",
|
||||
"dev:mp-baidu": "uni -p mp-baidu --mode development",
|
||||
"dev:mp-jd": "uni -p mp-jd",
|
||||
"dev:mp-kuaishou": "uni -p mp-kuaishou",
|
||||
"dev:mp-lark": "uni -p mp-lark",
|
||||
"dev:mp-qq": "uni -p mp-qq",
|
||||
"dev:mp-qq": "uni -p mp-qq --mode development",
|
||||
"dev:mp-toutiao": "uni -p mp-toutiao",
|
||||
"dev:mp-harmony": "uni -p mp-harmony",
|
||||
"dev:mp-weixin": "uni -p mp-weixin",
|
||||
"dev:mp-weixin": "uni -p mp-weixin --mode development",
|
||||
"dev:mp-xhs": "uni -p mp-xhs",
|
||||
"dev:quickapp-webview": "uni -p quickapp-webview",
|
||||
"dev:quickapp-webview-huawei": "uni -p quickapp-webview-huawei",
|
||||
"dev:quickapp-webview-union": "uni -p quickapp-webview-union",
|
||||
"build:custom": "uni build -p",
|
||||
"build:h5": "uni build",
|
||||
"build:staging": "uni build --mode staging",
|
||||
"build:custom": "uni build -p --mode production",
|
||||
"build:h5": "uni build --mode production",
|
||||
"build:h5:ssr": "uni build --ssr",
|
||||
"build:mp-alipay": "uni build -p mp-alipay",
|
||||
"build:mp-baidu": "uni build -p mp-baidu",
|
||||
"build:mp-alipay": "uni build -p mp-alipay --mode production",
|
||||
"build:mp-baidu": "uni build -p mp-baidu --mode production",
|
||||
"build:mp-jd": "uni build -p mp-jd",
|
||||
"build:mp-kuaishou": "uni build -p mp-kuaishou",
|
||||
"build:mp-lark": "uni build -p mp-lark",
|
||||
"build:mp-qq": "uni build -p mp-qq",
|
||||
"build:mp-toutiao": "uni build -p mp-toutiao",
|
||||
"build:mp-harmony": "uni build -p mp-harmony",
|
||||
"build:mp-weixin": "uni build -p mp-weixin",
|
||||
"build:mp-weixin": "uni build -p mp-weixin --mode production",
|
||||
"build:mp-xhs": "uni build -p mp-xhs",
|
||||
"build:quickapp-webview": "uni build -p quickapp-webview",
|
||||
"build:quickapp-webview-huawei": "uni build -p quickapp-webview-huawei",
|
||||
|
|
@ -63,6 +64,7 @@
|
|||
"@dcloudio/uni-stacktracey": "3.0.0-4050720250324001",
|
||||
"@dcloudio/vite-plugin-uni": "3.0.0-4050720250324001",
|
||||
"@vue/runtime-core": "^3.4.21",
|
||||
"concurrently": "^9.1.2",
|
||||
"vite": "5.2.8"
|
||||
},
|
||||
"json-comments": {
|
||||
|
|
@ -71,6 +73,9 @@
|
|||
"tabBar.color": " 默认文字颜色",
|
||||
"tabBar.selectedColor": "选中时文字颜色",
|
||||
"tabBar.backgroundColor": "背景颜色"
|
||||
},
|
||||
"package.json": {
|
||||
"scripts.build:staging": "构建测试"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -84,6 +84,9 @@ importers:
|
|||
'@vue/runtime-core':
|
||||
specifier: ^3.4.21
|
||||
version: 3.5.13
|
||||
concurrently:
|
||||
specifier: ^9.1.2
|
||||
version: 9.1.2
|
||||
vite:
|
||||
specifier: 5.2.8
|
||||
version: 5.2.8(@types/node@22.15.3)(terser@5.39.0)
|
||||
|
|
@ -1717,6 +1720,10 @@ packages:
|
|||
cliui@7.0.4:
|
||||
resolution: {integrity: sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==}
|
||||
|
||||
cliui@8.0.1:
|
||||
resolution: {integrity: sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
co@4.6.0:
|
||||
resolution: {integrity: sha512-QVb0dM5HvG+uaxitm8wONl7jltx8dqhfU33DcqtOZcLSVIKSDDLDi7+0LbAKiyI8hD9u42m2YxXSkMGWThaecQ==}
|
||||
engines: {iojs: '>= 1.0.0', node: '>= 0.12.0'}
|
||||
|
|
@ -1744,6 +1751,11 @@ packages:
|
|||
concat-map@0.0.1:
|
||||
resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==}
|
||||
|
||||
concurrently@9.1.2:
|
||||
resolution: {integrity: sha512-H9MWcoPsYddwbOGM6difjVwVZHl63nwMEwDJG/L7VGtuaJhb12h2caPG2tVPWs7emuYix252iGfqOyrz1GczTQ==}
|
||||
engines: {node: '>=18'}
|
||||
hasBin: true
|
||||
|
||||
confbox@0.1.8:
|
||||
resolution: {integrity: sha512-RMtmw0iFkeR4YV+fUOSucriAQNb9g8zFR52MWCtl+cCZOFRNL6zeB395vPzFhEjjn4fMxXudmELnl/KF/WrK6w==}
|
||||
|
||||
|
|
@ -2976,6 +2988,9 @@ packages:
|
|||
run-parallel@1.2.0:
|
||||
resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==}
|
||||
|
||||
rxjs@7.8.2:
|
||||
resolution: {integrity: sha512-dhKf903U/PQZY6boNNtAGdWbG85WAbjT/1xYoZIC7FAY0yWapOBQVsVrDl58W86//e1VpMNBtRV4MaXfdMySFA==}
|
||||
|
||||
safe-area-insets@1.4.1:
|
||||
resolution: {integrity: sha512-r/nRWTjFGhhm3w1Z6Kd/jY11srN+lHt2mNl1E/emQGW8ic7n3Avu4noibklfSM+Y34peNphHD/BSZecav0sXYQ==}
|
||||
|
||||
|
|
@ -3023,6 +3038,10 @@ packages:
|
|||
resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
shell-quote@1.8.2:
|
||||
resolution: {integrity: sha512-AzqKpGKjrj7EM6rKVQEPpB288oCfnrEIuyoT9cyF4nmGa7V8Zk6f7RRqYisX8X9m+Q7bd632aZW4ky7EhbQztA==}
|
||||
engines: {node: '>= 0.4'}
|
||||
|
||||
side-channel-list@1.0.0:
|
||||
resolution: {integrity: sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==}
|
||||
engines: {node: '>= 0.4'}
|
||||
|
|
@ -3172,6 +3191,13 @@ packages:
|
|||
resolution: {integrity: sha512-15Ih7phfcdP5YxqiB+iDtLoaTz4Nd35+IiAv0kQ5FNKHzXgdWqPoTIqEDDJmXceQt4JZk6lVPT8lnDlPpGDppw==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
tree-kill@1.2.2:
|
||||
resolution: {integrity: sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==}
|
||||
hasBin: true
|
||||
|
||||
tslib@2.8.1:
|
||||
resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==}
|
||||
|
||||
type-detect@4.0.8:
|
||||
resolution: {integrity: sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==}
|
||||
engines: {node: '>=4'}
|
||||
|
|
@ -3434,10 +3460,18 @@ packages:
|
|||
resolution: {integrity: sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==}
|
||||
engines: {node: '>=10'}
|
||||
|
||||
yargs-parser@21.1.1:
|
||||
resolution: {integrity: sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
yargs@16.2.0:
|
||||
resolution: {integrity: sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==}
|
||||
engines: {node: '>=10'}
|
||||
|
||||
yargs@17.7.2:
|
||||
resolution: {integrity: sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
snapshots:
|
||||
|
||||
'@ampproject/remapping@2.3.0':
|
||||
|
|
@ -5952,6 +5986,12 @@ snapshots:
|
|||
strip-ansi: 6.0.1
|
||||
wrap-ansi: 7.0.0
|
||||
|
||||
cliui@8.0.1:
|
||||
dependencies:
|
||||
string-width: 4.2.3
|
||||
strip-ansi: 6.0.1
|
||||
wrap-ansi: 7.0.0
|
||||
|
||||
co@4.6.0: {}
|
||||
|
||||
collect-v8-coverage@1.0.2: {}
|
||||
|
|
@ -5972,6 +6012,16 @@ snapshots:
|
|||
|
||||
concat-map@0.0.1: {}
|
||||
|
||||
concurrently@9.1.2:
|
||||
dependencies:
|
||||
chalk: 4.1.2
|
||||
lodash: 4.17.21
|
||||
rxjs: 7.8.2
|
||||
shell-quote: 1.8.2
|
||||
supports-color: 8.1.1
|
||||
tree-kill: 1.2.2
|
||||
yargs: 17.7.2
|
||||
|
||||
confbox@0.1.8: {}
|
||||
|
||||
confbox@0.2.2: {}
|
||||
|
|
@ -7397,6 +7447,10 @@ snapshots:
|
|||
dependencies:
|
||||
queue-microtask: 1.2.3
|
||||
|
||||
rxjs@7.8.2:
|
||||
dependencies:
|
||||
tslib: 2.8.1
|
||||
|
||||
safe-area-insets@1.4.1: {}
|
||||
|
||||
safe-buffer@5.2.1: {}
|
||||
|
|
@ -7450,6 +7504,8 @@ snapshots:
|
|||
|
||||
shebang-regex@3.0.0: {}
|
||||
|
||||
shell-quote@1.8.2: {}
|
||||
|
||||
side-channel-list@1.0.0:
|
||||
dependencies:
|
||||
es-errors: 1.3.0
|
||||
|
|
@ -7594,6 +7650,10 @@ snapshots:
|
|||
dependencies:
|
||||
punycode: 2.3.1
|
||||
|
||||
tree-kill@1.2.2: {}
|
||||
|
||||
tslib@2.8.1: {}
|
||||
|
||||
type-detect@4.0.8: {}
|
||||
|
||||
type-fest@0.21.3: {}
|
||||
|
|
@ -7811,6 +7871,8 @@ snapshots:
|
|||
|
||||
yargs-parser@20.2.9: {}
|
||||
|
||||
yargs-parser@21.1.1: {}
|
||||
|
||||
yargs@16.2.0:
|
||||
dependencies:
|
||||
cliui: 7.0.4
|
||||
|
|
@ -7820,3 +7882,13 @@ snapshots:
|
|||
string-width: 4.2.3
|
||||
y18n: 5.0.8
|
||||
yargs-parser: 20.2.9
|
||||
|
||||
yargs@17.7.2:
|
||||
dependencies:
|
||||
cliui: 8.0.1
|
||||
escalade: 3.2.0
|
||||
get-caller-file: 2.0.5
|
||||
require-directory: 2.1.1
|
||||
string-width: 4.2.3
|
||||
y18n: 5.0.8
|
||||
yargs-parser: 21.1.1
|
||||
|
|
|
|||
|
|
@ -1,28 +1,24 @@
|
|||
{
|
||||
"name" : "",
|
||||
"appid" : "",
|
||||
"description" : "",
|
||||
"versionName" : "1.0.0",
|
||||
"versionCode" : "100",
|
||||
"transformPx" : false,
|
||||
/* 5+App特有相关 */
|
||||
"app-plus" : {
|
||||
"usingComponents" : true,
|
||||
"nvueStyleCompiler" : "uni-app",
|
||||
"compilerVersion" : 3,
|
||||
"splashscreen" : {
|
||||
"alwaysShowBeforeRender" : true,
|
||||
"waiting" : true,
|
||||
"autoclose" : true,
|
||||
"delay" : 0
|
||||
"name": "",
|
||||
"appid": "",
|
||||
"description": "",
|
||||
"versionName": "1.0.0",
|
||||
"versionCode": "100",
|
||||
"transformPx": false,
|
||||
"app-plus": {
|
||||
"usingComponents": true,
|
||||
"nvueStyleCompiler": "uni-app",
|
||||
"compilerVersion": 3,
|
||||
"splashscreen": {
|
||||
"alwaysShowBeforeRender": true,
|
||||
"waiting": true,
|
||||
"autoclose": true,
|
||||
"delay": 0
|
||||
},
|
||||
/* 模块配置 */
|
||||
"modules" : {},
|
||||
/* 应用发布信息 */
|
||||
"distribute" : {
|
||||
/* android打包配置 */
|
||||
"android" : {
|
||||
"permissions" : [
|
||||
"modules": {},
|
||||
"distribute": {
|
||||
"android": {
|
||||
"permissions": [
|
||||
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
|
||||
|
|
@ -40,33 +36,29 @@
|
|||
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
|
||||
]
|
||||
},
|
||||
/* ios打包配置 */
|
||||
"ios" : {},
|
||||
/* SDK配置 */
|
||||
"sdkConfigs" : {}
|
||||
"ios": {},
|
||||
"sdkConfigs": {}
|
||||
}
|
||||
},
|
||||
/* 快应用特有相关 */
|
||||
"quickapp" : {},
|
||||
/* 小程序特有相关 */
|
||||
"mp-weixin" : {
|
||||
"appid" : "",
|
||||
"setting" : {
|
||||
"urlCheck" : false
|
||||
"quickapp": {},
|
||||
"mp-weixin": {
|
||||
"appid": "",
|
||||
"setting": {
|
||||
"urlCheck": false
|
||||
},
|
||||
"usingComponents" : true
|
||||
"usingComponents": true
|
||||
},
|
||||
"mp-alipay" : {
|
||||
"usingComponents" : true
|
||||
"mp-alipay": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"mp-baidu" : {
|
||||
"usingComponents" : true
|
||||
"mp-baidu": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"mp-toutiao" : {
|
||||
"usingComponents" : true
|
||||
"mp-toutiao": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"uniStatistics": {
|
||||
"uniStatistics": {
|
||||
"enable": false
|
||||
},
|
||||
"vueVersion" : "3"
|
||||
}
|
||||
"vueVersion": "3"
|
||||
}
|
||||
|
|
@ -0,0 +1,137 @@
|
|||
class Request {
|
||||
constructor() {
|
||||
// 全局默认配置
|
||||
this.config = {
|
||||
baseURL: import.meta.env.VITE_API_BASE,
|
||||
timeout: 10000,
|
||||
header: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
}
|
||||
|
||||
// 开发环境打印日志
|
||||
if (import.meta.env.VITE_DEBUG_MODE === 'true') {
|
||||
this._enableDebugLog()
|
||||
}
|
||||
|
||||
// 拦截器存储
|
||||
this.interceptors = {
|
||||
request: [],
|
||||
response: []
|
||||
}
|
||||
|
||||
// 请求队列(用于取消请求)
|
||||
this.pendingRequests = new Map()
|
||||
}
|
||||
|
||||
// 调试日志
|
||||
_enableDebugLog() {
|
||||
const originalRequest = this.request
|
||||
this.request = async function(config) {
|
||||
console.log('[HTTP Request]', config)
|
||||
const start = Date.now()
|
||||
try {
|
||||
const res = await originalRequest.call(this, config)
|
||||
console.log(`[HTTP Response] ${Date.now() - start}ms`, res)
|
||||
return res
|
||||
} catch (err) {
|
||||
console.error(`[HTTP Error] ${Date.now() - start}ms`, err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 小程序 HTTPS 强制转换
|
||||
_fixUrlProtocol(url) {
|
||||
// #ifdef MP-WEIXIN
|
||||
return url.replace(/^http:/, 'https:')
|
||||
// #else
|
||||
return url
|
||||
// #endif
|
||||
}
|
||||
// 核心请求方法
|
||||
async _request(config) {
|
||||
// 合并配置
|
||||
const mergedConfig = {
|
||||
...this.config,
|
||||
...config,
|
||||
url: this._fixUrlProtocol(config.url)
|
||||
}
|
||||
|
||||
// 生成请求标识
|
||||
const requestKey = `${mergedConfig.method}-${mergedConfig.url}`
|
||||
const controller = new AbortController()
|
||||
this.pendingRequests.set(requestKey, controller)
|
||||
|
||||
// 构建完整URL
|
||||
const fullUrl = `${mergedConfig.baseURL}${mergedConfig.url}`
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
...mergedConfig,
|
||||
url: fullUrl,
|
||||
signal: controller.signal,
|
||||
success: (res) => resolve(res),
|
||||
fail: (err) => reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 执行拦截器链
|
||||
async _runInterceptors(type, value) {
|
||||
let chain = type === 'request'
|
||||
? [...this.interceptors.request, this._request, undefined]
|
||||
: [undefined, ...this.interceptors.response]
|
||||
|
||||
let promise = Promise.resolve(value)
|
||||
for (let i = 0; i < chain.length; i += 2) {
|
||||
const thenFn = chain[i]
|
||||
const catchFn = chain[i + 1]
|
||||
promise = promise.then(thenFn, catchFn)
|
||||
}
|
||||
return promise
|
||||
}
|
||||
|
||||
// 公开请求方法
|
||||
async request(config) {
|
||||
try {
|
||||
// 执行请求拦截
|
||||
const processedConfig = await this._runInterceptors('request', config)
|
||||
// 发起请求
|
||||
const response = await this._request(processedConfig)
|
||||
// 执行响应拦截
|
||||
return this._runInterceptors('response', response)
|
||||
} catch (error) {
|
||||
// 统一错误处理
|
||||
this._handleError(error)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
|
||||
// 快捷方法
|
||||
get(url, config = {}) {
|
||||
return this.request({ ...config, url, method: 'GET' })
|
||||
}
|
||||
|
||||
post(url, data, config = {}) {
|
||||
return this.request({ ...config, url, data, method: 'POST' })
|
||||
}
|
||||
|
||||
// 错误处理
|
||||
_handleError(error) {
|
||||
let message = '请求失败'
|
||||
if (error.errMsg?.includes('timeout')) message = '网络超时'
|
||||
if (error.statusCode === 404) message = '接口不存在'
|
||||
uni.showToast({ title: message, icon: 'none' })
|
||||
}
|
||||
|
||||
// 取消请求
|
||||
cancelRequest(url, method = 'GET') {
|
||||
const key = `${method}-${url}`
|
||||
const controller = this.pendingRequests.get(key)
|
||||
controller?.abort()
|
||||
this.pendingRequests.delete(key)
|
||||
}
|
||||
}
|
||||
|
||||
export const http = new Request()
|
||||
Loading…
Reference in New Issue