mirror of
https://github.com/certd/certd.git
synced 2026-04-26 22:07:29 +08:00
feat: 支持企业级管理模式,项目管理,细分权限
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
import { defineStore } from "pinia";
|
||||
import * as api from "./api";
|
||||
import { message } from "ant-design-vue";
|
||||
import { computed, ref } from "vue";
|
||||
import { useSettingStore } from "../settings";
|
||||
import { LocalStorage } from "/@/utils/util.storage";
|
||||
|
||||
export type ProjectItem = {
|
||||
id: string;
|
||||
name: string;
|
||||
permission?: string;
|
||||
};
|
||||
|
||||
export const useProjectStore = defineStore("app.project", () => {
|
||||
const myProjects = ref([]);
|
||||
const lastProjectId = LocalStorage.get("currentProjectId");
|
||||
const currentProjectId = ref(lastProjectId); // 直接调用
|
||||
|
||||
const projects = computed(() => {
|
||||
return myProjects.value;
|
||||
});
|
||||
const currentProject = computed(() => {
|
||||
if (currentProjectId.value) {
|
||||
const project = projects.value.find(item => item.id === currentProjectId.value);
|
||||
if (project) {
|
||||
return project;
|
||||
}
|
||||
}
|
||||
if (projects.value.length > 0) {
|
||||
return projects.value[0];
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
const settingStore = useSettingStore();
|
||||
const isEnterprise = computed(() => {
|
||||
return settingStore.isEnterprise;
|
||||
});
|
||||
|
||||
function getSearchForm() {
|
||||
if (!currentProjectId.value || !isEnterprise.value) {
|
||||
return {};
|
||||
}
|
||||
return {
|
||||
projectId: currentProjectId.value,
|
||||
};
|
||||
}
|
||||
async function loadMyProjects(): Promise<ProjectItem[]> {
|
||||
if (!isEnterprise.value) {
|
||||
return [];
|
||||
}
|
||||
const projects = await api.MyProjectList();
|
||||
myProjects.value = projects;
|
||||
}
|
||||
|
||||
function changeCurrentProject(id: string) {
|
||||
currentProjectId.value = id;
|
||||
LocalStorage.set("currentProjectId", id);
|
||||
message.success("切换项目成功");
|
||||
}
|
||||
|
||||
async function reload() {
|
||||
const projects = await api.MyProjectList();
|
||||
myProjects.value = projects;
|
||||
}
|
||||
|
||||
async function init() {
|
||||
if (!myProjects.value) {
|
||||
await reload();
|
||||
}
|
||||
return myProjects.value;
|
||||
}
|
||||
|
||||
return {
|
||||
projects,
|
||||
myProjects,
|
||||
currentProject,
|
||||
isEnterprise,
|
||||
getSearchForm,
|
||||
loadMyProjects,
|
||||
changeCurrentProject,
|
||||
reload,
|
||||
init,
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user