11wqe1 17 hours ago
parent
commit
07ee476e8a
1 changed files with 81 additions and 7 deletions
  1. 81 7
      src/views/main.vue

+ 81 - 7
src/views/main.vue

@@ -120,6 +120,17 @@
         allow="camera *; microphone *;display-capture;midi;encrypted-media;clipboard-write;clipboard-read" :webkitallowfullscreen="true" :mozallowfullscreen="true" :allowfullscreen="true"
         ref="iframeRef" src="//app.cocorobo.cn/#/appSelection" frameborder="0"></iframe>
       </div>
+      <div class="iframe" :style="leftShow ? { width: '100%' } : ''" v-else-if="activeIndex === 'openApp'" v-loading="loading">
+        <iframe
+          ref="clearIframeRef"
+          :src="clearifa"
+          allow="camera *; microphone *;display-capture;midi;encrypted-media;clipboard-write;clipboard-read"
+          :webkitallowfullscreen="true"
+          :mozallowfullscreen="true"
+          :allowfullscreen="true"
+          frameborder="0"
+        ></iframe>
+      </div>
       <div class="iframe" :style="leftShow ? { width: '100%' } : ''" v-else v-loading="loading">
         <iframe 
         allow="camera *; microphone *;display-capture;midi;encrypted-media;clipboard-write;clipboard-read" :webkitallowfullscreen="true" :mozallowfullscreen="true" :allowfullscreen="true"
@@ -130,7 +141,7 @@
   </div>
 </template>
 <script setup>
-import { ref, watchEffect, onMounted, inject } from 'vue';
+import { ref, watchEffect, onMounted, onUnmounted, nextTick, inject } from 'vue';
 import { ArrowLeft,ArrowRight } from '@element-plus/icons-vue'
 import img1 from '@/assets/icon/1.png'
 import img11 from '@/assets/icon/1-1.png'
@@ -173,14 +184,77 @@ const iframeRef1Url4 = ref('')
 const iframeRef2Dialog = ref(false)
 const leftShow = ref(false)
 const admin = ref(false)
+const clearifa = ref('')
+const openAppCallback = ref(null)
+const clearIframeRef = ref(null)
+
+const resolveAppUrl = (val) => {
+  if (!val) return ''
+  const isBeta = window.location.href.includes('beta') ? 'beta.' : ''
+  const area = lang.lang == 'hk' ? 'hk' : lang.lang == 'en' ? 'com' : 'cn'
+  const userid = user.user.userid
+  const oid = user.user.organizeid
+  const org = user.user.org
+  const role = user.user.role
+  const type = user.user.type
+  if (val == 'cocoflow') {
+    return `https://${isBeta}app.cocorobo.${area}/#/?userid=${userid}&oid=${oid}&role=${type}&org=${org}`
+  }
+  if (val == 'cocoflow_agent') {
+    return `https://${isBeta}app.cocorobo.${area}/#/?userid=${userid}&oid=${oid}&role=${type}&org=${org}&tab=1`
+  }
+  if (val == 'project') {
+    return `https://${isBeta}pbl.cocorobo.${area}/pbl-teacher-table/dist/#/course?userid=${userid}&oid=${oid}&role=${role}&org=${org}`
+  }
+  if (val == 'cocostudy001') {
+    return `https://${isBeta}cocostudy.cocorobo.${area}/`
+  }
+  if (val == 'cocobookllm') {
+    return `https://${isBeta}pbl.cocorobo.${area}/pbl-teacher-table/dist/#/pptEasy?userid=${userid}&oid=${oid}&role=${role}&org=${org}`
+  }
+  return ''
+}
+
+const runOpenAppCallback = () => {
+  const cb = openAppCallback.value
+  openAppCallback.value = null
+  if (typeof cb === 'function') cb()
+}
+
+const listenOpenAppIframeLoad = (alreadyOpened) => {
+  const iframe = clearIframeRef.value
+  if (!iframe) {
+    runOpenAppCallback()
+    return
+  }
+  const onLoad = () => {
+    iframe.removeEventListener('load', onLoad)
+    loading.value = false
+    runOpenAppCallback()
+  }
+  iframe.addEventListener('load', onLoad)
+  if (alreadyOpened) onLoad()
+}
+
+const openWithCallback = (val, callback) => {
+  if (!val) return
+  openAppCallback.value = typeof callback === 'function' ? callback : null
+  const host = resolveAppUrl(val)
+  if (!host) return
+
+  const alreadyOpened = !!clearifa.value && clearifa.value === host && activeIndex.value === 'openApp'
+  loading.value = true
+  clearifa.value = host
+  activeIndex.value = 'openApp'
+  nextTick(() => listenOpenAppIframeLoad(alreadyOpened))
+}
 
 onMounted(() => {
-  // let timer = setInterval(() => {
-  //   if (JSON.stringify(user.user) != "{}") {
-  //     clickSwitch(1)
-  //     clearInterval(timer)
-  //   }
-  // }, 10);
+  window.openApp = (val, callback) => openWithCallback(val, callback)
+})
+
+onUnmounted(() => {
+  if (window.openApp) delete window.openApp
 })