自动填成当前登陆
This commit is contained in:
@@ -1,4 +1,16 @@
|
||||
import request from '@/utils/request'
|
||||
import store from '@/store'
|
||||
import { getLoginAccount } from '@/utils/auth'
|
||||
import { getBusinessHeaders } from '@/utils/business-headers'
|
||||
|
||||
function resolveCurrentLoginAccount() {
|
||||
const fromStore = (store.getters.account || '').trim()
|
||||
if (fromStore) return fromStore
|
||||
const fromStorage = getLoginAccount()
|
||||
if (fromStorage) return fromStorage
|
||||
const fromHeader = (getBusinessHeaders()['X-Account-Name'] || '').trim()
|
||||
return fromHeader || ''
|
||||
}
|
||||
|
||||
// 分页查询客户列表
|
||||
export function getCustomerList(params) {
|
||||
@@ -54,12 +66,17 @@ export function batchDeleteCustomer(ids) {
|
||||
})
|
||||
}
|
||||
|
||||
// 添加新的客户信息
|
||||
// 添加新的客户信息(自动附带当前登录人姓名、账号,供后端 salesName / salesPhone)
|
||||
export function addCustomer(data) {
|
||||
const body = data && typeof data === 'object' ? { ...data } : {}
|
||||
const salesName = (store.getters.name || '').trim()
|
||||
const salesPhone = resolveCurrentLoginAccount()
|
||||
if (salesName) body.salesName = salesName
|
||||
if (salesPhone) body.salesPhone = salesPhone
|
||||
return request({
|
||||
url: '/customerManagement/add',
|
||||
method: 'post',
|
||||
data
|
||||
data: body
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ const getters = {
|
||||
avatar: state => state.user.avatar,
|
||||
name: state => state.user.name,
|
||||
phone: state => state.user.phone,
|
||||
account: state => state.user.account,
|
||||
permission_routes: state => state.permission.routes,
|
||||
cachedViews: state => state.tagsView.cachedViews,
|
||||
visitedViews: state => state.tagsView.visitedViews
|
||||
|
||||
@@ -1,14 +1,33 @@
|
||||
import { login, getInfo } from '@/api/user'
|
||||
import { getToken, setToken, removeToken } from '@/utils/auth'
|
||||
import { getToken, setToken, removeToken, getLoginAccount, setLoginAccount, removeLoginAccount } from '@/utils/auth'
|
||||
import { removeBusinessHeaders } from '@/utils/business-headers'
|
||||
import { resetRouter } from '@/router'
|
||||
|
||||
/** 从登录/用户信息 payload 中解析登录账号(与展示姓名区分) */
|
||||
function pickLoginAccount(payload, fallback) {
|
||||
if (!payload || typeof payload !== 'object') {
|
||||
return (fallback || '').trim()
|
||||
}
|
||||
const v =
|
||||
payload.loginAccount ||
|
||||
payload.username ||
|
||||
payload.account ||
|
||||
payload.accountName ||
|
||||
payload.userAccount ||
|
||||
payload.userName ||
|
||||
''
|
||||
return String(v || fallback || '').trim()
|
||||
}
|
||||
|
||||
/** 从登录/用户信息 payload 中解析展示名,兼容多种后端字段名 */
|
||||
function pickUserDisplayFields(payload, fallbackAccount) {
|
||||
if (!payload || typeof payload !== 'object') {
|
||||
return { userName: (fallbackAccount || '').trim(), avatar: '', phone: '' }
|
||||
}
|
||||
const userName =
|
||||
payload.realName ||
|
||||
payload.actualName ||
|
||||
payload.nickName ||
|
||||
payload.userName ||
|
||||
payload.name ||
|
||||
payload.loginAccount ||
|
||||
@@ -28,7 +47,8 @@ const getDefaultState = () => {
|
||||
token: getToken(),
|
||||
name: '',
|
||||
avatar: '',
|
||||
phone: ''
|
||||
phone: '',
|
||||
account: getLoginAccount() || ''
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +69,9 @@ const mutations = {
|
||||
},
|
||||
SET_PHONE: (state, phone) => {
|
||||
state.phone = phone
|
||||
},
|
||||
SET_ACCOUNT: (state, account) => {
|
||||
state.account = account
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +94,9 @@ const actions = {
|
||||
commit('SET_NAME', profile.userName)
|
||||
commit('SET_AVATAR', profile.avatar || '')
|
||||
commit('SET_PHONE', profile.phone || '')
|
||||
const acc = pickLoginAccount(data, username.trim())
|
||||
commit('SET_ACCOUNT', acc)
|
||||
setLoginAccount(acc)
|
||||
resolve()
|
||||
}).catch(error => {
|
||||
reject(error)
|
||||
@@ -95,6 +121,9 @@ const actions = {
|
||||
commit('SET_NAME', profile.userName)
|
||||
commit('SET_AVATAR', profile.avatar || '')
|
||||
commit('SET_PHONE', profile.phone || '')
|
||||
const acc = pickLoginAccount(row, state.account || getLoginAccount())
|
||||
commit('SET_ACCOUNT', acc)
|
||||
if (acc) setLoginAccount(acc)
|
||||
resolve(data)
|
||||
}).catch(error => {
|
||||
reject(error)
|
||||
@@ -106,6 +135,7 @@ const actions = {
|
||||
logout({ commit, state }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
removeToken() // must remove token first
|
||||
removeLoginAccount()
|
||||
removeBusinessHeaders()
|
||||
resetRouter()
|
||||
commit('RESET_STATE')
|
||||
@@ -117,6 +147,7 @@ const actions = {
|
||||
resetToken({ commit }) {
|
||||
return new Promise(resolve => {
|
||||
removeToken() // must remove token first
|
||||
removeLoginAccount()
|
||||
removeBusinessHeaders()
|
||||
commit('RESET_STATE')
|
||||
resolve()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import Cookies from 'js-cookie'
|
||||
|
||||
const TokenKey = 'vue_admin_template_token'
|
||||
const LoginAccountKey = 'vue_admin_template_login_account'
|
||||
|
||||
export function getToken() {
|
||||
return Cookies.get(TokenKey)
|
||||
@@ -13,3 +14,33 @@ export function setToken(token) {
|
||||
export function removeToken() {
|
||||
return Cookies.remove(TokenKey)
|
||||
}
|
||||
|
||||
/** 当前登录账号(与 token 同步维护,刷新页面后仍可带给业务接口) */
|
||||
export function getLoginAccount() {
|
||||
try {
|
||||
return (window.localStorage.getItem(LoginAccountKey) || '').trim()
|
||||
} catch (e) {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
export function setLoginAccount(account) {
|
||||
const v = account == null ? '' : String(account).trim()
|
||||
try {
|
||||
if (v) {
|
||||
window.localStorage.setItem(LoginAccountKey, v)
|
||||
} else {
|
||||
window.localStorage.removeItem(LoginAccountKey)
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
export function removeLoginAccount() {
|
||||
try {
|
||||
window.localStorage.removeItem(LoginAccountKey)
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user