config.js
1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-08-27 20:41:05
* @FilePath: /lls_program/src/utils/config.js
* @Description: 环境配置文件 - 根据小程序运行环境自动切换API地址
*/
/**
* 获取当前小程序运行环境对应的API地址
* @returns {string} 对应环境的API基础地址
*/
function getBaseUrl() {
// 获取当前小程序的运行环境
const accountInfo = wx.getAccountInfoSync();
const envVersion = accountInfo.miniProgram.envVersion;
// 定义不同环境的服务器地址
let baseUrl = '';
switch (envVersion) {
case 'develop': // 开发版
baseUrl = 'https://oa-dev.onwall.cn';
break;
case 'trial': // 体验版
baseUrl = 'https://oa-dev.onwall.cn'; // 体验版暂时使用开发环境
break;
case 'release': // 正式版
baseUrl = 'https://jiangedianlv.onwall.cn';
break;
default: // 未知环境,默认使用正式版地址
baseUrl = 'https://jiangedianlv.onwall.cn';
}
// eslint-disable-next-line no-console
console.log(`当前小程序环境: ${envVersion}, 使用API地址: ${baseUrl}`);
return baseUrl;
}
// 导出API基础地址
const BASE_URL = getBaseUrl();
export default BASE_URL;
// 默认封面图片地址
export const DEFAULT_COVER_IMG = 'https://images.unsplash.com/photo-1558981806-ec527fa84c39?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'