Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
jgdl
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
hookehuyr
2025-08-15 10:51:21 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f1393e98576445883dc1a15aca1845782b0e2f7f
f1393e98
1 parent
6947ba0d
feat(配置): 根据小程序环境动态设置API地址
添加getBaseUrl函数自动检测小程序运行环境并返回对应的API地址,简化环境切换流程
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
6 deletions
src/utils/config.js
src/utils/config.js
View file @
f1393e9
/*
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-08-1
2 15:09:48
* @LastEditTime: 2025-08-1
5 10:50:51
* @FilePath: /jgdl/src/utils/config.js
* @Description:
文件描述
* @Description:
环境配置文件 - 根据小程序运行环境自动切换API地址
*/
// TAG:服务器环境配置
const
BASE_URL
=
"https://oa-dev.onwall.cn"
;
// 测试服务器
// const BASE_URL = "https://jiangedianlv.onwall.cn"; // 正式服务器
export
default
BASE_URL
/**
* 获取当前小程序运行环境对应的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'
...
...
Please
register
or
login
to post a comment