This commit is contained in:
@@ -5,11 +5,13 @@
|
||||
<view class="avatar">
|
||||
<text class="username">{{ userInfo.username || '用户' }}</text>
|
||||
</view>
|
||||
<view class="role-tag">{{ userInfo.role || '销售员' }}</view>
|
||||
<view class="role-tag" :class="isCustomer ? 'customer' : 'admin'">
|
||||
{{ roleText }}
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 功能菜单 -->
|
||||
<view class="menu-grid">
|
||||
<!-- 功能菜单 - 管理员/销售 -->
|
||||
<view class="menu-grid" v-if="!isCustomer">
|
||||
<view class="menu-item" @click="goTo('/pages/product/list')">
|
||||
<text class="menu-icon">📦</text>
|
||||
<text class="menu-text">商品管理</text>
|
||||
@@ -28,8 +30,20 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 快捷操作 -->
|
||||
<view class="section">
|
||||
<!-- 功能菜单 - 顾客 -->
|
||||
<view class="menu-grid" v-else>
|
||||
<view class="menu-item" @click="goTo('/pages/product/list')">
|
||||
<text class="menu-icon">📦</text>
|
||||
<text class="menu-text">商品浏览</text>
|
||||
</view>
|
||||
<view class="menu-item" @click="goTo('/pages/order/list')">
|
||||
<text class="menu-icon">📋</text>
|
||||
<text class="menu-text">我的订单</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 快捷操作 - 管理员/销售 -->
|
||||
<view class="section" v-if="!isCustomer">
|
||||
<view class="section-title">今日概览</view>
|
||||
<view class="stats-grid">
|
||||
<view class="stat-item">
|
||||
@@ -47,6 +61,16 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 顾客提示 -->
|
||||
<view class="section" v-else>
|
||||
<view class="section-title">温馨提示</view>
|
||||
<view class="tips">
|
||||
<text class="tip-text">• 您可以浏览商品</text>
|
||||
<text class="tip-text">• 您可以查看半年内的订单</text>
|
||||
<text class="tip-text">• 如需下单,请联系销售人员</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 退出登录 -->
|
||||
<button class="logout-btn" @click="logout">退出登录</button>
|
||||
</view>
|
||||
@@ -56,11 +80,14 @@
|
||||
import authApi from '@/api/auth'
|
||||
import orderApi from '@/api/order'
|
||||
import productApi from '@/api/product'
|
||||
import { getRole, isCustomer as checkIsCustomer } from '@/utils/auth'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
userInfo: {},
|
||||
role: 'admin',
|
||||
isCustomer: false,
|
||||
stats: {
|
||||
orderCount: 0,
|
||||
actualAmount: 0,
|
||||
@@ -68,12 +95,31 @@ export default {
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
roleText() {
|
||||
return this.isCustomer ? '顾客' : '销售员'
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.role = getRole()
|
||||
this.isCustomer = checkIsCustomer()
|
||||
this.loadUserInfo()
|
||||
this.loadStats()
|
||||
if (!this.isCustomer) {
|
||||
this.loadStats()
|
||||
}
|
||||
},
|
||||
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
|
||||
@@ -83,13 +129,11 @@ export default {
|
||||
},
|
||||
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) {
|
||||
@@ -109,6 +153,8 @@ export default {
|
||||
console.error(e)
|
||||
}
|
||||
uni.removeStorageSync('token')
|
||||
uni.removeStorageSync('userId')
|
||||
uni.removeStorageSync('role')
|
||||
uni.reLaunch({ url: '/pages/login/index' })
|
||||
}
|
||||
}
|
||||
@@ -144,12 +190,20 @@ export default {
|
||||
.role-tag {
|
||||
margin-left: 20rpx;
|
||||
padding: 8rpx 16rpx;
|
||||
background: #e6f7ff;
|
||||
color: #1890ff;
|
||||
border-radius: 8rpx;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.role-tag.admin {
|
||||
background: #e6f7ff;
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
.role-tag.customer {
|
||||
background: #fff7e6;
|
||||
color: #fa8c16;
|
||||
}
|
||||
|
||||
.menu-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
@@ -210,6 +264,17 @@ export default {
|
||||
margin-top: 10rpx;
|
||||
}
|
||||
|
||||
.tips {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.tip-text {
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
line-height: 40rpx;
|
||||
}
|
||||
|
||||
.logout-btn {
|
||||
background: #fff;
|
||||
color: #ff4d4f;
|
||||
|
||||
@@ -95,11 +95,48 @@ export default {
|
||||
return
|
||||
}
|
||||
|
||||
// 假登录(演示用)
|
||||
if (this.username === 'admin' && this.password === 'admin') {
|
||||
const mockData = {
|
||||
token: 'mock-token-admin',
|
||||
userId: 'admin-001',
|
||||
role: 'admin'
|
||||
}
|
||||
uni.setStorageSync('token', mockData.token)
|
||||
uni.setStorageSync('userId', mockData.userId)
|
||||
uni.setStorageSync('role', mockData.role)
|
||||
|
||||
uni.showToast({ title: '登录成功', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: '/pages/index/index' })
|
||||
}, 1000)
|
||||
return
|
||||
}
|
||||
|
||||
// 顾客登录
|
||||
if (this.username === 'customer' && this.password === 'customer') {
|
||||
const mockData = {
|
||||
token: 'mock-token-customer',
|
||||
userId: 'customer-001',
|
||||
role: 'customer'
|
||||
}
|
||||
uni.setStorageSync('token', mockData.token)
|
||||
uni.setStorageSync('userId', mockData.userId)
|
||||
uni.setStorageSync('role', mockData.role)
|
||||
|
||||
uni.showToast({ title: '登录成功', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: '/pages/index/index' })
|
||||
}, 1000)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await authApi.passwordLogin(this.username, this.password)
|
||||
uni.setStorageSync('token', data.token)
|
||||
uni.setStorageSync('refreshToken', data.refreshToken)
|
||||
uni.setStorageSync('userId', data.userId)
|
||||
uni.setStorageSync('role', data.role || 'customer')
|
||||
|
||||
uni.showToast({ title: '登录成功', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
|
||||
Reference in New Issue
Block a user