From 9637e5c210136511e46a91028a91ba49d0d758cd Mon Sep 17 00:00:00 2001 From: ccy <55274652@qq.com> Date: Wed, 1 Oct 2025 17:16:41 +0800 Subject: [PATCH] =?UTF-8?q?=20=E7=99=BB=E5=BD=95=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Custom/CustomPage.js | 2 +- src/index.js | 6 ++++- src/layout/Main.js | 4 ++- src/layout/Sider.js | 6 +++-- src/models/login.js | 38 ++++++++++++++--------------- src/routes/Login.js | 32 ++++++++++++++++++++++-- src/services/login.js | 2 +- src/utils/request.js | 35 ++++++++++++++++++++++++-- 8 files changed, 96 insertions(+), 29 deletions(-) diff --git a/src/components/Custom/CustomPage.js b/src/components/Custom/CustomPage.js index 73a0859..bdd6073 100644 --- a/src/components/Custom/CustomPage.js +++ b/src/components/Custom/CustomPage.js @@ -1,7 +1,7 @@ import React from 'react' import { connect } from 'dva' import { initFilter, getCustomParams } from "../../utils/common" -import loadPage from '../../utils/customConfig1'//便捷开发 请勿提交 +import loadPage from '../../utils/customConfig'//便捷开发 请勿提交 //import loadPage from '../../utils/customConfig' class CustomPage extends React.Component { diff --git a/src/index.js b/src/index.js index 0a95e21..990ef7f 100644 --- a/src/index.js +++ b/src/index.js @@ -5,7 +5,11 @@ import * as BizCharts from 'bizcharts'; import { message } from 'antd' import './index.css'; import './styles/feui/index.less' -BizCharts.track(false); +import { preloadCommonComponents } from './utils/customConfig'; + +// 应用启动时预加载常用组件 +// 预加载常用组件 - 根据环境自动选择配置策略 +// preloadCommonComponents(); // 1. Initialize const app = dva({ diff --git a/src/layout/Main.js b/src/layout/Main.js index 8c877b4..4468cce 100644 --- a/src/layout/Main.js +++ b/src/layout/Main.js @@ -26,10 +26,12 @@ const MainLayout = (props) => { let matchHome =false; const [matchPost, setMatchPost] = useState(false) /** 手机端隐藏 */ - if (window.navigator.userAgent.indexOf("Windows") < 1) + // 修复逻辑:如果用户代理中不包含"Windows",则认为是手机端 + if (window.navigator.userAgent.indexOf("Windows") === -1) { matchHome =true } + const repost=()=>{ setMatchPost(!matchPost) } diff --git a/src/layout/Sider.js b/src/layout/Sider.js index 82be6e5..90723ff 100644 --- a/src/layout/Sider.js +++ b/src/layout/Sider.js @@ -162,7 +162,8 @@ const Sider = (props) => { /** 常用菜单 */ const favorMenus = useMemo(() => { const { flatMenus } = props.login; - return flatMenus.filter((menu) => menu.IS_RESIDENT); + const filtered = flatMenus.filter((menu) => menu.IS_RESIDENT); + return filtered; }, [props.login.flatMenus]); /** 一级菜单 */ @@ -175,11 +176,12 @@ const Sider = (props) => { // 叶子菜单需要换行展示个数 const leafMenuSections = menus.length < 3 ? 1 : menus.length === 3 ? 2 : menus.length - 2; - return { + const result = { menus, width: menuWidth < 120 ? 120 : menuWidth, leafMenuSections, }; + return result; }, [props.login.loginInfo?.Menus]); /** 二三级子菜单 */ diff --git a/src/models/login.js b/src/models/login.js index e3c11dd..3a75fdc 100644 --- a/src/models/login.js +++ b/src/models/login.js @@ -264,29 +264,29 @@ export default { if (currentMineType) { storage("lacal").setItem("currentMineType", currentMineType); var filterObj = function (item) { - if (item.Node.MineType && item.Node.MineType.indexOf(currentMineType) > -1) { - if (item.Children.length !== 0) { - item.Children = item.Children.filter(function (child) { - if (child.Children.length !== 0) { - return filterObj(child); - } else { - if (child.Node.MineType) { - return child.Node.MineType.indexOf(currentMineType) > -1 - } + if (item.Node.MineType && item.Node.MineType.indexOf("_" + currentMineType + "_") > -1) { + if (item.Children.length !== 0) { + item.Children = item.Children.filter(function (child) { + if (child.Children.length !== 0) { + return filterObj(child); + } else { + if (child.Node.MineType) { + return child.Node.MineType.indexOf("_" + currentMineType + "_") > -1 } - }); - if (item.Children.length > 0) { - return true; } - } else { - if (item.Node.MineType) { - return item.Node.MineType.indexOf(currentMineType) > -1; - } - return; + }); + if (item.Children.length > 0) { + return true; } - return true; + } else { + if (item.Node.MineType) { + return item.Node.MineType.indexOf("_" + currentMineType + "_") > -1; + } + return; } - + return true; + } + }; var filter = ret.Menus.filter(function (item) { return filterObj(item); diff --git a/src/routes/Login.js b/src/routes/Login.js index 316811e..a65aa03 100644 --- a/src/routes/Login.js +++ b/src/routes/Login.js @@ -73,7 +73,7 @@ class LoginPage extends React.Component { } // if (window.navigator.userAgent.indexOf("Windows") < 1) openNotificationMobile('bottomRight'); this.removeRequestKey() - this.getOrgList() + //this.getOrgList() } 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({ type: 'login/toLogin', payload: { @@ -246,6 +263,7 @@ class LoginPage extends React.Component { userid: tokenData.userid } }).then(validRes => { + console.log('✅ dispatch login/toLogin 返回结果:', validRes); if (validRes) { storage('lacal').setItem('verifyPhoneCode', tokenData.userid) this.props.dispatch({ @@ -295,7 +313,17 @@ class LoginPage extends React.Component { this.setState({ loginError: res.error_description }) 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 if (isCheckPhoneCode && (!hasCheckPhoneCode || hasCheckPhoneCode.indexOf(userid) === -1)) { // 需要进行验证码验证 diff --git a/src/services/login.js b/src/services/login.js index 3ca9ff3..5b36ca6 100644 --- a/src/services/login.js +++ b/src/services/login.js @@ -1,7 +1,7 @@ import { httpPost } from '../utils/request' export function getOrg(params) { // 获取组织列表(service) - return httpPost('OP/TenantInfo/GetOrgList', params) + //return httpPost('OP/TenantInfo/GetOrgList', params) } export function getToken(params) { // 获取Token(service) PF diff --git a/src/utils/request.js b/src/utils/request.js index 2622f37..e87fb03 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -7,10 +7,12 @@ import { history } from './history' import storage from './storage' export function request(url, options, onlyData, requestKey, onException) { + return fetch( config.serviceHost('api/' + url), options || {} ).then(response => { + // 登陆过期 if (response.status === 401) { window.localStorage.removeItem('accessToken') @@ -20,11 +22,14 @@ export function request(url, options, onlyData, requestKey, onException) { requestKey && window.localStorage.removeItem(requestKey) return response.json() }).then(data => { + data.IsSuccessful !== undefined && !data.IsSuccessful && message.error(data.ErrorMessage) return onlyData ? data.Data : data }).catch(err => { + requestKey && window.localStorage.removeItem(requestKey) 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', Authorization: addHeader, userid: userId, - username: user ? user.username : '', + username: user && user.username ? user.username : '', departmentId: depId, MineType: mineType, RootOrgId, @@ -61,7 +66,33 @@ export function getRequestHeaders(url, type = 'post', isIgnoreTenant) { } // 非 OP 路径接口,header 需要添加 Tenant 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 }