pref: 绑定设备、匹配pk

This commit is contained in:
2026-04-28 08:59:16 +08:00
parent 8c48216a75
commit f07facd98b
7 changed files with 137 additions and 95 deletions

View File

@@ -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,
});
};

View File

@@ -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">

View File

@@ -1,68 +1,70 @@
{
"name": "shoot-miniprograms",
"appid": "",
"description": "",
"versionName": "1.0.0",
"versionCode": "100",
"transformPx": false,
"uniStatistics": {
"enable": false
},
"app-plus": {
"bounce": "none",
"usingComponents": true,
"nvueStyleCompiler": "uni-app",
"compilerVersion": 3,
"splashscreen": {
"alwaysShowBeforeRender": true,
"waiting": true,
"autoclose": true,
"delay": 0
"name" : "shoot-miniprograms",
"appid" : "__UNI__B03E251",
"description" : "",
"versionName" : "1.0.0",
"versionCode" : "100",
"transformPx" : false,
"uniStatistics" : {
"enable" : false
},
"modules": {},
"distribute": {
"android": {
"permissions": [
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
]
},
"ios": {},
"sdkConfigs": {}
"app-plus" : {
"bounce" : "none",
"usingComponents" : true,
"nvueStyleCompiler" : "uni-app",
"compilerVersion" : 3,
"splashscreen" : {
"alwaysShowBeforeRender" : true,
"waiting" : true,
"autoclose" : true,
"delay" : 0
},
"modules" : {},
"distribute" : {
"android" : {
"permissions" : [
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
]
},
"ios" : {
"dSYMs" : false
},
"sdkConfigs" : {}
}
},
"h5" : {
"darkmode" : true,
"themeLocation" : "theme.json"
},
"quickapp" : {},
"mp-weixin" : {
"appid" : "wxa8f5989dcd45cc23",
"setting" : {
"urlCheck" : false,
"minified" : true,
"uglifyFileName" : true,
"useCompilerModule" : true,
"useIsolateContext" : true
},
"lazyCodeLoading" : "requiredComponents",
"usingComponents" : true,
"darkmode" : true,
"themeLocation" : "theme.json",
"permission" : {},
"requiredPrivateInfos" : [ "getLocation", "chooseLocation" ]
}
},
"h5": {
"darkmode": true,
"themeLocation": "theme.json"
},
"quickapp": {},
"mp-weixin": {
"appid": "wxa8f5989dcd45cc23",
"setting": {
"urlCheck": false,
"minified": true,
"uglifyFileName": true,
"useCompilerModule": true,
"useIsolateContext": true
},
"lazyCodeLoading": "requiredComponents",
"usingComponents": true,
"darkmode": true,
"themeLocation": "theme.json",
"permission": {},
"requiredPrivateInfos": ["getLocation", "chooseLocation"]
}
}

View File

@@ -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>

View File

@@ -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>

View File

@@ -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: "绑定成功",

View File

@@ -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
);
},