소스 검색

Merge branch '2024鹅状元' of https://gogs.mtavip.com/wangguoyu/uniProject into 2024鹅状元

tanxue 5 달 전
부모
커밋
1c3346f17d

+ 24 - 0
api/game.js

@@ -0,0 +1,24 @@
+import request from '@/utils/request'
+export function getYouxiInfo(data = {}) {
+    return request({
+        'url': '/app/youxi/info',
+        headers: {
+            isToken: true
+        },
+        method: 'post',
+        data,
+        timeout: 20000
+    })
+}
+
+export function getYouxiWeishi(data = {}) {
+    return request({
+        'url': '/app/youxi/weishi',
+        headers: {
+            isToken: true
+        },
+        method: 'post',
+        data,
+        timeout: 20000
+    })
+}

+ 36 - 0
pages/game/components/constantConfig.js

@@ -0,0 +1,36 @@
+// 食物种类列表
+export const foodSpeciesList = [{
+		id: 25,
+		imgUrl: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
+		credit: 100
+	},
+	{
+		id: 50,
+		imgUrl: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
+		credit: 200
+	},
+	{
+		id: 100,
+		imgUrl: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
+		credit: 300
+	}
+]
+
+// 大鹅成长阶段
+export const gooseGrowthTypeList = [{
+		id: 0,
+		imgUrl: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
+	},
+	{
+		id: 1,
+		imgUrl: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
+	},
+	{
+		id: 2,
+		imgUrl: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
+	},
+	{
+		id: 3,
+		imgUrl: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
+	}
+]

+ 21 - 0
pages/game/components/food.vue

@@ -0,0 +1,21 @@
+<template>
+	<view>
+		<image v-if="imgUrl" :src="imgUrl"></image>
+	</view>
+</template>
+
+<script setup>
+	import {foodSpeciesList} from './constantConfig';
+	import { ref,computed } from "vue";
+	const props = defineProps({
+		shiwuId: [String,Number]
+	})
+	
+	const imgUrl = computed(() => {
+		const active = foodSpeciesList.find(item => item.id == props.shiwuId)
+		return active ? active.imgUrl: ''
+	})
+</script>
+
+<style>
+</style>

+ 41 - 0
pages/game/components/foodSelect.vue

@@ -0,0 +1,41 @@
+<template>
+	<!-- 食物图标按钮 -->
+	<view @click="handleOpen">选择</view>
+	<uni-popup ref="popupRef" type="bottom" border-radius="10px 10px 0 0" background-color="#fff">
+		<view style="height: 300px;display: flex;justify-content: space-between;">
+			<view v-for="item in foodSpeciesList" :key="item.id" @click="handleSelectFood(item)">
+				<img style="width: 50px;height: auto;" :src="item.imgUrl">
+				<text>{{item.credit}}</text>
+			</view>
+		</view>
+	</uni-popup>
+</template>
+
+<script setup>
+	import {foodSpeciesList} from './constantConfig';
+	import {ref} from "vue";
+	const emits = defineEmits(['weishi'])
+	const props = defineProps({
+		shiwuId: {
+			type: [String,Number]
+		}
+	})
+	
+	const popupRef = ref(null);
+	function handleOpen() {
+		popupRef.value.open();
+	}
+	function handleClose() {
+		popupRef.value.close();
+	}
+	function handleSelectFood(shiwu) {
+		emits('weishi',shiwu);
+	}
+	
+	defineExpose({
+		handleClose
+	})
+</script>
+
+<style>
+</style>

+ 30 - 0
pages/game/components/goose.vue

@@ -0,0 +1,30 @@
+<template>
+	<view>
+		<up-line-progress :percentage="progress" activeColor="#ff0000"></up-line-progress>
+		<image :src="imgUrl"></image>
+	</view>
+</template>
+
+<script setup>
+	import {gooseGrowthTypeList} from "./constantConfig.js"
+	import { ref,computed } from "vue";
+	import upLineProgress from "uview-plus/components/u-line-progress/u-line-progress.vue";  
+	
+	const props = defineProps({
+		grouthType: {
+			type: [String,Number]
+		},
+		progress: {
+			type: [String,Number],
+			default: 0
+		}
+	})
+	
+	const imgUrl = computed(() => {
+		const active = gooseGrowthTypeList.find(item => item.grouthType == props.grouthType)
+		return active ? active.imgUrl: ''
+	})
+</script>
+
+<style>
+</style>

+ 7 - 3
pages/game/index.vue

@@ -7,19 +7,23 @@
 	<!-- 大鹅 4阶段 -->
 	<gooseVue :growth="growth" :growthType="growthType" :progress="progress"></gooseVue>
 	<!-- 食物选择 -->
-	<foodSelectVue :shiwuId="shiwuId" @weishi="onWeiShi"></foodSelectVue>
+	<foodSelectVue ref="foodSelectRef" :shiwuId="shiwuId" @weishi="onWeiShi"></foodSelectVue>
 </template>
 
 <script setup>
-
+	import {ref} from "vue";
 	import foodVue from "./components/food.vue";
 	import gooseVue from "./components/goose.vue";
 	import foodSelectVue from "./components/foodSelect.vue";
 	import { useGame } from "./useGame";
 	const {	credit,growth,growthType,progress,shiwuId ,handleWeishi } = useGame();
 	
+	const foodSelectRef = ref(null);
+	
 	function onWeiShi(data) {
-		handleWeishi(data)
+		handleWeishi(data.id, () => {
+			foodSelectRef.value.handleClose();
+		})
 	}
 </script>
 

+ 84 - 0
pages/game/useGame.js

@@ -0,0 +1,84 @@
+import {
+	reactive,
+	ref,
+	getCurrentInstance,
+	onMounted,
+	toRefs
+} from "vue";
+import {
+	onLoad
+} from '@dcloudio/uni-app';
+import {toast,getUserIdentity,catchError} from "@/utils/common";
+import {getYouxiInfo, getYouxiWeishi} from "@/api/game.js";
+import cacheManager from "@/utils/cacheManager.js"
+
+
+export function useGame() {
+	const UserCode = getUserIdentity();
+	const data = reactive({
+			credit: 0, // 当前积分
+			growth: 0, // 成长值
+			growthType:0, // 成长类型
+			progress:0, // 当前进度
+			shiwuId:null // 上一次食物
+	})
+	async function getGameInfo() {
+		const [err, info] = await catchError(getYouxiInfo());
+		if (err) {
+			toast("请求异常,请稍后尝试");
+			return;
+		}
+		const {
+			credit,growth,growthType,progress,shiwuId
+		} = info;
+		
+		data.credit = credit;
+		data.growth = growth;
+		data.growthType = growthType;
+		data.progress = progress;
+		data.shiwuId = shiwuId;
+	}
+	
+	async function handleWeishi(cShiwuId, doFinish) {
+		const [err, info] = await catchError(getYouxiWeishi({shiwuId:cShiwuId}));
+		if (err) {
+			toast("请求异常,请稍后尝试");
+			return;
+		}
+		const {
+			credit,growth,growthType,progress,shiwuId,changeFlag
+		} = info;
+		
+		data.credit = credit;
+		data.growthType = growthType;
+		data.progress = progress;
+		data.shiwuId = shiwuId;
+		
+		if (changeFlag) {
+			// 更新成长状态
+			updateCachegrowthType();
+		}
+		
+		doFinish && doFinish();
+	}
+	
+	// 更新缓存 大鹅成长值
+	function updateCachegrowthType(growthType) {
+		cacheManager.updateObject('auth', { growthType })
+	}
+	
+
+	onLoad(async (options) => {
+		if (UserCode !== "Visitor") {
+			getGameInfo();
+		} else {}
+	})
+	
+	return {
+		...toRefs(data),
+		UserCode,
+		handleWeishi,
+	}
+	
+}
+

+ 19 - 6
pages/selectGradesTerms/index.vue

@@ -2,7 +2,7 @@
 	<view class="grades-terms-page">
 		<view class="icon-title-navBar-box">
 			<!-- 返回按钮↓ -->
-			<view class="nav-bar-icon"></view>
+			<view class="nav-bar-icon"  @click="handleBack"></view>
 		</view>
 		<view class="grades-body">
 			<view class="grades-change-title"></view>
@@ -26,7 +26,8 @@
 <script setup>
 	import {
 		reactive,
-		toRefs
+		toRefs,
+		ref,
 	} from "vue";
 	import {
 		nianji_list,
@@ -37,7 +38,7 @@
 	} from "@dcloudio/uni-app";
 	import {getUserIdentity} from "@/utils/common.js"
 	import cacheManager from "@/utils/cacheManager.js"
-		
+
 	function useSelectGrade() {
 		const userCode = getUserIdentity();
 		const data = reactive({
@@ -66,6 +67,7 @@
 				uni.showToast({
 					title: "请选择年级",
 					duration: 2000,
+					icon: 'error'
 				});
 				return;
 			}
@@ -74,6 +76,7 @@
 				uni.showToast({
 					title: "请选择学科",
 					duration: 2000,
+					icon: 'error'
 				});
 				return;
 			}
@@ -102,10 +105,17 @@
 			}
 
 		}
-
+		function handleBack() {
+			if (userCode !== 'Visitor') {
+				uni.redirectTo({ url: `/pages/study/index`})
+			} else {
+				uni.redirectTo({url: '/pages/login/index'})
+			}
+		}
+		
 		return {
 			...toRefs(data),
-
+			handleBack,
 			// 方法
 			handleConfirm, // 选择年级+学科
 		};
@@ -114,7 +124,8 @@
 	const {
 		activeNianji,
 		activeXueke,
-		handleConfirm
+		handleConfirm,
+		handleBack
 	} = useSelectGrade()
 
 	function handleSelectGrade(item) {
@@ -124,4 +135,6 @@
 	function handleSelectXueke(item) {
 		activeXueke.value = item.id;
 	}
+	
+
 </script>