|
@@ -38,12 +38,13 @@ import { onLoad } from '@dcloudio/uni-app';
|
|
|
import { reactive, onMounted } from 'vue'
|
|
|
import { getCardDetailById, submitlearnPortAns } from '@/api/card'
|
|
|
import { getCollectionDetailById } from '@/api/collection'
|
|
|
-import { useAudioMange, useScheduler } from '@/hooks/index'
|
|
|
+import { useAudioMange, useScheduler, useBase64, useSchedulerOnce } from '@/hooks/index'
|
|
|
import { usePracticeStore, useOpraRecordStore, useGameCountdownStore, useCalcQuantityStore, useWisdomCoinStore } from '@/store'
|
|
|
import riveAni from '@/components/rive-ani/rive-ani.vue';
|
|
|
import { ref } from 'vue';
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* README.md 里有详细的参数说明
|
|
|
*/
|
|
@@ -58,7 +59,8 @@ interface State extends QueryParams {
|
|
|
card: Partial<API.Card> | null,
|
|
|
cardIds: string[],
|
|
|
playLoading: boolean,
|
|
|
- userCardAnswerList: any[]
|
|
|
+ userCardAnswerList: any[],
|
|
|
+ queryParams: API.P | null
|
|
|
}
|
|
|
|
|
|
const atx = useAudioMange()
|
|
@@ -73,11 +75,29 @@ const calcQuantityStore = useCalcQuantityStore()
|
|
|
|
|
|
const wisdomCoinStore = useWisdomCoinStore()
|
|
|
|
|
|
+const base64 = useBase64()
|
|
|
+
|
|
|
onLoad(query => {
|
|
|
- const options = query as QueryParams
|
|
|
- state.mode = options.mode
|
|
|
+
|
|
|
+ let options
|
|
|
+ if (import.meta.env.MODE !== "development") {
|
|
|
+ state.queryParams = base64.decode<API.P>(query!.p)
|
|
|
+ options = state.queryParams.data
|
|
|
+ } else {
|
|
|
+ state.queryParams = base64.decode<API.P>(query!.p)
|
|
|
+ options = state.queryParams.data
|
|
|
+ }
|
|
|
+ console.log(state.queryParams);
|
|
|
+
|
|
|
+ state.mode = options.mode || CardModeEnum.PREVIEW
|
|
|
state.collectionId = options.collectionId
|
|
|
if (options.cardId) state.cardId = options.cardId
|
|
|
+
|
|
|
+ wisdomCoinStore.total = options.userWisdomCoin
|
|
|
+ wisdomCoinStore.remainderWisdomCoin = options.remainderWisdomCoin
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
})
|
|
|
|
|
|
const riveAniRef = ref()
|
|
@@ -103,7 +123,8 @@ const state = reactive<State>({
|
|
|
}
|
|
|
},
|
|
|
playLoading: false,
|
|
|
- userCardAnswerList: []
|
|
|
+ userCardAnswerList: [],
|
|
|
+ queryParams: null
|
|
|
})
|
|
|
|
|
|
const stx = useScheduler(() => {
|
|
@@ -116,7 +137,7 @@ const stx = useScheduler(() => {
|
|
|
|
|
|
// 控制游戏开始
|
|
|
const gameStart = () => {
|
|
|
- navbarState.countdownTotal = 60
|
|
|
+ navbarState.countdownTotal = 5
|
|
|
stx.start()
|
|
|
playAudio()
|
|
|
}
|
|
@@ -130,25 +151,46 @@ const onSubmitCard = async () => {
|
|
|
await riveAniRef.value.start(3)
|
|
|
|
|
|
wisdomCoinStore.itemCoin += 3
|
|
|
-
|
|
|
+ console.log({
|
|
|
+ correctQuantity: calcQuantityStore.correctQuantity,
|
|
|
+ totalQuantity: calcQuantityStore.totalQuantity,
|
|
|
+ capability: state.card?.cardAble
|
|
|
+ });
|
|
|
+
|
|
|
// 保存做题记录
|
|
|
- opraRecordStore.push(calcQuantityStore)
|
|
|
+ opraRecordStore.push({
|
|
|
+ ...calcQuantityStore,
|
|
|
+ capability: state.card?.cardAble
|
|
|
+ })
|
|
|
|
|
|
// 保存做题时间
|
|
|
gameCountdownStore.sum(60 - navbarState.countdownTotal)
|
|
|
|
|
|
+ console.log("opraRecordStore:", opraRecordStore, navbarState.progress);
|
|
|
+
|
|
|
+
|
|
|
// 触发游戏结束
|
|
|
- if (opraRecordStore.length == 5) {
|
|
|
- // 重置一些东西
|
|
|
+ if (navbarState.progress == state.cardIds.length) {
|
|
|
+ console.log('我会触发吗');
|
|
|
+
|
|
|
+ gameCompleted()
|
|
|
+
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
// 切换题卡
|
|
|
- navbarState.progress++
|
|
|
|
|
|
- state.cardId = state.cardIds[navbarState.progress - 1]
|
|
|
+ if (state.opraMode == OpraModeEnum.PRACTICE) {
|
|
|
|
|
|
- GetCardDetailById()
|
|
|
+ // state.cardId
|
|
|
|
|
|
+ } else {
|
|
|
+ navbarState.progress++
|
|
|
+
|
|
|
+ state.cardId = state.cardIds[navbarState.progress - 1]
|
|
|
+ }
|
|
|
+
|
|
|
+ GetCardDetailById()
|
|
|
}
|
|
|
|
|
|
// 提交题卡
|
|
@@ -156,8 +198,8 @@ const gameCompleted = async () => {
|
|
|
// state
|
|
|
const $par = {
|
|
|
"attach": {
|
|
|
- "itemId": "",
|
|
|
- "recordId": ""
|
|
|
+ "itemId": state.queryParams?.attach.itemId,
|
|
|
+ "recordId": state.queryParams?.attach.recordId
|
|
|
},
|
|
|
"data": {
|
|
|
"correctQuantity": opraRecordStore.totalCorrectQuantity,
|
|
@@ -168,13 +210,17 @@ const gameCompleted = async () => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- const data = await submitlearnPortAns($par)
|
|
|
+ const data = await submitlearnPortAns($par, state.queryParams?.submitUrl!)
|
|
|
+
|
|
|
+ opraRecordStore.clear()
|
|
|
+ // 如果opraMode 的是learn 则跳转到app-web页面
|
|
|
+ // if (state.opraMode == OpraModeEnum.LEARN) {
|
|
|
+ window.location.href = `https://nginx.test.luojigou.vip/app_web/learn-plan.html#/?from='exercise'`
|
|
|
+ // }
|
|
|
|
|
|
}
|
|
|
|
|
|
const playAudio = () => {
|
|
|
- console.log('state.card?.audio:', state.card?.audio);
|
|
|
-
|
|
|
state.playLoading = true
|
|
|
atx.play(state.card?.audio!)
|
|
|
atx.onplayend(() => state.playLoading = false)
|
|
@@ -185,6 +231,7 @@ const GetCollectionDetailById = async () => {
|
|
|
const { data } = await getCollectionDetailById(state.collectionId)
|
|
|
if ( state.opraMode === OpraModeEnum.PRACTICE) {
|
|
|
state.cardIds = practiceStore.get(state.collectionId, data.cardIds)
|
|
|
+ state.cardId = practiceStore.nextId(state.cardIds)
|
|
|
} else {
|
|
|
state.cardIds = data.cardIds
|
|
|
}
|
|
@@ -200,20 +247,17 @@ const GetCardDetailById = async () => {
|
|
|
const { data } = await getCardDetailById(state.cardId!, state.mode)
|
|
|
state.card = data
|
|
|
if (state.mode === CardModeEnum.OPRA) {
|
|
|
- gameStart()
|
|
|
+ useSchedulerOnce(gameStart)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
|
- console.log('riveAniRef.value:', riveAniRef.value);
|
|
|
-
|
|
|
if (state.mode === 'preview') {
|
|
|
GetCardDetailById()
|
|
|
} else {
|
|
|
GetCollectionDetailById()
|
|
|
-
|
|
|
}
|
|
|
})
|
|
|
|