任一存 2 лет назад
Родитель
Сommit
276a2d3207

+ 7 - 0
game/src/api.js

@@ -290,4 +290,11 @@ export async function redeem(description, name, phone, prizeId, score) {
   } else {
     return res.data.data
   }
+}
+
+export function notifyQuit() {
+  window.parent?.postMessage({
+    frome: 'game',
+    message: 'quit',
+  }, '*')
 }

BIN
game/src/assets/images/icon_home_2.png


+ 6 - 2
game/src/store/index.js

@@ -33,8 +33,9 @@ export default createStore({
       // second: 60,
       // type: "game",
       // updateTime: "2024-01-08 19:28:35",
-      // }
+      // },
     ],
+    isDirectPlayGame: false,
     score: undefined,
     ifScoreLimitReached: undefined,
     scoreLimit: undefined,
@@ -80,7 +81,10 @@ export default createStore({
     },
     setScoreLimit(state, value) {
       state.scoreLimit = value
-    }
+    },
+    setIsDirectPlayGame(state, value) {
+      state.isDirectPlayGame = value
+    },
   },
   actions: {
   },

+ 8 - 4
game/src/views/ExamPaper2.vue

@@ -130,7 +130,7 @@ import { useRoute, useRouter } from "vue-router"
 import { useStore } from "vuex"
 import dayjs from 'dayjs'
 import { shuffle } from 'lodash'
-import { addScore, getScore, getExamQuestionList } from '@/api.js'
+import { addScore, getScore, getExamQuestionList, notifyQuit } from '@/api.js'
 import GameRule from '@/components/GameRule.vue'
 import NotifyBonusPointReachedLimit from '@/components/NotifyBonusPointReachedLimit.vue'
 
@@ -184,9 +184,13 @@ getExamQuestionList().then((res) => {
 })
 
 function onClickReturnHome() {
-  router.push({
-    name: 'HomeView',
-  })
+  if (store.state.isDirectPlayGame) {
+    notifyQuit()
+  } else {
+    router.push({
+      name: 'HomeView',
+    })
+  }
 }
 
 /**

+ 8 - 3
game/src/views/ExamPaper3.vue

@@ -48,6 +48,7 @@
 import { ref, computed, watch, onMounted } from "vue"
 import { useRoute, useRouter } from "vue-router"
 import { useStore } from "vuex"
+import { notifyQuit } from '@/api.js'
 
 const route = useRoute()
 const router = useRouter()
@@ -59,9 +60,13 @@ const {
 } = useSizeAdapt(390, 752)
 
 function onClickReturnHome() {
-  router.push({
-    name: 'HomeView',
-  })
+  if (store.state.isDirectPlayGame) {
+    notifyQuit()
+  } else {
+    router.push({
+      name: 'HomeView',
+    })
+  }
 }
 
 </script>

+ 8 - 3
game/src/views/GameByUnity.vue

@@ -44,6 +44,7 @@ import { useStore } from "vuex"
 import GameRule from '@/components/GameRule.vue'
 import NotifyBonusPointReachedLimit from '@/components/NotifyBonusPointReachedLimit.vue'
 import { onBeforeUnmount } from "vue"
+import { notifyQuit } from '@/api.js'
 
 const route = useRoute()
 const router = useRouter()
@@ -77,9 +78,13 @@ const returnHomeBtnBgImgUrl = require(`@/assets/images/icon_home${floatingBtnFil
 const gameRuleBtnBgImgUrl = require(`@/assets/images/icon_rules${floatingBtnFileNameAffix}.png`)
 
 function onClickReturnHome() {
-  router.push({
-    name: 'HomeView',
-  })
+  if (store.state.isDirectPlayGame) {
+    notifyQuit()
+  } else {
+    router.push({
+      name: 'HomeView',
+    })
+  }
 }
 
 const gameRuleConfigMap = {

+ 16 - 2
game/src/views/HomeView.vue

@@ -196,6 +196,17 @@
           draggable="false"
         >
       </button>
+      <button
+        class="quit"
+        @click="onClickQuit"
+      >
+        <img
+          class=""
+          src="@/assets/images/icon_home_2.png"
+          alt=""
+          draggable="false"
+        >
+      </button>
     </div>
 
     <!-- 让用户选择是否登录、注册 -->
@@ -222,7 +233,7 @@ import { useRoute, useRouter } from "vue-router"
 import { useStore } from "vuex"
 import ClipboardJS from 'clipboard'
 import { showDialog } from 'vant'
-import { logout, getScore } from '@/api.js'
+import { logout, getScore, notifyQuit } from '@/api.js'
 import LoginChoice from '@/components/LoginChoice.vue'
 
 const route = useRoute()
@@ -393,6 +404,7 @@ if (route.query.gameIdx) {
   router.replace({
     name: route.name
   })
+  store.commit('setIsDirectPlayGame', true)
   if (isShowLoading.value) {
     hideLoadingCallback = () => {
       onClickGameEntry(gameIdx)
@@ -402,7 +414,9 @@ if (route.query.gameIdx) {
   }
 }
 
-console.log(route.query)
+function onClickQuit() {
+  notifyQuit()
+}
 </script>
 
 <style lang="less" scoped>

+ 8 - 4
game/src/views/PairUp.vue

@@ -114,7 +114,7 @@ import { useStore } from "vuex"
 import dayjs from 'dayjs'
 import { shuffle } from 'lodash'
 import PairUpOver from '@/components/PairUpOver.vue'
-import { addScore, getScore } from '@/api.js'
+import { addScore, getScore, notifyQuit } from '@/api.js'
 import GameRule from '@/components/GameRule.vue'
 import NotifyBonusPointReachedLimit from '@/components/NotifyBonusPointReachedLimit.vue'
 
@@ -130,9 +130,13 @@ const {
 const isShowRule = ref(false)
 
 function onClickReturnHome() {
-  router.push({
-    name: 'HomeView',
-  })
+  if (store.state.isDirectPlayGame) {
+    notifyQuit()
+  } else {
+    router.push({
+      name: 'HomeView',
+    })
+  }
 }
 
 const isOver = ref(false)

+ 8 - 4
game/src/views/PlantTree.vue

@@ -155,7 +155,7 @@ import { useStore } from "vuex"
 import dayjs from 'dayjs'
 import { showDialog } from 'vant'
 import { shuffle } from 'lodash'
-import { addScore, getScore } from '@/api.js'
+import { addScore, getScore, notifyQuit } from '@/api.js'
 import GameRule from '@/components/GameRule.vue'
 import NotifyBonusPointReachedLimit from '@/components/NotifyBonusPointReachedLimit.vue'
 
@@ -169,9 +169,13 @@ const {
 } = useSizeAdapt(390, 752)
 
 function onClickReturnHome() {
-  router.push({
-    name: 'HomeView',
-  })
+  if (store.state.isDirectPlayGame) {
+    notifyQuit()
+  } else {
+    router.push({
+      name: 'HomeView',
+    })
+  }
 }
 
 const isShowRule = ref(false)