Template
1
0
mirror of https://github.com/un-pany/v3-admin-vite.git synced 2025-04-21 11:29:20 +08:00

perf: 代码优化 所有的 type 类型命名

This commit is contained in:
pany 2023-05-21 10:42:50 +08:00
parent 05712f4adc
commit e4d9673a2b
6 changed files with 30 additions and 30 deletions

View File

@ -5,10 +5,10 @@ import { Bell } from "@element-plus/icons-vue"
import NotifyList from "./NotifyList.vue"
import { type ListItem, notifyData, messageData, todoData } from "./data"
type TabNameType = "通知" | "消息" | "待办"
type TabName = "通知" | "消息" | "待办"
interface DataItem {
name: TabNameType
name: TabName
type: "primary" | "success" | "warning" | "danger" | "info"
list: ListItem[]
}
@ -26,7 +26,7 @@ const badgeMax = 99
/** 面板宽度 */
const popoverWidth = 350
/** 当前 Tab */
const activeName = ref<TabNameType>("通知")
const activeName = ref<TabName>("通知")
/** 所有数据 */
const data = ref<DataItem[]>([
//

View File

@ -1,10 +1,10 @@
import { ref, onMounted } from "vue"
type OptionValueType = string | number
type OptionValue = string | number
/** Select 需要的数据格式 */
interface SelectOption {
value: OptionValueType
value: OptionValue
label: string
disabled?: boolean
}
@ -26,7 +26,7 @@ export function useFetchSelect(props: FetchSelectProps) {
const loading = ref<boolean>(false)
const options = ref<SelectOption[]>([])
const value = ref<OptionValueType>("")
const value = ref<OptionValue>("")
/** 调用接口获取数据 */
const loadData = () => {

View File

@ -2,10 +2,10 @@ import { ref, watchEffect } from "vue"
import { getActiveThemeName, setActiveThemeName } from "@/utils/cache/localStorage"
const DEFAULT_THEME_NAME = "normal"
type DefaultThemeNameType = typeof DEFAULT_THEME_NAME
type DefaultThemeName = typeof DEFAULT_THEME_NAME
/** 注册的主题名称, 其中 DefaultThemeNameType 是必填的 */
export type ThemeName = DefaultThemeNameType | "dark" | "dark-blue"
/** 注册的主题名称, 其中 DefaultThemeName 是必填的 */
export type ThemeName = DefaultThemeName | "dark" | "dark-blue"
interface ThemeList {
title: string

View File

@ -1,7 +1,7 @@
<script lang="ts" setup>
import { getCurrentInstance, onMounted, ref, watch } from "vue"
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 ScrollPane from "./ScrollPane.vue"
import path from "path-browserify"
@ -18,19 +18,19 @@ const tagRefs = ref<InstanceType<typeof RouterLink>[]>([])
const visible = ref(false)
const top = ref(0)
const left = ref(0)
const selectedTag = ref<ITagView>({})
let affixTags: ITagView[] = []
const selectedTag = ref<TagView>({})
let affixTags: TagView[] = []
const isActive = (tag: ITagView) => {
const isActive = (tag: TagView) => {
return tag.path === route.path
}
const isAffix = (tag: ITagView) => {
const isAffix = (tag: TagView) => {
return tag.meta?.affix
}
const filterAffixTags = (routes: RouteRecordRaw[], basePath = "/") => {
let tags: ITagView[] = []
let tags: TagView[] = []
routes.forEach((route) => {
if (route.meta?.affix) {
const tagPath = path.resolve(basePath, route.path)
@ -68,12 +68,12 @@ const addTags = () => {
}
}
const refreshSelectedTag = (view: ITagView) => {
const refreshSelectedTag = (view: TagView) => {
tagsViewStore.delCachedView(view)
router.replace({ path: "/redirect" + view.path, query: view.query })
}
const closeSelectedTag = (view: ITagView) => {
const closeSelectedTag = (view: TagView) => {
tagsViewStore.delVisitedView(view)
tagsViewStore.delCachedView(view)
if (isActive(view)) {
@ -89,7 +89,7 @@ const closeOthersTags = () => {
tagsViewStore.delOthersCachedViews(selectedTag.value)
}
const closeAllTags = (view: ITagView) => {
const closeAllTags = (view: TagView) => {
tagsViewStore.delAllVisitedViews()
tagsViewStore.delAllCachedViews()
if (affixTags.some((tag) => tag.path === route.path)) {
@ -98,7 +98,7 @@ const closeAllTags = (view: ITagView) => {
toLastView(tagsViewStore.visitedViews, view)
}
const toLastView = (visitedViews: ITagView[], view: ITagView) => {
const toLastView = (visitedViews: TagView[], view: TagView) => {
const latestView = visitedViews.slice(-1)[0]
if (latestView !== undefined && latestView.fullPath !== undefined) {
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
// container margin left
const offsetLeft = instance!.proxy!.$el.getBoundingClientRect().left

View File

@ -2,14 +2,14 @@ import { ref } from "vue"
import { defineStore } from "pinia"
import { type RouteLocationNormalized } from "vue-router"
export type ITagView = Partial<RouteLocationNormalized>
export type TagView = Partial<RouteLocationNormalized>
export const useTagsViewStore = defineStore("tags-view", () => {
const visitedViews = ref<ITagView[]>([])
const visitedViews = ref<TagView[]>([])
const cachedViews = ref<string[]>([])
//#region add
const addVisitedView = (view: ITagView) => {
const addVisitedView = (view: TagView) => {
if (
visitedViews.value.some((v, index) => {
if (v.path === view.path) {
@ -25,7 +25,7 @@ export const useTagsViewStore = defineStore("tags-view", () => {
}
visitedViews.value.push(Object.assign({}, view))
}
const addCachedView = (view: ITagView) => {
const addCachedView = (view: TagView) => {
if (typeof view.name !== "string") return
if (cachedViews.value.includes(view.name)) return
if (view.meta?.keepAlive) {
@ -35,7 +35,7 @@ export const useTagsViewStore = defineStore("tags-view", () => {
//#endregion
//#region del
const delVisitedView = (view: ITagView) => {
const delVisitedView = (view: TagView) => {
for (const [i, v] of visitedViews.value.entries()) {
if (v.path === view.path) {
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
const index = cachedViews.value.indexOf(view.name)
index > -1 && cachedViews.value.splice(index, 1)
@ -51,12 +51,12 @@ export const useTagsViewStore = defineStore("tags-view", () => {
//#endregion
//#region delOthers
const delOthersVisitedViews = (view: ITagView) => {
const delOthersVisitedViews = (view: TagView) => {
visitedViews.value = visitedViews.value.filter((v) => {
return v.meta?.affix || v.path === view.path
})
}
const delOthersCachedViews = (view: ITagView) => {
const delOthersCachedViews = (view: TagView) => {
if (typeof view.name !== "string") return
const index = cachedViews.value.indexOf(view.name)
if (index > -1) {

View File

@ -4,10 +4,10 @@ import { useUserStore } from "@/store/modules/user"
import AdminDashboard from "./admin/index.vue"
import EditorDashboard from "./editor/index.vue"
type CurrentRoleType = "admin" | "editor"
type CurrentRole = "admin" | "editor"
const userStore = useUserStore()
const currentRole = ref<CurrentRoleType>("admin")
const currentRole = ref<CurrentRole>("admin")
if (!userStore.roles.includes("admin")) {
currentRole.value = "editor"
}