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) => { export const unbindDeviceAPI = (deviceId) => {
return request("POST", "/user/device/unbindDevice", { return request("POST", "/user/device/unbindDevice", {
deviceId, deviceId,
@@ -262,7 +268,8 @@ export const matchGameAPI = (match, gameType, teamSize) => {
match, match,
gameType, gameType,
teamSize, 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 Header from "@/components/Header.vue";
import ScreenHint from "@/components/ScreenHint.vue"; import ScreenHint from "@/components/ScreenHint.vue";
import BackToGame from "@/components/BackToGame.vue"; import BackToGame from "@/components/BackToGame.vue";
import { laserAimAPI, getBattleAPI } from "@/apis"; import {laserAimAPI, getBattleAPI, matchGameAPI} from "@/apis";
import { capsuleHeight, debounce } from "@/util"; import { capsuleHeight, debounce } from "@/util";
import AudioManager from "@/audioManager"; import AudioManager from "@/audioManager";
const props = defineProps({ const props = defineProps({
@@ -135,6 +135,10 @@ const goBack = () => {
uni.navigateBack(); uni.navigateBack();
}; };
const cancelMatching = async () => {
uni.$emit("cancelMatching");
}
const goCalibration = async () => { const goCalibration = async () => {
await laserAimAPI(); await laserAimAPI();
uni.navigateTo({ uni.navigateTo({
@@ -202,7 +206,7 @@ const goCalibration = async () => {
<button hover-class="none" @click="() => (showHint = false)"> <button hover-class="none" @click="() => (showHint = false)">
取消 取消
</button> </button>
<button hover-class="none" @click="goBack">确认</button> <button hover-class="none" @click="cancelMatching">确认</button>
</view> </view>
</view> </view>
<view v-if="hintType === 4" class="tip-content"> <view v-if="hintType === 4" class="tip-content">

View File

@@ -1,68 +1,70 @@
{ {
"name": "shoot-miniprograms", "name" : "shoot-miniprograms",
"appid": "", "appid" : "__UNI__B03E251",
"description": "", "description" : "",
"versionName": "1.0.0", "versionName" : "1.0.0",
"versionCode": "100", "versionCode" : "100",
"transformPx": false, "transformPx" : false,
"uniStatistics": { "uniStatistics" : {
"enable": false "enable" : false
},
"app-plus": {
"bounce": "none",
"usingComponents": true,
"nvueStyleCompiler": "uni-app",
"compilerVersion": 3,
"splashscreen": {
"alwaysShowBeforeRender": true,
"waiting": true,
"autoclose": true,
"delay": 0
}, },
"modules": {}, "app-plus" : {
"distribute": { "bounce" : "none",
"android": { "usingComponents" : true,
"permissions": [ "nvueStyleCompiler" : "uni-app",
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>", "compilerVersion" : 3,
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>", "splashscreen" : {
"<uses-permission android:name=\"android.permission.VIBRATE\"/>", "alwaysShowBeforeRender" : true,
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>", "waiting" : true,
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>", "autoclose" : true,
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>", "delay" : 0
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>", },
"<uses-permission android:name=\"android.permission.CAMERA\"/>", "modules" : {},
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>", "distribute" : {
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>", "android" : {
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>", "permissions" : [
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>", "<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>", "<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-feature android:name=\"android.hardware.camera\"/>", "<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>" "<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\"/>",
"ios": {}, "<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"sdkConfigs": {} "<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, updateDevice,
updateRank, updateRank,
getLvlName, getLvlName,
getLvlNameByScore,
updateOnline, updateOnline,
} = store; } = store;
const { user, device, rankData, online, game } = storeToRefs(store); const { user, device, rankData, online, game } = storeToRefs(store);
@@ -221,7 +222,7 @@ onShareTimeline(() => {
<view> <view>
<text>段位</text> <text>段位</text>
<text>{{ <text>{{
user.rankLvl ? getLvlName(user.rankLvl) : "暂无" user.lvlName || "暂无"
}}</text> }}</text>
</view> </view>
<view> <view>

View File

@@ -3,8 +3,6 @@ import { ref, onMounted, onBeforeUnmount } from "vue";
import { onLoad, onShow, onHide } from "@dcloudio/uni-app"; import { onLoad, onShow, onHide } from "@dcloudio/uni-app";
import Container from "@/components/Container.vue"; import Container from "@/components/Container.vue";
import Matching from "@/components/Matching.vue"; import Matching from "@/components/Matching.vue";
import RoundEndTip from "@/components/RoundEndTip.vue";
import TestDistance from "@/components/TestDistance.vue";
import { matchGameAPI } from "@/apis"; import { matchGameAPI } from "@/apis";
import { MESSAGETYPESV2 } from "@/constants"; import { MESSAGETYPESV2 } from "@/constants";
@@ -17,6 +15,13 @@ async function stopMatch() {
uni.$showHint(3); uni.$showHint(3);
} }
async function cancelMatch() {
if (gameType.value && teamSize.value) {
await matchGameAPI(false, gameType.value, teamSize.value);
}
uni.navigateBack()
}
async function onReceiveMessage(msg) { async function onReceiveMessage(msg) {
if (msg.type === MESSAGETYPESV2.MatchSuccess) { if (msg.type === MESSAGETYPESV2.MatchSuccess) {
matchSuccess.value = true; matchSuccess.value = true;
@@ -46,6 +51,7 @@ onMounted(() => {
keepScreenOn: true, keepScreenOn: true,
}); });
uni.$on("socket-inbox", onReceiveMessage); uni.$on("socket-inbox", onReceiveMessage);
uni.$on("cancelMatching", cancelMatch);
}); });
onBeforeUnmount(() => { onBeforeUnmount(() => {
@@ -53,9 +59,7 @@ onBeforeUnmount(() => {
keepScreenOn: false, keepScreenOn: false,
}); });
uni.$off("socket-inbox", onReceiveMessage); uni.$off("socket-inbox", onReceiveMessage);
if (gameType.value && teamSize.value && !matchSuccess.value) { uni.$off("cancelMatching", cancelMatch);
matchGameAPI(false, gameType.value, teamSize.value);
}
}); });
onShow(async () => { onShow(async () => {
@@ -65,9 +69,7 @@ onShow(async () => {
}); });
onHide(() => { onHide(() => {
if (gameType.value && teamSize.value && !matchSuccess.value) {
matchGameAPI(false, gameType.value, teamSize.value);
}
}); });
</script> </script>

View File

@@ -8,7 +8,7 @@ import {
bindDeviceAPI, bindDeviceAPI,
getMyDevicesAPI, getMyDevicesAPI,
unbindDeviceAPI, unbindDeviceAPI,
laserAimAPI, laserAimAPI, bindDeviceAPIV2,
} from "@/apis"; } from "@/apis";
import useStore from "@/store"; import useStore from "@/store";
import { storeToRefs } from "pinia"; import { storeToRefs } from "pinia";
@@ -20,6 +20,7 @@ const { updateDevice } = store;
const { user, device } = storeToRefs(store); const { user, device } = storeToRefs(store);
const justBind = ref(false); const justBind = ref(false);
const calibration = ref(false); const calibration = ref(false);
const token = ref(null);
// 扫描二维码方法 // 扫描二维码方法
const handleScan = () => { const handleScan = () => {
@@ -30,13 +31,14 @@ const handleScan = () => {
scanType: ["qrCode"], scanType: ["qrCode"],
success: async (res) => { success: async (res) => {
try { try {
const base64Decode = (str) => { // const base64Decode = (str) => {
// 将 base64 转换为 utf8 字符串 // // 将 base64 转换为 utf8 字符串
const bytes = wx.base64ToArrayBuffer(str); // const bytes = wx.base64ToArrayBuffer(str);
return String.fromCharCode.apply(null, new Uint8Array(bytes)); // return String.fromCharCode.apply(null, new Uint8Array(bytes));
}; // };
//
addDevice.value = JSON.parse(base64Decode(res.result)); // addDevice.value = JSON.parse(base64Decode(res.result));
token.value = res.result;
confirmBindTip.value = true; confirmBindTip.value = true;
} catch (err) { } catch (err) {
uni.showToast({ uni.showToast({
@@ -57,8 +59,8 @@ const handleScan = () => {
}; };
const confirmBind = async () => { const confirmBind = async () => {
if (!justBind.value && addDevice.value.id) { if (!justBind.value && token.value) {
const result = await bindDeviceAPI(addDevice.value); const result = await bindDeviceAPIV2(token.value);
confirmBindTip.value = false; confirmBindTip.value = false;
if (result.binded) { if (result.binded) {
return uni.showToast({ return uni.showToast({
@@ -66,7 +68,7 @@ const confirmBind = async () => {
icon: "none", icon: "none",
}); });
} }
updateDevice(addDevice.value.id, addDevice.value.name); updateDevice(result.deviceId, result.name);
justBind.value = true; justBind.value = true;
uni.showToast({ uni.showToast({
title: "绑定成功", title: "绑定成功",

View File

@@ -22,6 +22,19 @@ const getLvlName = (rankLvl, rankList = []) => {
return lvlName; 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 = []) => { const getLvlImage = (rankLvl, rankList = []) => {
if (!rankList) return; if (!rankList) return;
let lvlImage = ""; let lvlImage = "";
@@ -35,6 +48,19 @@ const getLvlImage = (rankLvl, rankList = []) => {
return lvlImage; 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 // 定义游戏相关的 store
export default defineStore("store", { export default defineStore("store", {
// 状态 // 状态
@@ -65,6 +91,9 @@ export default defineStore("store", {
// 方法 // 方法
actions: { actions: {
getLvlNameByScore(score) {
return getLvlNameByScore(score, this.config.randInfos);
},
getLvlName(rankLvl) { getLvlName(rankLvl) {
return getLvlName(rankLvl, this.config.randInfos); return getLvlName(rankLvl, this.config.randInfos);
}, },
@@ -79,14 +108,9 @@ export default defineStore("store", {
}, },
async updateUser(user = {}) { async updateUser(user = {}) {
this.user = { ...defaultUser, ...user }; this.user = { ...defaultUser, ...user };
if (this.user.rankLvl !== undefined) { this.user.lvlName = getLvlNameByScore(this.user.scores, this.config.randInfos)
this.user.lvlName = getLvlName( this.user.lvlImage = getLvlImageByScore(
this.user.rankLvl, this.user.scores,
this.config.randInfos
);
}
this.user.lvlImage = getLvlImage(
this.user.rankLvl,
this.config.randInfos this.config.randInfos
); );
}, },