feat: 删除 GA JS;菜单显示用户姓名;用户信息增加姓名和角色;Auth 增加初始指,统一登陆和超时接口

perf/export-docx feat-RBAC-0.9.1
Jimmy Liow 1 year ago
parent 9304c4735d
commit 579689f3e0

@ -14,13 +14,6 @@
100%{-webkit-transform:translate(150px)}
}
</style>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-7JN1HT1DY4"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-7JN1HT1DY4');
</script>
</head>
<body>
<div id="root">

@ -22,6 +22,7 @@
"Login": "Login",
"Username": "Username",
"Realname": "Realname",
"Password": "Password",
"ChangePassword": "Change password",

@ -22,6 +22,7 @@
"Login": "登录",
"Username": "账号",
"Realname": "姓名",
"Password": "密码",
"ChangePassword": "修改密码",

@ -1,5 +1,6 @@
import { create } from 'zustand'
import { fetchJSON, postForm } from '@/utils/request'
import { isEmpty } from '@/utils/commons'
import { HT_HOST } from "@/config"
import { usingStorage } from '@/hooks/usingStorage'
@ -147,6 +148,7 @@ const useAccountStore = create((set, get) => ({
const resultArray = await fetchAccountList(searchParams)
console.info(resultArray)
const mapAccoutList = resultArray.map((r) => {
return {
accountId: r.wu_id,
@ -160,7 +162,7 @@ const useAccountStore = create((set, get) => ({
travelAgencyId: r.travel_agency_id,
disabled: r.wu_limitsign,
// 数据库支持逗号分隔多角色(5,6,7),目前界面只需单个。
roleId: parseInt(r.roles),
roleId: isEmpty(r.roles) ? 0 : parseInt(r.roles),
role: r.roles_name,
}
})

@ -43,8 +43,18 @@ async function fetchLastRequet() {
return errcode !== 0 ? {} : result
}
const initialState = {
tokenInterval: null,
tokenTimeout: true,
loginStatus: 0,
defaltRoute: '',
permissionList: []
}
const useAuthStore = create(lifecycleware((set, get) => ({
...initialState,
onAuth: async () => {
const { startTokenInterval, loadUserPermission } = get()
const { userId, loginToken } = usingStorage()
@ -98,16 +108,11 @@ const useAuthStore = create(lifecycleware((set, get) => ({
const { clearStorage } = usingStorage()
clearStorage()
clearInterval(tokenInterval)
set(() => ({
defaultRoute: '/',
loginStatus: 0,
tokenInterval: null,
tokenTimeout: true
}))
set(initialState)
},
startTokenInterval: () => {
const { loginTimeout } = get()
const { logout } = get()
async function checkTokenTimeout() {
const { LastReqDate } = await fetchLastRequet()
@ -116,27 +121,17 @@ const useAuthStore = create(lifecycleware((set, get) => ({
const diffTime = now.getTime() - lastReqDate.getTime()
const diffHours = diffTime/1000/60/60
if (diffHours > 1) {
loginTimeout()
logout()
}
}
const interval = setInterval(() => checkTokenTimeout(), 1000*60*20)
const interval = setInterval(() => checkTokenTimeout(), 1000*60*10)
set(() => ({
tokenInterval: interval
}))
},
loginTimeout: () => {
const { tokenInterval } = get()
const { clearStorage } = usingStorage()
clearStorage()
clearInterval(tokenInterval)
set(() => ({
tokenTimeout: true
}))
},
// 迁移到 Account.js
// TODO: 迁移到 Account.js
changeUserPassword: (password, newPassword) => {
const { userId } = usingStorage()
const formData = new FormData();
@ -174,16 +169,6 @@ const useAuthStore = create(lifecycleware((set, get) => ({
})
},
tokenInterval: null,
tokenTimeout: false,
loginStatus: 0,
defaltRoute: '',
permissionList: [],
})))
export default useAuthStore

@ -48,6 +48,7 @@ function App() {
.then(u => {
setUserDetail({
username: u.LoginName,
realname: u.real_name,
travelAgencyName: u.VName,
})
})
@ -157,7 +158,6 @@ function App() {
items: [...[
{ label: <Link to='/account/change-password'>{t('ChangePassword')}</Link>, key: '0' },
{ label: <Link to='/account/profile'>{t('Profile')}</Link>, key: '1' },
{ type: 'divider' },
isPermitted(PERM_ACCOUNT_MANAGEMENT) ? { label: <Link to='/account/management'>{t('account:accountList')}</Link>, key: '3' } : null,
isPermitted(PERM_ROLE_NEW) ? { label: <Link to='/account/role-list'>{t('account:roleList')}</Link>, key: '4' } : null,
{ type: 'divider' },
@ -169,7 +169,7 @@ function App() {
>
<a onClick={e => e.preventDefault()}>
<Space>
{userDetail?.username}
{userDetail?.realname}
<DownOutlined />
</Space>
</a>

@ -81,13 +81,15 @@ function Management() {
useEffect(() => {
fetchRoleList()
.then((roleList) => {
setRoleAllList(roleList.map(r => {
const roleListMap = roleList.map(r => {
return {
value: r.role_id,
label: r.role_name,
disabled: r.role_id === 1
}
}))
})
roleListMap.unshift({ value: 0, label: '未设置', disabled: true });
setRoleAllList(roleListMap)
})
}, [])

@ -15,7 +15,8 @@ function Profile() {
.then(json => {
setUserDetail({
username: json.LoginName,
telephone: json.LkPhone,
realname: json.real_name,
rolesName: json.roles_name,
emailAddress: json.LMI_listmail,
travelAgencyName: json.VName,
})
@ -28,7 +29,7 @@ function Profile() {
<Col span={12} offset={6}>
<Descriptions title={t('userProfile')} layout="vertical" column={2}>
<Descriptions.Item label={t("Username")}>{userDetail?.username}</Descriptions.Item>
<Descriptions.Item label={t("Telephone")}>{userDetail?.telephone}</Descriptions.Item>
<Descriptions.Item label={t("Realname")}>{userDetail?.realname}({userDetail?.rolesName})</Descriptions.Item>
<Descriptions.Item label={t("Email")}>{userDetail?.emailAddress}</Descriptions.Item>
<Descriptions.Item label={t("Company")}>{userDetail?.travelAgencyName}</Descriptions.Item>
</Descriptions>

Loading…
Cancel
Save