This commit is contained in:
Hooray
2025-01-24 11:44:38 +08:00
parent 3d993bb0b4
commit 6ed480cc2f
370 changed files with 11494 additions and 6938 deletions
+5 -2
View File
@@ -7,9 +7,12 @@ export default function useMenu() {
const settingsStore = useSettingsStore()
const menuStore = useMenuStore()
function switchTo(index: number | string) {
function switchTo(index: number) {
menuStore.setActived(index)
if (settingsStore.settings.menu.switchMainMenuAndPageJump) {
if (
settingsStore.settings.menu.mainMenuClickMode === 'jump'
|| (settingsStore.settings.menu.mainMenuClickMode === 'smart' && menuStore.sidebarMenusHasOnlyMenu)
) {
router.push(menuStore.sidebarMenusFirstDeepestPath)
}
}
+40 -22
View File
@@ -1,6 +1,6 @@
import type { RouteLocationRaw } from 'vue-router'
import useTabbarStore from '@/store/modules/tabbar'
import Message from 'vue-m-message'
import { toast } from 'vue-sonner'
export default function useTabbar() {
const route = useRoute()
@@ -26,6 +26,13 @@ export default function useTabbar() {
tabbarStore.remove(tabId)
}
function replace(to: RouteLocationRaw) {
const tabId = getId()
router.replace(to).then(() => {
tabbarStore.remove(tabId)
})
}
function close(to: RouteLocationRaw) {
const tabId = getId()
router.push(to).then(() => {
@@ -34,34 +41,22 @@ export default function useTabbar() {
}
function closeById(tabId = getId()) {
const activedTabId = getId()
if (tabbarStore.list.some(item => item.tabId === tabId)) {
if (tabbarStore.list.length > 1) {
// 如果关闭的标签正好是当前路由
if (tabId === activedTabId) {
const index = tabbarStore.list.findIndex(item => item.tabId === tabId)
if (index < tabbarStore.list.length - 1) {
close(tabbarStore.list[index + 1].fullPath)
}
else {
close(tabbarStore.list[index - 1].fullPath)
}
if (checkClose(tabId, false)) {
const activedTabId = getId()
// 如果关闭的标签正好是当前路由
if (tabId === activedTabId) {
const index = tabbarStore.list.findIndex(item => item.tabId === tabId)
if (index < tabbarStore.list.length - 1) {
close(tabbarStore.list[index + 1].fullPath)
}
else {
tabbarStore.remove(tabId)
close(tabbarStore.list[index - 1].fullPath)
}
}
else {
Message.error('当前只有一个标签页,已阻止关闭', {
zIndex: 2000,
})
tabbarStore.remove(tabId)
}
}
else {
Message.error('关闭的页面不存在', {
zIndex: 2000,
})
}
}
/**
@@ -109,6 +104,27 @@ export default function useTabbar() {
tabbarStore.removeRightSide(tabId)
}
/**
* 校验指定标签是否可关闭
*/
function checkClose(tabId = getId(), checkOnly = true) {
let flag = true
const index = tabbarStore.list.findIndex(item => item.tabId === tabId)
if (index < 0) {
flag = false
!checkOnly && toast.warning('关闭的标签页不存在', {
position: 'top-center',
})
}
else if (tabbarStore.list.length <= 1) {
flag = false
!checkOnly && toast.warning('当前只有一个标签页,不可关闭', {
position: 'top-center',
})
}
return flag
}
/**
* 校验指定标签两侧是否有可关闭的标签
*/
@@ -156,11 +172,13 @@ export default function useTabbar() {
getId,
open,
go,
replace,
close,
closeById,
closeOtherSide,
closeLeftSide,
closeRightSide,
checkClose,
checkCloseOtherSide,
checkCloseLeftSide,
checkCloseRightSide,
+5 -6
View File
@@ -2,11 +2,10 @@ import type { App, DirectiveBinding } from 'vue'
export default function directive(app: App) {
app.directive('auth', (el: HTMLElement, binding: DirectiveBinding) => {
if (binding.modifiers.all ? useAuth().authAll(binding.value) : useAuth().auth(binding.value)) {
el.style.display = ''
}
else {
el.style.display = 'none'
}
watch(() => binding.modifiers.all ? useAuth().authAll(binding.value) : useAuth().auth(binding.value), (val) => {
el.style.display = val ? '' : 'none'
}, {
immediate: true,
})
})
}
-1
View File
@@ -2,7 +2,6 @@ import mitt from 'mitt'
interface MittTypes {
[key: string | symbol]: any
'global-search-toggle'?: 'menu' | 'tab'
}
export default mitt<MittTypes>()
+6
View File
@@ -1,4 +1,10 @@
import { type ClassValue, clsx } from 'clsx'
import path from 'path-browserify'
import { twMerge } from 'tailwind-merge'
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
export function resolveRoutePath(basePath?: string, routePath?: string) {
return basePath ? path.resolve(basePath, routePath ?? '') : routePath ?? ''
+54
View File
@@ -0,0 +1,54 @@
import { createDefu } from 'defu'
/** 合并对象 */
const merge = createDefu((obj, key, value) => {
if (Array.isArray(obj[key]) && Array.isArray(value)) {
obj[key] = value
return true
}
})
/** 合并对象,并移除不存在的属性 */
const mergeWithoutUndefinedProps = createDefu((obj, key, value) => {
if (obj[key] === undefined) {
delete obj[key]
return true
}
if (Array.isArray(obj[key]) && Array.isArray(value)) {
obj[key] = value
return true
}
})
function isObject(value: any) {
return typeof value === 'object' && !Array.isArray(value)
}
/** 比较两个对象,提取出不同的部分 */
function diffTwoObj(originalObj: Record<string, any>, diffObj: Record<string, any>) {
if (!isObject(originalObj) || !isObject(diffObj)) {
return diffObj
}
const diff: Record<string, any> = {}
for (const key in diffObj) {
const originalValue = originalObj[key]
const diffValue = diffObj[key]
if (JSON.stringify(originalValue) !== JSON.stringify(diffValue)) {
if (isObject(originalValue) && isObject(diffValue)) {
const nestedDiff = diffTwoObj(originalValue, diffValue)
if (Object.keys(nestedDiff).length > 0) {
diff[key] = nestedDiff
}
}
else {
diff[key] = diffValue
}
}
}
return diff
}
export {
diffTwoObj,
merge,
mergeWithoutUndefinedProps,
}
+3
View File
@@ -0,0 +1,3 @@
import { UAParser } from 'ua-parser-js'
export const ua = new UAParser()