ソースを参照

1、检测窗口关闭时清除登录信息
2、cocos嵌入窗口逻辑实现

JutarryWu 2 週間 前
コミット
10747a0d55

+ 2 - 2
.env.development

@@ -2,8 +2,8 @@
 VITE_NODE_ENV = 'development'
 
 # 应用端口
-# VITE_APP_PORT = 3000
-VITE_APP_PORT = 5588
+VITE_APP_PORT = 3000
+# VITE_APP_PORT = 5588
 
 # 代理前缀
 VITE_APP_BASE_API = '/dev-api'

BIN
public/static/image/game/avatar/icon-31.png


BIN
public/static/image/game/avatar/icon-32.png


+ 18 - 0
src/layout/components/NavBar/components/NavbarRight.vue

@@ -42,7 +42,9 @@
 import { useAppStore, useTagsViewStore, useUserStore, useSettingsStore } from '@/store'
 import defaultSettings from '@/settings'
 import { DeviceEnum } from '@/enums/DeviceEnum'
+import { useSocket } from '@/utils/websoket'
 
+const { socket } = useSocket()
 const appStore = useAppStore()
 const tagsViewStore = useTagsViewStore()
 const userStore = useUserStore()
@@ -75,6 +77,22 @@ function logout() {
       })
   })
 }
+
+onMounted(() => {
+  socket.on('message', (data: any) => {
+    // 若Electron关闭窗口,则注销并退出系统
+    if (data === 'close-win-after') {
+      userStore
+        .logout()
+        .then(() => {
+          tagsViewStore.delAllViews()
+        })
+        .then(() => {
+          router.push(`/login?redirect=${route.fullPath}`)
+        })
+    }
+  })
+})
 </script>
 <style lang="scss" scoped>
 .setting-item {

+ 4 - 5
src/views/gameCenter/components/Introduction/index.vue

@@ -80,7 +80,7 @@
       <!-- 工作记忆 WorkingMemory -->
       <working-memory v-if="gameFlag.WorkingMemory" @game-over="gameOver" />
 
-      <cocos-dialog v-if="gameFlag.CocosDialog" :code="cocosType" @game-over="gameOver" />
+      <cocos-dialog v-if="gameFlag.CocosDialog" :code="cocosType" :url="cocosUrl" @game-over="gameOver" />
 
       <voice-imp ref="VoiceImpRef" />
     </div>
@@ -133,6 +133,7 @@ const gameFlag = ref<StrKeyObj>({
   SetTransferTest: false // 定式转移测验
 })
 const cocosType = ref('')
+const cocosUrl = ref('')
 const VoiceImpRef = ref()
 
 const beginGame = () => {
@@ -148,11 +149,9 @@ const beginGame = () => {
         tempPlanId = JSON.parse(currentPlanInfo).id
       }
     }
+    cocosUrl.value = `${window.location.origin}/cocos/${cocosType.value}/?userID=${userStore.user.id}&planID=${tempPlanId}`
     VoiceImpRef.value.pauseIntro()
-    window.open(
-      `${window.location.origin}/cocos/${cocosType.value}/?userID=${userStore.user.id}&planID=${tempPlanId}`,
-      '_blank'
-    )
+    gameFlag.value.CocosDialog = true
   } else {
     VoiceImpRef.value.pauseIntro()
     gameFlag.value[props.gameInfo.code] = true

+ 13 - 8
src/views/gameCenter/components/games/CocosDialog/index.vue

@@ -1,9 +1,8 @@
 <template>
-  <my-full-screen-dialog ref="openDialogRef" close-color="#134FA4" @close-dialog="handleClose">
+  <my-full-screen-dialog ref="openDialogRef" close-color="#134FA4" :show-close="false" @close-dialog="handleClose">
     <div class="cocos-container w-full h-full flex flex-col items-center text-[#134FA4]">
-      <iframe :src="`/src/views/gameCenter/cocos/${props.code}/build/pack/index.html`" frameborder="0"></iframe>
-<!--      <iframe :src="`/public/cocos/${props.code}/build/pack/index.html`" frameborder="0"></iframe>-->
-<!--      <iframe src="http://192.168.0.39:7457/web-mobile/pack/index.html" frameborder="0"></iframe>-->
+      <iframe :src="props.url" frameborder="0"></iframe>
+      <!--<iframe src="http://192.168.1.10:7456/web-mobile/ADL/index.html" frameborder="0"></iframe>-->
     </div>
   </my-full-screen-dialog>
 </template>
@@ -22,18 +21,25 @@ const props = defineProps({
     type: String,
     required: true,
     default: ''
+  },
+  url: {
+    type: String,
+    required: true,
+    default: ''
   }
 })
 const $emits = defineEmits(['gameOver'])
 const openDialogRef = ref()
 const handleClose = (done: () => void) => {
-  $emits('gameOver', 'COCOSDialog')
+  $emits('gameOver', 'CocosDialog')
 }
 
 async function exec() {
   openDialogRef.value.openDialog()
-  window.addEventListener('message',(e) => {
-    console.log(e)
+  window.addEventListener('message', (e: MessageEvent) => {
+    if (e.data === 'close') {
+      handleClose(() => {})
+    }
   })
 }
 
@@ -44,7 +50,6 @@ onMounted(() => {
 
 <style scoped lang="scss">
 .cocos-container {
-
   iframe {
     width: 100%;
     height: 100%;

+ 13 - 9
src/views/gameCenter/manage/index.vue

@@ -281,15 +281,19 @@ function resetForm() {
 
 const handlePlay = (row: any) => {
   if (row.status === '1') {
-    if (row.code.includes('Cocos')) {
-      let tempCode = row.code.replace('Cocos-', '')
-      const userStore = useUserStore()
-      window.open(`${window.location.origin}/cocos/${tempCode}/?userID=${userStore.user.id}&planID=`, '_blank')
-    } else {
-      gameInfo.value = row
-      showCurrentCode.value = row.code
-      showIntroFlag.value = true
-    }
+    gameInfo.value = row
+    showCurrentCode.value = row.code
+    showIntroFlag.value = true
+
+    // if (row.code.includes('Cocos')) {
+    //   let tempCode = row.code.replace('Cocos-', '')
+    //   const userStore = useUserStore()
+    //   window.open(`${window.location.origin}/cocos/${tempCode}/?userID=${userStore.user.id}&planID=`, '_blank')
+    // } else {
+    //   gameInfo.value = row
+    //   showCurrentCode.value = row.code
+    //   showIntroFlag.value = true
+    // }
   } else {
     ElMessage.warning('该游戏暂未完成,敬请期待!')
   }

+ 1 - 1
src/views/tester/components/RehabilitationEvaluation/CognitiveAbilityTask/index.vue

@@ -87,7 +87,7 @@ import { useUserStore } from '@/store'
 
 import { useSocket } from '@/utils/websoket'
 import { isJSON } from '@/utils'
-const { socket, wsSend, wsOn, wsOff } = useSocket()
+const { wsSend } = useSocket()
 
 const props = defineProps({
   cognitionId: {