feat(mp): 新增 AvatarCircle/ShortcutButton/TodoAlert 组件 + 商品详情页
- AvatarCircle: 头像圆形组件 - ShortcutButton: 快捷操作按钮 - TodoAlert: 待办提醒组件 - pkg-mall/product: 积分商品详情页
This commit is contained in:
14
apps/miniprogram/src/components/ui/AvatarCircle/index.scss
Normal file
14
apps/miniprogram/src/components/ui/AvatarCircle/index.scss
Normal file
@@ -0,0 +1,14 @@
|
||||
@import '../../../styles/variables.scss';
|
||||
|
||||
.avatar-circle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
|
||||
&__text {
|
||||
font-family: 'Georgia', 'Times New Roman', serif;
|
||||
font-weight: 700;
|
||||
line-height: 1;
|
||||
}
|
||||
}
|
||||
52
apps/miniprogram/src/components/ui/AvatarCircle/index.tsx
Normal file
52
apps/miniprogram/src/components/ui/AvatarCircle/index.tsx
Normal file
@@ -0,0 +1,52 @@
|
||||
import React, { useMemo } from 'react';
|
||||
import { View, Text } from '@tarojs/components';
|
||||
import './index.scss';
|
||||
|
||||
type AvatarColor = 'pri' | 'acc' | 'wrn' | 'dan';
|
||||
|
||||
interface AvatarCircleProps {
|
||||
name: string;
|
||||
size?: number;
|
||||
color?: AvatarColor;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const COLOR_MAP: Record<AvatarColor, { bg: string; fg: string }> = {
|
||||
pri: { bg: '#D4E5F0', fg: '#3A6B8C' },
|
||||
acc: { bg: '#E8F0E8', fg: '#5B7A5E' },
|
||||
wrn: { bg: '#FFF3E0', fg: '#C4873A' },
|
||||
dan: { bg: '#FDEAEA', fg: '#B54A4A' },
|
||||
};
|
||||
|
||||
const AvatarCircle: React.FC<AvatarCircleProps> = ({
|
||||
name,
|
||||
size = 44,
|
||||
color = 'pri',
|
||||
className = '',
|
||||
}) => {
|
||||
const initial = useMemo(() => name?.charAt(0) || '?', [name]);
|
||||
const colorStyle = COLOR_MAP[color];
|
||||
|
||||
const cls = ['avatar-circle', className].filter(Boolean).join(' ');
|
||||
|
||||
return (
|
||||
<View
|
||||
className={cls}
|
||||
style={{
|
||||
width: `${size}px`,
|
||||
height: `${size}px`,
|
||||
borderRadius: `${size / 2}px`,
|
||||
background: colorStyle.bg,
|
||||
}}
|
||||
>
|
||||
<Text
|
||||
className="avatar-circle__text"
|
||||
style={{ color: colorStyle.fg, fontSize: `${Math.round(size * 0.4)}px` }}
|
||||
>
|
||||
{initial}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default React.memo(AvatarCircle);
|
||||
79
apps/miniprogram/src/components/ui/ShortcutButton/index.scss
Normal file
79
apps/miniprogram/src/components/ui/ShortcutButton/index.scss
Normal file
@@ -0,0 +1,79 @@
|
||||
@import '../../../styles/variables.scss';
|
||||
|
||||
.shortcut-btn {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
cursor: pointer;
|
||||
|
||||
&:active {
|
||||
opacity: var(--tk-touch-feedback-opacity);
|
||||
}
|
||||
|
||||
&__icon-wrap {
|
||||
position: relative;
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
border-radius: 26px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: transform 0.15s;
|
||||
}
|
||||
|
||||
&__icon {
|
||||
font-size: 22px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
&__badge {
|
||||
position: absolute;
|
||||
top: -4px;
|
||||
right: -8px;
|
||||
min-width: 18px;
|
||||
height: 18px;
|
||||
line-height: 18px;
|
||||
text-align: center;
|
||||
background: $dan;
|
||||
color: $white;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
border-radius: $r-pill;
|
||||
padding: 0 4px;
|
||||
}
|
||||
|
||||
&__label {
|
||||
font-size: 12px;
|
||||
color: $tx2;
|
||||
}
|
||||
|
||||
// ── 色彩变体(对齐 SPEC T.priL/T.accL/T.wrnL/T.danL)──
|
||||
&--pri .shortcut-btn__icon-wrap {
|
||||
background: #D4E5F0;
|
||||
}
|
||||
&--pri .shortcut-btn__icon {
|
||||
color: #3A6B8C;
|
||||
}
|
||||
|
||||
&--acc .shortcut-btn__icon-wrap {
|
||||
background: #E8F0E8;
|
||||
}
|
||||
&--acc .shortcut-btn__icon {
|
||||
color: #5B7A5E;
|
||||
}
|
||||
|
||||
&--wrn .shortcut-btn__icon-wrap {
|
||||
background: #FFF3E0;
|
||||
}
|
||||
&--wrn .shortcut-btn__icon {
|
||||
color: #C4873A;
|
||||
}
|
||||
|
||||
&--dan .shortcut-btn__icon-wrap {
|
||||
background: #FDEAEA;
|
||||
}
|
||||
&--dan .shortcut-btn__icon {
|
||||
color: #B54A4A;
|
||||
}
|
||||
}
|
||||
39
apps/miniprogram/src/components/ui/ShortcutButton/index.tsx
Normal file
39
apps/miniprogram/src/components/ui/ShortcutButton/index.tsx
Normal file
@@ -0,0 +1,39 @@
|
||||
import React from 'react';
|
||||
import { View, Text } from '@tarojs/components';
|
||||
import './index.scss';
|
||||
|
||||
type ButtonColor = 'pri' | 'acc' | 'wrn' | 'dan';
|
||||
|
||||
interface ShortcutButtonProps {
|
||||
icon: string;
|
||||
label: string;
|
||||
color?: ButtonColor;
|
||||
onPress?: () => void;
|
||||
badge?: number;
|
||||
}
|
||||
|
||||
const ShortcutButton: React.FC<ShortcutButtonProps> = ({
|
||||
icon,
|
||||
label,
|
||||
color = 'pri',
|
||||
onPress,
|
||||
badge,
|
||||
}) => {
|
||||
const cls = ['shortcut-btn', `shortcut-btn--${color}`].join(' ');
|
||||
|
||||
return (
|
||||
<View className={cls} onClick={onPress}>
|
||||
<View className="shortcut-btn__icon-wrap">
|
||||
<Text className="shortcut-btn__icon">{icon}</Text>
|
||||
{badge != null && badge > 0 && (
|
||||
<Text className="shortcut-btn__badge">
|
||||
{badge > 99 ? '99+' : badge}
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
<Text className="shortcut-btn__label">{label}</Text>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default React.memo(ShortcutButton);
|
||||
87
apps/miniprogram/src/components/ui/TodoAlert/index.scss
Normal file
87
apps/miniprogram/src/components/ui/TodoAlert/index.scss
Normal file
@@ -0,0 +1,87 @@
|
||||
@import '../../../styles/variables.scss';
|
||||
|
||||
.todo-alert {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
border-radius: $r;
|
||||
padding: 14px 16px;
|
||||
margin-bottom: 10px;
|
||||
|
||||
&:active {
|
||||
opacity: var(--tk-touch-feedback-opacity);
|
||||
}
|
||||
|
||||
&__icon-wrap {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
&__icon {
|
||||
font-size: 18px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
&__body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
&__title {
|
||||
display: block;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: $tx;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
&__subtitle {
|
||||
display: block;
|
||||
font-size: 12px;
|
||||
color: $tx3;
|
||||
margin-top: 2px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
&__arrow {
|
||||
flex-shrink: 0;
|
||||
font-size: 20px;
|
||||
color: $tx3;
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
// ── 靛蓝变体 ──
|
||||
&--pri {
|
||||
background: #D4E5F0;
|
||||
border-left: 4px solid #3A6B8C;
|
||||
|
||||
.todo-alert__icon-wrap {
|
||||
background: rgba(58, 107, 140, 0.15);
|
||||
}
|
||||
.todo-alert__icon {
|
||||
color: #3A6B8C;
|
||||
}
|
||||
}
|
||||
|
||||
// ── 警告变体 ──
|
||||
&--wrn {
|
||||
background: #FFF3E0;
|
||||
border-left: 4px solid #C4873A;
|
||||
|
||||
.todo-alert__icon-wrap {
|
||||
background: rgba(196, 135, 58, 0.15);
|
||||
}
|
||||
.todo-alert__icon {
|
||||
color: #C4873A;
|
||||
}
|
||||
}
|
||||
}
|
||||
40
apps/miniprogram/src/components/ui/TodoAlert/index.tsx
Normal file
40
apps/miniprogram/src/components/ui/TodoAlert/index.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import React from 'react';
|
||||
import { View, Text } from '@tarojs/components';
|
||||
import './index.scss';
|
||||
|
||||
type AlertColor = 'pri' | 'wrn';
|
||||
|
||||
interface TodoAlertProps {
|
||||
icon?: string;
|
||||
title: string;
|
||||
subtitle?: string;
|
||||
color?: AlertColor;
|
||||
onPress?: () => void;
|
||||
}
|
||||
|
||||
const TodoAlert: React.FC<TodoAlertProps> = ({
|
||||
icon,
|
||||
title,
|
||||
subtitle,
|
||||
color = 'pri',
|
||||
onPress,
|
||||
}) => {
|
||||
const cls = ['todo-alert', `todo-alert--${color}`].join(' ');
|
||||
|
||||
return (
|
||||
<View className={cls} onClick={onPress}>
|
||||
{icon && (
|
||||
<View className="todo-alert__icon-wrap">
|
||||
<Text className="todo-alert__icon">{icon}</Text>
|
||||
</View>
|
||||
)}
|
||||
<View className="todo-alert__body">
|
||||
<Text className="todo-alert__title">{title}</Text>
|
||||
{subtitle && <Text className="todo-alert__subtitle">{subtitle}</Text>}
|
||||
</View>
|
||||
<Text className="todo-alert__arrow">›</Text>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default React.memo(TodoAlert);
|
||||
Reference in New Issue
Block a user