feat: 添加假登录和权限控制
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Agent
2026-03-24 00:36:40 +00:00
parent 7ca2e1d5a4
commit 17f6b49e5d
4 changed files with 141 additions and 11 deletions

View File

@@ -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(() => {