perf: 代码优化 所有的 type 类型命名
This commit is contained in:
parent
05712f4adc
commit
e4d9673a2b
@ -5,10 +5,10 @@ import { Bell } from "@element-plus/icons-vue"
|
|||||||
import NotifyList from "./NotifyList.vue"
|
import NotifyList from "./NotifyList.vue"
|
||||||
import { type ListItem, notifyData, messageData, todoData } from "./data"
|
import { type ListItem, notifyData, messageData, todoData } from "./data"
|
||||||
|
|
||||||
type TabNameType = "通知" | "消息" | "待办"
|
type TabName = "通知" | "消息" | "待办"
|
||||||
|
|
||||||
interface DataItem {
|
interface DataItem {
|
||||||
name: TabNameType
|
name: TabName
|
||||||
type: "primary" | "success" | "warning" | "danger" | "info"
|
type: "primary" | "success" | "warning" | "danger" | "info"
|
||||||
list: ListItem[]
|
list: ListItem[]
|
||||||
}
|
}
|
||||||
@ -26,7 +26,7 @@ const badgeMax = 99
|
|||||||
/** 面板宽度 */
|
/** 面板宽度 */
|
||||||
const popoverWidth = 350
|
const popoverWidth = 350
|
||||||
/** 当前 Tab */
|
/** 当前 Tab */
|
||||||
const activeName = ref<TabNameType>("通知")
|
const activeName = ref<TabName>("通知")
|
||||||
/** 所有数据 */
|
/** 所有数据 */
|
||||||
const data = ref<DataItem[]>([
|
const data = ref<DataItem[]>([
|
||||||
// 通知数据
|
// 通知数据
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { ref, onMounted } from "vue"
|
import { ref, onMounted } from "vue"
|
||||||
|
|
||||||
type OptionValueType = string | number
|
type OptionValue = string | number
|
||||||
|
|
||||||
/** Select 需要的数据格式 */
|
/** Select 需要的数据格式 */
|
||||||
interface SelectOption {
|
interface SelectOption {
|
||||||
value: OptionValueType
|
value: OptionValue
|
||||||
label: string
|
label: string
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
}
|
}
|
||||||
@ -26,7 +26,7 @@ export function useFetchSelect(props: FetchSelectProps) {
|
|||||||
|
|
||||||
const loading = ref<boolean>(false)
|
const loading = ref<boolean>(false)
|
||||||
const options = ref<SelectOption[]>([])
|
const options = ref<SelectOption[]>([])
|
||||||
const value = ref<OptionValueType>("")
|
const value = ref<OptionValue>("")
|
||||||
|
|
||||||
/** 调用接口获取数据 */
|
/** 调用接口获取数据 */
|
||||||
const loadData = () => {
|
const loadData = () => {
|
||||||
|
@ -2,10 +2,10 @@ import { ref, watchEffect } from "vue"
|
|||||||
import { getActiveThemeName, setActiveThemeName } from "@/utils/cache/localStorage"
|
import { getActiveThemeName, setActiveThemeName } from "@/utils/cache/localStorage"
|
||||||
|
|
||||||
const DEFAULT_THEME_NAME = "normal"
|
const DEFAULT_THEME_NAME = "normal"
|
||||||
type DefaultThemeNameType = typeof DEFAULT_THEME_NAME
|
type DefaultThemeName = typeof DEFAULT_THEME_NAME
|
||||||
|
|
||||||
/** 注册的主题名称, 其中 DefaultThemeNameType 是必填的 */
|
/** 注册的主题名称, 其中 DefaultThemeName 是必填的 */
|
||||||
export type ThemeName = DefaultThemeNameType | "dark" | "dark-blue"
|
export type ThemeName = DefaultThemeName | "dark" | "dark-blue"
|
||||||
|
|
||||||
interface ThemeList {
|
interface ThemeList {
|
||||||
title: string
|
title: string
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { getCurrentInstance, onMounted, ref, watch } from "vue"
|
import { getCurrentInstance, onMounted, ref, watch } from "vue"
|
||||||
import { type RouteRecordRaw, RouterLink, useRoute, useRouter } from "vue-router"
|
import { type RouteRecordRaw, RouterLink, useRoute, useRouter } from "vue-router"
|
||||||
import { type ITagView, useTagsViewStore } from "@/store/modules/tags-view"
|
import { type TagView, useTagsViewStore } from "@/store/modules/tags-view"
|
||||||
import { usePermissionStore } from "@/store/modules/permission"
|
import { usePermissionStore } from "@/store/modules/permission"
|
||||||
import ScrollPane from "./ScrollPane.vue"
|
import ScrollPane from "./ScrollPane.vue"
|
||||||
import path from "path-browserify"
|
import path from "path-browserify"
|
||||||
@ -18,19 +18,19 @@ const tagRefs = ref<InstanceType<typeof RouterLink>[]>([])
|
|||||||
const visible = ref(false)
|
const visible = ref(false)
|
||||||
const top = ref(0)
|
const top = ref(0)
|
||||||
const left = ref(0)
|
const left = ref(0)
|
||||||
const selectedTag = ref<ITagView>({})
|
const selectedTag = ref<TagView>({})
|
||||||
let affixTags: ITagView[] = []
|
let affixTags: TagView[] = []
|
||||||
|
|
||||||
const isActive = (tag: ITagView) => {
|
const isActive = (tag: TagView) => {
|
||||||
return tag.path === route.path
|
return tag.path === route.path
|
||||||
}
|
}
|
||||||
|
|
||||||
const isAffix = (tag: ITagView) => {
|
const isAffix = (tag: TagView) => {
|
||||||
return tag.meta?.affix
|
return tag.meta?.affix
|
||||||
}
|
}
|
||||||
|
|
||||||
const filterAffixTags = (routes: RouteRecordRaw[], basePath = "/") => {
|
const filterAffixTags = (routes: RouteRecordRaw[], basePath = "/") => {
|
||||||
let tags: ITagView[] = []
|
let tags: TagView[] = []
|
||||||
routes.forEach((route) => {
|
routes.forEach((route) => {
|
||||||
if (route.meta?.affix) {
|
if (route.meta?.affix) {
|
||||||
const tagPath = path.resolve(basePath, route.path)
|
const tagPath = path.resolve(basePath, route.path)
|
||||||
@ -68,12 +68,12 @@ const addTags = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const refreshSelectedTag = (view: ITagView) => {
|
const refreshSelectedTag = (view: TagView) => {
|
||||||
tagsViewStore.delCachedView(view)
|
tagsViewStore.delCachedView(view)
|
||||||
router.replace({ path: "/redirect" + view.path, query: view.query })
|
router.replace({ path: "/redirect" + view.path, query: view.query })
|
||||||
}
|
}
|
||||||
|
|
||||||
const closeSelectedTag = (view: ITagView) => {
|
const closeSelectedTag = (view: TagView) => {
|
||||||
tagsViewStore.delVisitedView(view)
|
tagsViewStore.delVisitedView(view)
|
||||||
tagsViewStore.delCachedView(view)
|
tagsViewStore.delCachedView(view)
|
||||||
if (isActive(view)) {
|
if (isActive(view)) {
|
||||||
@ -89,7 +89,7 @@ const closeOthersTags = () => {
|
|||||||
tagsViewStore.delOthersCachedViews(selectedTag.value)
|
tagsViewStore.delOthersCachedViews(selectedTag.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
const closeAllTags = (view: ITagView) => {
|
const closeAllTags = (view: TagView) => {
|
||||||
tagsViewStore.delAllVisitedViews()
|
tagsViewStore.delAllVisitedViews()
|
||||||
tagsViewStore.delAllCachedViews()
|
tagsViewStore.delAllCachedViews()
|
||||||
if (affixTags.some((tag) => tag.path === route.path)) {
|
if (affixTags.some((tag) => tag.path === route.path)) {
|
||||||
@ -98,7 +98,7 @@ const closeAllTags = (view: ITagView) => {
|
|||||||
toLastView(tagsViewStore.visitedViews, view)
|
toLastView(tagsViewStore.visitedViews, view)
|
||||||
}
|
}
|
||||||
|
|
||||||
const toLastView = (visitedViews: ITagView[], view: ITagView) => {
|
const toLastView = (visitedViews: TagView[], view: TagView) => {
|
||||||
const latestView = visitedViews.slice(-1)[0]
|
const latestView = visitedViews.slice(-1)[0]
|
||||||
if (latestView !== undefined && latestView.fullPath !== undefined) {
|
if (latestView !== undefined && latestView.fullPath !== undefined) {
|
||||||
router.push(latestView.fullPath)
|
router.push(latestView.fullPath)
|
||||||
@ -113,7 +113,7 @@ const toLastView = (visitedViews: ITagView[], view: ITagView) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const openMenu = (tag: ITagView, e: MouseEvent) => {
|
const openMenu = (tag: TagView, e: MouseEvent) => {
|
||||||
const menuMinWidth = 105
|
const menuMinWidth = 105
|
||||||
// container margin left
|
// container margin left
|
||||||
const offsetLeft = instance!.proxy!.$el.getBoundingClientRect().left
|
const offsetLeft = instance!.proxy!.$el.getBoundingClientRect().left
|
||||||
|
@ -2,14 +2,14 @@ import { ref } from "vue"
|
|||||||
import { defineStore } from "pinia"
|
import { defineStore } from "pinia"
|
||||||
import { type RouteLocationNormalized } from "vue-router"
|
import { type RouteLocationNormalized } from "vue-router"
|
||||||
|
|
||||||
export type ITagView = Partial<RouteLocationNormalized>
|
export type TagView = Partial<RouteLocationNormalized>
|
||||||
|
|
||||||
export const useTagsViewStore = defineStore("tags-view", () => {
|
export const useTagsViewStore = defineStore("tags-view", () => {
|
||||||
const visitedViews = ref<ITagView[]>([])
|
const visitedViews = ref<TagView[]>([])
|
||||||
const cachedViews = ref<string[]>([])
|
const cachedViews = ref<string[]>([])
|
||||||
|
|
||||||
//#region add
|
//#region add
|
||||||
const addVisitedView = (view: ITagView) => {
|
const addVisitedView = (view: TagView) => {
|
||||||
if (
|
if (
|
||||||
visitedViews.value.some((v, index) => {
|
visitedViews.value.some((v, index) => {
|
||||||
if (v.path === view.path) {
|
if (v.path === view.path) {
|
||||||
@ -25,7 +25,7 @@ export const useTagsViewStore = defineStore("tags-view", () => {
|
|||||||
}
|
}
|
||||||
visitedViews.value.push(Object.assign({}, view))
|
visitedViews.value.push(Object.assign({}, view))
|
||||||
}
|
}
|
||||||
const addCachedView = (view: ITagView) => {
|
const addCachedView = (view: TagView) => {
|
||||||
if (typeof view.name !== "string") return
|
if (typeof view.name !== "string") return
|
||||||
if (cachedViews.value.includes(view.name)) return
|
if (cachedViews.value.includes(view.name)) return
|
||||||
if (view.meta?.keepAlive) {
|
if (view.meta?.keepAlive) {
|
||||||
@ -35,7 +35,7 @@ export const useTagsViewStore = defineStore("tags-view", () => {
|
|||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region del
|
//#region del
|
||||||
const delVisitedView = (view: ITagView) => {
|
const delVisitedView = (view: TagView) => {
|
||||||
for (const [i, v] of visitedViews.value.entries()) {
|
for (const [i, v] of visitedViews.value.entries()) {
|
||||||
if (v.path === view.path) {
|
if (v.path === view.path) {
|
||||||
visitedViews.value.splice(i, 1)
|
visitedViews.value.splice(i, 1)
|
||||||
@ -43,7 +43,7 @@ export const useTagsViewStore = defineStore("tags-view", () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const delCachedView = (view: ITagView) => {
|
const delCachedView = (view: TagView) => {
|
||||||
if (typeof view.name !== "string") return
|
if (typeof view.name !== "string") return
|
||||||
const index = cachedViews.value.indexOf(view.name)
|
const index = cachedViews.value.indexOf(view.name)
|
||||||
index > -1 && cachedViews.value.splice(index, 1)
|
index > -1 && cachedViews.value.splice(index, 1)
|
||||||
@ -51,12 +51,12 @@ export const useTagsViewStore = defineStore("tags-view", () => {
|
|||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region delOthers
|
//#region delOthers
|
||||||
const delOthersVisitedViews = (view: ITagView) => {
|
const delOthersVisitedViews = (view: TagView) => {
|
||||||
visitedViews.value = visitedViews.value.filter((v) => {
|
visitedViews.value = visitedViews.value.filter((v) => {
|
||||||
return v.meta?.affix || v.path === view.path
|
return v.meta?.affix || v.path === view.path
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
const delOthersCachedViews = (view: ITagView) => {
|
const delOthersCachedViews = (view: TagView) => {
|
||||||
if (typeof view.name !== "string") return
|
if (typeof view.name !== "string") return
|
||||||
const index = cachedViews.value.indexOf(view.name)
|
const index = cachedViews.value.indexOf(view.name)
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
|
@ -4,10 +4,10 @@ import { useUserStore } from "@/store/modules/user"
|
|||||||
import AdminDashboard from "./admin/index.vue"
|
import AdminDashboard from "./admin/index.vue"
|
||||||
import EditorDashboard from "./editor/index.vue"
|
import EditorDashboard from "./editor/index.vue"
|
||||||
|
|
||||||
type CurrentRoleType = "admin" | "editor"
|
type CurrentRole = "admin" | "editor"
|
||||||
|
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
const currentRole = ref<CurrentRoleType>("admin")
|
const currentRole = ref<CurrentRole>("admin")
|
||||||
if (!userStore.roles.includes("admin")) {
|
if (!userStore.roles.includes("admin")) {
|
||||||
currentRole.value = "editor"
|
currentRole.value = "editor"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user