fix: 登录时保存username,修复订单列表无数据
This commit is contained in:
@@ -4,7 +4,8 @@ const BASE_URL = 'https://sales.violin-work.online/api/v1'
|
||||
// 请求拦截器
|
||||
const request = (url, method, data = {}) => {
|
||||
const token = uni.getStorageSync('token')
|
||||
const userInfo = uni.getStorageSync('userInfo') || {}
|
||||
const userId = uni.getStorageSync('userId') || ''
|
||||
const username = uni.getStorageSync('username') || ''
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
@@ -14,8 +15,8 @@ const request = (url, method, data = {}) => {
|
||||
header: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': token ? `Bearer ${token}` : '',
|
||||
'X-User-Id': userInfo.userId || '',
|
||||
'X-Username': userInfo.username || ''
|
||||
'X-User-Id': userId,
|
||||
'X-Username': username
|
||||
},
|
||||
success: (res) => {
|
||||
if (res.data.code === 0) {
|
||||
|
||||
@@ -101,10 +101,12 @@ export default {
|
||||
const mockData = {
|
||||
token: 'mock-token-admin',
|
||||
userId: 'admin-001',
|
||||
username: 'admin',
|
||||
role: 'admin'
|
||||
}
|
||||
uni.setStorageSync('token', mockData.token)
|
||||
uni.setStorageSync('userId', mockData.userId)
|
||||
uni.setStorageSync('username', mockData.username)
|
||||
uni.setStorageSync('role', mockData.role)
|
||||
|
||||
uni.showToast({ title: '管理员登录成功', icon: 'success' })
|
||||
@@ -119,10 +121,12 @@ export default {
|
||||
const mockData = {
|
||||
token: 'mock-token-sales',
|
||||
userId: 'sales-001',
|
||||
username: '张三',
|
||||
role: 'sales'
|
||||
}
|
||||
uni.setStorageSync('token', mockData.token)
|
||||
uni.setStorageSync('userId', mockData.userId)
|
||||
uni.setStorageSync('username', mockData.username)
|
||||
uni.setStorageSync('role', mockData.role)
|
||||
|
||||
uni.showToast({ title: '销售人员登录成功', icon: 'success' })
|
||||
@@ -137,10 +141,12 @@ export default {
|
||||
const mockData = {
|
||||
token: 'mock-token-customer',
|
||||
userId: 'customer-001',
|
||||
username: '顾客',
|
||||
role: 'customer'
|
||||
}
|
||||
uni.setStorageSync('token', mockData.token)
|
||||
uni.setStorageSync('userId', mockData.userId)
|
||||
uni.setStorageSync('username', mockData.username)
|
||||
uni.setStorageSync('role', mockData.role)
|
||||
|
||||
uni.showToast({ title: '登录成功', icon: 'success' })
|
||||
@@ -155,6 +161,7 @@ export default {
|
||||
uni.setStorageSync('token', data.token)
|
||||
uni.setStorageSync('refreshToken', data.refreshToken)
|
||||
uni.setStorageSync('userId', data.userId)
|
||||
uni.setStorageSync('username', data.username || this.username)
|
||||
uni.setStorageSync('role', data.role || 'customer')
|
||||
|
||||
uni.showToast({ title: '登录成功', icon: 'success' })
|
||||
|
||||
Reference in New Issue
Block a user