Files
smartDriveEEUniApp/unpackage/dist/dev/mp-weixin/pages/ucenter/ucenter.js
2026-03-31 21:04:53 +08:00

599 lines
21 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
const common_vendor = require("../../common/vendor.js");
const common_store = require("../../common/store.js");
const common_request = require("../../common/request.js");
const db = common_vendor._r.database();
common_vendor._r.importObject("uni-id-co", {
customUI: true
});
const DeviceBindPopup = () => "./components/DeviceBindPopup.js";
const DeviceListPopup = () => "./components/DeviceListPopup.js";
const CloudImage = () => "../../uni_modules/uni-id-pages/components/cloud-image/cloud-image.js";
const _sfc_main = {
components: {
DeviceBindPopup,
DeviceListPopup,
CloudImage
},
data() {
return {
tenantId: "",
loginUserInfo: {},
totalDevices: 0,
totalSales: 0,
totalProjects: 0,
gridList: [
{
"text": "设备总数",
"icon": "gear"
},
{
"text": "人员总数",
"icon": "person-filled"
},
{
"text": "项目总数",
"icon": "list"
},
{
"text": "修改密码",
"icon": "locked"
}
],
changePwdForm: {
oldPassword: "",
newPassword: "",
confirmPassword: ""
},
changePwdSubmitting: false,
ucenterList: [
[
{
"title": "设备绑定",
"event": "openDeviceBind",
"icon": "compose"
},
{
"title": "设备列表",
"event": "openDeviceList",
"icon": "paperplane"
}
],
[{
"title": this.$t("mine.settings"),
"to": "/pages-subpackage/ucenter/settings/settings",
"icon": "gear"
}]
],
listStyles: {
"height": "150rpx",
// 边框高度
"width": "150rpx",
// 边框宽度
"border": {
// 如果为 Boolean 值,可以控制边框显示与否
"color": "#eee",
// 边框颜色
"width": "1px",
// 边框宽度
"style": "solid",
// 边框样式
"radius": "100%"
// 边框圆角,支持百分比
}
}
};
},
onLoad() {
this.loadUserInfo();
},
onShow() {
try {
const storageUserInfo = common_vendor.index.getStorageSync("uni-id-pages-userInfo") || {};
if (Object.keys(storageUserInfo).length > 0 && Object.keys(common_store.store.userInfo || {}).length === 0) {
const synced = common_store.mutations.syncUserInfoFromStorage();
if (!synced) {
common_store.mutations.setUserInfo(storageUserInfo, { cover: true });
}
}
} catch (e) {
}
this.loadUserInfo();
this.loadDeviceStatistics();
this.loadSalesStatistics();
this.loadProjectStatistics();
},
onReady() {
this.initUrlHidingAfterPageLoad();
},
computed: {
userInfo() {
return common_store.store.userInfo || {};
},
hasLogin() {
return common_store.store.hasLogin || false;
},
appConfig() {
try {
const app = getApp({ allowDefault: true });
return app && app.globalData ? app.globalData.config : {};
} catch (e) {
return {};
}
}
},
methods: {
/**
* 加载用户信息租户ID和登录人信息
*/
loadUserInfo() {
try {
this.tenantId = common_vendor.index.getStorageSync("backend-tenant-id") || "";
const loginResponse = common_vendor.index.getStorageSync("backend-login-response") || {};
this.loginUserInfo = {
userName: loginResponse.userName || "",
phone: loginResponse.phone || "",
email: loginResponse.email || "",
userId: loginResponse.userId || ""
};
} catch (e) {
common_vendor.index.__f__("error", "at pages/ucenter/ucenter.vue:302", "加载用户信息失败:", e);
}
},
/**
* 加载设备统计信息
*/
async loadDeviceStatistics() {
var _a, _b;
try {
const res = await common_request.get("/api/deviceManagement/statistics");
if (res.statusCode === 200 && res.data && res.data.success) {
this.totalDevices = ((_a = res.data.data) == null ? void 0 : _a.totalDevices) || 0;
} else {
common_vendor.index.__f__("error", "at pages/ucenter/ucenter.vue:315", "获取设备统计信息失败:", ((_b = res.data) == null ? void 0 : _b.message) || "未知错误");
this.totalDevices = 0;
}
} catch (e) {
common_vendor.index.__f__("error", "at pages/ucenter/ucenter.vue:319", "获取设备统计信息异常:", e);
this.totalDevices = 0;
}
},
/**
* 加载销售(人员)统计信息
*/
async loadSalesStatistics() {
var _a, _b;
try {
const res = await common_request.get("/api/salesManagement/statistics");
if (res.statusCode === 200 && res.data && res.data.success) {
this.totalSales = ((_a = res.data.data) == null ? void 0 : _a.totalSales) || 0;
} else {
common_vendor.index.__f__("error", "at pages/ucenter/ucenter.vue:333", "获取销售统计信息失败:", ((_b = res.data) == null ? void 0 : _b.message) || "未知错误");
this.totalSales = 0;
}
} catch (e) {
common_vendor.index.__f__("error", "at pages/ucenter/ucenter.vue:337", "获取销售统计信息异常:", e);
this.totalSales = 0;
}
},
/**
* 加载项目统计信息
*/
async loadProjectStatistics() {
var _a, _b;
try {
const res = await common_request.get("/api/projectManagement/statistics");
if (res.statusCode === 200 && res.data && res.data.success) {
this.totalProjects = ((_a = res.data.data) == null ? void 0 : _a.totalProjects) || 0;
} else {
common_vendor.index.__f__("error", "at pages/ucenter/ucenter.vue:351", "获取项目统计信息失败:", ((_b = res.data) == null ? void 0 : _b.message) || "未知错误");
this.totalProjects = 0;
}
} catch (e) {
common_vendor.index.__f__("error", "at pages/ucenter/ucenter.vue:355", "获取项目统计信息异常:", e);
this.totalProjects = 0;
}
},
toSettings() {
common_vendor.index.navigateTo({
url: "/pages-subpackage/ucenter/settings/settings"
});
},
signIn() {
this.$refs.signIn.open();
},
signInByAd() {
this.$refs.signIn.showRewardedVideoAd();
},
/**
* 个人中心项目列表点击事件
*/
ucenterListClick(item) {
if (!item.to && item.event) {
this[item.event]();
} else if (item.to) {
const tabBarPages = ["/pages/furniture_reception/furniture_reception", "/pages/furniture_customer/furniture_customer", "/pages/ai_qa/ai_qa", "/pages/ai_analysis/ai_analysis", "/pages/ucenter/ucenter"];
if (tabBarPages.includes(item.to)) {
common_vendor.index.switchTab({
url: item.to
});
} else {
common_vendor.index.navigateTo({
url: item.to
});
}
}
},
async checkVersion() {
let res = await callCheckVersion();
common_vendor.index.__f__("log", "at pages/ucenter/ucenter.vue:393", res);
if (res.result.code > 0) {
checkUpdate();
} else {
common_vendor.index.showToast({
title: res.result.message,
icon: "none"
});
}
},
toUserInfo() {
common_vendor.index.navigateTo({
url: "/uni_modules/uni-id-pages/pages/userinfo/userinfo"
});
},
tapGrid(index) {
if (index === 3) {
if (!this.hasLogin) {
return common_vendor.index.showToast({
title: "请先登录后再修改密码",
icon: "none"
});
}
this.openChangePasswordDialog();
} else {
common_vendor.index.showToast({
title: this.$t("mine.clicked") + " " + (index + 1),
icon: "none"
});
}
},
/**
* 去应用市场评分
*/
gotoMarket() {
},
/**
* 获取积分信息
*/
getScore() {
if (!this.userInfo)
return common_vendor.index.showToast({
title: this.$t("mine.checkScore"),
icon: "none"
});
common_vendor.index.showLoading({
mask: true
});
db.collection("uni-id-scores").where('"user_id" == $env.uid').field("score,balance").orderBy("create_date", "desc").limit(1).get().then((res) => {
common_vendor.index.__f__("log", "at pages/ucenter/ucenter.vue:466", res);
const data = res.result.data[0];
let msg = "";
msg = data ? this.$t("mine.currentScore") + data.balance : this.$t("mine.noScore");
common_vendor.index.showToast({
title: msg,
icon: "none"
});
}).finally(() => {
common_vendor.index.hideLoading();
});
},
async share() {
let { result } = await db.collection("uni-id-users").where("'_id' == $cloudEnv_uid").field("my_invite_code").get();
let myInviteCode = result.data[0].my_invite_code;
if (!myInviteCode) {
return common_vendor.index.showToast({
title: "请检查uni-config-center中uni-id配置是否已启用 autoSetInviteCode",
icon: "none"
});
}
common_vendor.index.__f__("log", "at pages/ucenter/ucenter.vue:487", { myInviteCode });
this.appConfig.about;
},
/**
* 打开设备绑定弹窗
*/
openDeviceBind() {
if (this.$refs.deviceBindPopup) {
this.$refs.deviceBindPopup.open();
}
},
/**
* 设备绑定成功回调
*/
onDeviceBindSuccess() {
this.loadDeviceStatistics();
},
/**
* 打开设备列表弹窗
*/
openDeviceList() {
if (this.$refs.deviceListPopup) {
this.$refs.deviceListPopup.open();
}
},
/**
* 打开修改密码弹窗
*/
openChangePasswordDialog() {
this.changePwdForm = {
oldPassword: "",
newPassword: "",
confirmPassword: ""
};
if (this.$refs.changePwdPopup) {
this.$refs.changePwdPopup.open();
}
},
/**
* 关闭修改密码弹窗
*/
closeChangePasswordDialog() {
if (this.$refs.changePwdPopup) {
this.$refs.changePwdPopup.close();
}
},
/**
* 提交修改密码
*/
async submitChangePassword() {
var _a, _b;
if (this.changePwdSubmitting)
return;
const { oldPassword, newPassword, confirmPassword } = this.changePwdForm;
if (!oldPassword) {
return common_vendor.index.showToast({
title: "请输入原始密码",
icon: "none"
});
}
if (!newPassword) {
return common_vendor.index.showToast({
title: "请输入新密码",
icon: "none"
});
}
if (newPassword.length < 6 || newPassword.length > 20) {
return common_vendor.index.showToast({
title: "新密码长度需为 6-20 位",
icon: "none"
});
}
if (newPassword !== confirmPassword) {
return common_vendor.index.showToast({
title: "两次输入的新密码不一致",
icon: "none"
});
}
this.changePwdSubmitting = true;
try {
if (!this.loginUserInfo.userId) {
return common_vendor.index.showToast({
title: "用户信息不完整,请重新登录",
icon: "none"
});
}
const requestData = {
password: newPassword,
originalPassword: oldPassword,
userId: this.loginUserInfo.userId,
tenantId: this.tenantId
};
if (this.loginUserInfo.phone) {
requestData.phone = this.loginUserInfo.phone;
}
const res = await common_request.put("/api/sys/user/update", requestData);
if (res.statusCode === 200 && res.data && res.data.success) {
this.closeChangePasswordDialog();
common_vendor.index.showModal({
content: res.data.message || "密码修改成功,请重新登录",
showCancel: false,
success: () => {
common_vendor.index.removeStorageSync("backend-token");
common_vendor.index.removeStorageSync("backend-login-response");
common_vendor.index.removeStorageSync("backend-user-id");
common_vendor.index.removeStorageSync("backend-tenant-id");
common_vendor.index.removeStorageSync("uni_id_token");
common_vendor.index.setStorageSync("uni_id_token_expired", 0);
common_vendor.index.redirectTo({
url: "/uni_modules/uni-id-pages/pages/login/login-withpwd"
});
}
});
} else {
const errorMessage = ((_a = res.data) == null ? void 0 : _a.message) || "密码修改失败,请稍后重试";
common_vendor.index.showModal({
content: errorMessage,
showCancel: false
});
}
} catch (e) {
common_vendor.index.__f__("error", "at pages/ucenter/ucenter.vue:683", "密码修改失败:", e);
const errorMessage = ((_b = e == null ? void 0 : e.data) == null ? void 0 : _b.message) || (e == null ? void 0 : e.message) || "密码修改失败,请稍后重试";
common_vendor.index.showModal({
content: errorMessage,
showCancel: false
});
} finally {
this.changePwdSubmitting = false;
}
},
// 页面加载后的URL隐藏初始化只在用户导航时执行
initUrlHidingAfterPageLoad() {
},
// 设置tab导航时的URL隐藏
setupTabNavigationHiding() {
},
// 设置浏览器导航时的URL隐藏
setupBrowserNavigationHiding() {
},
// 为当前页面尝试URL隐藏
attemptUrlHidingForCurrentPage() {
}
}
};
if (!Array) {
const _easycom_uni_sign_in2 = common_vendor.resolveComponent("uni-sign-in");
const _easycom_cloud_image2 = common_vendor.resolveComponent("cloud-image");
const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
const _easycom_uni_grid_item2 = common_vendor.resolveComponent("uni-grid-item");
const _easycom_uni_grid2 = common_vendor.resolveComponent("uni-grid");
const _easycom_uni_list_item2 = common_vendor.resolveComponent("uni-list-item");
const _easycom_uni_list2 = common_vendor.resolveComponent("uni-list");
const _component_device_bind_popup = common_vendor.resolveComponent("device-bind-popup");
const _component_device_list_popup = common_vendor.resolveComponent("device-list-popup");
const _easycom_uni_easyinput2 = common_vendor.resolveComponent("uni-easyinput");
const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
(_easycom_uni_sign_in2 + _easycom_cloud_image2 + _easycom_uni_icons2 + _easycom_uni_grid_item2 + _easycom_uni_grid2 + _easycom_uni_list_item2 + _easycom_uni_list2 + _component_device_bind_popup + _component_device_list_popup + _easycom_uni_easyinput2 + _easycom_uni_popup2)();
}
const _easycom_uni_sign_in = () => "../../uni_modules/uni-sign-in/components/uni-sign-in/uni-sign-in.js";
const _easycom_cloud_image = () => "../../uni_modules/uni-id-pages/components/cloud-image/cloud-image.js";
const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
const _easycom_uni_grid_item = () => "../../uni_modules/uni-grid/components/uni-grid-item/uni-grid-item.js";
const _easycom_uni_grid = () => "../../uni_modules/uni-grid/components/uni-grid/uni-grid.js";
const _easycom_uni_list_item = () => "../../uni_modules/uni-list/components/uni-list-item/uni-list-item.js";
const _easycom_uni_list = () => "../../uni_modules/uni-list/components/uni-list/uni-list.js";
const _easycom_uni_easyinput = () => "../../uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.js";
const _easycom_uni_popup = () => "../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
if (!Math) {
(_easycom_uni_sign_in + _easycom_cloud_image + _easycom_uni_icons + _easycom_uni_grid_item + _easycom_uni_grid + _easycom_uni_list_item + _easycom_uni_list + _easycom_uni_easyinput + _easycom_uni_popup)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return common_vendor.e({
a: common_vendor.sr("signIn", "b6546e32-0"),
b: $options.hasLogin && $options.userInfo.avatar_file && $options.userInfo.avatar_file.url
}, $options.hasLogin && $options.userInfo.avatar_file && $options.userInfo.avatar_file.url ? {
c: common_vendor.p({
width: "150rpx",
height: "150rpx",
src: $options.userInfo.avatar_file.url
})
} : {
d: common_vendor.p({
color: "#ffffff",
size: "50",
type: "person-filled"
})
}, {
e: $options.hasLogin
}, $options.hasLogin ? {
f: common_vendor.t($options.userInfo.nickname || $options.userInfo.username || $options.userInfo.mobile)
} : {
g: common_vendor.t(_ctx.$t("mine.notLogged"))
}, {
h: common_vendor.o((...args) => $options.toUserInfo && $options.toUserInfo(...args), "89"),
i: $options.hasLogin
}, $options.hasLogin ? common_vendor.e({
j: common_vendor.t($data.tenantId || "未设置"),
k: common_vendor.t($data.loginUserInfo.userName || "未设置"),
l: $data.loginUserInfo.phone
}, $data.loginUserInfo.phone ? {
m: common_vendor.t($data.loginUserInfo.phone)
} : {}, {
n: $data.loginUserInfo.email
}, $data.loginUserInfo.email ? {
o: common_vendor.t($data.loginUserInfo.email)
} : {}) : {}, {
p: common_vendor.f($data.gridList, (item, index, i0) => {
return common_vendor.e({
a: "b6546e32-5-" + i0 + "," + ("b6546e32-4-" + i0),
b: common_vendor.p({
color: "#007AFF",
type: item.icon,
size: "26"
}),
c: index === 0
}, index === 0 ? {
d: common_vendor.t($data.totalDevices)
} : index === 1 ? {
f: common_vendor.t($data.totalSales)
} : index === 2 ? {
h: common_vendor.t($data.totalProjects)
} : {
i: common_vendor.t(item.text)
}, {
e: index === 1,
g: index === 2,
j: common_vendor.o(($event) => $options.tapGrid(index), index),
k: index,
l: "b6546e32-4-" + i0 + ",b6546e32-3"
});
}),
q: common_vendor.p({
column: 4,
showBorder: false,
square: true
}),
r: common_vendor.f($data.ucenterList, (sublist, index, i0) => {
return {
a: common_vendor.f(sublist, (item, i, i1) => {
return common_vendor.e({
a: item.showBadge
}, item.showBadge ? {
b: common_vendor.t(item.rightText)
} : {}, {
c: i,
d: common_vendor.o(($event) => $options.ucenterListClick(item), i),
e: "b6546e32-7-" + i0 + "-" + i1 + "," + ("b6546e32-6-" + i0),
f: common_vendor.p({
title: item.title,
link: true,
rightText: item.rightText,
clickable: true,
to: item.to,
["show-extra-icon"]: true,
extraIcon: {
type: item.icon,
color: "#999"
}
})
});
}),
b: index,
c: "b6546e32-6-" + i0
};
}),
s: common_vendor.sr("deviceBindPopup", "b6546e32-8"),
t: common_vendor.o($options.onDeviceBindSuccess, "a5"),
v: common_vendor.sr("deviceListPopup", "b6546e32-9"),
w: common_vendor.o(($event) => $data.changePwdForm.oldPassword = $event, "5e"),
x: common_vendor.p({
type: "password",
placeholder: "请输入原始密码",
modelValue: $data.changePwdForm.oldPassword
}),
y: common_vendor.o(($event) => $data.changePwdForm.newPassword = $event, "a1"),
z: common_vendor.p({
type: "password",
placeholder: "请输入新密码6-20位",
modelValue: $data.changePwdForm.newPassword
}),
A: common_vendor.o(($event) => $data.changePwdForm.confirmPassword = $event, "06"),
B: common_vendor.p({
type: "password",
placeholder: "请再次输入新密码",
modelValue: $data.changePwdForm.confirmPassword
}),
C: common_vendor.o((...args) => $options.closeChangePasswordDialog && $options.closeChangePasswordDialog(...args), "b4"),
D: common_vendor.t($data.changePwdSubmitting ? "提交中..." : "提交"),
E: $data.changePwdSubmitting,
F: common_vendor.o((...args) => $options.submitChangePassword && $options.submitChangePassword(...args), "16"),
G: common_vendor.sr("changePwdPopup", "b6546e32-10"),
H: common_vendor.p({
type: "dialog"
})
});
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-b6546e32"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/ucenter/ucenter.js.map