| | |
| | | const useUserStore = defineStore(
|
| | | 'user',
|
| | | {
|
| | | state: () => ({
|
| | | token: getToken(),
|
| | | id: '',
|
| | | name: '',
|
| | | avatar: '',
|
| | | roles: [],
|
| | | permissions: []
|
| | | state: () => ({ |
| | | token: getToken(), |
| | | id: '', |
| | | name: '', |
| | | avatar: '', |
| | | roles: [], |
| | | permissions: [], |
| | | aiEnabled: 0 |
| | | }),
|
| | | actions: {
|
| | | // 登录
|
| | |
| | | this.id = user.userId
|
| | | this.name = user.userName
|
| | | this.avatar = avatar
|
| | | this.currentFactoryName = user.currentFactoryName
|
| | | this.nickName = user.nickName
|
| | | this.roleName = user.roles[0].roleName
|
| | | this.currentDeptId = user.tenantId
|
| | | this.currentLoginTime = this.getCurrentTime()
|
| | | resolve(res)
|
| | | }).catch(error => {
|
| | | reject(error)
|
| | | })
|
| | | })
|
| | | this.currentFactoryName = user.currentFactoryName |
| | | this.nickName = user.nickName |
| | | this.roleName = user.roles[0].roleName |
| | | this.currentDeptId = user.tenantId |
| | | this.currentLoginTime = this.getCurrentTime() |
| | | this.aiEnabled = Number(res.aiEnabled) === 1 ? 1 : 0 |
| | | resolve(res) |
| | | }).catch(error => { |
| | | reject(error) |
| | | }) |
| | | }) |
| | | },
|
| | | // 退出系统
|
| | | logOut() {
|
| | | return new Promise((resolve, reject) => {
|
| | | logout(this.token).then(() => {
|
| | | this.token = ''
|
| | | this.roles = []
|
| | | this.permissions = []
|
| | | removeToken()
|
| | | resolve()
|
| | | }).catch(error => {
|
| | | reject(error)
|
| | | })
|
| | | this.token = '' |
| | | this.roles = [] |
| | | this.permissions = [] |
| | | this.aiEnabled = 0 |
| | | removeToken() |
| | | resolve() |
| | | }).catch(error => { |
| | | reject(error) |
| | | }) |
| | | })
|
| | | },
|
| | | // 登录校验
|
| | |
| | | loginCheckFactory(userInfo) {
|
| | | const username = userInfo.username.trim()
|
| | | const password = userInfo.password
|
| | | const factoryId = userInfo.currentFatoryId
|
| | | return new Promise((resolve, reject) => {
|
| | | loginCheckFactory(username, password, factoryId).then(res => {
|
| | | loginCheckFactory(username, password).then(res => {
|
| | | setToken(res.token)
|
| | | this.token = res.token
|
| | | resolve()
|