refactor(customer): 优化客户数据查询和表单字段校验
- 移除新增客户页面对手机号的必填和格式校验 - 修改手机号字段标签为“手机号/微信号”,取消必填和长度限制 - 新增判断当前用户是否为超级管理员逻辑 - 抽取并统一构建客户查询参数方法,根据权限动态设置筛选条件 - 优化客户列表数据获取逻辑,支持超级管理员查看全部客户 - 调整依赖项,更新使用了新构建的查询参数函数 - 增强状态统计接口参数构建,统一调用参数生成函数 - 优化副作用 Hook 依赖,保证数据加载时机正确
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import {Headphones, Share} from '@nutui/icons-react-taro'
|
import {Headphones, Share} from '@nutui/icons-react-taro'
|
||||||
import navTo from "@/utils/common";
|
|
||||||
import Taro, { getCurrentInstance } from '@tarojs/taro';
|
import Taro, { getCurrentInstance } from '@tarojs/taro';
|
||||||
import {getUserInfo} from "@/api/layout";
|
import {getUserInfo} from "@/api/layout";
|
||||||
import {useEffect, useState} from "react";
|
import {useEffect, useState} from "react";
|
||||||
@@ -8,7 +7,6 @@ import {CmsArticle} from "@/api/cms/cmsArticle/model";
|
|||||||
|
|
||||||
function AddCartBar() {
|
function AddCartBar() {
|
||||||
const { router } = getCurrentInstance();
|
const { router } = getCurrentInstance();
|
||||||
const [id, setId] = useState<number>()
|
|
||||||
const [article, setArticle] = useState<CmsArticle>()
|
const [article, setArticle] = useState<CmsArticle>()
|
||||||
const [IsLogin, setIsLogin] = useState<boolean>(false)
|
const [IsLogin, setIsLogin] = useState<boolean>(false)
|
||||||
const onPay = () => {
|
const onPay = () => {
|
||||||
@@ -24,7 +22,7 @@ function AddCartBar() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const reload = (id) => {
|
const reload = (id: any) => {
|
||||||
getCmsArticle(id).then(data => {
|
getCmsArticle(id).then(data => {
|
||||||
setArticle(data)
|
setArticle(data)
|
||||||
})
|
})
|
||||||
@@ -40,7 +38,6 @@ function AddCartBar() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const id = router?.params.id as number | undefined;
|
const id = router?.params.id as number | undefined;
|
||||||
setId(id)
|
|
||||||
reload(id);
|
reload(id);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ export const useUser = () => {
|
|||||||
|
|
||||||
// 获取用户显示名称
|
// 获取用户显示名称
|
||||||
const getDisplayName = () => {
|
const getDisplayName = () => {
|
||||||
return user?.nickname || user?.realName || user?.username || '未登录';
|
return user?.nickname || user?.realName || user?.username || '点击登录';
|
||||||
};
|
};
|
||||||
|
|
||||||
// 角色名称:优先取用户 roles 数组的第一个角色名称
|
// 角色名称:优先取用户 roles 数组的第一个角色名称
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ const Header = (props: any) => {
|
|||||||
<div>Logo: <img src={getWebsiteLogo()} alt="logo" style={{width: '50px', height: '50px'}} /></div>
|
<div>Logo: <img src={getWebsiteLogo()} alt="logo" style={{width: '50px', height: '50px'}} /></div>
|
||||||
|
|
||||||
<h3>用户信息</h3>
|
<h3>用户信息</h3>
|
||||||
<div>登录状态: {isLoggedIn ? '已登录' : '未登录'}</div>
|
<div>登录状态: {isLoggedIn ? '已登录' : '点击登录'}</div>
|
||||||
{user && (
|
{user && (
|
||||||
<>
|
<>
|
||||||
<div>用户ID: {user.userId}</div>
|
<div>用户ID: {user.userId}</div>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
Wallet
|
Wallet
|
||||||
} from '@nutui/icons-react-taro'
|
} from '@nutui/icons-react-taro'
|
||||||
import navTo from '@/utils/common'
|
import navTo from '@/utils/common'
|
||||||
|
import { requireLogin } from '@/utils/common'
|
||||||
import './QuickActions.scss'
|
import './QuickActions.scss'
|
||||||
|
|
||||||
const QuickActions: React.FC = () => {
|
const QuickActions: React.FC = () => {
|
||||||
@@ -42,10 +43,7 @@ const QuickActions: React.FC = () => {
|
|||||||
]
|
]
|
||||||
|
|
||||||
const handleClick = (action: { path: string }) => {
|
const handleClick = (action: { path: string }) => {
|
||||||
if (!Taro.getStorageSync('access_token') || !Taro.getStorageSync('UserId')) {
|
if (!requireLogin(action.path)) return
|
||||||
Taro.navigateTo({url: '/passport/login'})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
navTo(action.path)
|
navTo(action.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -127,7 +127,7 @@
|
|||||||
width: 180px;
|
width: 180px;
|
||||||
height: 180px;
|
height: 180px;
|
||||||
border-radius: 40px;
|
border-radius: 40px;
|
||||||
background: rgba(255, 255, 255, 0.95);
|
background-color: #ffffff;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|||||||
@@ -275,7 +275,7 @@ const Login = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<View className='login-methods__tip'>
|
<View className='login-methods__tip'>
|
||||||
<Text style={{ color: 'rgba(255, 255, 255, 0.7)', fontSize: '24px' }}>点击上方按钮,快速登录</Text>
|
<Text style={{ color: 'rgba(255, 255, 255, 0.7)', fontSize: '16px' }}>点击上方按钮,快速登录</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<View className='login-methods__divider'>
|
<View className='login-methods__divider'>
|
||||||
|
|||||||
@@ -1,15 +1,41 @@
|
|||||||
import Taro from '@tarojs/taro'
|
import Taro from '@tarojs/taro'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查是否已登录
|
||||||
|
* @returns 已登录返回 true,未登录返回 false
|
||||||
|
*/
|
||||||
|
export function isLoggedIn(): boolean {
|
||||||
|
return !!(Taro.getStorageSync('access_token') && Taro.getStorageSync('UserId'))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 要求登录:未登录时弹出提示,3秒后自动跳转到登录页
|
||||||
|
* @param redirect 登录成功后跳转的目标页面(可选)
|
||||||
|
* @returns 已登录返回 true;未登录时执行跳转并返回 false
|
||||||
|
*/
|
||||||
|
export function requireLogin(redirect?: string): boolean {
|
||||||
|
if (isLoggedIn()) return true
|
||||||
|
|
||||||
|
const redirectParam = redirect
|
||||||
|
? `?redirect=${encodeURIComponent(redirect)}`
|
||||||
|
: ''
|
||||||
|
|
||||||
|
Taro.showToast({
|
||||||
|
title: '请先登录',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 2000,
|
||||||
|
})
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
Taro.navigateTo({ url: `/passport/login${redirectParam}` })
|
||||||
|
}, 1500)
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
export default function navTo(url: string, isLogin = false) {
|
export default function navTo(url: string, isLogin = false) {
|
||||||
if (isLogin && url != '/pages/user/user') {
|
if (isLogin && url != '/pages/user/user') {
|
||||||
if (!Taro.getStorageSync('access_token') || !Taro.getStorageSync('UserId')) {
|
if (!requireLogin(url)) return false
|
||||||
Taro.showToast({
|
|
||||||
title: '请先登录',
|
|
||||||
icon: 'none',
|
|
||||||
duration: 500
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Taro.navigateTo({
|
Taro.navigateTo({
|
||||||
url: url
|
url: url
|
||||||
|
|||||||
Reference in New Issue
Block a user