pref: 绑定设备、匹配pk
This commit is contained in:
@@ -185,6 +185,12 @@ export const bindDeviceAPI = (device) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const bindDeviceAPIV2 = (token) => {
|
||||
return request("POST", "/user/device/bindDevice/v2", {
|
||||
token: token,
|
||||
});
|
||||
};
|
||||
|
||||
export const unbindDeviceAPI = (deviceId) => {
|
||||
return request("POST", "/user/device/unbindDevice", {
|
||||
deviceId,
|
||||
@@ -262,7 +268,8 @@ export const matchGameAPI = (match, gameType, teamSize) => {
|
||||
match,
|
||||
gameType,
|
||||
teamSize,
|
||||
readyTime: 1.5,
|
||||
readyTime: 15,
|
||||
targetType: 20,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import AppBackground from "@/components/AppBackground.vue";
|
||||
import Header from "@/components/Header.vue";
|
||||
import ScreenHint from "@/components/ScreenHint.vue";
|
||||
import BackToGame from "@/components/BackToGame.vue";
|
||||
import { laserAimAPI, getBattleAPI } from "@/apis";
|
||||
import {laserAimAPI, getBattleAPI, matchGameAPI} from "@/apis";
|
||||
import { capsuleHeight, debounce } from "@/util";
|
||||
import AudioManager from "@/audioManager";
|
||||
const props = defineProps({
|
||||
@@ -135,6 +135,10 @@ const goBack = () => {
|
||||
uni.navigateBack();
|
||||
};
|
||||
|
||||
const cancelMatching = async () => {
|
||||
uni.$emit("cancelMatching");
|
||||
}
|
||||
|
||||
const goCalibration = async () => {
|
||||
await laserAimAPI();
|
||||
uni.navigateTo({
|
||||
@@ -202,7 +206,7 @@ const goCalibration = async () => {
|
||||
<button hover-class="none" @click="() => (showHint = false)">
|
||||
取消
|
||||
</button>
|
||||
<button hover-class="none" @click="goBack">确认</button>
|
||||
<button hover-class="none" @click="cancelMatching">确认</button>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="hintType === 4" class="tip-content">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name" : "shoot-miniprograms",
|
||||
"appid": "",
|
||||
"appid" : "__UNI__B03E251",
|
||||
"description" : "",
|
||||
"versionName" : "1.0.0",
|
||||
"versionCode" : "100",
|
||||
@@ -40,7 +40,9 @@
|
||||
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
|
||||
]
|
||||
},
|
||||
"ios": {},
|
||||
"ios" : {
|
||||
"dSYMs" : false
|
||||
},
|
||||
"sdkConfigs" : {}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -27,6 +27,7 @@ const {
|
||||
updateDevice,
|
||||
updateRank,
|
||||
getLvlName,
|
||||
getLvlNameByScore,
|
||||
updateOnline,
|
||||
} = store;
|
||||
const { user, device, rankData, online, game } = storeToRefs(store);
|
||||
@@ -221,7 +222,7 @@ onShareTimeline(() => {
|
||||
<view>
|
||||
<text>段位</text>
|
||||
<text>{{
|
||||
user.rankLvl ? getLvlName(user.rankLvl) : "暂无"
|
||||
user.lvlName || "暂无"
|
||||
}}</text>
|
||||
</view>
|
||||
<view>
|
||||
|
||||
@@ -3,8 +3,6 @@ import { ref, onMounted, onBeforeUnmount } from "vue";
|
||||
import { onLoad, onShow, onHide } from "@dcloudio/uni-app";
|
||||
import Container from "@/components/Container.vue";
|
||||
import Matching from "@/components/Matching.vue";
|
||||
import RoundEndTip from "@/components/RoundEndTip.vue";
|
||||
import TestDistance from "@/components/TestDistance.vue";
|
||||
import { matchGameAPI } from "@/apis";
|
||||
import { MESSAGETYPESV2 } from "@/constants";
|
||||
|
||||
@@ -17,6 +15,13 @@ async function stopMatch() {
|
||||
uni.$showHint(3);
|
||||
}
|
||||
|
||||
async function cancelMatch() {
|
||||
if (gameType.value && teamSize.value) {
|
||||
await matchGameAPI(false, gameType.value, teamSize.value);
|
||||
}
|
||||
uni.navigateBack()
|
||||
}
|
||||
|
||||
async function onReceiveMessage(msg) {
|
||||
if (msg.type === MESSAGETYPESV2.MatchSuccess) {
|
||||
matchSuccess.value = true;
|
||||
@@ -46,6 +51,7 @@ onMounted(() => {
|
||||
keepScreenOn: true,
|
||||
});
|
||||
uni.$on("socket-inbox", onReceiveMessage);
|
||||
uni.$on("cancelMatching", cancelMatch);
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
@@ -53,9 +59,7 @@ onBeforeUnmount(() => {
|
||||
keepScreenOn: false,
|
||||
});
|
||||
uni.$off("socket-inbox", onReceiveMessage);
|
||||
if (gameType.value && teamSize.value && !matchSuccess.value) {
|
||||
matchGameAPI(false, gameType.value, teamSize.value);
|
||||
}
|
||||
uni.$off("cancelMatching", cancelMatch);
|
||||
});
|
||||
|
||||
onShow(async () => {
|
||||
@@ -65,9 +69,7 @@ onShow(async () => {
|
||||
});
|
||||
|
||||
onHide(() => {
|
||||
if (gameType.value && teamSize.value && !matchSuccess.value) {
|
||||
matchGameAPI(false, gameType.value, teamSize.value);
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
bindDeviceAPI,
|
||||
getMyDevicesAPI,
|
||||
unbindDeviceAPI,
|
||||
laserAimAPI,
|
||||
laserAimAPI, bindDeviceAPIV2,
|
||||
} from "@/apis";
|
||||
import useStore from "@/store";
|
||||
import { storeToRefs } from "pinia";
|
||||
@@ -20,6 +20,7 @@ const { updateDevice } = store;
|
||||
const { user, device } = storeToRefs(store);
|
||||
const justBind = ref(false);
|
||||
const calibration = ref(false);
|
||||
const token = ref(null);
|
||||
|
||||
// 扫描二维码方法
|
||||
const handleScan = () => {
|
||||
@@ -30,13 +31,14 @@ const handleScan = () => {
|
||||
scanType: ["qrCode"],
|
||||
success: async (res) => {
|
||||
try {
|
||||
const base64Decode = (str) => {
|
||||
// 将 base64 转换为 utf8 字符串
|
||||
const bytes = wx.base64ToArrayBuffer(str);
|
||||
return String.fromCharCode.apply(null, new Uint8Array(bytes));
|
||||
};
|
||||
|
||||
addDevice.value = JSON.parse(base64Decode(res.result));
|
||||
// const base64Decode = (str) => {
|
||||
// // 将 base64 转换为 utf8 字符串
|
||||
// const bytes = wx.base64ToArrayBuffer(str);
|
||||
// return String.fromCharCode.apply(null, new Uint8Array(bytes));
|
||||
// };
|
||||
//
|
||||
// addDevice.value = JSON.parse(base64Decode(res.result));
|
||||
token.value = res.result;
|
||||
confirmBindTip.value = true;
|
||||
} catch (err) {
|
||||
uni.showToast({
|
||||
@@ -57,8 +59,8 @@ const handleScan = () => {
|
||||
};
|
||||
|
||||
const confirmBind = async () => {
|
||||
if (!justBind.value && addDevice.value.id) {
|
||||
const result = await bindDeviceAPI(addDevice.value);
|
||||
if (!justBind.value && token.value) {
|
||||
const result = await bindDeviceAPIV2(token.value);
|
||||
confirmBindTip.value = false;
|
||||
if (result.binded) {
|
||||
return uni.showToast({
|
||||
@@ -66,7 +68,7 @@ const confirmBind = async () => {
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
updateDevice(addDevice.value.id, addDevice.value.name);
|
||||
updateDevice(result.deviceId, result.name);
|
||||
justBind.value = true;
|
||||
uni.showToast({
|
||||
title: "绑定成功",
|
||||
|
||||
40
src/store.js
40
src/store.js
@@ -22,6 +22,19 @@ const getLvlName = (rankLvl, rankList = []) => {
|
||||
return lvlName;
|
||||
};
|
||||
|
||||
const getLvlNameByScore = (score, rankList = []) => {
|
||||
if (!rankList) return;
|
||||
let lvlName = "";
|
||||
rankList.some((r, index) => {
|
||||
if (r.upgrade_scores && r.upgrade_scores < score) {
|
||||
lvlName = rankList[index].name;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return lvlName;
|
||||
};
|
||||
|
||||
const getLvlImage = (rankLvl, rankList = []) => {
|
||||
if (!rankList) return;
|
||||
let lvlImage = "";
|
||||
@@ -35,6 +48,19 @@ const getLvlImage = (rankLvl, rankList = []) => {
|
||||
return lvlImage;
|
||||
};
|
||||
|
||||
const getLvlImageByScore = (score, rankList = []) => {
|
||||
if (!rankList) return;
|
||||
let lvlImage = "";
|
||||
rankList.some((r, index) => {
|
||||
if (r.upgrade_scores && r.upgrade_scores < score) {
|
||||
lvlImage = rankList[index].icoin;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return lvlImage;
|
||||
};
|
||||
|
||||
// 定义游戏相关的 store
|
||||
export default defineStore("store", {
|
||||
// 状态
|
||||
@@ -65,6 +91,9 @@ export default defineStore("store", {
|
||||
|
||||
// 方法
|
||||
actions: {
|
||||
getLvlNameByScore(score) {
|
||||
return getLvlNameByScore(score, this.config.randInfos);
|
||||
},
|
||||
getLvlName(rankLvl) {
|
||||
return getLvlName(rankLvl, this.config.randInfos);
|
||||
},
|
||||
@@ -79,14 +108,9 @@ export default defineStore("store", {
|
||||
},
|
||||
async updateUser(user = {}) {
|
||||
this.user = { ...defaultUser, ...user };
|
||||
if (this.user.rankLvl !== undefined) {
|
||||
this.user.lvlName = getLvlName(
|
||||
this.user.rankLvl,
|
||||
this.config.randInfos
|
||||
);
|
||||
}
|
||||
this.user.lvlImage = getLvlImage(
|
||||
this.user.rankLvl,
|
||||
this.user.lvlName = getLvlNameByScore(this.user.scores, this.config.randInfos)
|
||||
this.user.lvlImage = getLvlImageByScore(
|
||||
this.user.scores,
|
||||
this.config.randInfos
|
||||
);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user