环境切换
小程序有四个环境
- 开发环境
- 体验版(测试环境)
- 灰度环境(发布正式版时可选)
- 正式环境
通过内置的函数getAccountInfoSync返回客户端**账号信息**
getAccountInfoSync函数返回值
返回两个对象:miniProgram和plugin
miniProgram返回值
| 结构属性 | 类型 | 说明 |
|---|---|---|
| appId | string | 小程序 appId |
| envVersion | string | 小程序版本 |
| version | string | 线上小程序版本号 |
/**
* 域名动态切换函数
* @param {object} config 分别配置:开发、体验、正式三个环境
*/
function envControl(config) {
const { miniProgram: { envVersion } } = wx.getAccountInfoSync();
const { develop, trial, release } = config
const configList = { develop, trial, release }
console.log('项目环境 ------',envVersion)
return configList[envVersion]
}
module.exports = {
baseUrl: envControl({
develop: 'https://yyzxt.sun309.com',
trial: 'https://yyzxt.sun309.com',
release: 'https://yctoss.mhealth100.com',
})
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18