feat(env): 新增环境识别,网关地址按环境自动切换
- 新增 utils/env,用 wx.getAccountInfoSync().miniProgram.envVersion 识别 develop/trial/release - request 与 lefu 的地址由硬编码改为按环境映射,develop/trial 走测试网关,release 走正式网关 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
b4b2d2c7f3
commit
b94a6780f0
@@ -1,11 +1,25 @@
|
|||||||
import type { LeFuConfig } from './types'
|
import type { LeFuConfig } from './types'
|
||||||
|
import { ENV, type EnvType } from '../utils/env/index'
|
||||||
|
|
||||||
|
/** 各环境配网网关地址:develop / trial 走测试网关,release 走正式网关 */
|
||||||
|
const DOMAINS: Record<EnvType, { domain1: string; domain2: string }> = {
|
||||||
|
develop: {
|
||||||
|
domain1: 'http://10.10.10.10:8889',
|
||||||
|
domain2: 'http://10.10.10.10:8889/weight',
|
||||||
|
},
|
||||||
|
trial: {
|
||||||
|
domain1: 'http://10.10.10.10:8889',
|
||||||
|
domain2: 'http://10.10.10.10:8889/weight',
|
||||||
|
},
|
||||||
|
release: {
|
||||||
|
domain1: 'http://device.shuziweidao.com:80/gateway',
|
||||||
|
domain2: 'http://device.shuziweidao.com:80/weight',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
/** 乐福 SDK 配置 */
|
/** 乐福 SDK 配置 */
|
||||||
export const LEFU_CONFIG: LeFuConfig = {
|
export const LEFU_CONFIG: LeFuConfig = {
|
||||||
key: 'lefudc91611833e18d94',
|
key: 'lefudc91611833e18d94',
|
||||||
secret: 'eQ50JYimMp0X7uhNLj6D3lTEk4TUUvEG7dvaqKM9t1U=',
|
secret: 'eQ50JYimMp0X7uhNLj6D3lTEk4TUUvEG7dvaqKM9t1U=',
|
||||||
// domain1: 'http://10.10.10.10:8889',
|
...DOMAINS[ENV],
|
||||||
// domain2: 'http://10.10.10.10:8889/weight',
|
|
||||||
domain1: 'http://device.shuziweidao.com:80/gateway',
|
|
||||||
domain2: 'http://device.shuziweidao.com:80/weight',
|
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+12
@@ -0,0 +1,12 @@
|
|||||||
|
import type { EnvType } from './types'
|
||||||
|
|
||||||
|
export type { EnvType }
|
||||||
|
|
||||||
|
/** 获取当前运行环境,基础库不支持 getAccountInfoSync 时回退 develop */
|
||||||
|
export const ENV: EnvType = (() => {
|
||||||
|
try {
|
||||||
|
return wx.getAccountInfoSync().miniProgram.envVersion as EnvType
|
||||||
|
} catch {
|
||||||
|
return 'develop'
|
||||||
|
}
|
||||||
|
})()
|
||||||
Vendored
+2
@@ -0,0 +1,2 @@
|
|||||||
|
/** 小程序运行环境:develop 开发版 / trial 体验版 / release 正式版 */
|
||||||
|
export type EnvType = 'develop' | 'trial' | 'release'
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
// TODO: 替换为实际接口地址
|
import { ENV, type EnvType } from '../env/index'
|
||||||
const IS_DEV = true
|
|
||||||
|
|
||||||
export const BASE_URL = IS_DEV
|
/** 各环境接口网关地址:develop / trial 走测试网关,release 走正式网关 */
|
||||||
? 'http://10.10.10.10:8889/'
|
const BASE_URLS: Record<EnvType, string> = {
|
||||||
: ''
|
develop: 'http://10.10.10.10:8889/',
|
||||||
|
trial: 'http://10.10.10.10:8889/',
|
||||||
|
release: 'https://device.shuziweidao.com/gateway/',
|
||||||
|
}
|
||||||
|
|
||||||
|
export const BASE_URL = BASE_URLS[ENV]
|
||||||
|
|
||||||
export const TIMEOUT = 30000
|
export const TIMEOUT = 30000
|
||||||
|
|||||||
Reference in New Issue
Block a user