mirror of https://gitee.com/lmlz_0/dc-ui.git
bobol
11 months ago
6 changed files with 700 additions and 311 deletions
@ -1,53 +1,62 @@ |
|||||
import request from '@/utils/request' |
import request from "@/utils/request"; |
||||
|
|
||||
// 查询资产参数列表
|
// 查询资产参数列表
|
||||
export function listParams(query) { |
export function listParams(query) { |
||||
return request({ |
return request({ |
||||
url: '/model/dcBaseAssetParams/list', |
url: "/model/dcBaseAssetParams/list", |
||||
method: 'get', |
method: "get", |
||||
params: query |
params: query, |
||||
}) |
}); |
||||
} |
} |
||||
|
|
||||
// 查询资产参数详细
|
// 查询资产参数详细
|
||||
export function getParams(id) { |
export function getParams(id) { |
||||
return request({ |
return request({ |
||||
url: '/model/dcBaseAssetParams/' + id, |
url: "/model/dcBaseAssetParams/" + id, |
||||
method: 'get' |
method: "get", |
||||
}) |
}); |
||||
} |
} |
||||
|
|
||||
// 新增资产参数
|
// 新增资产参数
|
||||
export function addParams(data) { |
export function addParams(data) { |
||||
return request({ |
return request({ |
||||
url: '/model/dcBaseAssetParams', |
url: "/model/dcBaseAssetParams", |
||||
method: 'post', |
method: "post", |
||||
data: data |
data: data, |
||||
}) |
}); |
||||
} |
} |
||||
|
|
||||
// 修改资产参数
|
// 修改资产参数
|
||||
export function updateParams(data) { |
export function updateParams(data) { |
||||
return request({ |
return request({ |
||||
url: '/model/dcBaseAssetParams', |
url: "/model/dcBaseAssetParams", |
||||
method: 'put', |
method: "put", |
||||
data: data |
data: data, |
||||
}) |
}); |
||||
} |
} |
||||
|
|
||||
// 删除资产参数
|
// 删除资产参数
|
||||
export function delParams(id) { |
export function delParams(id) { |
||||
return request({ |
return request({ |
||||
url: '/model/dcBaseAssetParams/' + id, |
url: "/model/dcBaseAssetParams/" + id, |
||||
method: 'delete' |
method: "delete", |
||||
}) |
}); |
||||
} |
} |
||||
|
|
||||
// 导出资产参数
|
// 导出资产参数
|
||||
export function exportParams(query) { |
export function exportParams(query) { |
||||
return request({ |
return request({ |
||||
url: '/${baseUrl}/export', |
url: "/${baseUrl}/export", |
||||
method: 'get', |
method: "get", |
||||
params: query |
params: query, |
||||
}) |
}); |
||||
|
} |
||||
|
|
||||
|
// 根据设备查询设备参数列表
|
||||
|
export function listByDeviceUuids(data) { |
||||
|
return request({ |
||||
|
url: "/model/dcBaseDeviceParam/listByDeviceUuids", |
||||
|
method: "post", |
||||
|
data: data, |
||||
|
}); |
||||
} |
} |
@ -1,70 +1,78 @@ |
|||||
import { login, logout, getInfo } from '@/api/login' |
import { login, logout, getInfo } from "@/api/login"; |
||||
import { getToken, setToken, removeToken } from '@/utils/auth' |
import { getToken, setToken, removeToken } from "@/utils/auth"; |
||||
import defAva from '@/assets/images/profile.jpg' |
import defAva from "@/assets/images/profile.jpg"; |
||||
|
|
||||
const useUserStore = defineStore( |
const useUserStore = defineStore("user", { |
||||
'user', |
state: () => ({ |
||||
{ |
token: getToken(), |
||||
state: () => ({ |
name: "", |
||||
token: getToken(), |
avatar: "", |
||||
name: '', |
roles: [], |
||||
avatar: '', |
permissions: [], |
||||
roles: [], |
}), |
||||
permissions: [] |
actions: { |
||||
}), |
// 登录
|
||||
actions: { |
login(userInfo) { |
||||
// 登录
|
const username = userInfo.username.trim(); |
||||
login(userInfo) { |
const password = userInfo.password; |
||||
const username = userInfo.username.trim() |
const code = userInfo.code; |
||||
const password = userInfo.password |
const uuid = userInfo.uuid; |
||||
const code = userInfo.code |
return new Promise((resolve, reject) => { |
||||
const uuid = userInfo.uuid |
login(username, password, code, uuid) |
||||
return new Promise((resolve, reject) => { |
.then((res) => { |
||||
login(username, password, code, uuid).then(res => { |
setToken(res.token); |
||||
setToken(res.token) |
this.token = res.token; |
||||
this.token = res.token |
resolve(); |
||||
resolve() |
|
||||
}).catch(error => { |
|
||||
reject(error) |
|
||||
}) |
}) |
||||
}) |
.catch((error) => { |
||||
}, |
reject(error); |
||||
// 获取用户信息
|
}); |
||||
getInfo() { |
}); |
||||
return new Promise((resolve, reject) => { |
}, |
||||
getInfo().then(res => { |
// 获取用户信息
|
||||
const user = res.user |
getInfo() { |
||||
const avatar = (user.avatar == "" || user.avatar == null) ? defAva : import.meta.env.VITE_APP_BASE_API + user.avatar; |
return new Promise((resolve, reject) => { |
||||
|
getInfo() |
||||
|
.then((res) => { |
||||
|
const user = res.user; |
||||
|
const avatar = |
||||
|
user.avatar == "" || user.avatar == null |
||||
|
? defAva |
||||
|
: import.meta.env.VITE_APP_BASE_API + user.avatar; |
||||
|
|
||||
if (res.roles && res.roles.length > 0) { // 验证返回的roles是否是一个非空数组
|
if (res.roles && res.roles.length > 0) { |
||||
this.roles = res.roles |
// 验证返回的roles是否是一个非空数组
|
||||
this.permissions = res.permissions |
this.roles = res.roles; |
||||
|
this.permissions = res.permissions; |
||||
} else { |
} else { |
||||
this.roles = ['ROLE_DEFAULT'] |
this.roles = ["ROLE_DEFAULT"]; |
||||
} |
} |
||||
this.name = user.userName |
this.name = user.userName; |
||||
this.avatar = avatar; |
this.avatar = avatar; |
||||
resolve(res) |
resolve(res); |
||||
}).catch(error => { |
|
||||
reject(error) |
|
||||
}) |
}) |
||||
}) |
.catch((error) => { |
||||
}, |
reject(error); |
||||
// 退出系统
|
}); |
||||
logOut() { |
}); |
||||
return new Promise((resolve, reject) => { |
}, |
||||
logout(this.token).then(() => { |
// 退出系统
|
||||
this.token = '' |
logOut() { |
||||
this.roles = [] |
return new Promise((resolve, reject) => { |
||||
this.permissions = [] |
logout(this.token) |
||||
removeToken() |
.then(() => { |
||||
resolve() |
this.token = ""; |
||||
}).catch(error => { |
this.roles = []; |
||||
reject(error) |
this.permissions = []; |
||||
|
removeToken(); |
||||
|
resolve(); |
||||
}) |
}) |
||||
}) |
.catch((error) => { |
||||
} |
reject(error); |
||||
} |
}); |
||||
}) |
}); |
||||
|
}, |
||||
|
}, |
||||
|
}); |
||||
|
|
||||
export default useUserStore |
export default useUserStore; |
||||
|
Loading…
Reference in new issue