✨ update permission
This commit is contained in:
parent
e32b3853a3
commit
abc538cbc8
15
config.ts
Normal file
15
config.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
export const AppConfig: {
|
||||||
|
[key:string]: {
|
||||||
|
ldapApiUrl: string,
|
||||||
|
ldapApiKey: string
|
||||||
|
}
|
||||||
|
} = {
|
||||||
|
default:{
|
||||||
|
ldapApiUrl: 'https://test-api.hkchc.team',
|
||||||
|
ldapApiKey: 'MPCbsNa6l2RJ7D1Zo6D03qtVF1P93st3'
|
||||||
|
},
|
||||||
|
production:{
|
||||||
|
ldapApiUrl: 'https://test-api.hkchc.team',
|
||||||
|
ldapApiKey: 'MPCbsNa6l2RJ7D1Zo6D03qtVF1P93st3'
|
||||||
|
}
|
||||||
|
}
|
35
src/hooks/useRemoteUserList.ts
Normal file
35
src/hooks/useRemoteUserList.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import {useEffect, useState} from "react";
|
||||||
|
|
||||||
|
function getRemoteUserNameList() {
|
||||||
|
return new Promise<string[][]>((resolve, reject) => {
|
||||||
|
fetch(`${AppConfig.ldapApiUrl}/api/v1/hkchc/user/ldap/get_staff_list`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
Apikey: AppConfig.ldapApiKey
|
||||||
|
},
|
||||||
|
redirect: 'follow'
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(ret => {
|
||||||
|
const result = ret as APIResponse<string[][]>;
|
||||||
|
if (result.code === 0) {
|
||||||
|
resolve(result.data!)
|
||||||
|
} else {
|
||||||
|
reject(result.message)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(reject);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useRemoteUserList() {
|
||||||
|
|
||||||
|
const [usernameList, setUserList] = useState<string[]>([])
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
getRemoteUserNameList().then(data=>{
|
||||||
|
setUserList(data.flat())
|
||||||
|
})
|
||||||
|
},[])
|
||||||
|
return usernameList
|
||||||
|
}
|
@ -1,9 +1,10 @@
|
|||||||
import {Card} from "@/components/card";
|
import {Card} from "@/components/card";
|
||||||
import {useSetState} from "ahooks";
|
import {useSetState} from "ahooks";
|
||||||
import {Button, Space, TagInput, Toast} from "@douyinfe/semi-ui";
|
import {Button, Select, Space, Toast} from "@douyinfe/semi-ui";
|
||||||
import {useTranslation} from "react-i18next";
|
import {useTranslation} from "react-i18next";
|
||||||
import {useEffect} from "react";
|
import {useEffect, useMemo} from "react";
|
||||||
import {getPermissionList, savePermissionList} from "@/service/api/user.ts";
|
import {getPermissionList, savePermissionList} from "@/service/api/user.ts";
|
||||||
|
import {useRemoteUserList} from "@/hooks/useRemoteUserList.ts";
|
||||||
|
|
||||||
const DEFAULT_ROLES = [
|
const DEFAULT_ROLES = [
|
||||||
'root', 'ro', 'fo'
|
'root', 'ro', 'fo'
|
||||||
@ -11,6 +12,7 @@ const DEFAULT_ROLES = [
|
|||||||
|
|
||||||
const Permission = () => {
|
const Permission = () => {
|
||||||
const {t} = useTranslation()
|
const {t} = useTranslation()
|
||||||
|
const usernameList = useRemoteUserList();
|
||||||
const [state, setState] = useSetState<{
|
const [state, setState] = useSetState<{
|
||||||
list: PermissionUserList[];
|
list: PermissionUserList[];
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
@ -67,20 +69,28 @@ const Permission = ()=>{
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
useEffect(loadAllPermission, [])
|
useEffect(loadAllPermission, [])
|
||||||
|
const optionList = useMemo(() => (usernameList.map(name => ({label: name, value: name}))), [usernameList])
|
||||||
|
|
||||||
return (<Card style={{marginBottom: 20}}>
|
return (<Card style={{marginBottom: 20}}>
|
||||||
{state.list.map(it => (<div key={it.role_name} style={{marginBottom: 20}}>
|
{state.list.map(it => (<div key={it.role_name} style={{marginBottom: 20}}>
|
||||||
<div className="permission-title" style={{marginBottom: 5}}>{it.role_name.toUpperCase()}</div>
|
<div className="permission-title" style={{marginBottom: 5}}>{it.role_name.toUpperCase()}</div>
|
||||||
<TagInput
|
<Select
|
||||||
defaultValue={it.username_list}
|
style={{width: '100%', backgroundColor: 'var(--semi-color-fill-0)'}}
|
||||||
|
filter
|
||||||
|
multiple
|
||||||
size={'large'}
|
size={'large'}
|
||||||
addOnBlur={true} allowDuplicates={false}
|
defaultValue={it.username_list}
|
||||||
placeholder={t('base.please_enter')}
|
optionList={optionList}
|
||||||
onChange={users => onUsernameChange(it.role_name,users)}
|
defaultActiveFirstOption
|
||||||
|
allowCreate={true}
|
||||||
|
placeholder={t('base.please_select')}
|
||||||
|
onChange={(users) => onUsernameChange(it.role_name, users as string[])}
|
||||||
/>
|
/>
|
||||||
</div>))}
|
</div>))}
|
||||||
<Space>
|
<Space>
|
||||||
<Button loading={state.loading} onClick={saveRoles} theme={'solid'}>{state.loading ? 'Loading' :t('base.save')}</Button>
|
<Button
|
||||||
|
loading={state.loading} onClick={saveRoles}
|
||||||
|
theme={'solid'}>{state.loading ? 'Loading' : t('base.save')}</Button>
|
||||||
{/*<div>{state.message||''}</div>*/}
|
{/*<div>{state.message||''}</div>*/}
|
||||||
</Space>
|
</Space>
|
||||||
</Card>)
|
</Card>)
|
||||||
|
3
src/vite-env.d.ts
vendored
3
src/vite-env.d.ts
vendored
@ -18,8 +18,11 @@ declare const AppConfig: {
|
|||||||
SSO_AUTH_CLIENT_KEY: string;
|
SSO_AUTH_CLIENT_KEY: string;
|
||||||
// 登录凭证 token key
|
// 登录凭证 token key
|
||||||
AUTH_TOKEN_KEY: string;
|
AUTH_TOKEN_KEY: string;
|
||||||
|
ldapApiUrl:string;
|
||||||
|
ldapApiKey: string;
|
||||||
};
|
};
|
||||||
declare const AppMode: 'test' | 'production' | 'development';
|
declare const AppMode: 'test' | 'production' | 'development';
|
||||||
|
declare const AppMode: 'test' | 'production' | 'development';
|
||||||
|
|
||||||
declare type BasicComponentProps = {
|
declare type BasicComponentProps = {
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
"strict": true
|
"strict": true
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"vite.config.ts"
|
"config.ts",
|
||||||
|
"vite.config.ts",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
import {defineConfig} from 'vite'
|
import {defineConfig} from 'vite'
|
||||||
import react from '@vitejs/plugin-react'
|
import react from '@vitejs/plugin-react'
|
||||||
import {resolve} from "path";
|
import {resolve} from "path";
|
||||||
|
import {AppConfig} from './config'
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig(({mode}) => {
|
export default defineConfig(({mode}) => {
|
||||||
|
let configs = AppConfig['default'];
|
||||||
|
if(AppConfig[mode]){
|
||||||
|
configs = {...configs,...AppConfig[mode]}
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
base: mode == 'for-wm' ? './' : '/',
|
base: mode == 'for-wm' ? './' : '/',
|
||||||
@ -16,6 +20,7 @@ export default defineConfig(({mode}) => {
|
|||||||
SSO_AUTH_URL: process.env.SSO_AUTH_URL || 'https://portal.chuhai.edu.hk',
|
SSO_AUTH_URL: process.env.SSO_AUTH_URL || 'https://portal.chuhai.edu.hk',
|
||||||
SSO_AUTH_CLIENT_KEY: process.env.AUTH_CLIENT_KEY || 'payment',
|
SSO_AUTH_CLIENT_KEY: process.env.AUTH_CLIENT_KEY || 'payment',
|
||||||
AUTH_TOKEN_KEY: process.env.AUTH_TOKEN_KEY || 'payment-auth-token',
|
AUTH_TOKEN_KEY: process.env.AUTH_TOKEN_KEY || 'payment-auth-token',
|
||||||
|
...configs
|
||||||
}),
|
}),
|
||||||
AppMode: JSON.stringify(mode)
|
AppMode: JSON.stringify(mode)
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user