feat:"完成页面接口的对接"

This commit is contained in:
2026-01-29 17:58:19 +08:00
parent 2774a539bf
commit 2b69da3c15
98 changed files with 9504 additions and 592 deletions

View File

@@ -1,6 +1,7 @@
"use strict";
const common_vendor = require("../../common/vendor.js");
const utils_config = require("../../utils/config.js");
const api_index = require("../../api/index.js");
class UserInfo extends UTS.UTSType {
static get$UTSMetadata$() {
return {
@@ -67,33 +68,69 @@ const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
}
}));
};
const fetchStats = () => {
bookingCount.value = 0;
const favorites = common_vendor.index.getStorageSync(utils_config.STORAGE_KEYS.FAVORITES);
favoriteCount.value = favorites ? favorites.length : 0;
};
const handleLogin = () => {
common_vendor.index.getUserProfile(new UTSJSONObject({
desc: "用于完善用户资料",
success: (res = null) => {
userInfo.value = new UserInfo(
{
id: "",
nickName: res.userInfo.nickName,
avatar: res.userInfo.avatarUrl,
phone: ""
success: (profileRes = null) => {
common_vendor.index.login(new UTSJSONObject({
provider: "weixin",
success: (loginRes) => {
return common_vendor.__awaiter(this, void 0, void 0, function* () {
var _a;
const code = loginRes.code;
try {
const res = yield api_index.wechatLogin(code);
if (res.code === 0 && res.data != null) {
const data = res.data;
const token = data["access_token"];
const userDataObj = data["user"];
common_vendor.index.setStorageSync(utils_config.STORAGE_KEYS.TOKEN, token);
userInfo.value = new UserInfo({
id: String(userDataObj["id"]),
nickName: profileRes.userInfo.nickName,
avatar: profileRes.userInfo.avatarUrl,
phone: (_a = userDataObj["phone"]) !== null && _a !== void 0 ? _a : ""
});
common_vendor.index.setStorageSync(utils_config.STORAGE_KEYS.USER_INFO, new UTSJSONObject({
id: userDataObj["id"],
nickName: profileRes.userInfo.nickName,
avatar: profileRes.userInfo.avatarUrl,
phone: userDataObj["phone"]
}));
isLoggedIn.value = true;
common_vendor.index.showToast({
title: "登录成功",
icon: "success"
});
fetchStats();
} else {
throw new Error(res.message);
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/user/index.uvue:248", "登录失败", error);
common_vendor.index.showToast({
title: "登录失败,请重试",
icon: "none"
});
}
});
},
fail: () => {
common_vendor.index.showToast({
title: "登录失败",
icon: "none"
});
}
// 保存用户信息
);
common_vendor.index.setStorageSync(utils_config.STORAGE_KEYS.USER_INFO, new UTSJSONObject({
nickName: res.userInfo.nickName,
avatar: res.userInfo.avatarUrl
}));
common_vendor.index.setStorageSync(utils_config.STORAGE_KEYS.TOKEN, "mock_token_" + Date.now().toString());
isLoggedIn.value = true;
common_vendor.index.showToast({
title: "登录成功",
icon: "success"
});
},
fail: () => {
common_vendor.index.showToast({
title: "登录失败",
title: "授权失败",
icon: "none"
});
}
@@ -123,15 +160,27 @@ const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
}));
};
const goToBookingList = () => {
common_vendor.index.showToast({
title: "功能开发中",
icon: "none"
if (!isLoggedIn.value) {
common_vendor.index.showToast({
title: "请先登录",
icon: "none"
});
return null;
}
common_vendor.index.navigateTo({
url: "/pages/user/booking-list"
});
};
const goToFavorites = () => {
common_vendor.index.showToast({
title: "功能开发中",
icon: "none"
if (!isLoggedIn.value) {
common_vendor.index.showToast({
title: "请先登录",
icon: "none"
});
return null;
}
common_vendor.index.navigateTo({
url: "/pages/user/favorites"
});
};
const goToAbout = () => {