代码优化
This commit is contained in:
@@ -5,5 +5,5 @@ POST {{serverUrl}}/index/arrow
|
|||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
{
|
{
|
||||||
"device_id": "iXAx67Ce"
|
"device_id": "H9hL8GaA"
|
||||||
}
|
}
|
||||||
@@ -33,20 +33,20 @@ export const getHomeData = () => {
|
|||||||
return request("GET", "/user/myHome");
|
return request("GET", "/user/myHome");
|
||||||
};
|
};
|
||||||
|
|
||||||
// 获取省份及下属城市列表
|
|
||||||
export const getProvinceData = () => {
|
export const getProvinceData = () => {
|
||||||
return request("GET", "/index/provinces/list");
|
return request("GET", "/index/provinces/list");
|
||||||
};
|
};
|
||||||
|
|
||||||
// 获取省份及下属城市列表
|
export const loginAPI = async (nickName, avatarUrl, code) => {
|
||||||
export const loginAPI = (nickName, avatarUrl, code) => {
|
const result = await request("POST", "/index/code", {
|
||||||
return request("POST", "/index/code", {
|
|
||||||
appName: "shoot",
|
appName: "shoot",
|
||||||
appId: "wxa8f5989dcd45cc23",
|
appId: "wxa8f5989dcd45cc23",
|
||||||
nickName,
|
nickName,
|
||||||
avatarUrl,
|
avatarUrl,
|
||||||
code,
|
code,
|
||||||
});
|
});
|
||||||
|
uni.setStorageSync("token", result.token);
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const bindDeviceAPI = (device) => {
|
export const bindDeviceAPI = (device) => {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ defineProps({
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<view>
|
<view>
|
||||||
<AppBackground :bgType="bgType" />
|
<AppBackground :type="bgType" />
|
||||||
<Header :title="title" />
|
<Header :title="title" />
|
||||||
<view class="content">
|
<view class="content">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ import { onMounted } from "vue";
|
|||||||
import AppFooter from "@/components/AppFooter.vue";
|
import AppFooter from "@/components/AppFooter.vue";
|
||||||
import AppBackground from "@/components/AppBackground.vue";
|
import AppBackground from "@/components/AppBackground.vue";
|
||||||
import UserHeader from "@/components/UserHeader.vue";
|
import UserHeader from "@/components/UserHeader.vue";
|
||||||
import { getAppConfig } from "@/apis";
|
import { getAppConfig, getHomeData } from "@/apis";
|
||||||
import useStore from "@/store";
|
import useStore from "@/store";
|
||||||
|
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
const store = useStore();
|
const store = useStore();
|
||||||
const { updateConfig } = store;
|
const { updateConfig, updateUser } = store;
|
||||||
// 使用storeToRefs,用于UI里显示,保持响应性
|
// 使用storeToRefs,用于UI里显示,保持响应性
|
||||||
const { user } = storeToRefs(store);
|
const { user } = storeToRefs(store);
|
||||||
|
|
||||||
@@ -67,7 +67,9 @@ onMounted(async () => {
|
|||||||
const config = await getAppConfig();
|
const config = await getAppConfig();
|
||||||
console.log("全局配置:", config);
|
console.log("全局配置:", config);
|
||||||
updateConfig(config);
|
updateConfig(config);
|
||||||
// 这里可以处理配置数据
|
const result = await getHomeData();
|
||||||
|
if (result.user) updateUser(result.user);
|
||||||
|
console.log("首页数据:", result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("获取配置失败:", error);
|
console.error("获取配置失败:", error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,9 @@ function createWebSocket(token, onMessage) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 关闭处理
|
// 关闭处理
|
||||||
uni.onSocketClose(() => {
|
uni.onSocketClose((result) => {
|
||||||
console.log("WebSocket 已关闭");
|
console.log("WebSocket 已关闭", result);
|
||||||
|
stopHeartbeat();
|
||||||
});
|
});
|
||||||
|
|
||||||
// 启动心跳
|
// 启动心跳
|
||||||
@@ -44,9 +45,11 @@ function startHeartbeat() {
|
|||||||
|
|
||||||
heartbeatInterval = setInterval(() => {
|
heartbeatInterval = setInterval(() => {
|
||||||
if (socket && uni.sendSocketMessage) {
|
if (socket && uni.sendSocketMessage) {
|
||||||
console.log("ping");
|
|
||||||
uni.sendSocketMessage({
|
uni.sendSocketMessage({
|
||||||
data: "ping",
|
data: {
|
||||||
|
event: "ping",
|
||||||
|
data: {},
|
||||||
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
console.error("发送心跳失败", err);
|
console.error("发送心跳失败", err);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user