调整目录结构

This commit is contained in:
hooray
2022-07-30 01:37:40 +08:00
parent 80182c54c3
commit 421a8e0612
22 changed files with 18 additions and 18 deletions
+14010
View File
File diff suppressed because it is too large Load Diff
+43
View File
@@ -0,0 +1,43 @@
import useSettingsStore from '@/store/modules/settings'
import useUserStore from '@/store/modules/user'
function useAuth() {
function hasPermission(permission) {
const settingsStore = useSettingsStore()
const userStore = useUserStore()
if (settingsStore.app.enablePermission) {
return userStore.permissions.some(v => {
return v === permission
})
} else {
return true
}
}
function auth(value) {
let auth
if (typeof value === 'string') {
auth = hasPermission(value)
} else {
auth = value.some(item => {
return hasPermission(item)
})
}
return auth
}
function authAll(value) {
const auth = value.every(item => {
return hasPermission(item)
})
return auth
}
return {
hasPermission,
auth,
authAll
}
}
export default useAuth
+9
View File
@@ -0,0 +1,9 @@
import useAuth from './auth'
import useMainPage from './mainPage'
import useMenu from './menu'
export {
useAuth,
useMainPage,
useMenu
}
+15
View File
@@ -0,0 +1,15 @@
import router from '@/router'
function useMainPage() {
function reload() {
router.push({
name: 'reload'
})
}
return {
reload
}
}
export default useMainPage
+24
View File
@@ -0,0 +1,24 @@
import router from '@/router'
import useSettingsStore from '@/store/modules/settings'
import useMenuStore from '@/store/modules/menu'
import { isExternalLink } from '@/utils'
export default function useMenu() {
const settingsStore = useSettingsStore()
const menuStore = useMenuStore()
function switchTo(index) {
menuStore.setActived(index)
if (settingsStore.menu.switchMainMenuAndPageJump) {
if (isExternalLink(menuStore.sidebarMenusFirstDeepestPath))
window.open(menuStore.sidebarMenusFirstDeepestPath, '_blank')
else
router.push(menuStore.sidebarMenusFirstDeepestPath)
}
}
return {
switchTo
}
}
+19
View File
@@ -0,0 +1,19 @@
import { useAuth } from '@/utils/composables'
export default function directive(app) {
// 注册 v-auth 和 v-auth-all 指令
app.directive('auth', {
mounted: (el, binding) => {
if (!useAuth().auth(binding.value)) {
el.remove()
}
}
})
app.directive('auth-all', {
mounted: (el, binding) => {
if (!useAuth().authAll(binding.value)) {
el.remove()
}
}
})
}
+3
View File
@@ -0,0 +1,3 @@
import mitt from 'mitt'
export default mitt()
+48
View File
@@ -0,0 +1,48 @@
import path from 'path-browserify'
export function deepClone(target) {
// 定义一个变量
let result
// 如果当前需要深拷贝的是一个对象的话
if (typeof target === 'object') {
// 如果是一个数组的话
if (Array.isArray(target)) {
result = [] // 将result赋值为一个数组,并且执行遍历
for (let i in target) {
// 递归克隆数组中的每一项
result.push(deepClone(target[i]))
}
// 判断如果当前的值是null的话;直接赋值为null
} else if (target === null) {
result = null
// 判断如果当前的值是一个RegExp对象的话,直接赋值
} else if (target.constructor === RegExp) {
result = target
} else {
// 否则是普通对象,直接for in循环,递归赋值对象的所有值
result = {}
for (let i in target) {
result[i] = deepClone(target[i])
}
}
// 如果不是对象的话,就是基本数据类型,那么直接赋值
} else {
result = target
}
// 返回最终结果
return result
}
export function isExternalLink(path) {
return /^(https?:|mailto:|tel:)/.test(path)
}
export function resolveRoutePath(basePath, routePath) {
if (isExternalLink(routePath)) {
return routePath
}
if (isExternalLink(basePath)) {
return basePath
}
return basePath ? path.resolve(basePath, routePath) : routePath
}