refactor: 重新设计首页布局,美化样式和图标
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Agent
2026-03-28 13:26:29 +00:00
parent 01ad62e3f6
commit 81ec7dd2cf
2 changed files with 233 additions and 460 deletions

View File

@@ -1,54 +1,49 @@
<template>
<text class="icon" :class="'icon-' + name" :style="iconStyle">{{ iconChar }}</text>
<view class="icon-box" :style="{ width: size + 'rpx', height: size + 'rpx' }">
<text :style="{ fontSize: (size * 0.6) + 'rpx', color: color }">{{ iconChar }}</text>
</view>
</template>
<script>
// Element UI 风格图标(使用更专业的 Unicode 符号)
const icons = {
home: '',
home: '🏠',
user: '👤',
chart: '📈',
product: '📦',
add: '',
search: '🔎',
order: '📝',
edit: '',
check: '',
search: '🔍',
order: '📋',
edit: '✏️',
check: '',
close: '✕',
stock: '📦',
alert: '⚠',
in: '',
out: '',
stock: '🏭',
alert: '⚠',
in: '⬇️',
out: '⬆️',
customer: '👥',
money: '💴',
logout: '↪',
right: '',
left: '',
down: '',
money: '💰',
logout: '↪',
right: '',
left: '',
down: '',
lock: '🔒',
calendar: '📅',
setting: '⚙',
setting: '⚙',
wechat: '💬',
cash: '💵',
alipay: '💙',
plus: '',
flow: ''
plus: '',
flow: '📊'
}
export default {
name: 'Icon',
props: {
name: { type: String, required: true },
size: { type: [Number, String], default: 32 },
size: { type: [Number, String], default: 48 },
color: { type: String, default: '' }
},
computed: {
iconStyle() {
const style = {}
if (this.size) style.fontSize = typeof this.size === 'number' ? `${this.size}rpx` : this.size
if (this.color) style.color = this.color
return style
},
iconChar() {
return icons[this.name] || '•'
}
@@ -57,10 +52,9 @@ export default {
</script>
<style>
.icon {
font-family: system-ui, -apple-system, sans-serif;
display: inline-block;
text-align: center;
line-height: 1;
.icon-box {
display: flex;
align-items: center;
justify-content: center;
}
</style>

View File

@@ -1,253 +1,192 @@
<template>
<view class="page">
<!-- 顶部欢迎区 -->
<!-- 顶部欢迎区 -->
<view class="header">
<view class="welcome-section">
<text class="welcome-text">欢迎回来</text>
<text class="username">{{ userInfo.username || '用户' }}</text>
<view class="user-info">
<text class="greeting">{{ greeting }}</text>
<text class="username" v-if="username">{{ username }}</text>
</view>
<view class="role-badge" :class="roleClass">
<Icon name="user" :size="24" color="#667eea" />
<text class="role-text">{{ roleText }}</text>
<view class="logout-btn" @click="logout" v-if="isLoggedIn">
<text>退出</text>
</view>
</view>
<!-- 快捷操作 - 管理员/销售 -->
<view class="stats-card" v-if="!isCustomer && !isGuest">
<view class="card-header">
<text class="card-title">今日概览</text>
</view>
<view class="stats-grid">
<view class="stat-item">
<view class="stat-icon order-icon">
<Icon name="order" :size="40" color="#667eea" />
</view>
<view class="stat-info">
<text class="stat-value">{{ stats.orderCount || 0 }}</text>
<!-- 统计概览 -->
<view class="stats-section" v-if="isAdmin || isSales">
<view class="stat-card">
<text class="stat-value">{{ stats.todayOrders }}</text>
<text class="stat-label">今日订单</text>
</view>
</view>
<view class="stat-item">
<view class="stat-icon money-icon">
<Icon name="money" :size="40" color="#fa8c16" />
</view>
<view class="stat-info">
<text class="stat-value">¥{{ stats.actualAmount || 0 }}</text>
<view class="stat-card">
<text class="stat-value">¥{{ stats.todayAmount }}</text>
<text class="stat-label">今日销售额</text>
</view>
</view>
<view class="stat-item">
<view class="stat-icon alert-icon">
<Icon name="alert" :size="40" color="#ff4d4f" />
</view>
<view class="stat-info">
<text class="stat-value">{{ stats.stockAlerts || 0 }}</text>
<text class="stat-label">库存预警</text>
</view>
</view>
<view class="stat-card">
<text class="stat-value">{{ stats.totalCustomers }}</text>
<text class="stat-label">客户数</text>
</view>
</view>
<!-- 功能菜单 -->
<view class="menu-section">
<!-- 订单相关 -->
<view class="menu-section">
<text class="section-title">订单</text>
<view class="menu-grid">
<!-- 管理员菜单 -->
<template v-if="isAdmin">
<view class="menu-card" @click="goTo('/pages/order/create')">
<Icon name="edit" :size="36" color="#667eea" />
<text class="menu-card-title">创建订单</text>
<view class="menu-item" @click="goTo('/pages/order/create')">
<view class="menu-icon" style="background: #e8f4ff;">
<text style="color: #1890ff;">📝</text>
</view>
<view class="menu-card" @click="goToTab('/pages/order/list')">
<Icon name="order" :size="36" color="#667eea" />
<text class="menu-card-title">订单列表</text>
<text class="menu-text">创建订单</text>
</view>
<view class="menu-card" @click="goTo('/pages/order/search')">
<Icon name="search" :size="36" color="#667eea" />
<text class="menu-card-title">订单查询</text>
<view class="menu-item" @click="goToTab('/pages/order/list')">
<view class="menu-icon" style="background: #f6ffed;">
<text style="color: #52c41a;">📋</text>
</view>
<view class="menu-card" @click="goTo('/pages/order/return')">
<Icon name="right" :size="36" color="#667eea" />
<text class="menu-card-title">退货</text>
<text class="menu-text">订单列表</text>
</view>
<view class="menu-item" @click="goTo('/pages/order/search')">
<view class="menu-icon" style="background: #fff7e6;">
<text style="color: #fa8c16;">🔍</text>
</view>
<text class="menu-text">订单查询</text>
</view>
<view class="menu-item" @click="goTo('/pages/order/return')">
<view class="menu-icon" style="background: #fff1f0;">
<text style="color: #ff4d4f;"></text>
</view>
<text class="menu-text">退货</text>
</view>
</template>
<!-- 销售菜单 -->
<template v-else-if="isSales">
<view class="menu-card" @click="goTo('/pages/order/create')">
<Icon name="edit" :size="36" color="#667eea" />
<text class="menu-card-title">创建订单</text>
<view class="menu-item" @click="goTo('/pages/order/create')">
<view class="menu-icon" style="background: #e8f4ff;">
<text style="color: #1890ff;">📝</text>
</view>
<view class="menu-card" @click="goToTab('/pages/order/list')">
<Icon name="order" :size="36" color="#667eea" />
<text class="menu-card-title">订单列表</text>
<text class="menu-text">创建订单</text>
</view>
<view class="menu-item" @click="goToTab('/pages/order/list')">
<view class="menu-icon" style="background: #f6ffed;">
<text style="color: #52c41a;">📋</text>
</view>
<text class="menu-text">订单列表</text>
</view>
</template>
<!-- 顾客菜单 -->
<template v-else-if="isCustomer">
<view class="menu-card" @click="goToTab('/pages/order/list')">
<Icon name="order" :size="36" color="#667eea" />
<text class="menu-card-title">我的订单</text>
<view class="menu-item" @click="goToTab('/pages/order/list')">
<view class="menu-icon" style="background: #f6ffed;">
<text style="color: #52c41a;">📋</text>
</view>
<text class="menu-text">我的订单</text>
</view>
</template>
</view>
</view>
<!-- 管理相关 -->
<text class="section-title" style="margin-top: 30rpx;">管理</text>
<view class="menu-section" v-if="isAdmin || isSales">
<text class="section-title">管理</text>
<view class="menu-grid">
<!-- 管理员菜单 -->
<template v-if="isAdmin">
<view class="menu-card" @click="goTo('/pages/product/manage')">
<Icon name="product" :size="36" color="#667eea" />
<text class="menu-card-title">商品管理</text>
<view class="menu-item" @click="goTo('/pages/product/manage')">
<view class="menu-icon" style="background: #f9f0ff;">
<text style="color: #722ed1;">📦</text>
</view>
<view class="menu-card" @click="goTo('/pages/category/index')">
<Icon name="setting" :size="36" color="#667eea" />
<text class="menu-card-title">种类管理</text>
<text class="menu-text">商品管理</text>
</view>
<view class="menu-card" @click="goStock()">
<Icon name="stock" :size="36" color="#667eea" />
<text class="menu-card-title">库存管理</text>
<view class="menu-item" @click="goTo('/pages/category/index')">
<view class="menu-icon" style="background: #fff0f6;">
<text style="color: #eb2f96;">📂</text>
</view>
<view class="menu-card" @click="goTo('/pages/stock/in')">
<Icon name="plus" :size="36" color="#667eea" />
<text class="menu-card-title">入库</text>
<text class="menu-text">种类管理</text>
</view>
<view class="menu-card" @click="goTo('/pages/stock/flow')">
<Icon name="flow" :size="36" color="#667eea" />
<text class="menu-card-title">库存流水</text>
<view class="menu-item" @click="goStock()">
<view class="menu-icon" style="background: #e6f7ff;">
<text style="color: #13c2c2;">🏭</text>
</view>
<text class="menu-text">库存管理</text>
</view>
<view class="menu-item" @click="goTo('/pages/stock/in')">
<view class="menu-icon" style="background: #fff7e6;">
<text style="color: #fa8c16;"></text>
</view>
<text class="menu-text">入库</text>
</view>
<view class="menu-item" @click="goTo('/pages/stock/flow')">
<view class="menu-icon" style="background: #f6ffed;">
<text style="color: #52c41a;">📊</text>
</view>
<text class="menu-text">库存流水</text>
</view>
</template>
<!-- 销售菜单 -->
<template v-else-if="isSales">
<view class="menu-card" @click="goTo('/pages/product/list')">
<Icon name="product" :size="36" color="#667eea" />
<text class="menu-card-title">商品浏览</text>
<view class="menu-item" @click="goTo('/pages/product/list')">
<view class="menu-icon" style="background: #f9f0ff;">
<text style="color: #722ed1;">📦</text>
</view>
<text class="menu-text">商品浏览</text>
</view>
</template>
<!-- 顾客菜单 -->
<template v-else-if="isCustomer">
<view class="menu-card" @click="goTo('/pages/product/list')">
<Icon name="product" :size="36" color="#667eea" />
<text class="menu-card-title">商品浏览</text>
</view>
</template>
<!-- 游客菜单 -->
<template v-else-if="isGuest">
</view>
<!-- 商品浏览顾客 -->
<view class="menu-section" v-if="isCustomer">
<text class="section-title">商品</text>
<view class="menu-grid">
<view class="menu-item" @click="goTo('/pages/product/list')">
<view class="menu-icon" style="background: #f9f0ff;">
<text style="color: #722ed1;">📦</text>
</view>
<text class="menu-text">商品浏览</text>
</view>
</view>
</view>
<!-- 游客登录 -->
<view class="guest-section" v-if="isGuest">
<view class="guest-card" @click="goTo('/pages/login/index')">
<Icon name="user" :size="80" color="#667eea" />
<text class="guest-icon">👤</text>
<text class="guest-text">点击登录</text>
<text class="guest-hint">登录后可使用更多功能</text>
</view>
</template>
</view>
</view>
<!-- 提示区域 -->
<view class="tips-section" v-if="isCustomer">
<view class="tip-card">
<text class="tip-title">温馨提示</text>
<view class="tip-list">
<text class="tip-item"> 您可以浏览商品</text>
<text class="tip-item"> 您可以查看半年内的订单</text>
<text class="tip-item"> 如需下单请联系销售人员</text>
</view>
</view>
</view>
<view class="tips-section" v-if="isGuest">
<view class="tip-card">
<text class="tip-title">欢迎使用</text>
<view class="tip-list">
<text class="tip-item"> 请登录后使用完整功能</text>
<text class="tip-item"> 登录后可浏览商品和查看订单</text>
</view>
</view>
</view>
<!-- 退出登录 -->
<view class="logout-section" v-if="!isGuest">
<button class="logout-btn" @click="logout">
<Icon name="logout" :size="32" color="#667eea" style="margin-right: 10rpx" />
退出登录
</button>
</view>
</view>
</template>
<script>
import authApi from '@/api/auth'
import orderApi from '@/api/order'
import productApi from '@/api/product'
import { getRole, isAdmin, isSales, isCustomer as checkIsCustomer, isGuest as checkIsGuest, canManageProduct, canCreateOrder, canViewStats } from '@/utils/auth'
import { isAdmin, isSales, isCustomer, isGuest, isLoggedIn, getUsername } from '@/utils/auth'
export default {
data() {
return {
userInfo: {},
role: 'guest',
isAdmin: false,
isSales: false,
isCustomer: false,
isGuest: false,
username: '',
greeting: '',
stats: {
orderCount: 0,
actualAmount: 0,
stockAlerts: 0
todayOrders: 0,
todayAmount: '0',
totalCustomers: 0
}
}
},
computed: {
roleText() {
if (this.isAdmin) return '管理员'
if (this.isSales) return '销售员'
if (this.isCustomer) return '顾客'
return '游客'
isAdmin() { return isAdmin() },
isSales() { return isSales() },
isCustomer() { return isCustomer() },
isGuest() { return isGuest() },
isLoggedIn() { return isLoggedIn() }
},
roleClass() {
if (this.isAdmin) return 'admin'
if (this.isCustomer) return 'customer'
return ''
}
},
onLoad() {
this.role = getRole()
this.isAdmin = isAdmin()
this.isSales = isSales()
this.isCustomer = checkIsCustomer()
this.isGuest = checkIsGuest()
this.loadUserInfo()
if (canViewStats()) {
this.loadStats()
}
onShow() {
this.username = getUsername() || ''
this.setGreeting()
},
methods: {
async loadUserInfo() {
const localRole = uni.getStorageSync('role')
if (localRole) {
this.userInfo = {
username: localRole === 'admin' ? '管理员' : '顾客',
role: localRole
}
return
}
try {
const userInfo = await authApi.getCurrentUser()
this.userInfo = userInfo
} catch (e) {
console.error(e)
}
},
async loadStats() {
try {
const today = new Date().toISOString().split('T')[0]
const stats = await orderApi.getStatistics({ startDate: today })
this.stats.orderCount = stats.orderCount || 0
this.stats.actualAmount = stats.actualAmount || 0
const alerts = await productApi.getStockAlerts()
this.stats.stockAlerts = alerts ? alerts.length : 0
} catch (e) {
console.error(e)
}
setGreeting() {
const hour = new Date().getHours()
if (hour < 6) this.greeting = '凌晨好'
else if (hour < 12) this.greeting = '上午好'
else if (hour < 14) this.greeting = '中午好'
else if (hour < 18) this.greeting = '下午好'
else this.greeting = '晚上好'
},
goTo(url) {
uni.navigateTo({ url })
@@ -258,16 +197,17 @@ export default {
goStock() {
uni.navigateTo({ url: '/pages/stock/list' })
},
async logout() {
try {
await authApi.logout()
} catch (e) {
console.error(e)
logout() {
uni.showModal({
title: '退出登录',
content: '确定要退出登录吗?',
success: (res) => {
if (res.confirm) {
uni.clearStorageSync()
uni.reLaunch({ url: '/pages/index/index' })
}
uni.removeStorageSync('token')
uni.removeStorageSync('userId')
uni.removeStorageSync('role')
uni.reLaunch({ url: '/pages/login/index' })
}
})
}
}
}
@@ -276,7 +216,7 @@ export default {
<style>
.page {
min-height: 100vh;
background: #f5f5f5;
background: #f7f8fa;
padding: 30rpx;
}
@@ -284,107 +224,52 @@ export default {
display: flex;
justify-content: space-between;
align-items: center;
padding: 40rpx 20rpx;
margin-bottom: 30rpx;
}
.welcome-section {
.user-info {
display: flex;
flex-direction: column;
}
.welcome-text {
font-size: 28rpx;
color: rgba(255, 255, 255, 0.8);
margin-bottom: 8rpx;
.greeting {
font-size: 26rpx;
color: #999;
}
.username {
font-size: 48rpx;
font-weight: bold;
color: #fff;
}
.role-badge {
display: flex;
align-items: center;
padding: 12rpx 24rpx;
border-radius: 30rpx;
background: rgba(255, 255, 255, 0.2);
backdrop-filter: blur(10px);
}
.role-badge.admin {
background: rgba(255, 215, 0, 0.3);
}
.role-badge.customer {
background: rgba(255, 255, 255, 0.2);
}
.role-text {
font-size: 24rpx;
color: #fff;
margin-left: 8rpx;
}
.stats-card {
background: #fff;
border-radius: 24rpx;
padding: 30rpx;
margin-bottom: 30rpx;
box-shadow: 0 8rpx 30rpx rgba(0, 0, 0, 0.1);
}
.card-header {
margin-bottom: 20rpx;
}
.card-title {
font-size: 30rpx;
font-size: 36rpx;
font-weight: bold;
color: #333;
margin-top: 8rpx;
}
.stats-grid {
.logout-btn {
font-size: 26rpx;
color: #666;
padding: 10rpx 20rpx;
background: #f0f0f0;
border-radius: 20rpx;
}
.stats-section {
display: flex;
justify-content: space-between;
margin-bottom: 30rpx;
}
.stat-item {
display: flex;
align-items: center;
.stat-card {
flex: 1;
}
.stat-icon {
width: 80rpx;
height: 80rpx;
border-radius: 20rpx;
display: flex;
align-items: center;
justify-content: center;
margin-right: 16rpx;
}
.order-icon {
background: #e6f7ff;
}
.money-icon {
background: #fff7e6;
}
.alert-icon {
background: #fff1f0;
}
.stat-info {
display: flex;
flex-direction: column;
background: #fff;
border-radius: 16rpx;
padding: 24rpx;
margin: 0 8rpx;
text-align: center;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
}
.stat-value {
display: block;
font-size: 36rpx;
font-weight: bold;
color: #333;
@@ -393,7 +278,7 @@ export default {
.stat-label {
font-size: 22rpx;
color: #999;
margin-top: 4rpx;
margin-top: 8rpx;
}
.menu-section {
@@ -401,183 +286,77 @@ export default {
}
.section-title {
font-size: 32rpx;
font-weight: bold;
color: #fff;
margin-bottom: 20rpx;
display: block;
}
.menu-grid {
display: flex;
flex-wrap: wrap;
}
/* 手机端 - 等间距布局 */
.menu-grid {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
padding: 10rpx;
}
.menu-card {
width: 18%;
aspect-ratio: 1;
background: #ffffff;
border-radius: 12rpx;
margin: 8rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 6rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.06);
}
.menu-card:active {
opacity: 0.9;
}
.menu-card-title {
font-size: 20rpx;
color: #333;
font-weight: bold;
margin-top: 6rpx;
}
@media (min-width: 768px) {
.menu-card {
width: 15%;
}
}
.menu-card:active {
transform: scale(0.98);
opacity: 0.9;
}
.menu-card-icon {
width: 50rpx;
height: 50rpx;
border-radius: 12rpx;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 6rpx;
}
.menu-card-icon.blue {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.menu-card-icon.green {
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
}
.menu-card-icon.orange {
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}
.menu-card-icon.red {
background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
}
.menu-card-icon.purple {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.menu-card-title {
color: #333;
font-size: 28rpx;
font-weight: bold;
color: #333;
margin-bottom: 8rpx;
margin-bottom: 20rpx;
padding-left: 10rpx;
border-left: 6rpx solid #1890ff;
}
.menu-card-desc {
.menu-grid {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
gap: 20rpx;
}
.menu-item {
width: calc(25% - 15rpx);
display: flex;
flex-direction: column;
align-items: center;
padding: 24rpx 10rpx;
background: #fff;
border-radius: 16rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
}
.menu-icon {
width: 80rpx;
height: 80rpx;
border-radius: 20rpx;
display: flex;
align-items: center;
justify-content: center;
font-size: 40rpx;
margin-bottom: 12rpx;
}
.menu-text {
font-size: 22rpx;
color: #999;
color: #333;
}
.guest-section {
margin-top: 100rpx;
}
.guest-card {
width: 100%;
background: rgba(255, 255, 255, 0.2);
backdrop-filter: blur(10px);
background: #fff;
border-radius: 24rpx;
padding: 60rpx;
display: flex;
flex-direction: column;
align-items: center;
border: 2rpx dashed rgba(255, 255, 255, 0.5);
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
}
.guest-icon {
margin-bottom: 20rpx;
font-size: 100rpx;
margin-bottom: 30rpx;
}
.guest-text {
font-size: 32rpx;
font-weight: bold;
color: #fff;
margin-bottom: 10rpx;
color: #333;
}
.guest-desc {
.guest-hint {
font-size: 24rpx;
color: rgba(255, 255, 255, 0.7);
}
.tips-section {
margin-bottom: 30rpx;
}
.tip-card {
background: rgba(255, 255, 255, 0.2);
backdrop-filter: blur(10px);
border-radius: 24rpx;
padding: 30rpx;
}
.tip-title {
font-size: 28rpx;
font-weight: bold;
color: #fff;
display: block;
margin-bottom: 16rpx;
}
.tip-list {
display: flex;
flex-direction: column;
}
.tip-item {
font-size: 24rpx;
color: rgba(255, 255, 255, 0.8);
line-height: 36rpx;
}
.logout-section {
padding: 0 20rpx;
}
.logout-btn {
width: 100%;
background: rgba(255, 255, 255, 0.2);
backdrop-filter: blur(10px);
border: 2rpx solid rgba(255, 255, 255, 0.3);
border-radius: 50rpx;
padding: 24rpx;
color: #fff;
font-size: 28rpx;
font-weight: bold;
display: flex;
align-items: center;
justify-content: center;
}
.logout-btn:active {
background: rgba(255, 255, 255, 0.3);
color: #999;
margin-top: 16rpx;
}
</style>