| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- /**
- * 小程序环境开关 —— **只改这一处** 即可切换本机 / 测试 / 生产 / 本机联调 H5
- *
- * | APP_ENV 值 | 用途 |
- * |------------------|------|
- * | `local` | 本机 backend + 本机 web-admin |
- * | `test` | 测试门户(API / H5 / 静态 均 9911) |
- * | `testLocalH5` | 测试 API + 本机 H5(仅联调 webview 样式;需本机 `pnpm dev` 且代理到测试 API) |
- * | `production` | 生产门户 https://w.shanxiachem.com |
- *
- * 上生产:改成 `export const APP_ENV = 'production'`,再执行 `npm run release:check-api`
- */
- export const APP_ENV = 'local'
- /** 微信小程序 AppID(生产正式号;测试号若不同可按环境再拆) */
- export const WECHAT_MP_APPID = 'wx7db1ddb2a90c9425'
- /**
- * 环境预设(由生产 Web https://w.shanxiachem.com/ 与部署文档核对)
- *
- * | 项 | 生产实测 |
- * |----|----------|
- * | Web | https://w.shanxiachem.com/ |
- * | API | https://w.shanxiachem.com/api |
- * | 静态资源 | https://w.shanxiachem.com/shanxia-static/ |
- * | MinIO 附件 | https://res.shanxiachem.com/ruoyi |
- */
- export const ENV_PRESETS = {
- local: {
- key: 'local',
- label: '本机',
- apiBaseUrl: 'http://127.0.0.1:8000/api',
- staticAssetsBaseUrl: 'http://121.43.228.102:9911/shanxia-static/',
- webOrigin: 'http://127.0.0.1:3006',
- minioBaseUrl: 'http://47.99.164.66:20004/zkxw'
- },
- test: {
- key: 'test',
- label: '测试',
- apiBaseUrl: 'http://121.43.228.102:9911/api',
- staticAssetsBaseUrl: 'http://121.43.228.102:9911/shanxia-static/',
- webOrigin: 'http://121.43.228.102:9911',
- minioBaseUrl: 'http://121.43.228.102:9911/ruoyi'
- },
- /** 测试业务数据 + 本机 H5 资源(改样式时用,不用于发测试包) */
- testLocalH5: {
- key: 'testLocalH5',
- label: '测试API+本机H5',
- apiBaseUrl: 'http://121.43.228.102:9911/api',
- staticAssetsBaseUrl: 'http://121.43.228.102:9911/shanxia-static/',
- webOrigin: 'http://127.0.0.1:3006',
- minioBaseUrl: 'http://121.43.228.102:9911/ruoyi'
- },
- production: {
- key: 'production',
- label: '生产',
- apiBaseUrl: 'https://w.shanxiachem.com/api',
- staticAssetsBaseUrl: 'https://w.shanxiachem.com/shanxia-static/',
- webOrigin: 'https://w.shanxiachem.com',
- minioBaseUrl: 'https://res.shanxiachem.com/ruoyi'
- }
- }
- const preset = ENV_PRESETS[APP_ENV] || ENV_PRESETS.local
- export const CURRENT_ENV = preset
- export const IS_PRODUCTION = preset.key === 'production'
- export const IS_TEST = preset.key === 'test'
- export const IS_TEST_LOCAL_H5 = preset.key === 'testLocalH5'
- export const IS_LOCAL = preset.key === 'local'
- export const API_BASE_URL = preset.apiBaseUrl
- export const STATIC_ASSETS_BASE_URL = preset.staticAssetsBaseUrl
- export const WEB_ORIGIN = preset.webOrigin
- export const MINIO_BASE_URL = preset.minioBaseUrl
- /** 历史 MinIO 公网前缀 → 展示时改写到当前 MINIO_BASE_URL */
- const LEGACY_MINIO_BASE_PREFIXES = [
- 'https://w.shanxiachem.com/ruoyi',
- 'http://w.shanxiachem.com/ruoyi',
- 'https://121.43.228.102:9911/ruoyi',
- 'http://121.43.228.102:9911/ruoyi',
- 'https://www.chengyantek.cn/zkxw',
- 'http://www.chengyantek.cn/zkxw',
- 'http://47.99.164.66:20004/zkxw',
- 'https://47.99.164.66:20004/zkxw'
- ]
- /** 拼 MinIO 完整访问地址;旧主机绝对 URL 改写到当前环境前缀 */
- export function resolveMinioUrl(url) {
- const trimmed = String(url || '').trim()
- if (!trimmed) return ''
- const base = String(
- (ENV_PRESETS[APP_ENV] || ENV_PRESETS.local).minioBaseUrl || ''
- ).replace(/\/$/, '')
- if (/^https?:\/\//i.test(trimmed)) {
- if (base && trimmed.toLowerCase().startsWith(base.toLowerCase())) {
- return trimmed
- }
- for (const prefix of LEGACY_MINIO_BASE_PREFIXES) {
- if (trimmed.toLowerCase().startsWith(prefix.toLowerCase())) {
- const objectPath = trimmed.slice(prefix.length).replace(/^\//, '')
- return base ? `${base}/${objectPath}` : trimmed
- }
- }
- return trimmed
- }
- let rel = trimmed.replace(/^\//, '')
- if (base.endsWith('/ruoyi') && (rel === 'ruoyi' || rel.startsWith('ruoyi/'))) {
- rel = rel.replace(/^ruoyi\/?/, '')
- }
- if (base.endsWith('/zkxw') && (rel === 'zkxw' || rel.startsWith('zkxw/'))) {
- rel = rel.replace(/^zkxw\/?/, '')
- }
- return base ? `${base}/${rel}` : trimmed
- }
- /** 每次调用按当前 APP_ENV 取值,避免热更新后 api.js 里拷贝的常量仍指向旧环境 */
- export function resolveApiBase() {
- return (ENV_PRESETS[APP_ENV] || ENV_PRESETS.local).apiBaseUrl
- }
- export function resolveWebOrigin() {
- return (ENV_PRESETS[APP_ENV] || ENV_PRESETS.local).webOrigin
- }
|