Files
track/track-uniapp/src/App.vue

58 lines
1.4 KiB
Vue
Raw Normal View History

<script>
import { getNotifications } from "./api/notification";
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;
const res = await getNotifications(userId, 0, 1);
const unreadCount = res.unread_count || 0;
if (unreadCount > 0) {
uni.setTabBarBadge({
index: 2,
text: unreadCount > 99 ? "99+" : String(unreadCount),
});
} else {
uni.removeTabBarBadge({ index: 2 });
}
} catch {
// 静默失败
}
},
},
};
</script>
<style>
page {
background-color: #f3f4f6;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
font-size: 14px;
color: #1f2937;
}
</style>