2026-08-07 11:44:20 +08:00
|
|
|
<script>
|
|
|
|
|
import { getNotifications } from "./api/notification";
|
2026-08-05 15:01:46 +08:00
|
|
|
|
2026-08-07 11:44:20 +08:00
|
|
|
export default {
|
|
|
|
|
onLaunch() {
|
|
|
|
|
console.log("生产流转 T1.0.1 启动");
|
|
|
|
|
// 无 Token 跳转登录页
|
|
|
|
|
const token = uni.getStorageSync("access_token");
|
|
|
|
|
if (!token) {
|
|
|
|
|
uni.reLaunch({ url: "/pages/login/login" });
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onShow() {
|
|
|
|
|
console.log("App 显示");
|
|
|
|
|
this.updateTabBarBadge();
|
|
|
|
|
},
|
|
|
|
|
onHide() {
|
|
|
|
|
console.log("App 隐藏");
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
/** 更新底部 TabBar「消息」红点角标 */
|
|
|
|
|
async updateTabBarBadge() {
|
|
|
|
|
try {
|
|
|
|
|
let user = uni.getStorageSync("user");
|
|
|
|
|
if (typeof user === "string" && user) {
|
|
|
|
|
try { user = JSON.parse(user); } catch (e) { user = null; }
|
|
|
|
|
}
|
|
|
|
|
const userId = user?.username || user?.id || "";
|
|
|
|
|
if (!userId) return;
|
2026-08-05 15:01:46 +08:00
|
|
|
|
2026-08-07 11:44:20 +08:00
|
|
|
const res = await getNotifications(userId, 0, 1);
|
|
|
|
|
const unreadCount = res.unread_count || 0;
|
2026-08-05 15:01:46 +08:00
|
|
|
|
2026-08-07 11:44:20 +08:00
|
|
|
if (unreadCount > 0) {
|
|
|
|
|
uni.setTabBarBadge({
|
|
|
|
|
index: 2,
|
|
|
|
|
text: unreadCount > 99 ? "99+" : String(unreadCount),
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
uni.removeTabBarBadge({ index: 2 });
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
// 静默失败
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
2026-08-05 15:01:46 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
page {
|
|
|
|
|
background-color: #f3f4f6;
|
|
|
|
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
color: #1f2937;
|
|
|
|
|
}
|
|
|
|
|
</style>
|