mirror of
https://github.com/fantastic-admin/basic.git
synced 2026-10-07 14:57:52 +08:00
调整目录结构
This commit is contained in:
+14010
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
@@ -0,0 +1,9 @@
|
||||
import useAuth from './auth'
|
||||
import useMainPage from './mainPage'
|
||||
import useMenu from './menu'
|
||||
|
||||
export {
|
||||
useAuth,
|
||||
useMainPage,
|
||||
useMenu
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import router from '@/router'
|
||||
|
||||
function useMainPage() {
|
||||
function reload() {
|
||||
router.push({
|
||||
name: 'reload'
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
reload
|
||||
}
|
||||
}
|
||||
|
||||
export default useMainPage
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import mitt from 'mitt'
|
||||
|
||||
export default mitt()
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user