feat: 环境变量方案管理API和H5地址
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -28,7 +28,7 @@ steps:
|
||||
- name: dev-build
|
||||
image: ccr.ccs.tencentyun.com/violin/node:22-bookworm
|
||||
commands:
|
||||
- npm run build:h5
|
||||
- npm run build:h5 -- --mode development
|
||||
volumes:
|
||||
- name: node-cache
|
||||
path: /root/.npm
|
||||
@@ -85,7 +85,7 @@ steps:
|
||||
- name: prod-build
|
||||
image: ccr.ccs.tencentyun.com/violin/node:22-bookworm
|
||||
commands:
|
||||
- npm run build:h5
|
||||
- npm run build:h5 -- --mode production
|
||||
volumes:
|
||||
- name: node-cache
|
||||
path: /root/.npm
|
||||
|
||||
3
.env.development
Normal file
3
.env.development
Normal file
@@ -0,0 +1,3 @@
|
||||
# 开发环境
|
||||
VITE_API_BASE_URL=http://localhost:8080/api/v1
|
||||
VITE_H5_BASE_URL=http://localhost:8080
|
||||
3
.env.production
Normal file
3
.env.production
Normal file
@@ -0,0 +1,3 @@
|
||||
# 生产环境
|
||||
VITE_API_BASE_URL=https://sales.violin-work.online/api/v1
|
||||
VITE_H5_BASE_URL=https://sales.violin-work.online
|
||||
16
.gitignore
vendored
Normal file
16
.gitignore
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
# 本地环境变量覆盖(不提交)
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
# 构建输出
|
||||
dist/
|
||||
unpackage/
|
||||
|
||||
# IDE
|
||||
.idea/
|
||||
.vscode/
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
@@ -1,5 +1,5 @@
|
||||
// API基础配置
|
||||
const BASE_URL = 'https://sales.violin-work.online/api/v1'
|
||||
const BASE_URL = import.meta.env.VITE_API_BASE_URL || 'https://sales.violin-work.online/api/v1'
|
||||
|
||||
// 请求拦截器
|
||||
const request = (url, method, query = {}, data = {}) => {
|
||||
|
||||
@@ -217,7 +217,7 @@ export default {
|
||||
},
|
||||
shareOrder() {
|
||||
// 构建分享链接(包含订单号和客户ID)
|
||||
const h5BaseUrl = 'https://sales.violin-work.online/h5'
|
||||
const h5BaseUrl = import.meta.env.VITE_H5_BASE_URL
|
||||
const customerId = this.order.customerId || ''
|
||||
const shareUrl = `${h5BaseUrl}/#/pages/share/order?orderNo=${this.order.orderNo}&customerId=${customerId}`
|
||||
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import { defineConfig, loadEnv } from 'vite'
|
||||
import uni from '@dcloudio/vite-plugin-uni'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
uni()
|
||||
],
|
||||
root: '.',
|
||||
build: {
|
||||
rollupOptions: {
|
||||
input: './index.html'
|
||||
export default defineConfig(({ mode }) => {
|
||||
// 加载当前环境的环境变量
|
||||
const env = loadEnv(mode, process.cwd())
|
||||
|
||||
return {
|
||||
plugins: [
|
||||
uni()
|
||||
],
|
||||
root: '.',
|
||||
build: {
|
||||
rollupOptions: {
|
||||
input: './index.html'
|
||||
}
|
||||
},
|
||||
define: {
|
||||
// 注入环境变量到代码中
|
||||
'import.meta.env.VITE_API_BASE_URL': JSON.stringify(env.VITE_API_BASE_URL || 'https://sales.violin-work.online/api/v1'),
|
||||
'import.meta.env.VITE_H5_BASE_URL': JSON.stringify(env.VITE_H5_BASE_URL || 'https://sales.violin-work.online')
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user