Procházet zdrojové kódy

提交测试结果调用微信apicocos联调

周玉佂 před 1 měsícem
rodič
revize
9f2f57e9fd
2 změnil soubory, kde provedl 212 přidání a 39 odebrání
  1. 16 13
      .idea/workspace.xml
  2. 196 26
      src/views/cognitiveTasks/cocos/index.vue

+ 16 - 13
.idea/workspace.xml

@@ -4,16 +4,7 @@
     <option name="autoReloadType" value="SELECTIVE" />
   </component>
   <component name="ChangeListManager">
-    <list default="true" id="b347610e-2e38-40df-8414-1dc079962726" name="更改" comment="提交">
-      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/index.html" beforeDir="false" afterPath="$PROJECT_DIR$/index.html" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/views/cognitiveTasks/BreadthTraining/index.vue" beforeDir="false" afterPath="$PROJECT_DIR$/src/views/cognitiveTasks/BreadthTraining/index.vue" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/views/cognitiveTasks/ContinueAddition/index.vue" beforeDir="false" afterPath="$PROJECT_DIR$/src/views/cognitiveTasks/ContinueAddition/index.vue" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/views/cognitiveTasks/PictureNaming/index.vue" beforeDir="false" afterPath="$PROJECT_DIR$/src/views/cognitiveTasks/PictureNaming/index.vue" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/views/cognitiveTasks/PicturePuzzle/index.vue" beforeDir="false" afterPath="$PROJECT_DIR$/src/views/cognitiveTasks/PicturePuzzle/index.vue" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/views/cognitiveTasks/RouletteGame/index.vue" beforeDir="false" afterPath="$PROJECT_DIR$/src/views/cognitiveTasks/RouletteGame/index.vue" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/views/cognitiveTasks/spatialOrientationAbility/index.vue" beforeDir="false" afterPath="$PROJECT_DIR$/src/views/cognitiveTasks/spatialOrientationAbility/index.vue" afterDir="false" />
-    </list>
+    <list default="true" id="b347610e-2e38-40df-8414-1dc079962726" name="更改" comment="提交测试结果调用微信api" />
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
     <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@@ -62,6 +53,9 @@
       <recent name="D:\word\word\insomnia-cognition-h5\public\static\image\game\logo" />
       <recent name="D:\word\word\insomnia-cognition-h5\src\views\cognitiveTasks\SlotMachine" />
     </key>
+    <key name="MoveFile.RECENT_KEYS">
+      <recent name="D:\word\word\insomnia-cognition-h5" />
+    </key>
   </component>
   <component name="SharedIndexes">
     <attachedChunks>
@@ -80,7 +74,7 @@
       <updated>1734514599924</updated>
       <workItem from="1734514601970" duration="154000" />
       <workItem from="1734571154985" duration="23532000" />
-      <workItem from="1747192052253" duration="5220000" />
+      <workItem from="1747192052253" duration="13962000" />
     </task>
     <task id="LOCAL-00001" summary="提交">
       <option name="closed" value="true" />
@@ -90,7 +84,15 @@
       <option name="project" value="LOCAL" />
       <updated>1734663799815</updated>
     </task>
-    <option name="localTasksCounter" value="2" />
+    <task id="LOCAL-00002" summary="提交测试结果调用微信api">
+      <option name="closed" value="true" />
+      <created>1747210302000</created>
+      <option name="number" value="00002" />
+      <option name="presentableId" value="LOCAL-00002" />
+      <option name="project" value="LOCAL" />
+      <updated>1747210302000</updated>
+    </task>
+    <option name="localTasksCounter" value="3" />
     <servers />
   </component>
   <component name="TypeScriptGeneratedFilesManager">
@@ -100,6 +102,7 @@
     <option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
     <MESSAGE value="init" />
     <MESSAGE value="提交" />
-    <option name="LAST_COMMIT_MESSAGE" value="提交" />
+    <MESSAGE value="提交测试结果调用微信api" />
+    <option name="LAST_COMMIT_MESSAGE" value="提交测试结果调用微信api" />
   </component>
 </project>

+ 196 - 26
src/views/cognitiveTasks/cocos/index.vue

@@ -1,36 +1,206 @@
-<script setup lang="ts">
-/*
- * 组件名: cocos
- * 组件用途: cocos外框
- * 创建日期: 2024/8/21
- * 编写者: JutarryWu
- */
+<!--<script setup lang="ts">-->
+<!--/*-->
+<!-- * 组件名: cocos-->
+<!-- * 组件用途: cocos外框-->
+<!-- * 创建日期: 2024/8/21-->
+<!-- * 编写者: JutarryWu-->
+<!-- */-->
+<!--const userId = sessionStorage.getItem('userId')-->
+<!--// const src = `https://byly.jue-ming.com/xuanZeXunLian/?userId=${userId}`-->
+<!--const src = `http://192.168.1.20:7456/?userId=${userId}`-->
+<!--async function exec() {-->
+<!--}-->
+<!--// 定义响应式数据-->
+<!--const hideOne = ref(true)-->
+<!--const hideTwo = ref(true)-->
+<!--const iframe = ref()-->
+<!--// 显示 Cocos 模态框-->
+<!--const showCocos = () => {-->
+<!--  hideTwo.value = false-->
+<!--  setTimeout(() => {-->
+<!--    hideOne.value = false-->
+<!--  }, 260)-->
+<!--}-->
+
+<!--// 隐藏 Cocos 模态框-->
+<!--const hideCocos = () => {-->
+<!--  hideOne.value = true-->
+<!--  setTimeout(() => {-->
+<!--    hideTwo.value = true-->
+<!--  }, 260)-->
+<!--}-->
+<!--// 初始化 iframe-->
+<!--const initIframe = () => {-->
+<!--  showCocos()-->
+<!--  iframe.value = document.getElementById('cocosDialog')-->
+<!--  iframe.value.onload = () => {-->
+<!--    window.addEventListener('message', (e) => {-->
+<!--      if (e.data === 'close') {-->
+<!--        hideCocos()-->
+<!--      } else if (e.data === 'cocos-game-load-over') {-->
+<!--        // console.log('cocos-game-load-over', props.level)-->
+<!--        // sendMessage(props.level)-->
+<!--      }-->
+<!--    })-->
+<!--  }-->
+<!--}-->
+
+<!--// 组件挂载后执行-->
+<!--onMounted(() => {-->
+<!--  nextTick(() => {-->
+<!--    initIframe()-->
+<!--  })-->
+<!--})-->
+<!--// onMounted(() => {-->
+<!--//   exec()-->
+<!--// })-->
+<!--</script>-->
+
+<!--<template>-->
+<!--  <section class="app-container">-->
+<!--    <div v-if="false" class="absolute right-[12px] top-[12px] z-[999] cursor-pointer">-->
+<!--      <van-icon name="arrow-up" class="text-[24px] text-[#fff]" />-->
+<!--    </div>-->
+<!--    <iframe-->
+<!--      id="cocosDialog"-->
+<!--      :src="src"-->
+<!--      width="100%"-->
+<!--      height="100%"-->
+<!--      frameborder="0"-->
+<!--      scrolling="no"-->
+<!--    />-->
+<!--  </section>-->
+<!--</template>-->
+
+<!--<style scoped lang="scss">-->
+<!--.app-container {-->
+<!--}-->
+<!--</style>-->
+<template>
+  <div
+    :class="{ 'hide-one': hideOne, 'hide-two': hideTwo }"
+    class="cocos-modal"
+  >
+    <iframe
+      id="cocosDialog"
+      :src="src"
+      allow="microphone *;camera *"
+      style="border: none;"
+    ></iframe>
+  </div>
+</template>
+
+<script setup>
+import { ref, onMounted, nextTick, onUnmounted } from 'vue'
+import {showSuccessToast} from "vant";
 const userId = sessionStorage.getItem('userId')
-const src = `https://byly.jue-ming.com/xuanZeXunLian/?userId=${userId}`
-async function exec() {
+const src = `https://byly.jue-ming.com/xuanZeXunLian/?userID=${userId}`
+// const src = `http://192.168.1.20:7456/?userID=${userId}`
+// 定义响应式数据
+const hideOne = ref(true)
+const hideTwo = ref(true)
+const iframe = ref(null)
+const router = useRouter()
+
+// 显示 Cocos 模态框
+const showCocos = () => {
+  hideTwo.value = false
+  setTimeout(() => {
+    hideOne.value = false
+  }, 260)
 }
 
+// 隐藏 Cocos 模态框
+const hideCocos = () => {
+  hideOne.value = true
+  setTimeout(() => {
+    hideTwo.value = true
+    // emit('queryLevel')
+  }, 260)
+}
+
+// 处理接收到的消息
+const handleMessage = (e) => {
+  console.log('接收到消息', e.data)
+  // 限定消息来源,替换为实际的 Cocos 页面域名
+  // const expectedOrigin = 'http://192.168.1.20:7456'
+  // if (e.origin !== expectedOrigin) return
+  if (e.data === 'close') {
+    console.log('收到关闭消息')
+    router.go(-1)
+  }else if (e.data === 'cocos-close') {
+    // showSuccessToast('本次训练已结束')
+    setTimeout(() => {
+      // 使用示例
+      const userAgent = navigator.userAgent.toLowerCase()
+      const isWechatEnvironment = userAgent.includes('micromessenger')
+      if (isWechatEnvironment) {
+        // 执行微信环境下的逻辑,如调用微信JS-SDK
+        if (wx && wx.miniProgram) {
+          wx.miniProgram.navigateTo({
+            url: '/pages/media/pages/feedbackTask/finish/finish',
+          })
+        }
+      }
+      else {
+        router.go(-1)
+        // 执行浏览器环境下的逻辑
+      }
+    }, 1300)
+
+  }
+}
+
+// 初始化 iframe
+const initIframe = () => {
+  showCocos()
+  iframe.value = document.getElementById('cocosDialog')
+  if (iframe.value) {
+    iframe.value.onload = () => {
+      // 监听消息事件
+      console.log('iframe加载完成')
+      window.addEventListener('message', handleMessage)
+    }
+  }
+}
+
+// 组件挂载后执行
 onMounted(() => {
-  exec()
+  nextTick(() => {
+    initIframe()
+  })
+})
+
+// 组件卸载时移除事件监听器
+onUnmounted(() => {
+  window.removeEventListener('message', handleMessage)
 })
 </script>
 
-<template>
-  <section class="app-container">
-    <div v-if="false" class="absolute right-[12px] top-[12px] z-[999] cursor-pointer">
-      <van-icon name="arrow-up" class="text-[24px] text-[#fff]" />
-    </div>
-    <iframe
-      :src="src"
-      width="100%"
-      height="100%"
-      frameborder="0"
-      scrolling="no"
-    />
-  </section>
-</template>
+<style lang="scss" scoped>
+.cocos-modal {
+  background: #1e2022;
+  width: 100%;
+  height: 100%;
+  position: fixed;
+  top: 0;
+  left: 0;
+  z-index: 99;
+  opacity: 1;
+  transition: all 0.2s ease-in-out;
+  overflow: hidden;
+
+  &.hide-one {
+    opacity: 0;
+  }
+
+  &.hide-two {
+    top: 110%;
+  }
 
-<style scoped lang="scss">
-.app-container {
+  iframe {
+    width: 100%;
+    height: 100%;
+  }
 }
 </style>