add Notify
This commit is contained in:
@@ -14,15 +14,19 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useUserStore } from "timi-web";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { NotifyAPI, useUserStore } from "timi-web";
|
||||
import { useNavBarStore } from "@/store/navBarStore";
|
||||
import { corePermissionCodes, permissionCodes } from "@/utils/permission";
|
||||
|
||||
defineOptions({
|
||||
name: "HomeTab"
|
||||
});
|
||||
|
||||
const router = useRouter();
|
||||
const navBarStore = useNavBarStore();
|
||||
const userStore = useUserStore();
|
||||
const unreadNotifyCount = ref(0);
|
||||
let isPageActive = true;
|
||||
|
||||
const entryList = [
|
||||
{
|
||||
@@ -56,10 +60,41 @@ const entryList = [
|
||||
];
|
||||
|
||||
const visibleEntryList = computed(() => entryList.filter(item => userStore.hasPermissions(item.permission)));
|
||||
const canReadNotify = computed(() => userStore.hasPermissions(corePermissionCodes.notify.read));
|
||||
|
||||
async function go(path: string): Promise<void> {
|
||||
await router.push(path);
|
||||
}
|
||||
|
||||
async function goNotifyList(): Promise<void> {
|
||||
await router.push("/notify");
|
||||
}
|
||||
|
||||
async function loadUnreadNotifyCount(): Promise<void> {
|
||||
try {
|
||||
unreadNotifyCount.value = Math.max(0, await NotifyAPI.countUnreadInternal());
|
||||
} catch (error) {
|
||||
unreadNotifyCount.value = 0;
|
||||
console.warn("未读通知数量加载失败", error);
|
||||
}
|
||||
if (isPageActive) {
|
||||
navBarStore.setRightBadge(unreadNotifyCount.value);
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
navBarStore.clearRight();
|
||||
if (canReadNotify.value) {
|
||||
navBarStore.setRightIcon("notification", goNotifyList);
|
||||
navBarStore.setRightBadge(0);
|
||||
await loadUnreadNotifyCount();
|
||||
}
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
isPageActive = false;
|
||||
navBarStore.clearRight();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
|
||||
Reference in New Issue
Block a user