feat: 移动端双Token队列拦截器 + 通知列表 + 登录页 + TabBar红点 + v1.0.1

This commit is contained in:
2026-08-07 11:44:20 +08:00
parent 721cfe1504
commit 0df7215134
13 changed files with 1013 additions and 206 deletions

View File

@ -1,21 +1,53 @@
<script setup>
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
<script>
import { getNotifications } from "./api/notification";
onLaunch(() => {
console.log("生产流转 App 启动");
});
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;
onShow(() => {
console.log("App 显示");
});
const res = await getNotifications(userId, 0, 1);
const unreadCount = res.unread_count || 0;
onHide(() => {
console.log("App 隐藏");
});
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;