refactor: 优化类型定义并重构代码逻辑
This commit is contained in:
@@ -180,6 +180,9 @@ export interface UserInfo {
|
|||||||
/** 邮箱 */
|
/** 邮箱 */
|
||||||
email?: string;
|
email?: string;
|
||||||
|
|
||||||
|
/** 性别 */
|
||||||
|
gender?: number;
|
||||||
|
|
||||||
/** 部门名称 */
|
/** 部门名称 */
|
||||||
deptName?: string;
|
deptName?: string;
|
||||||
|
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ import { useRouter } from "uni-mini-router";
|
|||||||
import { useUserStore } from "@/store";
|
import { useUserStore } from "@/store";
|
||||||
import { menuConfig } from "@/config/menu";
|
import { menuConfig } from "@/config/menu";
|
||||||
import { checkLogin, isLoggedIn } from "@/utils/auth";
|
import { checkLogin, isLoggedIn } from "@/utils/auth";
|
||||||
|
import { hasPermission } from "@/utils/permission";
|
||||||
import LogAPI, { type VisitOverview as ApiVisitOverview, type VisitTrend } from "@/api/log";
|
import LogAPI, { type VisitOverview as ApiVisitOverview, type VisitTrend } from "@/api/log";
|
||||||
import NoticeAPI, { type NoticeItem } from "@/api/notice";
|
import NoticeAPI, { type NoticeItem } from "@/api/notice";
|
||||||
|
|
||||||
@@ -157,12 +158,6 @@ const isLogged = computed(() => isLoggedIn());
|
|||||||
|
|
||||||
const hasAnyPerm = computed(() => userPerms.value.length > 0);
|
const hasAnyPerm = computed(() => userPerms.value.length > 0);
|
||||||
|
|
||||||
// 检查是否有权限
|
|
||||||
const hasPermission = (perm: string) => {
|
|
||||||
if (!perm) return true;
|
|
||||||
return userPerms.value.includes(perm) || userPerms.value.includes("*:*:*");
|
|
||||||
};
|
|
||||||
|
|
||||||
// 默认菜单(未登录时显示)
|
// 默认菜单(未登录时显示)
|
||||||
const defaultNavList = computed(() => {
|
const defaultNavList = computed(() => {
|
||||||
const result: { icon: string; title: string; url: string; perm: string }[] = [];
|
const result: { icon: string; title: string; url: string; perm: string }[] = [];
|
||||||
|
|||||||
@@ -208,6 +208,7 @@ import { useToast, useMessage } from "wot-design-uni";
|
|||||||
import { useUserStore, useThemeStore } from "@/store";
|
import { useUserStore, useThemeStore } from "@/store";
|
||||||
import { useRouter } from "uni-mini-router";
|
import { useRouter } from "uni-mini-router";
|
||||||
import { useNavbar } from "@/composables/useNavbar";
|
import { useNavbar } from "@/composables/useNavbar";
|
||||||
|
import type { UserInfo } from "@/api/user";
|
||||||
import { getAccessToken } from "@/utils/auth";
|
import { getAccessToken } from "@/utils/auth";
|
||||||
|
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
@@ -235,11 +236,11 @@ const appVersion = ref("1.0.0");
|
|||||||
const navbar = useNavbar({ hasTabbar: true });
|
const navbar = useNavbar({ hasTabbar: true });
|
||||||
|
|
||||||
const hasUserProfile = computed(() => {
|
const hasUserProfile = computed(() => {
|
||||||
const info = userInfo.value as any;
|
const info = userInfo.value;
|
||||||
return !!(info && (info.id || info.userId || info.username || info.nickname));
|
return !!(info && (info.userId || info.username || info.nickname));
|
||||||
});
|
});
|
||||||
|
|
||||||
const genderValue = computed(() => (userInfo.value as any)?.gender);
|
const genderValue = computed(() => userInfo.value?.gender);
|
||||||
const normalizedGender = computed(() => {
|
const normalizedGender = computed(() => {
|
||||||
const v = genderValue.value;
|
const v = genderValue.value;
|
||||||
const n = typeof v === "number" ? v : Number(v);
|
const n = typeof v === "number" ? v : Number(v);
|
||||||
@@ -248,7 +249,7 @@ const normalizedGender = computed(() => {
|
|||||||
|
|
||||||
const deptNameText = computed(() => {
|
const deptNameText = computed(() => {
|
||||||
if (!isLogin.value) return "";
|
if (!isLogin.value) return "";
|
||||||
return (userInfo.value as any)?.deptName || "";
|
return userInfo.value?.deptName || "";
|
||||||
});
|
});
|
||||||
|
|
||||||
const genderIconName = computed(() => {
|
const genderIconName = computed(() => {
|
||||||
@@ -347,7 +348,7 @@ const openAbout = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const clearing = ref(false);
|
const clearing = ref(false);
|
||||||
const cacheSize = ref<any>("计算中...");
|
const cacheSize = ref<string>("计算中...");
|
||||||
|
|
||||||
const formatBytes = (size: number) => {
|
const formatBytes = (size: number) => {
|
||||||
if (size < 1024) {
|
if (size < 1024) {
|
||||||
|
|||||||
@@ -72,6 +72,4 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
router.afterEach(() => {});
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|||||||
2
src/shime-uni.d.ts → src/shims-uni.d.ts
vendored
2
src/shime-uni.d.ts → src/shims-uni.d.ts
vendored
@@ -1,4 +1,4 @@
|
|||||||
export {};
|
export {};
|
||||||
|
|
||||||
declare module "vue" {
|
declare module "vue" {
|
||||||
type Hooks = App.AppInstance & Page.PageInstance;
|
type Hooks = App.AppInstance & Page.PageInstance;
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
/**
|
/**
|
||||||
* localStorage 存储
|
* localStorage 存储
|
||||||
*/
|
*/
|
||||||
function set(key: string, value: any): void {
|
function set<T>(key: string, value: T): void {
|
||||||
uni.setStorageSync(key, JSON.stringify(value));
|
uni.setStorageSync(key, JSON.stringify(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user