xsh_1997 hai 2 semanas
pai
achega
f30209808e

+ 5 - 0
ruoyi-jiaoyi/.env.development

@@ -0,0 +1,5 @@
1
+# 开发环境(对齐 ruoyi-ui/.env.development)
2
+VITE_APP_TITLE=交易市场
3
+VITE_APP_BASE_API=/dev-api
4
+# H5 直连后端时使用(与 ruoyi-ui/vue.config.js baseUrl 一致)
5
+VITE_APP_API_HOST=http://192.168.1.6:8010

+ 3 - 0
ruoyi-jiaoyi/.env.production

@@ -0,0 +1,3 @@
1
+# 生产环境(对齐 ruoyi-ui/.env.production)
2
+VITE_APP_TITLE=交易市场
3
+VITE_APP_BASE_API=/prod-api

+ 24 - 12
ruoyi-jiaoyi/config/index.js

@@ -1,25 +1,37 @@
1 1
 /**
2
- * 接口根地址配置
2
+ * 接口根地址(与 ruoyi-ui 的 VUE_APP_BASE_API 对齐)
3 3
  *
4
- * 若依后端真实路径是 /login、/getInfo(没有 /dev-api 前缀)。
5
- * PC 端 ruoyi-ui 的 /dev-api 仅用于 H5 开发代理,代理会去掉该前缀再转发。
4
+ * - 开发:.env.development → /dev-api(H5 代理)或 VITE_APP_API_HOST 直连
5
+ * - 生产:.env.production → /prod-api(与 ruoyi-ui/.env.production 一致,由 Nginx 转发)
6
+ *
7
+ * 打包 H5:uni build -p h5
6 8
  */
7 9
 
8
-/** 与 ruoyi-ui/vue.config.js 中 baseUrl 一致 */
9
-export const DEV_API_HOST = 'http://192.168.1.6:8010'
10
+const apiHost = String(import.meta.env.VITE_APP_API_HOST || 'http://192.168.1.6:8010').replace(/\/$/, '')
11
+
12
+/** 与 ruoyi-ui 的 VUE_APP_BASE_API 同源配置(dev/prod 由 .env 注入) */
13
+const envBaseApi = String(import.meta.env.VITE_APP_BASE_API || '').trim()
10 14
 
11 15
 /**
12
- * H5 是否走 /dev-api 开发代理(需 vite.config.js rewrite)
13
- * 默认 false:直连 DEV_API_HOST(后端已配置 CORS)
16
+ * H5 开发是否走 /dev-api 代理(需 vite.config.js rewrite)
17
+ * 默认 false:直连 VITE_APP_API_HOST
14 18
  */
15 19
 export const H5_USE_PROXY = false
16 20
 
17
-let _baseApi = DEV_API_HOST
18
-// #ifdef H5
19
-_baseApi = H5_USE_PROXY ? '/dev-api' : DEV_API_HOST
20
-// #endif
21
+function resolveBaseApi() {
22
+  if (import.meta.env.PROD) {
23
+    return envBaseApi || '/prod-api'
24
+  }
25
+  const devBase = envBaseApi || '/dev-api'
26
+  // #ifdef H5
27
+  return H5_USE_PROXY ? devBase : apiHost
28
+  // #endif
29
+  // #ifndef H5
30
+  return apiHost
31
+  // #endif
32
+}
21 33
 
22
-export const BASE_API = _baseApi
34
+export const BASE_API = resolveBaseApi()
23 35
 
24 36
 /**
25 37
  * 拼接接口或静态资源地址(/login、/profile/...)

+ 5 - 0
ruoyi-jiaoyi/manifest.json

@@ -76,6 +76,11 @@
76 76
                     }
77 77
                 }
78 78
             }
79
+        },
80
+        "title" : "巴青交易",
81
+        "router" : {
82
+            "mode" : "history",
83
+            "base" : "/bqjy/"
79 84
         }
80 85
     },
81 86
     "uniStatistics" : {

+ 17 - 14
ruoyi-jiaoyi/vite.config.js

@@ -1,21 +1,24 @@
1
-import { defineConfig } from 'vite'
1
+import { defineConfig, loadEnv } from 'vite'
2 2
 import uni from '@dcloudio/vite-plugin-uni'
3 3
 
4
-/** 与 config/index.js 中 DEV_API_HOST 保持一致 */
5
-const DEV_API_TARGET = 'http://192.168.1.6:8010'
6
-
7 4
 /**
8
- * uni-app Vue3 H5 开发代理(Vite rewrite)
9
- * - /dev-api → 若依后端(config/index.js H5_USE_PROXY
5
+ * uni-app Vue3 H5 开发代理
6
+ * - /dev-api → 若依后端(.env.development 的 VITE_APP_API_HOST)
10 7
  */
11
-export default defineConfig({
12
-  plugins: [uni()],
13
-  server: {
14
-    proxy: {
15
-      '/dev-api': {
16
-        target: DEV_API_TARGET,
17
-        changeOrigin: true,
18
-        rewrite: (path) => path.replace(/^\/dev-api/, '')
8
+export default defineConfig(({ mode }) => {
9
+  const env = loadEnv(mode, process.cwd(), '')
10
+  const devApiTarget = String(env.VITE_APP_API_HOST || 'http://192.168.1.6:8010').replace(/\/$/, '')
11
+  const devApiPrefix = String(env.VITE_APP_BASE_API || '/dev-api')
12
+
13
+  return {
14
+    plugins: [uni()],
15
+    server: {
16
+      proxy: {
17
+        [devApiPrefix]: {
18
+          target: devApiTarget,
19
+          changeOrigin: true,
20
+          rewrite: (path) => path.replace(new RegExp(`^${devApiPrefix}`), '')
21
+        }
19 22
       }
20 23
     }
21 24
   }

+ 3 - 0
ruoyi-screen/.env.production

@@ -7,6 +7,9 @@ ENV=production
7 7
 # 若依后端 API(与 ruoyi-ui 一致,由 Nginx 反代到真实后端)
8 8
 VITE_APP_BASE_API=/prod-api
9 9
 
10
+# 生产部署子路径(对齐 ruoyi-ui publicPath: /client)
11
+VITE_APP_PUBLIC_PATH=/screen
12
+
10 13
 # 天启气象(前端直连)
11 14
 VITE_WEATHER_APP_ID=36793262
12 15
 VITE_WEATHER_APP_SECRET=t6a6z0H8

+ 1 - 1
ruoyi-screen/package.json

@@ -9,7 +9,7 @@
9 9
   "scripts": {
10 10
     "dev": "vite",
11 11
     "build": "vite build",
12
-    "preview": "vite preview"
12
+    "preview": "vite preview --mode production"
13 13
   },
14 14
   "dependencies": {
15 15
     "axios": "^1.16.1",

+ 3 - 2
ruoyi-screen/src/router/index.js

@@ -1,4 +1,4 @@
1
-import { createRouter, createWebHashHistory } from "vue-router"
1
+import { createRouter, createWebHistory } from "vue-router"
2 2
 import ScreenLayout from "../layout/ScreenLayout.vue"
3 3
 import { getToken } from "../utils/auth"
4 4
 
@@ -82,7 +82,8 @@ const routes = [
82 82
 ]
83 83
 
84 84
 const router = createRouter({
85
-  history: createWebHashHistory(import.meta.env.BASE_URL),
85
+  // 与 ruoyi-ui router.base 一致;生产 import.meta.env.BASE_URL 为 /screen/
86
+  history: createWebHistory(import.meta.env.BASE_URL),
86 87
   routes
87 88
 })
88 89
 

+ 65 - 50
ruoyi-screen/vite.config.js

@@ -1,50 +1,65 @@
1
-import { defineConfig, loadEnv } from 'vite'
2
-import vue from '@vitejs/plugin-vue'
3
-import path from 'path'
4
-import { fileURLToPath } from 'url'
5
-
6
-const __dirname = path.dirname(fileURLToPath(import.meta.url))
7
-
8
-// https://vite.dev/config/
9
-export default defineConfig(({ mode }) => {
10
-  const env = loadEnv(mode, process.cwd(), '')
11
-
12
-  const baseApi = env.VITE_APP_BASE_API || '/dev-api'
13
-  const proxyTarget = (env.VITE_PROXY_TARGET || 'http://192.168.1.6:8010').replace(/\/$/, '')
14
-
15
-  const proxy = {
16
-    [baseApi]: {
17
-      target: proxyTarget,
18
-      changeOrigin: true,
19
-      rewrite: (path) => path.replace(new RegExp(`^${baseApi}`), '')
20
-    },
21
-    '^/v3/api-docs/(.*)': {
22
-      target: proxyTarget,
23
-      changeOrigin: true
24
-    }
25
-  }
26
-
27
-  const llmTarget = env.LLM_PROXY_TARGET
28
-  if (llmTarget) {
29
-    proxy['^/llm-dev-proxy'] = {
30
-      target: llmTarget.replace(/\/$/, ''),
31
-      changeOrigin: true,
32
-      rewrite: (path) => path.replace(/^\/llm-dev-proxy/, '')
33
-    }
34
-  }
35
-
36
-  return {
37
-    plugins: [vue()],
38
-    resolve: {
39
-      alias: {
40
-        '@': path.resolve(__dirname, 'src')
41
-      }
42
-    },
43
-    server: {
44
-      host: true,
45
-      port: 5188,
46
-      strictPort: false,
47
-      proxy
48
-    }
49
-  }
50
-})
1
+import { defineConfig, loadEnv } from 'vite'

2
+import vue from '@vitejs/plugin-vue'

3
+import path from 'path'

4
+import { fileURLToPath } from 'url'

5
+

6
+const __dirname = path.dirname(fileURLToPath(import.meta.url))

7
+

8
+/** 与 ruoyi-ui vue.config.js publicPath 一致:生产 /screen,开发 / */

9
+function resolvePublicPath(mode, env) {

10
+  if (mode !== 'production') {

11
+    return '/'

12
+  }

13
+  const raw = String(env.VITE_APP_PUBLIC_PATH || '/screen').trim()

14
+  if (!raw || raw === '/') {

15
+    return '/'

16
+  }

17
+  return `/${raw.replace(/^\/+|\/+$/g, '')}/`

18
+}

19
+

20
+// https://vite.dev/config/

21
+export default defineConfig(({ mode }) => {

22
+  const env = loadEnv(mode, process.cwd(), '')

23
+  const base = resolvePublicPath(mode, env)

24
+

25
+  const baseApi = env.VITE_APP_BASE_API || '/dev-api'

26
+  const proxyTarget = (env.VITE_PROXY_TARGET || 'http://192.168.1.6:8010').replace(/\/$/, '')

27
+

28
+  const proxy = {

29
+    [baseApi]: {

30
+      target: proxyTarget,

31
+      changeOrigin: true,

32
+      rewrite: (path) => path.replace(new RegExp(`^${baseApi}`), '')

33
+    },

34
+    '^/v3/api-docs/(.*)': {

35
+      target: proxyTarget,

36
+      changeOrigin: true

37
+    }

38
+  }

39
+

40
+  const llmTarget = env.LLM_PROXY_TARGET

41
+  if (llmTarget) {

42
+    proxy['^/llm-dev-proxy'] = {

43
+      target: llmTarget.replace(/\/$/, ''),

44
+      changeOrigin: true,

45
+      rewrite: (path) => path.replace(/^\/llm-dev-proxy/, '')

46
+    }

47
+  }

48
+

49
+  return {

50
+    base,

51
+    plugins: [vue()],

52
+    resolve: {

53
+      alias: {

54
+        '@': path.resolve(__dirname, 'src')

55
+      }

56
+    },

57
+    server: {

58
+      host: true,

59
+      port: 5188,

60
+      strictPort: false,

61
+      proxy

62
+    }

63
+  }

64
+})

65
+

+ 5 - 0
ruoyi-ui-app/.env.development

@@ -0,0 +1,5 @@
1
+# 开发环境(对齐 ruoyi-ui/.env.development)
2
+VITE_APP_TITLE=掌上巴青
3
+VITE_APP_BASE_API=/dev-api
4
+# H5 直连后端时使用(与 ruoyi-ui/vue.config.js baseUrl 一致)
5
+VITE_APP_API_HOST=http://192.168.1.6:8010

+ 3 - 0
ruoyi-ui-app/.env.production

@@ -0,0 +1,3 @@
1
+# 生产环境(对齐 ruoyi-ui/.env.production)
2
+VITE_APP_TITLE=掌上巴青
3
+VITE_APP_BASE_API=/prod-api

+ 23 - 18
ruoyi-ui-app/config/index.js

@@ -1,32 +1,37 @@
1 1
 /**
2
- * 接口根地址配置
2
+ * 接口根地址(与 ruoyi-ui 的 VUE_APP_BASE_API 对齐)
3 3
  *
4
- * 若依后端真实路径是 /login、/getInfo(没有 /dev-api 前缀)。
5
- * PC 端 ruoyi-ui 的 /dev-api 仅用于 H5 开发代理,代理会去掉该前缀再转发。
4
+ * - 开发:.env.development → /dev-api(H5 代理)或 VITE_APP_API_HOST 直连
5
+ * - 生产:.env.production → /prod-api(与 ruoyi-ui/.env.production 一致,由 Nginx 转发)
6 6
  *
7
- * 登录 404 常见原因:
8
- * 1. 后端未启动,或 DEV_API_HOST 与真实地址不一致
9
- * 2. H5 未用 uni 开发服务运行,相对路径 /dev-api 会打到前端服务器 → 404
10
- * 3. 代理未改写路径,后端收到 /dev-api/login 也会 404
11
- *
12
- * 请先确认 ruoyi-ui 能登录;再改 DEV_API_HOST;仍 404 时将 H5_USE_PROXY 设为 false。
7
+ * 打包 H5:uni build -p h5
13 8
  */
14 9
 
15
-/** 与 ruoyi-ui/vue.config.js 中 baseUrl 一致 */
16
-export const DEV_API_HOST = 'http://192.168.1.6:8010'
10
+const apiHost = String(import.meta.env.VITE_APP_API_HOST || 'http://192.168.1.6:8010').replace(/\/$/, '')
11
+
12
+/** 与 ruoyi-ui 的 VUE_APP_BASE_API 同源配置(dev/prod 由 .env 注入) */
13
+const envBaseApi = String(import.meta.env.VITE_APP_BASE_API || '').trim()
17 14
 
18 15
 /**
19
- * H5 是否走 /dev-api 开发代理(需 vite.config.js rewrite,manifest 的 pathRewrite 在 Vue3 常不生效
20
- * 默认 false:直连 DEV_API_HOST(后端已配置 CORS,与 ruoyi-ui 实际请求路径一致)
16
+ * H5 开发是否走 /dev-api 代理(需 vite.config.js rewrite)
17
+ * 默认 false:直连 VITE_APP_API_HOST
21 18
  */
22 19
 export const H5_USE_PROXY = false
23 20
 
24
-let _baseApi = DEV_API_HOST
25
-// #ifdef H5
26
-_baseApi = H5_USE_PROXY ? '/dev-api' : DEV_API_HOST
27
-// #endif
21
+function resolveBaseApi() {
22
+  if (import.meta.env.PROD) {
23
+    return envBaseApi || '/prod-api'
24
+  }
25
+  const devBase = envBaseApi || '/dev-api'
26
+  // #ifdef H5
27
+  return H5_USE_PROXY ? devBase : apiHost
28
+  // #endif
29
+  // #ifndef H5
30
+  return apiHost
31
+  // #endif
32
+}
28 33
 
29
-export const BASE_API = _baseApi
34
+export const BASE_API = resolveBaseApi()
30 35
 
31 36
 /**
32 37
  * 拼接接口或静态资源地址(/login、/profile/...)

+ 9 - 3
ruoyi-ui-app/manifest.json

@@ -72,7 +72,7 @@
72 72
         "devServer" : {
73 73
             "proxy" : {
74 74
                 "/dev-api" : {
75
-                    "target" : "http://192.168.1.18:8010",
75
+                    "target" : "http://192.168.1.6:8010",
76 76
                     "changeOrigin" : true,
77 77
                     "pathRewrite" : {
78 78
                         "^/dev-api" : ""
@@ -85,8 +85,14 @@
85 85
                         "^/llm-dev-proxy" : ""
86 86
                     }
87 87
                 }
88
-            }
89
-        }
88
+            },
89
+            "https" : false
90
+        },
91
+        "router" : {
92
+            "mode" : "history",
93
+            "base" : "/bqH5/"
94
+        },
95
+        "title" : "掌上巴青"
90 96
     },
91 97
     "uniStatistics" : {
92 98
         "enable" : false

+ 23 - 20
ruoyi-ui-app/vite.config.js

@@ -1,30 +1,33 @@
1
-import { defineConfig } from 'vite'
1
+import { defineConfig, loadEnv } from 'vite'
2 2
 import uni from '@dcloudio/vite-plugin-uni'
3 3
 import { LLM_PROXY_TARGET } from './config/llm.js'
4 4
 
5
-/** 与 config/index.js 中 DEV_API_HOST 保持一致 */
6
-const DEV_API_TARGET = 'http://192.168.1.6:8010'
7
-
8 5
 const llmTarget = String(LLM_PROXY_TARGET || '').replace(/\/$/, '')
9 6
 
10 7
 /**
11
- * uni-app Vue3 H5 开发代理(Vite rewrite)
12
- * - /dev-api → 若依后端(config/index.js H5_USE_PROXY
13
- * - /llm-dev-proxy → 大模型网关(对齐 ruoyi-ui/vue.config.js devProxy)
8
+ * uni-app Vue3 H5 开发代理
9
+ * - /dev-api → 若依后端(.env.development 的 VITE_APP_API_HOST
10
+ * - /llm-dev-proxy → 大模型网关
14 11
  */
15
-export default defineConfig({
16
-  plugins: [uni()],
17
-  server: {
18
-    proxy: {
19
-      '/dev-api': {
20
-        target: DEV_API_TARGET,
21
-        changeOrigin: true,
22
-        rewrite: (path) => path.replace(/^\/dev-api/, '')
23
-      },
24
-      '/llm-dev-proxy': {
25
-        target: llmTarget,
26
-        changeOrigin: true,
27
-        rewrite: (path) => path.replace(/^\/llm-dev-proxy/, '')
12
+export default defineConfig(({ mode }) => {
13
+  const env = loadEnv(mode, process.cwd(), '')
14
+  const devApiTarget = String(env.VITE_APP_API_HOST || 'http://192.168.1.6:8010').replace(/\/$/, '')
15
+  const devApiPrefix = String(env.VITE_APP_BASE_API || '/dev-api')
16
+
17
+  return {
18
+    plugins: [uni()],
19
+    server: {
20
+      proxy: {
21
+        [devApiPrefix]: {
22
+          target: devApiTarget,
23
+          changeOrigin: true,
24
+          rewrite: (path) => path.replace(new RegExp(`^${devApiPrefix}`), '')
25
+        },
26
+        '/llm-dev-proxy': {
27
+          target: llmTarget,
28
+          changeOrigin: true,
29
+          rewrite: (path) => path.replace(/^\/llm-dev-proxy/, '')
30
+        }
28 31
       }
29 32
     }
30 33
   }

+ 2 - 1
ruoyi-ui/src/router/index.js

@@ -183,7 +183,8 @@ Router.prototype.replace = function push(location) {
183 183
 }
184 184
 
185 185
 export default new Router({
186
-  mode: 'history', // 去掉url中的#
186
+  mode: 'history', // 去掉url中的
187
+  base: '/client',
187 188
   scrollBehavior: () => ({ y: 0 }),
188 189
   routes: constantRoutes
189 190
 })

+ 1 - 1
ruoyi-ui/vue.config.js

@@ -37,7 +37,7 @@ module.exports = {
37 37
   // 部署生产环境和开发环境下的URL。
38 38
   // 默认情况下,Vue CLI 会假设你的应用是被部署在一个域名的根路径上
39 39
   // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
40
-  publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
40
+  publicPath: process.env.NODE_ENV === "production" ? "/client" : "/",
41 41
   // 在npm run build 或 yarn build 时 ,生成文件的目录名称(要和baseUrl的生产环境路径一致)(默认dist)
42 42
   outputDir: 'dist',
43 43
   // 用于放置生成的静态资源 (js、css、img、fonts) 的;(项目打包之后,静态资源会放在这个文件夹下)