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