mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-06 05:16:38 +08:00
chore(repo): add lint config and normalize scripts
This commit is contained in:
@@ -0,0 +1,9 @@
|
|||||||
|
* text=auto
|
||||||
|
|
||||||
|
.gitattributes text eol=lf
|
||||||
|
*.sh text eol=lf
|
||||||
|
*.yml text eol=lf
|
||||||
|
*.yaml text eol=lf
|
||||||
|
Dockerfile text eol=lf
|
||||||
|
|
||||||
|
*.ps1 text eol=crlf
|
||||||
@@ -27,6 +27,7 @@ data/
|
|||||||
cache/
|
cache/
|
||||||
logs/
|
logs/
|
||||||
.tmp-deploy-data/
|
.tmp-deploy-data/
|
||||||
|
.tmp-deploy-cache/
|
||||||
.tmp-deploy-server.*
|
.tmp-deploy-server.*
|
||||||
.mediastation.pid
|
.mediastation.pid
|
||||||
*.log
|
*.log
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import js from '@eslint/js'
|
||||||
|
import globals from 'globals'
|
||||||
|
import reactHooks from 'eslint-plugin-react-hooks'
|
||||||
|
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||||
|
import tseslint from 'typescript-eslint'
|
||||||
|
|
||||||
|
export default tseslint.config(
|
||||||
|
{ ignores: ['dist', 'node_modules'] },
|
||||||
|
js.configs.recommended,
|
||||||
|
...tseslint.configs.recommended,
|
||||||
|
{
|
||||||
|
files: ['**/*.{ts,tsx}'],
|
||||||
|
languageOptions: {
|
||||||
|
ecmaVersion: 2022,
|
||||||
|
globals: globals.browser,
|
||||||
|
},
|
||||||
|
plugins: {
|
||||||
|
'react-hooks': reactHooks,
|
||||||
|
'react-refresh': reactRefresh,
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
...reactHooks.configs.recommended.rules,
|
||||||
|
'react-hooks/immutability': 'off',
|
||||||
|
'react-hooks/purity': 'off',
|
||||||
|
'react-hooks/set-state-in-effect': 'off',
|
||||||
|
'@typescript-eslint/no-explicit-any': 'off',
|
||||||
|
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
|
||||||
|
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
Generated
+1197
-12
File diff suppressed because it is too large
Load Diff
@@ -22,13 +22,19 @@
|
|||||||
"zustand": "^4.5.2"
|
"zustand": "^4.5.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@eslint/js": "^10.0.1",
|
||||||
"@types/react": "^18.3.3",
|
"@types/react": "^18.3.3",
|
||||||
"@types/react-dom": "^18.3.0",
|
"@types/react-dom": "^18.3.0",
|
||||||
"@vitejs/plugin-react": "^4.3.0",
|
"@vitejs/plugin-react": "^4.3.0",
|
||||||
"autoprefixer": "^10.4.19",
|
"autoprefixer": "^10.4.19",
|
||||||
|
"eslint": "^10.4.1",
|
||||||
|
"eslint-plugin-react-hooks": "^7.1.1",
|
||||||
|
"eslint-plugin-react-refresh": "^0.5.2",
|
||||||
|
"globals": "^17.6.0",
|
||||||
"postcss": "^8.4.38",
|
"postcss": "^8.4.38",
|
||||||
"tailwindcss": "^3.4.4",
|
"tailwindcss": "^3.4.4",
|
||||||
"typescript": "^5.4.5",
|
"typescript": "^5.4.5",
|
||||||
|
"typescript-eslint": "^8.60.1",
|
||||||
"vite": "^5.3.1"
|
"vite": "^5.3.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,9 +32,17 @@ export function usePermission(
|
|||||||
const tier = useAuthStore((state) => state.tier)
|
const tier = useAuthStore((state) => state.tier)
|
||||||
const role = useAuthStore((state) => state.user?.role)
|
const role = useAuthStore((state) => state.user?.role)
|
||||||
const isAuthenticated = useAuthStore((state) => state.token !== null)
|
const isAuthenticated = useAuthStore((state) => state.token !== null)
|
||||||
|
const hasSuperAccess = isSuper || tier === 'plus' || role === 'admin'
|
||||||
|
|
||||||
|
// 权限未加载时自动获取
|
||||||
|
useEffect(() => {
|
||||||
|
if (!hasSuperAccess && isAuthenticated && autoFetch && Object.keys(permissions).length === 0 && !isLoading) {
|
||||||
|
fetchPermissions()
|
||||||
|
}
|
||||||
|
}, [autoFetch, fetchPermissions, hasSuperAccess, isAuthenticated, isLoading, permissions])
|
||||||
|
|
||||||
// 超级用户有所有权限
|
// 超级用户有所有权限
|
||||||
if (isSuper || tier === 'plus' || role === 'admin') {
|
if (hasSuperAccess) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,13 +51,6 @@ export function usePermission(
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 权限未加载时自动获取
|
|
||||||
useEffect(() => {
|
|
||||||
if (autoFetch && Object.keys(permissions).length === 0 && !isLoading) {
|
|
||||||
fetchPermissions()
|
|
||||||
}
|
|
||||||
}, [autoFetch, permissions, isLoading, fetchPermissions])
|
|
||||||
|
|
||||||
return hasPermission(key)
|
return hasPermission(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user