forked from gxwebsoft/mp-10550
feat(admin): 实现管理员模式切换和扫码登录功能
- 新增管理员模式切换方案,统一管理所有管理员功能 - 实现扫码登录功能,支持用户通过小程序扫描网页端二维码快速登录 - 添加管理员面板组件,集中展示所有管理员功能 - 开发扫码登录按钮和扫描器组件,方便集成到不同页面 - 优化用户界面设计,提高管理员用户的使用体验
This commit is contained in:
89
src/components/AdminPanel.scss
Normal file
89
src/components/AdminPanel.scss
Normal file
@@ -0,0 +1,89 @@
|
||||
.admin-panel {
|
||||
/* 面板动画 */
|
||||
.admin-panel-content {
|
||||
animation: slideUp 0.3s ease-out;
|
||||
}
|
||||
|
||||
/* 网格布局优化 */
|
||||
.admin-feature-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 12px;
|
||||
|
||||
@media (max-width: 375px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
/* 功能卡片样式 */
|
||||
.admin-feature-card {
|
||||
transition: all 0.2s ease;
|
||||
cursor: pointer;
|
||||
|
||||
&:active {
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
&:hover {
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
/* 图标容器 */
|
||||
.admin-feature-icon {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 8px;
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
/* 模式切换按钮动画 */
|
||||
.mode-toggle-btn {
|
||||
transition: all 0.3s ease;
|
||||
cursor: pointer;
|
||||
|
||||
&:active {
|
||||
transform: scale(0.95);
|
||||
}
|
||||
}
|
||||
|
||||
/* 管理面板按钮 */
|
||||
.admin-panel-btn {
|
||||
transition: all 0.2s ease;
|
||||
cursor: pointer;
|
||||
|
||||
&:active {
|
||||
transform: scale(0.95);
|
||||
background-color: rgba(59, 130, 246, 0.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 滑入动画 */
|
||||
@keyframes slideUp {
|
||||
from {
|
||||
transform: translateY(100%);
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
transform: translateY(0);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* 遮罩层动画 */
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.admin-panel-overlay {
|
||||
animation: fadeIn 0.3s ease-out;
|
||||
}
|
||||
151
src/components/AdminPanel.tsx
Normal file
151
src/components/AdminPanel.tsx
Normal file
@@ -0,0 +1,151 @@
|
||||
import React from 'react';
|
||||
import { View, Text } from '@tarojs/components';
|
||||
import { Button } from '@nutui/nutui-react-taro';
|
||||
import { Scan, Setting, User, Shop } from '@nutui/icons-react-taro';
|
||||
import navTo from '@/utils/common';
|
||||
import './AdminPanel.scss';
|
||||
|
||||
export interface AdminPanelProps {
|
||||
/** 是否显示面板 */
|
||||
visible: boolean;
|
||||
/** 关闭面板回调 */
|
||||
onClose?: () => void;
|
||||
/** 自定义样式类名 */
|
||||
className?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员功能面板组件
|
||||
*/
|
||||
const AdminPanel: React.FC<AdminPanelProps> = ({
|
||||
visible,
|
||||
onClose,
|
||||
className = ''
|
||||
}) => {
|
||||
if (!visible) return null;
|
||||
|
||||
// 管理员功能列表
|
||||
const adminFeatures = [
|
||||
{
|
||||
id: 'store-verification',
|
||||
title: '门店核销',
|
||||
description: '扫码核销用户优惠券',
|
||||
icon: <Scan className="text-blue-500" size="24" />,
|
||||
color: 'bg-blue-50 border-blue-200',
|
||||
onClick: () => {
|
||||
navTo('/user/store/verification', true);
|
||||
onClose?.();
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'qr-login',
|
||||
title: '扫码登录',
|
||||
description: '扫码快速登录网页端',
|
||||
icon: <Scan className="text-green-500" size="24" />,
|
||||
color: 'bg-green-50 border-green-200',
|
||||
onClick: () => {
|
||||
navTo('/pages/qr-login/index', true);
|
||||
onClose?.();
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'user-management',
|
||||
title: '用户管理',
|
||||
description: '管理系统用户信息',
|
||||
icon: <User className="text-purple-500" size="24" />,
|
||||
color: 'bg-purple-50 border-purple-200',
|
||||
onClick: () => {
|
||||
// TODO: 跳转到用户管理页面
|
||||
console.log('跳转到用户管理');
|
||||
onClose?.();
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'store-management',
|
||||
title: '门店管理',
|
||||
description: '管理门店信息和设置',
|
||||
icon: <Shop className="text-orange-500" size="24" />,
|
||||
color: 'bg-orange-50 border-orange-200',
|
||||
onClick: () => {
|
||||
// TODO: 跳转到门店管理页面
|
||||
console.log('跳转到门店管理');
|
||||
onClose?.();
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'system-settings',
|
||||
title: '系统设置',
|
||||
description: '系统配置和参数管理',
|
||||
icon: <Setting className="text-gray-500" size="24" />,
|
||||
color: 'bg-gray-50 border-gray-200',
|
||||
onClick: () => {
|
||||
// TODO: 跳转到系统设置页面
|
||||
console.log('跳转到系统设置');
|
||||
onClose?.();
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
return (
|
||||
<View className={`admin-panel ${className}`}>
|
||||
{/* 遮罩层 */}
|
||||
<View
|
||||
className="fixed inset-0 bg-black bg-opacity-50 z-40"
|
||||
onClick={onClose}
|
||||
/>
|
||||
|
||||
{/* 面板内容 */}
|
||||
<View className="fixed bottom-0 left-0 right-0 bg-white rounded-t-3xl z-50 max-h-[70vh] overflow-hidden">
|
||||
{/* 面板头部 */}
|
||||
<View className="flex items-center justify-between p-4 border-b border-gray-100">
|
||||
<View className="flex items-center">
|
||||
<Setting className="text-blue-500 mr-2" size="20" />
|
||||
<Text className="text-lg font-bold text-gray-800">管理员面板</Text>
|
||||
</View>
|
||||
<Button
|
||||
size="small"
|
||||
type="default"
|
||||
onClick={onClose}
|
||||
className="text-gray-500"
|
||||
>
|
||||
关闭
|
||||
</Button>
|
||||
</View>
|
||||
|
||||
{/* 功能网格 */}
|
||||
<View className="p-4 pb-8">
|
||||
<View className="grid grid-cols-2 gap-3">
|
||||
{adminFeatures.map((feature) => (
|
||||
<View
|
||||
key={feature.id}
|
||||
className={`${feature.color} border rounded-xl p-4 active:scale-95 transition-transform`}
|
||||
onClick={feature.onClick}
|
||||
>
|
||||
<View className="flex items-center mb-2">
|
||||
{feature.icon}
|
||||
<Text className="ml-2 font-medium text-gray-800">
|
||||
{feature.title}
|
||||
</Text>
|
||||
</View>
|
||||
<Text className="text-xs text-gray-600 leading-relaxed">
|
||||
{feature.description}
|
||||
</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{/* 底部提示 */}
|
||||
<View className="px-4 pb-4">
|
||||
<View className="bg-yellow-50 border border-yellow-200 rounded-lg p-3">
|
||||
<Text className="text-xs text-yellow-700 text-center">
|
||||
💡 管理员功能仅对具有管理权限的用户开放
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default AdminPanel;
|
||||
@@ -9,25 +9,25 @@
|
||||
border: 2px solid #f0f0f0;
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
|
||||
// 更精美的阴影效果
|
||||
//box-shadow:
|
||||
// 0 4px 20px rgba(0, 0, 0, 0.08),
|
||||
// 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
/* 更精美的阴影效果 */
|
||||
/*box-shadow:
|
||||
0 4px 20px rgba(0, 0, 0, 0.08),
|
||||
0 1px 3px rgba(0, 0, 0, 0.1);*/
|
||||
|
||||
// 边框光晕效果
|
||||
//&::before {
|
||||
// content: '';
|
||||
// position: absolute;
|
||||
// top: 0;
|
||||
// left: 0;
|
||||
// right: 0;
|
||||
// bottom: 0;
|
||||
// border-radius: 16px;
|
||||
// padding: 1px;
|
||||
// background: linear-gradient(135deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.1));
|
||||
// mask-composite: exclude;
|
||||
// pointer-events: none;
|
||||
//}
|
||||
/* 边框光晕效果 */
|
||||
/*&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
border-radius: 16px;
|
||||
padding: 1px;
|
||||
background: linear-gradient(135deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.1));
|
||||
mask-composite: exclude;
|
||||
pointer-events: none;
|
||||
}*/
|
||||
|
||||
&:active {
|
||||
transform: scale(0.98) translateY(1px);
|
||||
@@ -52,7 +52,7 @@
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
|
||||
// 添加光泽效果
|
||||
/* 添加光泽效果 */
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
@@ -199,7 +199,7 @@
|
||||
line-height: 1.3;
|
||||
letter-spacing: -0.5px;
|
||||
|
||||
// 添加文字渐变效果
|
||||
/* 添加文字渐变效果 */
|
||||
background: linear-gradient(135deg, #1a202c 0%, #2d3748 100%);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
@@ -212,7 +212,7 @@
|
||||
line-height: 1.2;
|
||||
font-weight: 500;
|
||||
|
||||
// 添加图标前缀
|
||||
/* 添加图标前缀 */
|
||||
&::before {
|
||||
content: '⏰';
|
||||
margin-right: 6px;
|
||||
@@ -239,7 +239,7 @@
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
|
||||
// 添加按钮光泽效果
|
||||
/* 添加按钮光泽效果 */
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
@@ -324,7 +324,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 动画效果
|
||||
/* 动画效果 */
|
||||
@keyframes shimmer {
|
||||
0% {
|
||||
transform: translateX(-100%) translateY(-100%) rotate(45deg);
|
||||
@@ -334,7 +334,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 响应式优化
|
||||
/* 响应式优化 */
|
||||
@media (max-width: 768px) {
|
||||
.coupon-card {
|
||||
height: 150px;
|
||||
|
||||
87
src/components/QRLoginButton.tsx
Normal file
87
src/components/QRLoginButton.tsx
Normal file
@@ -0,0 +1,87 @@
|
||||
import React from 'react';
|
||||
import { View, Text } from '@tarojs/components';
|
||||
import { Button } from '@nutui/nutui-react-taro';
|
||||
import { Scan } from '@nutui/icons-react-taro';
|
||||
import Taro from '@tarojs/taro';
|
||||
import { useQRLogin } from '@/hooks/useQRLogin';
|
||||
|
||||
export interface QRLoginButtonProps {
|
||||
/** 按钮类型 */
|
||||
type?: 'primary' | 'success' | 'warning' | 'danger' | 'default';
|
||||
/** 按钮大小 */
|
||||
size?: 'large' | 'normal' | 'small';
|
||||
/** 按钮文本 */
|
||||
text?: string;
|
||||
/** 是否显示图标 */
|
||||
showIcon?: boolean;
|
||||
/** 自定义样式类名 */
|
||||
className?: string;
|
||||
/** 点击成功回调 */
|
||||
onSuccess?: (result: any) => void;
|
||||
/** 点击失败回调 */
|
||||
onError?: (error: string) => void;
|
||||
/** 是否使用页面模式(跳转到专门页面) */
|
||||
usePageMode?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫码登录按钮组件
|
||||
*/
|
||||
const QRLoginButton: React.FC<QRLoginButtonProps> = ({
|
||||
type = 'primary',
|
||||
size = 'normal',
|
||||
text = '扫码登录',
|
||||
showIcon = true,
|
||||
className = '',
|
||||
onSuccess,
|
||||
onError,
|
||||
usePageMode = false
|
||||
}) => {
|
||||
const { startScan, isLoading, canScan } = useQRLogin();
|
||||
|
||||
// 处理点击事件
|
||||
const handleClick = async () => {
|
||||
if (usePageMode) {
|
||||
// 跳转到专门的扫码登录页面
|
||||
if (canScan()) {
|
||||
Taro.navigateTo({
|
||||
url: '/pages/qr-login/index'
|
||||
});
|
||||
} else {
|
||||
Taro.showToast({
|
||||
title: '请先登录小程序',
|
||||
icon: 'error'
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 直接执行扫码登录
|
||||
try {
|
||||
await startScan();
|
||||
// 成功回调会在Hook内部处理
|
||||
} catch (error: any) {
|
||||
onError?.(error.message || '扫码登录失败');
|
||||
}
|
||||
};
|
||||
|
||||
const disabled = !canScan() || isLoading;
|
||||
|
||||
return (
|
||||
<Button
|
||||
type={type}
|
||||
size={size}
|
||||
loading={isLoading}
|
||||
disabled={disabled}
|
||||
onClick={handleClick}
|
||||
className={className}
|
||||
>
|
||||
{showIcon && !isLoading && (
|
||||
<Scan className="mr-1" />
|
||||
)}
|
||||
{isLoading ? '扫码中...' : (disabled && !canScan() ? '请先登录' : text)}
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
|
||||
export default QRLoginButton;
|
||||
182
src/components/QRLoginScanner.tsx
Normal file
182
src/components/QRLoginScanner.tsx
Normal file
@@ -0,0 +1,182 @@
|
||||
import React from 'react';
|
||||
import { View, Text } from '@tarojs/components';
|
||||
import { Button, Loading } from '@nutui/nutui-react-taro';
|
||||
import { Scan, Success, Failure } from '@nutui/icons-react-taro';
|
||||
import { useQRLogin, ScanLoginState } from '@/hooks/useQRLogin';
|
||||
|
||||
export interface QRLoginScannerProps {
|
||||
/** 扫码成功回调 */
|
||||
onSuccess?: (result: any) => void;
|
||||
/** 扫码失败回调 */
|
||||
onError?: (error: string) => void;
|
||||
/** 自定义样式类名 */
|
||||
className?: string;
|
||||
/** 按钮文本 */
|
||||
buttonText?: string;
|
||||
/** 是否显示状态信息 */
|
||||
showStatus?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫码登录组件
|
||||
*/
|
||||
const QRLoginScanner: React.FC<QRLoginScannerProps> = ({
|
||||
onSuccess,
|
||||
onError,
|
||||
className = '',
|
||||
buttonText = '扫码登录',
|
||||
showStatus = true
|
||||
}) => {
|
||||
const {
|
||||
state,
|
||||
error,
|
||||
result,
|
||||
isLoading,
|
||||
startScan,
|
||||
cancel,
|
||||
reset,
|
||||
canScan
|
||||
} = useQRLogin();
|
||||
|
||||
// 处理扫码成功
|
||||
React.useEffect(() => {
|
||||
if (state === ScanLoginState.SUCCESS && result) {
|
||||
onSuccess?.(result);
|
||||
}
|
||||
}, [state, result, onSuccess]);
|
||||
|
||||
// 处理扫码失败
|
||||
React.useEffect(() => {
|
||||
if (state === ScanLoginState.ERROR && error) {
|
||||
onError?.(error);
|
||||
}
|
||||
}, [state, error, onError]);
|
||||
|
||||
// 获取状态显示内容
|
||||
const getStatusContent = () => {
|
||||
switch (state) {
|
||||
case ScanLoginState.SCANNING:
|
||||
return (
|
||||
<View className="flex items-center justify-center text-blue-500">
|
||||
<Loading className="mr-2" />
|
||||
<Text>请扫描登录二维码...</Text>
|
||||
</View>
|
||||
);
|
||||
|
||||
case ScanLoginState.CONFIRMING:
|
||||
return (
|
||||
<View className="flex items-center justify-center text-orange-500">
|
||||
<Loading className="mr-2" />
|
||||
<Text>正在确认登录...</Text>
|
||||
</View>
|
||||
);
|
||||
|
||||
case ScanLoginState.SUCCESS:
|
||||
return (
|
||||
<View className="flex items-center justify-center text-green-500">
|
||||
<Success className="mr-2" />
|
||||
<Text>登录确认成功!</Text>
|
||||
</View>
|
||||
);
|
||||
|
||||
case ScanLoginState.ERROR:
|
||||
return (
|
||||
<View className="flex items-center justify-center text-red-500">
|
||||
<Failure className="mr-2" />
|
||||
<Text>{error || '扫码登录失败'}</Text>
|
||||
</View>
|
||||
);
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
// 获取按钮状态
|
||||
const getButtonProps = () => {
|
||||
const disabled = !canScan() || isLoading;
|
||||
|
||||
switch (state) {
|
||||
case ScanLoginState.SCANNING:
|
||||
case ScanLoginState.CONFIRMING:
|
||||
return {
|
||||
loading: true,
|
||||
disabled: true,
|
||||
text: state === ScanLoginState.SCANNING ? '扫码中...' : '确认中...',
|
||||
onClick: cancel
|
||||
};
|
||||
|
||||
case ScanLoginState.SUCCESS:
|
||||
return {
|
||||
loading: false,
|
||||
disabled: false,
|
||||
text: '重新扫码',
|
||||
onClick: reset
|
||||
};
|
||||
|
||||
case ScanLoginState.ERROR:
|
||||
return {
|
||||
loading: false,
|
||||
disabled: false,
|
||||
text: '重试',
|
||||
onClick: startScan
|
||||
};
|
||||
|
||||
default:
|
||||
return {
|
||||
loading: false,
|
||||
disabled,
|
||||
text: disabled ? '请先登录' : buttonText,
|
||||
onClick: startScan
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const buttonProps = getButtonProps();
|
||||
|
||||
return (
|
||||
<View className={`qr-login-scanner ${className}`}>
|
||||
{/* 扫码按钮 */}
|
||||
<Button
|
||||
type="primary"
|
||||
size="large"
|
||||
loading={buttonProps.loading}
|
||||
disabled={buttonProps.disabled}
|
||||
onClick={buttonProps.onClick}
|
||||
className="w-full"
|
||||
>
|
||||
{!buttonProps.loading && (
|
||||
<Scan className="mr-2" />
|
||||
)}
|
||||
{buttonProps.text}
|
||||
</Button>
|
||||
|
||||
{/* 状态显示 */}
|
||||
{showStatus && (
|
||||
<View className="mt-4 text-center">
|
||||
{getStatusContent()}
|
||||
</View>
|
||||
)}
|
||||
|
||||
{/* 成功结果显示 */}
|
||||
{state === ScanLoginState.SUCCESS && result && (
|
||||
<View className="mt-4 p-4 bg-green-50 rounded-lg">
|
||||
<Text className="text-sm text-green-700">
|
||||
已为用户 {result.userInfo?.nickname || result.userInfo?.userId} 确认登录
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
|
||||
{/* 使用说明 */}
|
||||
{state === ScanLoginState.IDLE && (
|
||||
<View className="mt-4 text-center">
|
||||
<Text className="text-xs text-gray-500">
|
||||
扫描网页端显示的登录二维码即可快速登录
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default QRLoginScanner;
|
||||
Reference in New Issue
Block a user