添加模拟射箭按钮
This commit is contained in:
11
src/apis.js
11
src/apis.js
@@ -125,3 +125,14 @@ export const getGameAPI = (battleId) => {
|
||||
id: battleId,
|
||||
});
|
||||
};
|
||||
|
||||
export const simulShootAPI = (device_id, x, y) => {
|
||||
const data = {
|
||||
device_id,
|
||||
};
|
||||
if (x && y) {
|
||||
data.x = x;
|
||||
data.y = y;
|
||||
}
|
||||
return request("POST", "/index/arrow", data);
|
||||
};
|
||||
|
||||
@@ -1,10 +1,22 @@
|
||||
<script setup>
|
||||
import useStore from "@/store";
|
||||
import { simulShootAPI } from "@/apis";
|
||||
import { storeToRefs } from "pinia";
|
||||
const store = useStore();
|
||||
const { device } = storeToRefs(store);
|
||||
|
||||
defineProps({
|
||||
title: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
});
|
||||
|
||||
const simulShoot = async () => {
|
||||
if (device.value.deviceId) {
|
||||
await simulShootAPI(device.value.deviceId);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -13,6 +25,7 @@ defineProps({
|
||||
<image src="../static/back.png" mode="widthFix" />
|
||||
</navigator>
|
||||
<text>{{ title }}</text>
|
||||
<view class="simul" @click="simulShoot">S</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@@ -38,4 +51,8 @@ defineProps({
|
||||
.container > text {
|
||||
color: #fff;
|
||||
}
|
||||
.simul {
|
||||
color: #fff;
|
||||
margin-left: 20px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -3,12 +3,12 @@ import { onMounted } from "vue";
|
||||
import AppFooter from "@/components/AppFooter.vue";
|
||||
import AppBackground from "@/components/AppBackground.vue";
|
||||
import UserHeader from "@/components/UserHeader.vue";
|
||||
import { getAppConfig, getHomeData } from "@/apis";
|
||||
import { getAppConfig, getHomeData, getMyDevicesAPI } from "@/apis";
|
||||
import useStore from "@/store";
|
||||
|
||||
import { storeToRefs } from "pinia";
|
||||
const store = useStore();
|
||||
const { updateConfig, updateUser } = store;
|
||||
const { updateConfig, updateUser, updateDevice } = store;
|
||||
// 使用storeToRefs,用于UI里显示,保持响应性
|
||||
const { user } = storeToRefs(store);
|
||||
|
||||
@@ -68,7 +68,16 @@ onMounted(async () => {
|
||||
console.log("全局配置:", config);
|
||||
updateConfig(config);
|
||||
const result = await getHomeData();
|
||||
if (result.user) updateUser(result.user);
|
||||
if (result.user) {
|
||||
updateUser(result.user);
|
||||
const devices = await getMyDevicesAPI();
|
||||
if (devices.bindings.length) {
|
||||
updateDevice(
|
||||
devices.bindings[0].deviceId,
|
||||
devices.bindings[0].deviceName
|
||||
);
|
||||
}
|
||||
}
|
||||
console.log("首页数据:", result);
|
||||
} catch (error) {
|
||||
console.error("获取配置失败:", error);
|
||||
|
||||
@@ -11,7 +11,7 @@ export default defineStore("store", {
|
||||
trio: 0, // 大于1表示完成了新手引导
|
||||
},
|
||||
device: {
|
||||
id: "",
|
||||
deviceId: "",
|
||||
deviceName: "",
|
||||
},
|
||||
config: {},
|
||||
@@ -30,7 +30,7 @@ export default defineStore("store", {
|
||||
this.user = user;
|
||||
},
|
||||
updateDevice(deviceId, deviceName) {
|
||||
this.device.id = deviceId;
|
||||
this.device.deviceId = deviceId;
|
||||
this.device.deviceName = deviceName;
|
||||
},
|
||||
updateConfig(config) {
|
||||
|
||||
@@ -20,10 +20,12 @@ function createWebSocket(token, onMessage) {
|
||||
console.error("WebSocket 错误", err);
|
||||
});
|
||||
|
||||
// 关闭处理
|
||||
uni.onSocketClose((result) => {
|
||||
console.log("WebSocket 已关闭", result);
|
||||
stopHeartbeat();
|
||||
socket = uni.connectSocket({
|
||||
url: `ws://120.79.241.5:8000/socket?authorization=${token}`,
|
||||
success: () => console.log("websocket 连接成功"),
|
||||
});
|
||||
});
|
||||
|
||||
// 启动心跳
|
||||
|
||||
Reference in New Issue
Block a user