feat: 搭建后台管理框架
This commit is contained in:
1 parent
6d28bab72b
commit
40546bfd01
238 files changed
+18160
-3837
No files matched your search
+3
-1
@@ -17,6 +17,8 @@ export function useAuth() {
|
||||
currentRole.value = '超级管理员'
|
||||
authenticated.value = false
|
||||
}
|
||||
function setRole(role) { currentRole.value = role }
|
||||
function setRole(role) {
|
||||
currentRole.value = role
|
||||
}
|
||||
return { isAuthenticated, currentRole, login, logout, setRole }
|
||||
}
|
||||
+27
-8
@@ -3,23 +3,42 @@ import { defaultRolePermissions } from '../permissions/permissions'
|
||||
import { useAuth } from './auth'
|
||||
import { customMenus } from '../data/customMenus'
|
||||
|
||||
const rolePermissions = reactive(Object.fromEntries(Object.entries(defaultRolePermissions).map(([role, list]) => [role, [...list]])))
|
||||
rolePermissions['超级管理员'].push(...customMenus.map(menu => menu.permission))
|
||||
const rolePermissions = reactive(
|
||||
Object.fromEntries(
|
||||
Object.entries(defaultRolePermissions).map(([role, list]) => [role, [...list]])
|
||||
)
|
||||
)
|
||||
rolePermissions['超级管理员'].push(...customMenus.map((menu) => menu.permission))
|
||||
|
||||
export function useRbac() {
|
||||
const { currentRole } = useAuth()
|
||||
const permissions = computed(() => rolePermissions[currentRole.value] || [])
|
||||
const can = permission => permissions.value.includes(permission)
|
||||
const can = (permission) => permissions.value.includes(permission)
|
||||
function updateRolePermission(role, permission, enabled) {
|
||||
const current = rolePermissions[role] || (rolePermissions[role] = [])
|
||||
rolePermissions[role] = enabled ? [...new Set([...current, permission])] : current.filter(item => item !== permission)
|
||||
rolePermissions[role] = enabled
|
||||
? [...new Set([...current, permission])]
|
||||
: current.filter((item) => item !== permission)
|
||||
}
|
||||
function createRole(name) {
|
||||
if (!rolePermissions[name]) rolePermissions[name] = []
|
||||
}
|
||||
function createRole(name) { if (!rolePermissions[name]) rolePermissions[name] = [] }
|
||||
function createPermission(permission) {
|
||||
rolePermissions['超级管理员'] = [...new Set([...(rolePermissions['超级管理员'] || []), permission])]
|
||||
rolePermissions['超级管理员'] = [
|
||||
...new Set([...(rolePermissions['超级管理员'] || []), permission])
|
||||
]
|
||||
}
|
||||
function removePermission(permission) {
|
||||
for (const role of Object.keys(rolePermissions)) rolePermissions[role] = rolePermissions[role].filter(item => item !== permission)
|
||||
for (const role of Object.keys(rolePermissions))
|
||||
rolePermissions[role] = rolePermissions[role].filter((item) => item !== permission)
|
||||
}
|
||||
return {
|
||||
permissions,
|
||||
can,
|
||||
rolePermissions,
|
||||
updateRolePermission,
|
||||
createRole,
|
||||
createPermission,
|
||||
removePermission
|
||||
}
|
||||
return { permissions, can, rolePermissions, updateRolePermission, createRole, createPermission, removePermission }
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
import { ref } from 'vue'
|
||||
|
||||
const storageKey = 'reelshort-theme'
|
||||
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)')
|
||||
const storedTheme = localStorage.getItem(storageKey)
|
||||
const isDark = ref(storedTheme ? storedTheme === 'dark' : systemTheme.matches)
|
||||
|
||||
function applyTheme(value) {
|
||||
isDark.value = value
|
||||
document.documentElement.classList.toggle('dark', value)
|
||||
}
|
||||
|
||||
applyTheme(isDark.value)
|
||||
systemTheme.addEventListener?.('change', event => {
|
||||
if (!localStorage.getItem(storageKey)) applyTheme(event.matches)
|
||||
})
|
||||
|
||||
export function useTheme() {
|
||||
function toggleTheme() {
|
||||
const next = !isDark.value
|
||||
localStorage.setItem(storageKey, next ? 'dark' : 'light')
|
||||
applyTheme(next)
|
||||
}
|
||||
return { isDark, toggleTheme }
|
||||
}
|
||||
Reference in new issue
Block a user