Browse Source

feat(全局配置): 添加版本判断及全局变量支持

添加全局版本判断功能,根据URL自动识别当前版本(cn/hk/com)
声明全局类型并注册$version变量到Vue实例
在iframe处理中根据当前版本统一替换域名
lsc 1 month ago
parent
commit
d7b4832586
2 changed files with 40 additions and 1 deletions
  1. 24 0
      src/main.ts
  2. 16 1
      src/views/Student/index.vue

+ 24 - 0
src/main.ts

@@ -2,6 +2,13 @@ import { createApp } from 'vue'
 import { createPinia } from 'pinia'
 import App from './App.vue'
 
+// TypeScript declarations for global properties
+declare module '@vue/runtime-core' {
+  interface ComponentCustomProperties {
+    $version: 'cn' | 'hk' | 'com'
+  }
+}
+
 import '@icon-park/vue-next/styles/index.css'
 import 'prosemirror-view/style/prosemirror.css'
 import 'animate.css'
@@ -12,7 +19,24 @@ import '@/assets/styles/font.scss'
 import Icon from '@/plugins/icon'
 import Directive from '@/plugins/directive'
 
+// 全局变量:判断当前版本 (cn/hk/com)
+export const getCurrentVersion = () => {
+  const href = window.location.href.toLowerCase()
+  if (href.includes('cn')) return 'cn'
+  if (href.includes('hk')) return 'hk'
+  if (href.includes('com')) return 'com'
+  return 'cn' // 默认cn版本
+}
+
+// 当前版本
+const currentVersion = getCurrentVersion()
+
+export default currentVersion
+
 const app = createApp(App)
+// 注册全局变量
+app.config.globalProperties.$version = currentVersion
+
 app.use(Icon)
 app.use(Directive)
 app.use(createPinia())

+ 16 - 1
src/views/Student/index.vue

@@ -372,6 +372,7 @@ import useImport from '@/hooks/useImport'
 import message from '@/utils/message'
 import api, { API_URL } from '@/services/course'
 import axios from '@/services/config'
+import currentVersion from '@/main'
 import ShotWorkModal from './components/ShotWorkModal.vue'
 import QAWorkModal from './components/QAWorkModal.vue'
 import ChoiceWorkModal from './components/ChoiceWorkModal.vue'
@@ -1306,8 +1307,22 @@ const processIframeLinks = async () => {
             slide.elements.map(async (element) => {
               // 检查是否是iframe元素
               if (element.type === ElementTypes.FRAME && element.url) {
-                const iframeSrc = element.url
+                let iframeSrc = element.url
                 const toolType = element.toolType
+                console.log('当前版本:', currentVersion)
+                // 替换beta环境域名
+                iframeSrc = iframeSrc.replace(/https?:\/\/beta\.pbl\.cocorobo\.cn/g, 'https://pbl.cocorobo.cn')
+
+                // 根据当前版本统一域名
+                const versionMap = {
+                  cn: /cocorobo\.(hk|com)/g,
+                  hk: /cocorobo\.(cn|com)/g,
+                  com: /cocorobo\.(cn|hk)/g
+                }
+
+                const targetDomain = `cocorobo.${currentVersion}`
+                iframeSrc = iframeSrc.replace(versionMap[currentVersion], targetDomain)
+
 
                 if (iframeSrc.includes('workPage')) {
                   hasIframe = true