代码优化

This commit is contained in:
kron
2025-06-05 17:43:22 +08:00
parent 18fb0ee7d4
commit 219fdc54ad
5 changed files with 18 additions and 13 deletions

View File

@@ -5,5 +5,5 @@ POST {{serverUrl}}/index/arrow
Content-Type: application/json
{
"device_id": "iXAx67Ce"
"device_id": "H9hL8GaA"
}

View File

@@ -33,20 +33,20 @@ export const getHomeData = () => {
return request("GET", "/user/myHome");
};
// 获取省份及下属城市列表
export const getProvinceData = () => {
return request("GET", "/index/provinces/list");
};
// 获取省份及下属城市列表
export const loginAPI = (nickName, avatarUrl, code) => {
return request("POST", "/index/code", {
export const loginAPI = async (nickName, avatarUrl, code) => {
const result = await request("POST", "/index/code", {
appName: "shoot",
appId: "wxa8f5989dcd45cc23",
nickName,
avatarUrl,
code,
});
uni.setStorageSync("token", result.token);
return result;
};
export const bindDeviceAPI = (device) => {

View File

@@ -15,7 +15,7 @@ defineProps({
<template>
<view>
<AppBackground :bgType="bgType" />
<AppBackground :type="bgType" />
<Header :title="title" />
<view class="content">
<slot></slot>

View File

@@ -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 } from "@/apis";
import { getAppConfig, getHomeData } from "@/apis";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { updateConfig } = store;
const { updateConfig, updateUser } = store;
// 使用storeToRefs用于UI里显示保持响应性
const { user } = storeToRefs(store);
@@ -67,7 +67,9 @@ onMounted(async () => {
const config = await getAppConfig();
console.log("全局配置:", config);
updateConfig(config);
// 这里可以处理配置数据
const result = await getHomeData();
if (result.user) updateUser(result.user);
console.log("首页数据:", result);
} catch (error) {
console.error("获取配置失败:", error);
}

View File

@@ -21,8 +21,9 @@ function createWebSocket(token, onMessage) {
});
// 关闭处理
uni.onSocketClose(() => {
console.log("WebSocket 已关闭");
uni.onSocketClose((result) => {
console.log("WebSocket 已关闭", result);
stopHeartbeat();
});
// 启动心跳
@@ -44,9 +45,11 @@ function startHeartbeat() {
heartbeatInterval = setInterval(() => {
if (socket && uni.sendSocketMessage) {
console.log("ping");
uni.sendSocketMessage({
data: "ping",
data: {
event: "ping",
data: {},
},
fail: (err) => {
console.error("发送心跳失败", err);
},