登录功能优化

This commit is contained in:
ccy 2025-10-01 17:16:41 +08:00
parent aa6e19172b
commit 9637e5c210
8 changed files with 96 additions and 29 deletions

View File

@ -1,7 +1,7 @@
import React from 'react' import React from 'react'
import { connect } from 'dva' import { connect } from 'dva'
import { initFilter, getCustomParams } from "../../utils/common" import { initFilter, getCustomParams } from "../../utils/common"
import loadPage from '../../utils/customConfig1'//便捷开发 请勿提交 import loadPage from '../../utils/customConfig'//便捷开发 请勿提交
//import loadPage from '../../utils/customConfig' //import loadPage from '../../utils/customConfig'
class CustomPage extends React.Component { class CustomPage extends React.Component {

View File

@ -5,7 +5,11 @@ import * as BizCharts from 'bizcharts';
import { message } from 'antd' import { message } from 'antd'
import './index.css'; import './index.css';
import './styles/feui/index.less' import './styles/feui/index.less'
BizCharts.track(false); import { preloadCommonComponents } from './utils/customConfig';
// 应用启动时预加载常用组件
// 预加载常用组件 - 根据环境自动选择配置策略
// preloadCommonComponents();
// 1. Initialize // 1. Initialize
const app = dva({ const app = dva({

View File

@ -26,10 +26,12 @@ const MainLayout = (props) => {
let matchHome =false; let matchHome =false;
const [matchPost, setMatchPost] = useState(false) const [matchPost, setMatchPost] = useState(false)
/** 手机端隐藏 */ /** 手机端隐藏 */
if (window.navigator.userAgent.indexOf("Windows") < 1) // 修复逻辑:如果用户代理中不包含"Windows",则认为是手机端
if (window.navigator.userAgent.indexOf("Windows") === -1)
{ {
matchHome =true matchHome =true
} }
const repost=()=>{ const repost=()=>{
setMatchPost(!matchPost) setMatchPost(!matchPost)
} }

View File

@ -162,7 +162,8 @@ const Sider = (props) => {
/** 常用菜单 */ /** 常用菜单 */
const favorMenus = useMemo(() => { const favorMenus = useMemo(() => {
const { flatMenus } = props.login; const { flatMenus } = props.login;
return flatMenus.filter((menu) => menu.IS_RESIDENT); const filtered = flatMenus.filter((menu) => menu.IS_RESIDENT);
return filtered;
}, [props.login.flatMenus]); }, [props.login.flatMenus]);
/** 一级菜单 */ /** 一级菜单 */
@ -175,11 +176,12 @@ const Sider = (props) => {
// 叶子菜单需要换行展示个数 // 叶子菜单需要换行展示个数
const leafMenuSections = const leafMenuSections =
menus.length < 3 ? 1 : menus.length === 3 ? 2 : menus.length - 2; menus.length < 3 ? 1 : menus.length === 3 ? 2 : menus.length - 2;
return { const result = {
menus, menus,
width: menuWidth < 120 ? 120 : menuWidth, width: menuWidth < 120 ? 120 : menuWidth,
leafMenuSections, leafMenuSections,
}; };
return result;
}, [props.login.loginInfo?.Menus]); }, [props.login.loginInfo?.Menus]);
/** 二三级子菜单 */ /** 二三级子菜单 */

View File

@ -264,29 +264,29 @@ export default {
if (currentMineType) { if (currentMineType) {
storage("lacal").setItem("currentMineType", currentMineType); storage("lacal").setItem("currentMineType", currentMineType);
var filterObj = function (item) { var filterObj = function (item) {
if (item.Node.MineType && item.Node.MineType.indexOf(currentMineType) > -1) { if (item.Node.MineType && item.Node.MineType.indexOf("_" + currentMineType + "_") > -1) {
if (item.Children.length !== 0) { if (item.Children.length !== 0) {
item.Children = item.Children.filter(function (child) { item.Children = item.Children.filter(function (child) {
if (child.Children.length !== 0) { if (child.Children.length !== 0) {
return filterObj(child); return filterObj(child);
} else { } else {
if (child.Node.MineType) { if (child.Node.MineType) {
return child.Node.MineType.indexOf(currentMineType) > -1 return child.Node.MineType.indexOf("_" + currentMineType + "_") > -1
}
} }
});
if (item.Children.length > 0) {
return true;
} }
} else { });
if (item.Node.MineType) { if (item.Children.length > 0) {
return item.Node.MineType.indexOf(currentMineType) > -1; return true;
}
return;
} }
return true; } else {
if (item.Node.MineType) {
return item.Node.MineType.indexOf("_" + currentMineType + "_") > -1;
}
return;
} }
return true;
}
}; };
var filter = ret.Menus.filter(function (item) { var filter = ret.Menus.filter(function (item) {
return filterObj(item); return filterObj(item);

View File

@ -73,7 +73,7 @@ class LoginPage extends React.Component {
} }
// if (window.navigator.userAgent.indexOf("Windows") < 1) openNotificationMobile('bottomRight'); // if (window.navigator.userAgent.indexOf("Windows") < 1) openNotificationMobile('bottomRight');
this.removeRequestKey() this.removeRequestKey()
this.getOrgList() //this.getOrgList()
} }
componentWillUnmount() { componentWillUnmount() {
@ -227,6 +227,23 @@ class LoginPage extends React.Component {
// } // }
// }) // })
console.log('🚀 准备dispatch login/toLogin参数:', {
Parameter1: username,
Parameter2: MD5(password),
Parameter4: Parameter4,
Parameter5: storage('lacal').getItem('formConfigVersion').val,
Parameter6: requestCode,
Parameter7: phoneCode
});
console.log('🔑 loginPayload:', {
username: username,
password: MD5(password),
accessToken: tokenData.access_token,
refreshToken: tokenData.refreshToken,
expiresIn: tokenData.expiresIn,
userid: tokenData.userid
});
this.props.dispatch({ this.props.dispatch({
type: 'login/toLogin', type: 'login/toLogin',
payload: { payload: {
@ -246,6 +263,7 @@ class LoginPage extends React.Component {
userid: tokenData.userid userid: tokenData.userid
} }
}).then(validRes => { }).then(validRes => {
console.log('✅ dispatch login/toLogin 返回结果:', validRes);
if (validRes) { if (validRes) {
storage('lacal').setItem('verifyPhoneCode', tokenData.userid) storage('lacal').setItem('verifyPhoneCode', tokenData.userid)
this.props.dispatch({ this.props.dispatch({
@ -295,7 +313,17 @@ class LoginPage extends React.Component {
this.setState({ loginError: res.error_description }) this.setState({ loginError: res.error_description })
return return
} }
const { isCheckPhoneCode, userid } = res
// 存储Token/Gen返回的关键数据到localStorage
const { Tenant, userid, orgId, userName, isCheckPhoneCode } = res
console.log('🔄 存储Token/Gen返回数据到localStorage:', { Tenant, userid, orgId, userName })
// 存储到localStorage供后续接口使用
storage('lacal').setItem('Tenant', Tenant)
storage('lacal').setItem('Userid', userid)
storage('lacal').setItem('Orgid', orgId)
storage('lacal').setItem('Username', userName)
const { hasCheckPhoneCode } = this.state const { hasCheckPhoneCode } = this.state
if (isCheckPhoneCode && (!hasCheckPhoneCode || hasCheckPhoneCode.indexOf(userid) === -1)) { if (isCheckPhoneCode && (!hasCheckPhoneCode || hasCheckPhoneCode.indexOf(userid) === -1)) {
// 需要进行验证码验证 // 需要进行验证码验证

View File

@ -1,7 +1,7 @@
import { httpPost } from '../utils/request' import { httpPost } from '../utils/request'
export function getOrg(params) { // 获取组织列表service) export function getOrg(params) { // 获取组织列表service)
return httpPost('OP/TenantInfo/GetOrgList', params) //return httpPost('OP/TenantInfo/GetOrgList', params)
} }
export function getToken(params) { // 获取Tokenservice) PF export function getToken(params) { // 获取Tokenservice) PF

View File

@ -7,10 +7,12 @@ import { history } from './history'
import storage from './storage' import storage from './storage'
export function request(url, options, onlyData, requestKey, onException) { export function request(url, options, onlyData, requestKey, onException) {
return fetch( return fetch(
config.serviceHost('api/' + url), config.serviceHost('api/' + url),
options || {} options || {}
).then(response => { ).then(response => {
// 登陆过期 // 登陆过期
if (response.status === 401) { if (response.status === 401) {
window.localStorage.removeItem('accessToken') window.localStorage.removeItem('accessToken')
@ -20,11 +22,14 @@ export function request(url, options, onlyData, requestKey, onException) {
requestKey && window.localStorage.removeItem(requestKey) requestKey && window.localStorage.removeItem(requestKey)
return response.json() return response.json()
}).then(data => { }).then(data => {
data.IsSuccessful !== undefined && !data.IsSuccessful && message.error(data.ErrorMessage) data.IsSuccessful !== undefined && !data.IsSuccessful && message.error(data.ErrorMessage)
return onlyData ? data.Data : data return onlyData ? data.Data : data
}).catch(err => { }).catch(err => {
requestKey && window.localStorage.removeItem(requestKey) requestKey && window.localStorage.removeItem(requestKey)
onException instanceof Function && onException(err) onException instanceof Function && onException(err)
throw err; // 重新抛出错误,确保错误被正确传播
}) })
} }
@ -52,7 +57,7 @@ export function getRequestHeaders(url, type = 'post', isIgnoreTenant) {
'Content-Type': type === 'post' ? 'application/json' : 'application/x-www-form-urlencoded', 'Content-Type': type === 'post' ? 'application/json' : 'application/x-www-form-urlencoded',
Authorization: addHeader, Authorization: addHeader,
userid: userId, userid: userId,
username: user ? user.username : '', username: user && user.username ? user.username : '',
departmentId: depId, departmentId: depId,
MineType: mineType, MineType: mineType,
RootOrgId, RootOrgId,
@ -61,7 +66,33 @@ export function getRequestHeaders(url, type = 'post', isIgnoreTenant) {
} }
// 非 OP 路径接口header 需要添加 Tenant // 非 OP 路径接口header 需要添加 Tenant
const Tenant = storage('lacal').getItem('Tenant').val const Tenant = storage('lacal').getItem('Tenant').val
url.indexOf('OP') != 0 && !isIgnoreTenant && (headers.Tenant = Tenant) if (url.indexOf('PF/Login/Login') !== -1) {
// Login接口使用最新的Tenant、Orgid、userid、Username值
const latestTenant = storage('lacal').getItem('Tenant').val
const latestOrgid = storage('lacal').getItem('Orgid').val
const latestUserid = storage('lacal').getItem('Userid').val
const latestUsername = storage('lacal').getItem('Username').val
if (latestTenant) {
headers.Tenant = latestTenant
}
if (latestOrgid) {
// 覆盖原有的orgId字段使用最新值
headers.orgId = latestOrgid
}
if (latestUserid) {
// 覆盖原有的userid字段使用最新值
headers.userid = latestUserid
}
if (latestUsername) {
// 覆盖原有的username字段使用最新值
headers.username = latestUsername
}
} else if (url.indexOf('OP') != 0 && !isIgnoreTenant) {
headers.Tenant = Tenant
}
return headers return headers
} }