Commit 6c0755f11154aa99f06eb8241e2ff1302e1baab5
Merge branch 'ww' into 'main'
feat: pull out environment variables to app.config.js See merge request huang/yun-teng-iot-front!443
Showing
20 changed files
with
127 additions
and
61 deletions
| 1 | # Whether to open mock | 1 | # Whether to open mock |
| 2 | -# VITE_USE_MOCK = true | 2 | +# VITE_GLOB_USE_MOCK = true |
| 3 | 3 | ||
| 4 | # public path | 4 | # public path |
| 5 | -VITE_PUBLIC_PATH = / | 5 | +VITE_GLOB_PUBLIC_PATH = / |
| 6 | 6 | ||
| 7 | # Cross-domain proxy, you can configure multiple | 7 | # Cross-domain proxy, you can configure multiple |
| 8 | # Please note that no line breaks | 8 | # Please note that no line breaks |
| @@ -21,11 +21,11 @@ VITE_PROXY = [["/api","http://222.180.200.114:48080/api"],["/thingskit-drawio"," | @@ -21,11 +21,11 @@ VITE_PROXY = [["/api","http://222.180.200.114:48080/api"],["/thingskit-drawio"," | ||
| 21 | # 实时数据的ws地址 | 21 | # 实时数据的ws地址 |
| 22 | # VITE_WEB_SOCKET = ws://localhost:8080/api/ws/plugins/telemetry?token= | 22 | # VITE_WEB_SOCKET = ws://localhost:8080/api/ws/plugins/telemetry?token= |
| 23 | # VITE_WEB_SOCKET = ws://44.99.141.212:8080/api/ws/plugins/telemetry?token= | 23 | # VITE_WEB_SOCKET = ws://44.99.141.212:8080/api/ws/plugins/telemetry?token= |
| 24 | -VITE_WEB_SOCKET = ws://222.180.200.114:48080/api/ws/plugins/telemetry?token= | 24 | +VITE_GLOB_WEB_SOCKET = ws://222.180.200.114:48080/api/ws/plugins/telemetry?token= |
| 25 | # VITE_WEB_SOCKET = ws://121.37.251.8:8080/api/ws/plugins/telemetry?token= | 25 | # VITE_WEB_SOCKET = ws://121.37.251.8:8080/api/ws/plugins/telemetry?token= |
| 26 | 26 | ||
| 27 | # Delete console | 27 | # Delete console |
| 28 | -VITE_DROP_CONSOLE = true | 28 | +VITE_GLOB_DROP_CONSOLE = true |
| 29 | 29 | ||
| 30 | # Basic interface address SPA | 30 | # Basic interface address SPA |
| 31 | VITE_GLOB_API_URL=/api | 31 | VITE_GLOB_API_URL=/api |
| @@ -40,10 +40,10 @@ VITE_GLOB_API_URL_PREFIX=/yt | @@ -40,10 +40,10 @@ VITE_GLOB_API_URL_PREFIX=/yt | ||
| 40 | VITE_GLOB_CONFIGURATION = /thingskit-drawio | 40 | VITE_GLOB_CONFIGURATION = /thingskit-drawio |
| 41 | 41 | ||
| 42 | # Content Security Policy | 42 | # Content Security Policy |
| 43 | -VITE_CONTENT_SECURITY_POLICY = false | 43 | +VITE_GLOB_CONTENT_SECURITY_POLICY = true |
| 44 | 44 | ||
| 45 | # Alarm Notify Polling Interval Time | 45 | # Alarm Notify Polling Interval Time |
| 46 | -VITE_ALARM_NOTIFY_POLLING_INTERVAL_TIME = 500000 | 46 | +VITE_GLOB_ALARM_NOTIFY_POLLING_INTERVAL_TIME = 500000 |
| 47 | 47 | ||
| 48 | # Alarm Notify Auto Close Time Unit is Second | 48 | # Alarm Notify Auto Close Time Unit is Second |
| 49 | -VITE_ALARM_NOTIFY_DURATION = 5 | 49 | +VITE_GLOB_ALARM_NOTIFY_DURATION = 5 |
| 1 | # Whether to open mock | 1 | # Whether to open mock |
| 2 | -VITE_USE_MOCK = false | 2 | +VITE_GLOB_USE_MOCK = false |
| 3 | 3 | ||
| 4 | # public path | 4 | # public path |
| 5 | -VITE_PUBLIC_PATH = / | 5 | +VITE_GLOB_PUBLIC_PATH = / |
| 6 | 6 | ||
| 7 | # Delete console | 7 | # Delete console |
| 8 | -VITE_DROP_CONSOLE = true | 8 | +VITE_GLOB_DROP_CONSOLE = true |
| 9 | 9 | ||
| 10 | # Whether to enable gzip or brotli compression | 10 | # Whether to enable gzip or brotli compression |
| 11 | # Optional: gzip | brotli | none | 11 | # Optional: gzip | brotli | none |
| 12 | # If you need multiple forms, you can use `,` to separate | 12 | # If you need multiple forms, you can use `,` to separate |
| 13 | -VITE_BUILD_COMPRESS = 'gzip' | 13 | +VITE_GLOB_BUILD_COMPRESS = 'gzip' |
| 14 | 14 | ||
| 15 | # Whether to delete origin files when using compress, default false | 15 | # Whether to delete origin files when using compress, default false |
| 16 | -VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE = false | 16 | +VITE_GLOB_BUILD_COMPRESS_DELETE_ORIGIN_FILE = false |
| 17 | 17 | ||
| 18 | # Basic interface address SPA | 18 | # Basic interface address SPA |
| 19 | VITE_GLOB_API_URL=http://122.9.141.195:8080/api | 19 | VITE_GLOB_API_URL=http://122.9.141.195:8080/api |
| @@ -26,7 +26,7 @@ VITE_GLOB_UPLOAD_URL=http://122.9.141.195:8080/api/yt/oss/upload | @@ -26,7 +26,7 @@ VITE_GLOB_UPLOAD_URL=http://122.9.141.195:8080/api/yt/oss/upload | ||
| 26 | VITE_GLOB_API_URL_PREFIX=/yt | 26 | VITE_GLOB_API_URL_PREFIX=/yt |
| 27 | 27 | ||
| 28 | # Whether to enable image compression | 28 | # Whether to enable image compression |
| 29 | -VITE_USE_IMAGEMIN= false | 29 | +VITE_GLOB_USE_IMAGEMIN= false |
| 30 | 30 | ||
| 31 | # use pwa | 31 | # use pwa |
| 32 | VITE_USE_PWA = false | 32 | VITE_USE_PWA = false |
| @@ -35,16 +35,16 @@ VITE_USE_PWA = false | @@ -35,16 +35,16 @@ VITE_USE_PWA = false | ||
| 35 | VITE_LEGACY = true | 35 | VITE_LEGACY = true |
| 36 | 36 | ||
| 37 | # 实时数据的ws地址 | 37 | # 实时数据的ws地址 |
| 38 | -VITE_WEB_SOCKET = ws://122.9.141.195:8080/api/ws/plugins/telemetry?token= | 38 | +VITE_GLOB_WEB_SOCKET = ws://122.9.141.195:8080/api/ws/plugins/telemetry?token= |
| 39 | 39 | ||
| 40 | #configuration | 40 | #configuration |
| 41 | VITE_GLOB_CONFIGURATION = /thingskit-scada | 41 | VITE_GLOB_CONFIGURATION = /thingskit-scada |
| 42 | 42 | ||
| 43 | # Content Security Policy | 43 | # Content Security Policy |
| 44 | -VITE_CONTENT_SECURITY_POLICY = false | 44 | +VITE_GLOB_CONTENT_SECURITY_POLICY = false |
| 45 | 45 | ||
| 46 | # Alarm Notify Polling Interval Time | 46 | # Alarm Notify Polling Interval Time |
| 47 | -VITE_ALARM_NOTIFY_POLLING_INTERVAL_TIME = 60000 | 47 | +VITE_GLOB_ALARM_NOTIFY_POLLING_INTERVAL_TIME = 60000 |
| 48 | 48 | ||
| 49 | # Alarm Notify Auto Close Time Unit is Second | 49 | # Alarm Notify Auto Close Time Unit is Second |
| 50 | -VITE_ALARM_NOTIFY_DURATION = 5 | 50 | +VITE_GLOB_ALARM_NOTIFY_DURATION = 5 |
| @@ -10,9 +10,11 @@ import pkg from '../../../package.json'; | @@ -10,9 +10,11 @@ import pkg from '../../../package.json'; | ||
| 10 | import { GLOB_CONFIG_FILE_NAME } from '../../constant'; | 10 | import { GLOB_CONFIG_FILE_NAME } from '../../constant'; |
| 11 | 11 | ||
| 12 | export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) { | 12 | export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) { |
| 13 | - const { VITE_GLOB_APP_TITLE, VITE_PUBLIC_PATH, VITE_CONTENT_SECURITY_POLICY } = env; | 13 | + const { VITE_GLOB_APP_TITLE, VITE_GLOB_PUBLIC_PATH, VITE_GLOB_CONTENT_SECURITY_POLICY } = env; |
| 14 | 14 | ||
| 15 | - const path = VITE_PUBLIC_PATH.endsWith('/') ? VITE_PUBLIC_PATH : `${VITE_PUBLIC_PATH}/`; | 15 | + const path = VITE_GLOB_PUBLIC_PATH.endsWith('/') |
| 16 | + ? VITE_GLOB_PUBLIC_PATH | ||
| 17 | + : `${VITE_GLOB_PUBLIC_PATH}/`; | ||
| 16 | 18 | ||
| 17 | const getAppConfigSrc = () => { | 19 | const getAppConfigSrc = () => { |
| 18 | return `${path || '/'}${GLOB_CONFIG_FILE_NAME}?v=${pkg.version}-${new Date().getTime()}`; | 20 | return `${path || '/'}${GLOB_CONFIG_FILE_NAME}?v=${pkg.version}-${new Date().getTime()}`; |
| @@ -24,7 +26,7 @@ export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) { | @@ -24,7 +26,7 @@ export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) { | ||
| 24 | // Inject data into ejs template | 26 | // Inject data into ejs template |
| 25 | injectData: { | 27 | injectData: { |
| 26 | title: VITE_GLOB_APP_TITLE, | 28 | title: VITE_GLOB_APP_TITLE, |
| 27 | - contentSecurityPolicy: VITE_CONTENT_SECURITY_POLICY | 29 | + contentSecurityPolicy: VITE_GLOB_CONTENT_SECURITY_POLICY |
| 28 | ? `<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests" />` | 30 | ? `<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests" />` |
| 29 | : '', | 31 | : '', |
| 30 | }, | 32 | }, |
| @@ -19,11 +19,11 @@ import { configHmrPlugin } from './hmr'; | @@ -19,11 +19,11 @@ import { configHmrPlugin } from './hmr'; | ||
| 19 | 19 | ||
| 20 | export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) { | 20 | export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) { |
| 21 | const { | 21 | const { |
| 22 | - VITE_USE_IMAGEMIN, | ||
| 23 | - VITE_USE_MOCK, | 22 | + VITE_GLOB_USE_IMAGEMIN, |
| 23 | + VITE_GLOB_USE_MOCK, | ||
| 24 | VITE_LEGACY, | 24 | VITE_LEGACY, |
| 25 | - VITE_BUILD_COMPRESS, | ||
| 26 | - VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE, | 25 | + VITE_GLOB_BUILD_COMPRESS, |
| 26 | + VITE_GLOB_BUILD_COMPRESS_DELETE_ORIGIN_FILE, | ||
| 27 | } = viteEnv; | 27 | } = viteEnv; |
| 28 | 28 | ||
| 29 | const vitePlugins: (Plugin | Plugin[])[] = [ | 29 | const vitePlugins: (Plugin | Plugin[])[] = [ |
| @@ -49,7 +49,7 @@ export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) { | @@ -49,7 +49,7 @@ export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) { | ||
| 49 | vitePlugins.push(configSvgIconsPlugin(isBuild)); | 49 | vitePlugins.push(configSvgIconsPlugin(isBuild)); |
| 50 | 50 | ||
| 51 | // vite-plugin-mock | 51 | // vite-plugin-mock |
| 52 | - VITE_USE_MOCK && vitePlugins.push(configMockPlugin(isBuild)); | 52 | + VITE_GLOB_USE_MOCK && vitePlugins.push(configMockPlugin(isBuild)); |
| 53 | 53 | ||
| 54 | // vite-plugin-purge-icons | 54 | // vite-plugin-purge-icons |
| 55 | vitePlugins.push(purgeIcons()); | 55 | vitePlugins.push(purgeIcons()); |
| @@ -66,11 +66,11 @@ export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) { | @@ -66,11 +66,11 @@ export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) { | ||
| 66 | // The following plugins only work in the production environment | 66 | // The following plugins only work in the production environment |
| 67 | if (isBuild) { | 67 | if (isBuild) { |
| 68 | //vite-plugin-imagemin | 68 | //vite-plugin-imagemin |
| 69 | - VITE_USE_IMAGEMIN && vitePlugins.push(configImageminPlugin()); | 69 | + VITE_GLOB_USE_IMAGEMIN && vitePlugins.push(configImageminPlugin()); |
| 70 | 70 | ||
| 71 | // rollup-plugin-gzip | 71 | // rollup-plugin-gzip |
| 72 | vitePlugins.push( | 72 | vitePlugins.push( |
| 73 | - configCompressPlugin(VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE) | 73 | + configCompressPlugin(VITE_GLOB_BUILD_COMPRESS, VITE_GLOB_BUILD_COMPRESS_DELETE_ORIGIN_FILE) |
| 74 | ); | 74 | ); |
| 75 | 75 | ||
| 76 | // vite-plugin-pwa | 76 | // vite-plugin-pwa |
| @@ -65,6 +65,7 @@ | @@ -65,6 +65,7 @@ | ||
| 65 | import { isNumber } from '/@/utils/is'; | 65 | import { isNumber } from '/@/utils/is'; |
| 66 | import { useLocale } from '/@/locales/useLocale'; | 66 | import { useLocale } from '/@/locales/useLocale'; |
| 67 | import { useAppStore } from '/@/store/modules/app'; | 67 | import { useAppStore } from '/@/store/modules/app'; |
| 68 | + import { useGlobSetting } from '/@/hooks/setting'; | ||
| 68 | 69 | ||
| 69 | const tinymceProps = { | 70 | const tinymceProps = { |
| 70 | options: { | 71 | options: { |
| @@ -140,7 +141,8 @@ | @@ -140,7 +141,8 @@ | ||
| 140 | 141 | ||
| 141 | const initOptions = computed((): RawEditorSettings => { | 142 | const initOptions = computed((): RawEditorSettings => { |
| 142 | const { height, options, toolbar, plugins } = props; | 143 | const { height, options, toolbar, plugins } = props; |
| 143 | - const publicPath = import.meta.env.VITE_PUBLIC_PATH || '/'; | 144 | + useGlobSetting(); |
| 145 | + const publicPath = import.meta.env.VITE_GLOB_PUBLIC_PATH || '/'; | ||
| 144 | return { | 146 | return { |
| 145 | selector: `#${unref(tinymceId)}`, | 147 | selector: `#${unref(tinymceId)}`, |
| 146 | height, | 148 | height, |
| @@ -10,6 +10,11 @@ export const useGlobSetting = (): Readonly<GlobConfig> => { | @@ -10,6 +10,11 @@ export const useGlobSetting = (): Readonly<GlobConfig> => { | ||
| 10 | VITE_GLOB_APP_SHORT_NAME, | 10 | VITE_GLOB_APP_SHORT_NAME, |
| 11 | VITE_GLOB_API_URL_PREFIX, | 11 | VITE_GLOB_API_URL_PREFIX, |
| 12 | VITE_GLOB_UPLOAD_URL, | 12 | VITE_GLOB_UPLOAD_URL, |
| 13 | + VITE_GLOB_CONFIGURATION, | ||
| 14 | + VITE_GLOB_WEB_SOCKET, | ||
| 15 | + VITE_GLOB_CONTENT_SECURITY_POLICY, | ||
| 16 | + VITE_GLOB_ALARM_NOTIFY_POLLING_INTERVAL_TIME, | ||
| 17 | + VITE_GLOB_ALARM_NOTIFY_DURATION, | ||
| 13 | } = getAppEnvConfig(); | 18 | } = getAppEnvConfig(); |
| 14 | 19 | ||
| 15 | if (!/[a-zA-Z\_]*/.test(VITE_GLOB_APP_SHORT_NAME)) { | 20 | if (!/[a-zA-Z\_]*/.test(VITE_GLOB_APP_SHORT_NAME)) { |
| @@ -25,6 +30,11 @@ export const useGlobSetting = (): Readonly<GlobConfig> => { | @@ -25,6 +30,11 @@ export const useGlobSetting = (): Readonly<GlobConfig> => { | ||
| 25 | shortName: VITE_GLOB_APP_SHORT_NAME, | 30 | shortName: VITE_GLOB_APP_SHORT_NAME, |
| 26 | urlPrefix: VITE_GLOB_API_URL_PREFIX, | 31 | urlPrefix: VITE_GLOB_API_URL_PREFIX, |
| 27 | uploadUrl: VITE_GLOB_UPLOAD_URL, | 32 | uploadUrl: VITE_GLOB_UPLOAD_URL, |
| 33 | + configurationPrefix: VITE_GLOB_CONFIGURATION, | ||
| 34 | + socketUrl: VITE_GLOB_WEB_SOCKET, | ||
| 35 | + securityPolicy: VITE_GLOB_CONTENT_SECURITY_POLICY, | ||
| 36 | + alarmNotifyDuration: VITE_GLOB_ALARM_NOTIFY_DURATION, | ||
| 37 | + alarmPollingInterval: VITE_GLOB_ALARM_NOTIFY_POLLING_INTERVAL_TIME, | ||
| 28 | }; | 38 | }; |
| 29 | return glob as Readonly<GlobConfig>; | 39 | return glob as Readonly<GlobConfig>; |
| 30 | }; | 40 | }; |
src/hooks/web/useWebSecurityPolicy.ts
0 → 100644
| 1 | +import { useGlobSetting } from '../setting'; | ||
| 2 | + | ||
| 3 | +let initialFlag = false; | ||
| 4 | +export function useWebSecurityPolicy() { | ||
| 5 | + if (window && window.document && window.document.documentElement) { | ||
| 6 | + const { securityPolicy } = useGlobSetting(); | ||
| 7 | + if (securityPolicy === 'true' && !initialFlag) { | ||
| 8 | + const meta = document.createElement('meta'); | ||
| 9 | + meta.setAttribute('http-equiv', 'Content-Security-Policy'); | ||
| 10 | + meta.setAttribute('content', 'upgrade-insecure-requests'); | ||
| 11 | + const container = document.querySelector('head'); | ||
| 12 | + container?.prepend(meta); | ||
| 13 | + initialFlag = true; | ||
| 14 | + } | ||
| 15 | + } | ||
| 16 | +} |
| @@ -15,11 +15,14 @@ import { setupI18n } from '/@/locales/setupI18n'; | @@ -15,11 +15,14 @@ import { setupI18n } from '/@/locales/setupI18n'; | ||
| 15 | import { registerGlobComp } from '/@/components/registerGlobComp'; | 15 | import { registerGlobComp } from '/@/components/registerGlobComp'; |
| 16 | import '/@/assets/iconfont/iconfont'; | 16 | import '/@/assets/iconfont/iconfont'; |
| 17 | import { usePlatform } from './views/system/customize/hook/usePlatformInfo'; | 17 | import { usePlatform } from './views/system/customize/hook/usePlatformInfo'; |
| 18 | +import { useWebSecurityPolicy } from './hooks/web/useWebSecurityPolicy'; | ||
| 18 | 19 | ||
| 19 | if (import.meta.env.DEV) { | 20 | if (import.meta.env.DEV) { |
| 20 | import('ant-design-vue/dist/antd.less'); | 21 | import('ant-design-vue/dist/antd.less'); |
| 21 | } | 22 | } |
| 22 | async function bootstrap() { | 23 | async function bootstrap() { |
| 24 | + useWebSecurityPolicy(); | ||
| 25 | + | ||
| 23 | const app = createApp(App); | 26 | const app = createApp(App); |
| 24 | // Configure store | 27 | // Configure store |
| 25 | setupStore(app); | 28 | setupStore(app); |
| @@ -15,7 +15,7 @@ getRouteNames(basicRoutes); | @@ -15,7 +15,7 @@ getRouteNames(basicRoutes); | ||
| 15 | 15 | ||
| 16 | // app router | 16 | // app router |
| 17 | export const router = createRouter({ | 17 | export const router = createRouter({ |
| 18 | - history: createWebHistory(import.meta.env.VITE_PUBLIC_PATH), | 18 | + history: createWebHistory(import.meta.env.VITE_GLOB_PUBLIC_PATH), |
| 19 | routes: basicRoutes as unknown as RouteRecordRaw[], | 19 | routes: basicRoutes as unknown as RouteRecordRaw[], |
| 20 | strict: true, | 20 | strict: true, |
| 21 | scrollBehavior: () => ({ left: 0, top: 0 }), | 21 | scrollBehavior: () => ({ left: 0, top: 0 }), |
| @@ -21,7 +21,6 @@ export function getAppEnvConfig() { | @@ -21,7 +21,6 @@ export function getAppEnvConfig() { | ||
| 21 | ? // Get the global configuration (the configuration will be extracted independently when packaging) | 21 | ? // Get the global configuration (the configuration will be extracted independently when packaging) |
| 22 | (import.meta.env as unknown as GlobEnvConfig) | 22 | (import.meta.env as unknown as GlobEnvConfig) |
| 23 | : window[ENV_NAME as any]) as unknown as GlobEnvConfig; | 23 | : window[ENV_NAME as any]) as unknown as GlobEnvConfig; |
| 24 | - | ||
| 25 | const { | 24 | const { |
| 26 | VITE_GLOB_APP_TITLE, | 25 | VITE_GLOB_APP_TITLE, |
| 27 | VITE_GLOB_API_URL, | 26 | VITE_GLOB_API_URL, |
| @@ -29,6 +28,10 @@ export function getAppEnvConfig() { | @@ -29,6 +28,10 @@ export function getAppEnvConfig() { | ||
| 29 | VITE_GLOB_API_URL_PREFIX, | 28 | VITE_GLOB_API_URL_PREFIX, |
| 30 | VITE_GLOB_UPLOAD_URL, | 29 | VITE_GLOB_UPLOAD_URL, |
| 31 | VITE_GLOB_CONFIGURATION, | 30 | VITE_GLOB_CONFIGURATION, |
| 31 | + VITE_GLOB_WEB_SOCKET, | ||
| 32 | + VITE_GLOB_CONTENT_SECURITY_POLICY, | ||
| 33 | + VITE_GLOB_ALARM_NOTIFY_POLLING_INTERVAL_TIME, | ||
| 34 | + VITE_GLOB_ALARM_NOTIFY_DURATION, | ||
| 32 | } = ENV; | 35 | } = ENV; |
| 33 | 36 | ||
| 34 | if (!/^[a-zA-Z\_]*$/.test(VITE_GLOB_APP_SHORT_NAME)) { | 37 | if (!/^[a-zA-Z\_]*$/.test(VITE_GLOB_APP_SHORT_NAME)) { |
| @@ -44,6 +47,10 @@ export function getAppEnvConfig() { | @@ -44,6 +47,10 @@ export function getAppEnvConfig() { | ||
| 44 | VITE_GLOB_API_URL_PREFIX, | 47 | VITE_GLOB_API_URL_PREFIX, |
| 45 | VITE_GLOB_UPLOAD_URL, | 48 | VITE_GLOB_UPLOAD_URL, |
| 46 | VITE_GLOB_CONFIGURATION, | 49 | VITE_GLOB_CONFIGURATION, |
| 50 | + VITE_GLOB_WEB_SOCKET, | ||
| 51 | + VITE_GLOB_CONTENT_SECURITY_POLICY, | ||
| 52 | + VITE_GLOB_ALARM_NOTIFY_POLLING_INTERVAL_TIME, | ||
| 53 | + VITE_GLOB_ALARM_NOTIFY_DURATION, | ||
| 47 | }; | 54 | }; |
| 48 | } | 55 | } |
| 49 | 56 |
| @@ -7,6 +7,7 @@ import { alarmLevel } from '/@/views/device/list/config/detail.config'; | @@ -7,6 +7,7 @@ import { alarmLevel } from '/@/views/device/list/config/detail.config'; | ||
| 7 | import { RoleEnum } from '/@/enums/roleEnum'; | 7 | import { RoleEnum } from '/@/enums/roleEnum'; |
| 8 | import { usePermission } from '/@/hooks/web/usePermission'; | 8 | import { usePermission } from '/@/hooks/web/usePermission'; |
| 9 | import { useUserStore } from '/@/store/modules/user'; | 9 | import { useUserStore } from '/@/store/modules/user'; |
| 10 | +import { useGlobSetting } from '/@/hooks/setting'; | ||
| 10 | 11 | ||
| 11 | interface UseAlarmNotifyParams { | 12 | interface UseAlarmNotifyParams { |
| 12 | alarmNotifyStatus?: AlarmStatus; | 13 | alarmNotifyStatus?: AlarmStatus; |
| @@ -20,10 +21,11 @@ export enum AlarmPermissionKey { | @@ -20,10 +21,11 @@ export enum AlarmPermissionKey { | ||
| 20 | } | 21 | } |
| 21 | 22 | ||
| 22 | export function useAlarmNotify(params: UseAlarmNotifyParams = {}) { | 23 | export function useAlarmNotify(params: UseAlarmNotifyParams = {}) { |
| 24 | + const { alarmNotifyDuration, alarmPollingInterval } = useGlobSetting(); | ||
| 23 | const { | 25 | const { |
| 24 | alarmNotifyStatus = AlarmStatus.ACTIVE_UN_ACK, | 26 | alarmNotifyStatus = AlarmStatus.ACTIVE_UN_ACK, |
| 25 | - interval = import.meta.env.VITE_ALARM_NOTIFY_POLLING_INTERVAL_TIME || 60000, | ||
| 26 | - duration = import.meta.env.VITE_ALARM_NOTIFY_DURATION || 5, | 27 | + interval = Number(alarmPollingInterval) || 60000, |
| 28 | + duration = Number(alarmNotifyDuration) || 5, | ||
| 27 | color = 'orange', | 29 | color = 'orange', |
| 28 | } = params; | 30 | } = params; |
| 29 | const alarmNotifyStatusMean = AlarmStatusMean[alarmNotifyStatus]; | 31 | const alarmNotifyStatusMean = AlarmStatusMean[alarmNotifyStatus]; |
| @@ -84,10 +84,11 @@ | @@ -84,10 +84,11 @@ | ||
| 84 | deleteConfigurationCenter, | 84 | deleteConfigurationCenter, |
| 85 | } from '/@/api/configuration/center/configurationCenter'; | 85 | } from '/@/api/configuration/center/configurationCenter'; |
| 86 | import { useBatchDelete } from '/@/hooks/web/useBatchDelete'; | 86 | import { useBatchDelete } from '/@/hooks/web/useBatchDelete'; |
| 87 | - import { getAppEnvConfig, isDevMode } from '/@/utils/env'; | 87 | + import { isDevMode } from '/@/utils/env'; |
| 88 | import { Authority } from '/@/components/Authority'; | 88 | import { Authority } from '/@/components/Authority'; |
| 89 | import { Popconfirm } from 'ant-design-vue'; | 89 | import { Popconfirm } from 'ant-design-vue'; |
| 90 | import { Tag } from 'ant-design-vue'; | 90 | import { Tag } from 'ant-design-vue'; |
| 91 | + import { useGlobSetting } from '/@/hooks/setting'; | ||
| 91 | export default defineComponent({ | 92 | export default defineComponent({ |
| 92 | components: { | 93 | components: { |
| 93 | PageWrapper, | 94 | PageWrapper, |
| @@ -100,7 +101,7 @@ | @@ -100,7 +101,7 @@ | ||
| 100 | Tag, | 101 | Tag, |
| 101 | }, | 102 | }, |
| 102 | setup() { | 103 | setup() { |
| 103 | - const { VITE_GLOB_CONFIGURATION } = getAppEnvConfig(); | 104 | + const { configurationPrefix } = useGlobSetting(); |
| 104 | const isDev = isDevMode(); | 105 | const isDev = isDevMode(); |
| 105 | const searchInfo = reactive<Recordable>({}); | 106 | const searchInfo = reactive<Recordable>({}); |
| 106 | const { organizationIdTreeRef, resetFn } = useResetOrganizationTree(searchInfo); | 107 | const { organizationIdTreeRef, resetFn } = useResetOrganizationTree(searchInfo); |
| @@ -165,14 +166,14 @@ | @@ -165,14 +166,14 @@ | ||
| 165 | 166 | ||
| 166 | const handlePreview = (record: Recordable | null) => { | 167 | const handlePreview = (record: Recordable | null) => { |
| 167 | window.open( | 168 | window.open( |
| 168 | - `${VITE_GLOB_CONFIGURATION}/${isDev ? '?dev=1&' : '?'}configurationId=${ | 169 | + `${configurationPrefix}/${isDev ? '?dev=1&' : '?'}configurationId=${ |
| 169 | record!.id | 170 | record!.id |
| 170 | }&lightbox=1` | 171 | }&lightbox=1` |
| 171 | ); | 172 | ); |
| 172 | }; | 173 | }; |
| 173 | const handleDesign = (record: Recordable | null) => { | 174 | const handleDesign = (record: Recordable | null) => { |
| 174 | window.open( | 175 | window.open( |
| 175 | - `${VITE_GLOB_CONFIGURATION}/${isDev ? '?dev=1&' : '?'}configurationId=${record!.id}` | 176 | + `${configurationPrefix}/${isDev ? '?dev=1&' : '?'}configurationId=${record!.id}` |
| 176 | ); | 177 | ); |
| 177 | }; | 178 | }; |
| 178 | 179 |
| @@ -28,6 +28,7 @@ | @@ -28,6 +28,7 @@ | ||
| 28 | import configurationSrc from '/@/assets/icons/configuration.svg'; | 28 | import configurationSrc from '/@/assets/icons/configuration.svg'; |
| 29 | import { cloneDeep } from 'lodash'; | 29 | import { cloneDeep } from 'lodash'; |
| 30 | import { usePermission } from '/@/hooks/web/usePermission'; | 30 | import { usePermission } from '/@/hooks/web/usePermission'; |
| 31 | + import { useGlobSetting } from '/@/hooks/setting'; | ||
| 31 | 32 | ||
| 32 | const listColumn = ref(5); | 33 | const listColumn = ref(5); |
| 33 | 34 | ||
| @@ -110,23 +111,19 @@ | @@ -110,23 +111,19 @@ | ||
| 110 | } | 111 | } |
| 111 | }; | 112 | }; |
| 112 | 113 | ||
| 113 | - const { VITE_GLOB_CONFIGURATION } = import.meta.env; | 114 | + const { configurationPrefix } = useGlobSetting(); |
| 114 | const isDev = isDevMode(); | 115 | const isDev = isDevMode(); |
| 115 | 116 | ||
| 116 | const { hasPermission } = usePermission(); | 117 | const { hasPermission } = usePermission(); |
| 117 | const handlePreview = (record: ConfigurationCenterItemsModal) => { | 118 | const handlePreview = (record: ConfigurationCenterItemsModal) => { |
| 118 | if (!hasPermission('api:yt:configuration:center:get_configuration_info:get')) return; | 119 | if (!hasPermission('api:yt:configuration:center:get_configuration_info:get')) return; |
| 119 | window.open( | 120 | window.open( |
| 120 | - `${VITE_GLOB_CONFIGURATION}/${isDev ? '?dev=1&' : '?'}configurationId=${ | ||
| 121 | - record!.id | ||
| 122 | - }&lightbox=1` | 121 | + `${configurationPrefix}/${isDev ? '?dev=1&' : '?'}configurationId=${record!.id}&lightbox=1` |
| 123 | ); | 122 | ); |
| 124 | }; | 123 | }; |
| 125 | 124 | ||
| 126 | const handleDesign = (record: ConfigurationCenterItemsModal) => { | 125 | const handleDesign = (record: ConfigurationCenterItemsModal) => { |
| 127 | - window.open( | ||
| 128 | - `${VITE_GLOB_CONFIGURATION}/${isDev ? '?dev=1&' : '?'}configurationId=${record!.id}` | ||
| 129 | - ); | 126 | + window.open(`${configurationPrefix}/${isDev ? '?dev=1&' : '?'}configurationId=${record!.id}`); |
| 130 | }; | 127 | }; |
| 131 | 128 | ||
| 132 | const { createSyncConfirm } = useSyncConfirm(); | 129 | const { createSyncConfirm } = useSyncConfirm(); |
| @@ -113,6 +113,7 @@ | @@ -113,6 +113,7 @@ | ||
| 113 | import CustomerAlarmMessage from './CustomerAlarmMessage.vue'; | 113 | import CustomerAlarmMessage from './CustomerAlarmMessage.vue'; |
| 114 | import { useDate } from '../hooks/useDate'; | 114 | import { useDate } from '../hooks/useDate'; |
| 115 | import { getTrendData } from '/@/api/dashboard'; | 115 | import { getTrendData } from '/@/api/dashboard'; |
| 116 | + import { useGlobSetting } from '/@/hooks/setting'; | ||
| 116 | 117 | ||
| 117 | defineExpose({ | 118 | defineExpose({ |
| 118 | isAdmin, | 119 | isAdmin, |
| @@ -145,8 +146,9 @@ | @@ -145,8 +146,9 @@ | ||
| 145 | 146 | ||
| 146 | // web Socket | 147 | // web Socket |
| 147 | const token: string = getAuthCache(JWT_TOKEN_KEY); | 148 | const token: string = getAuthCache(JWT_TOKEN_KEY); |
| 149 | + const { socketUrl } = useGlobSetting(); | ||
| 148 | const state = reactive({ | 150 | const state = reactive({ |
| 149 | - server: `${import.meta.env.VITE_WEB_SOCKET}${token}`, | 151 | + server: `${socketUrl}${token}`, |
| 150 | alarmList: new Array<[number, string]>(), | 152 | alarmList: new Array<[number, string]>(), |
| 151 | alarmItem: new Array<[number, string]>(), | 153 | alarmItem: new Array<[number, string]>(), |
| 152 | dataPointList: new Array<[number, string]>(), | 154 | dataPointList: new Array<[number, string]>(), |
| @@ -19,6 +19,7 @@ | @@ -19,6 +19,7 @@ | ||
| 19 | import { Specs, StructJSON } from '/@/api/device/model/modelOfMatterModel'; | 19 | import { Specs, StructJSON } from '/@/api/device/model/modelOfMatterModel'; |
| 20 | import { isArray, isObject } from '/@/utils/is'; | 20 | import { isArray, isObject } from '/@/utils/is'; |
| 21 | import { DataTypeEnum } from '/@/components/Form/src/externalCompns/components/StructForm/config'; | 21 | import { DataTypeEnum } from '/@/components/Form/src/externalCompns/components/StructForm/config'; |
| 22 | + import { useGlobSetting } from '/@/hooks/setting'; | ||
| 22 | 23 | ||
| 23 | interface ReceiveMessage { | 24 | interface ReceiveMessage { |
| 24 | data: { | 25 | data: { |
| @@ -42,9 +43,9 @@ | @@ -42,9 +43,9 @@ | ||
| 42 | }; | 43 | }; |
| 43 | 44 | ||
| 44 | const token = getAuthCache(JWT_TOKEN_KEY); | 45 | const token = getAuthCache(JWT_TOKEN_KEY); |
| 45 | - | 46 | + const { socketUrl } = useGlobSetting(); |
| 46 | const socketInfo = reactive({ | 47 | const socketInfo = reactive({ |
| 47 | - origin: `${import.meta.env.VITE_WEB_SOCKET}${token}`, | 48 | + origin: `${socketUrl}${token}`, |
| 48 | attr: undefined as string | undefined, | 49 | attr: undefined as string | undefined, |
| 49 | originData: [] as DataSource[], | 50 | originData: [] as DataSource[], |
| 50 | dataSource: [] as DataSource[], | 51 | dataSource: [] as DataSource[], |
| @@ -12,6 +12,7 @@ | @@ -12,6 +12,7 @@ | ||
| 12 | import { getAuthCache } from '/@/utils/auth'; | 12 | import { getAuthCache } from '/@/utils/auth'; |
| 13 | import { useMessage } from '/@/hooks/web/useMessage'; | 13 | import { useMessage } from '/@/hooks/web/useMessage'; |
| 14 | import type { socketDataType } from '../../types'; | 14 | import type { socketDataType } from '../../types'; |
| 15 | + import { useGlobSetting } from '/@/hooks/setting'; | ||
| 15 | export default defineComponent({ | 16 | export default defineComponent({ |
| 16 | name: 'RealTimeData', | 17 | name: 'RealTimeData', |
| 17 | components: { | 18 | components: { |
| @@ -25,8 +26,9 @@ | @@ -25,8 +26,9 @@ | ||
| 25 | }, | 26 | }, |
| 26 | setup(props) { | 27 | setup(props) { |
| 27 | const token: string = getAuthCache(JWT_TOKEN_KEY); | 28 | const token: string = getAuthCache(JWT_TOKEN_KEY); |
| 29 | + const { socketUrl } = useGlobSetting(); | ||
| 28 | const state = reactive({ | 30 | const state = reactive({ |
| 29 | - server: `${import.meta.env.VITE_WEB_SOCKET}${token}`, | 31 | + server: `${socketUrl}${token}`, |
| 30 | sendValue: JSON.stringify({ | 32 | sendValue: JSON.stringify({ |
| 31 | attrSubCmds: [], | 33 | attrSubCmds: [], |
| 32 | tsSubCmds: [ | 34 | tsSubCmds: [ |
| @@ -2,6 +2,7 @@ import { useWebSocket } from '@vueuse/core'; | @@ -2,6 +2,7 @@ import { useWebSocket } from '@vueuse/core'; | ||
| 2 | import { Ref, unref } from 'vue'; | 2 | import { Ref, unref } from 'vue'; |
| 3 | import { DataBoardLayoutInfo } from '../types/type'; | 3 | import { DataBoardLayoutInfo } from '../types/type'; |
| 4 | import { JWT_TOKEN_KEY } from '/@/enums/cacheEnum'; | 4 | import { JWT_TOKEN_KEY } from '/@/enums/cacheEnum'; |
| 5 | +import { useGlobSetting } from '/@/hooks/setting'; | ||
| 5 | import { getAuthCache } from '/@/utils/auth'; | 6 | import { getAuthCache } from '/@/utils/auth'; |
| 6 | import { isNullAndUnDef } from '/@/utils/is'; | 7 | import { isNullAndUnDef } from '/@/utils/is'; |
| 7 | 8 | ||
| @@ -57,8 +58,10 @@ export function useSocketConnect(dataSourceRef: Ref<DataBoardLayoutInfo[]>) { | @@ -57,8 +58,10 @@ export function useSocketConnect(dataSourceRef: Ref<DataBoardLayoutInfo[]>) { | ||
| 57 | 58 | ||
| 58 | const waitSendQueue: string[] = []; | 59 | const waitSendQueue: string[] = []; |
| 59 | 60 | ||
| 61 | + const { socketUrl } = useGlobSetting(); | ||
| 62 | + | ||
| 60 | const config = { | 63 | const config = { |
| 61 | - server: `${import.meta.env.VITE_WEB_SOCKET}${token}`, | 64 | + server: `${socketUrl}${token}`, |
| 62 | }; | 65 | }; |
| 63 | 66 | ||
| 64 | // const getNeedUpdateValueById = (componentId: string, deviceId: string) => {}; | 67 | // const getNeedUpdateValueById = (componentId: string, deviceId: string) => {}; |
| @@ -146,6 +146,16 @@ export interface GlobConfig { | @@ -146,6 +146,16 @@ export interface GlobConfig { | ||
| 146 | urlPrefix?: string; | 146 | urlPrefix?: string; |
| 147 | // Project abbreviation | 147 | // Project abbreviation |
| 148 | shortName: string; | 148 | shortName: string; |
| 149 | + // configuration center proxy prefix | ||
| 150 | + configurationPrefix: string; | ||
| 151 | + // socket url | ||
| 152 | + socketUrl: string; | ||
| 153 | + // alarm notify alarm duration | ||
| 154 | + alarmNotifyDuration: string; | ||
| 155 | + // alarm notify polling interval | ||
| 156 | + alarmPollingInterval: string; | ||
| 157 | + // upgrade your http policy to https | ||
| 158 | + securityPolicy: string; | ||
| 149 | } | 159 | } |
| 150 | export interface GlobEnvConfig { | 160 | export interface GlobEnvConfig { |
| 151 | // Site title | 161 | // Site title |
| @@ -158,6 +168,14 @@ export interface GlobEnvConfig { | @@ -158,6 +168,14 @@ export interface GlobEnvConfig { | ||
| 158 | VITE_GLOB_APP_SHORT_NAME: string; | 168 | VITE_GLOB_APP_SHORT_NAME: string; |
| 159 | // Upload url | 169 | // Upload url |
| 160 | VITE_GLOB_UPLOAD_URL?: string; | 170 | VITE_GLOB_UPLOAD_URL?: string; |
| 161 | - //configuration | 171 | + // configuration |
| 162 | VITE_GLOB_CONFIGURATION: string; | 172 | VITE_GLOB_CONFIGURATION: string; |
| 173 | + // socket | ||
| 174 | + VITE_GLOB_WEB_SOCKET: string; | ||
| 175 | + // force transform http to https | ||
| 176 | + VITE_GLOB_CONTENT_SECURITY_POLICY: string; | ||
| 177 | + // notify polling interval time | ||
| 178 | + VITE_GLOB_ALARM_NOTIFY_POLLING_INTERVAL_TIME: string; | ||
| 179 | + // notify duration | ||
| 180 | + VITE_GLOB_ALARM_NOTIFY_DURATION: string; | ||
| 163 | } | 181 | } |
| @@ -58,22 +58,22 @@ declare global { | @@ -58,22 +58,22 @@ declare global { | ||
| 58 | 58 | ||
| 59 | declare interface ViteEnv { | 59 | declare interface ViteEnv { |
| 60 | VITE_PORT: number; | 60 | VITE_PORT: number; |
| 61 | - VITE_USE_MOCK: boolean; | 61 | + VITE_GLOB_USE_MOCK: boolean; |
| 62 | VITE_USE_PWA: boolean; | 62 | VITE_USE_PWA: boolean; |
| 63 | - VITE_PUBLIC_PATH: string; | 63 | + VITE_GLOB_PUBLIC_PATH: string; |
| 64 | VITE_PROXY: [string, string][]; | 64 | VITE_PROXY: [string, string][]; |
| 65 | VITE_GLOB_APP_TITLE: string; | 65 | VITE_GLOB_APP_TITLE: string; |
| 66 | VITE_GLOB_APP_SHORT_NAME: string; | 66 | VITE_GLOB_APP_SHORT_NAME: string; |
| 67 | VITE_USE_CDN: boolean; | 67 | VITE_USE_CDN: boolean; |
| 68 | - VITE_DROP_CONSOLE: boolean; | ||
| 69 | - VITE_BUILD_COMPRESS: 'gzip' | 'brotli' | 'none'; | ||
| 70 | - VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE: boolean; | 68 | + VITE_GLOB_DROP_CONSOLE: boolean; |
| 69 | + VITE_GLOB_BUILD_COMPRESS: 'gzip' | 'brotli' | 'none'; | ||
| 70 | + VITE_GLOB_BUILD_COMPRESS_DELETE_ORIGIN_FILE: boolean; | ||
| 71 | VITE_LEGACY: boolean; | 71 | VITE_LEGACY: boolean; |
| 72 | - VITE_USE_IMAGEMIN: boolean; | 72 | + VITE_GLOB_USE_IMAGEMIN: boolean; |
| 73 | VITE_GENERATE_UI: string; | 73 | VITE_GENERATE_UI: string; |
| 74 | - VITE_CONTENT_SECURITY_POLICY: boolean; | ||
| 75 | - VITE_ALARM_NOTIFY_POLLING_INTERVAL_TIME: number; | ||
| 76 | - VITE_ALARM_NOTIFY_DURATION: number; | 74 | + VITE_GLOB_CONTENT_SECURITY_POLICY: boolean; |
| 75 | + VITE_GLOB_ALARM_NOTIFY_POLLING_INTERVAL_TIME: number; | ||
| 76 | + VITE_GLOB_ALARM_NOTIFY_DURATION: number; | ||
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | declare function parseInt(s: string | number, radix?: number): number; | 79 | declare function parseInt(s: string | number, radix?: number): number; |
| @@ -30,12 +30,12 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { | @@ -30,12 +30,12 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { | ||
| 30 | // The boolean type read by loadEnv is a string. This function can be converted to boolean type | 30 | // The boolean type read by loadEnv is a string. This function can be converted to boolean type |
| 31 | const viteEnv = wrapperEnv(env); | 31 | const viteEnv = wrapperEnv(env); |
| 32 | 32 | ||
| 33 | - const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_DROP_CONSOLE } = viteEnv; | 33 | + const { VITE_PORT, VITE_GLOB_PUBLIC_PATH, VITE_PROXY, VITE_GLOB_DROP_CONSOLE } = viteEnv; |
| 34 | 34 | ||
| 35 | const isBuild = command === 'build'; | 35 | const isBuild = command === 'build'; |
| 36 | 36 | ||
| 37 | return { | 37 | return { |
| 38 | - base: VITE_PUBLIC_PATH, | 38 | + base: VITE_GLOB_PUBLIC_PATH, |
| 39 | root, | 39 | root, |
| 40 | resolve: { | 40 | resolve: { |
| 41 | alias: [ | 41 | alias: [ |
| @@ -70,7 +70,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { | @@ -70,7 +70,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { | ||
| 70 | compress: { | 70 | compress: { |
| 71 | keep_infinity: true, | 71 | keep_infinity: true, |
| 72 | // Used to delete console in production environment | 72 | // Used to delete console in production environment |
| 73 | - drop_console: VITE_DROP_CONSOLE, | 73 | + drop_console: VITE_GLOB_DROP_CONSOLE, |
| 74 | }, | 74 | }, |
| 75 | }, | 75 | }, |
| 76 | // Turning off brotliSize display can slightly reduce packaging time | 76 | // Turning off brotliSize display can slightly reduce packaging time |