2022-11-17 17:30:20 +08:00
|
|
|
import { login, logout, getInfo } from "@/api/login";
|
|
|
|
import { getToken, setToken, removeToken } from "@/utils/auth";
|
|
|
|
import defAva from "@/assets/images/profile.jpg";
|
|
|
|
import md5 from "js-md5";
|
|
|
|
import { companyList } from "@/api/dataList/enterprise";
|
|
|
|
import { expertList } from "@/api/expert/expert";
|
2022-11-21 16:40:21 +08:00
|
|
|
import { listCasDemand } from "../../api/dataApproval/enterpriseServiceDemand";
|
2022-12-05 15:58:30 +08:00
|
|
|
import { expertAchievementList } from "../../api/dataApproval/achivement";
|
|
|
|
import { businessList } from "../../api/Businessneeds";
|
|
|
|
import { enterpriseProductApprovalList } from "../../api/dataApproval/enterpriseProduct";
|
2021-11-30 09:55:37 +08:00
|
|
|
|
2022-11-17 17:30:20 +08:00
|
|
|
const useUserStore = defineStore("user", {
|
|
|
|
state: () => ({
|
|
|
|
token: getToken(),
|
|
|
|
name: "",
|
|
|
|
avatar: "",
|
|
|
|
roles: [],
|
|
|
|
permissions: [],
|
2022-12-05 15:58:30 +08:00
|
|
|
unApprovedBusiness: 0,
|
|
|
|
unApprovedExpert: 0,
|
|
|
|
unApprovedAchivement: 0,
|
|
|
|
unApprovedTechnology: 0,
|
|
|
|
unApprovedService: 0,
|
|
|
|
unApprovedProduct: 0,
|
2022-11-21 16:40:21 +08:00
|
|
|
serviceDemandTotal: 0,
|
2022-11-17 17:30:20 +08:00
|
|
|
}),
|
|
|
|
actions: {
|
|
|
|
// 登录
|
|
|
|
login(userInfo) {
|
|
|
|
const username = userInfo.username.trim();
|
|
|
|
const password = md5(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();
|
2022-05-29 21:40:32 +08:00
|
|
|
})
|
2022-11-17 17:30:20 +08:00
|
|
|
.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;
|
2021-11-30 09:55:37 +08:00
|
|
|
|
2022-11-17 17:30:20 +08:00
|
|
|
if (res.roles && res.roles.length > 0) {
|
|
|
|
// 验证返回的roles是否是一个非空数组
|
|
|
|
this.roles = res.roles;
|
|
|
|
this.permissions = res.permissions;
|
2022-05-29 21:40:32 +08:00
|
|
|
} else {
|
2022-11-17 17:30:20 +08:00
|
|
|
this.roles = ["ROLE_DEFAULT"];
|
2022-05-29 21:40:32 +08:00
|
|
|
}
|
2022-11-17 17:30:20 +08:00
|
|
|
this.name = user.userName;
|
2022-05-29 21:40:32 +08:00
|
|
|
this.avatar = avatar;
|
2022-11-17 17:30:20 +08:00
|
|
|
resolve(res);
|
|
|
|
// return res;
|
2022-05-29 21:40:32 +08:00
|
|
|
})
|
2022-11-17 17:30:20 +08:00
|
|
|
.catch((error) => {
|
|
|
|
reject(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
async getApprovalCount() {
|
2022-12-05 15:58:30 +08:00
|
|
|
this.getUnApprovedBusiness();
|
|
|
|
this.getUnApprovedExpert();
|
|
|
|
this.getUnApprovedAchivement();
|
|
|
|
this.getUnApprovedTechnology();
|
|
|
|
this.getUnApprovedService();
|
|
|
|
this.getUnApprovedProduct();
|
|
|
|
this.getServiceDemandTotal();
|
2022-11-17 17:30:20 +08:00
|
|
|
},
|
2022-12-05 15:58:30 +08:00
|
|
|
|
|
|
|
async getUnApprovedBusiness() {
|
|
|
|
const resp = await companyList({
|
|
|
|
examineStatus: 0,
|
|
|
|
pageSize: 1,
|
|
|
|
pageNum: 10,
|
|
|
|
});
|
|
|
|
this.unApprovedBusiness = resp.total;
|
|
|
|
},
|
|
|
|
async getUnApprovedExpert() {
|
|
|
|
const resp = await expertList({
|
|
|
|
examineStatus: 0,
|
|
|
|
pageSize: 1,
|
|
|
|
pageNum: 10,
|
|
|
|
});
|
|
|
|
this.unApprovedExpert = resp.total;
|
|
|
|
},
|
|
|
|
async getUnApprovedAchivement() {
|
|
|
|
const resp = await expertAchievementList({
|
|
|
|
status: 0,
|
|
|
|
pageNum: 1,
|
|
|
|
pageSize: 10,
|
|
|
|
});
|
|
|
|
this.unApprovedAchivement = resp.total;
|
|
|
|
},
|
|
|
|
async getUnApprovedTechnology() {
|
|
|
|
const resp = await businessList({ status: 0, pageNum: 1, pageSize: 10 });
|
|
|
|
this.unApprovedTechnology = resp.total;
|
|
|
|
},
|
|
|
|
async getUnApprovedService() {
|
|
|
|
const resp = await listCasDemand({
|
|
|
|
pageNum: 1,
|
|
|
|
pageSize: 10,
|
|
|
|
status: 0,
|
|
|
|
});
|
|
|
|
this.unApprovedService = resp.total;
|
|
|
|
},
|
|
|
|
async getUnApprovedProduct() {
|
|
|
|
const resp = await enterpriseProductApprovalList({
|
|
|
|
pageNum: 1,
|
|
|
|
pageSize: 10,
|
|
|
|
status: 0,
|
|
|
|
});
|
|
|
|
this.unApprovedProduct = resp.total;
|
|
|
|
},
|
|
|
|
|
|
|
|
async getServiceDemandTotal() {
|
|
|
|
const resp = await listCasDemand();
|
|
|
|
this.serviceDemandTotal = resp.total;
|
2022-11-17 17:30:20 +08:00
|
|
|
},
|
|
|
|
// 退出系统
|
|
|
|
logOut() {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
logout(this.token)
|
|
|
|
.then(() => {
|
|
|
|
this.token = "";
|
|
|
|
this.roles = [];
|
|
|
|
this.permissions = [];
|
|
|
|
removeToken();
|
|
|
|
resolve();
|
2022-05-29 21:40:32 +08:00
|
|
|
})
|
2022-11-17 17:30:20 +08:00
|
|
|
.catch((error) => {
|
|
|
|
reject(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2021-11-30 09:55:37 +08:00
|
|
|
|
2022-11-17 17:30:20 +08:00
|
|
|
export default useUserStore;
|