搜索结果列表页面开发
This commit is contained in:
131
src/stores/Repo/index.ts
Normal file
131
src/stores/Repo/index.ts
Normal file
@@ -0,0 +1,131 @@
|
||||
import { ref, reactive, computed } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
import { getRepo } from '@/api/repo';
|
||||
import getRepoId from '@/utils/getRepoId';
|
||||
import setting from '@/setting';
|
||||
|
||||
export interface repoInfoType {
|
||||
id?: number;
|
||||
name?:string;
|
||||
path?:string;
|
||||
path_with_namespace?:string;
|
||||
created_at?:string;
|
||||
star_count?:number;
|
||||
starred?:boolean;
|
||||
creator?:{
|
||||
id:number;
|
||||
iam_id:string;
|
||||
username:string;
|
||||
nick_name:string;
|
||||
};
|
||||
description?:string;
|
||||
module_setting?:{
|
||||
repo_id:string;
|
||||
modules:{
|
||||
key: string,
|
||||
type: string,
|
||||
value: string
|
||||
}[]
|
||||
};
|
||||
web_url?:string;
|
||||
[propName: string]: any;
|
||||
}
|
||||
|
||||
const { visitor, developer, admin } = setting.role;
|
||||
|
||||
export const repoInfoStore = defineStore('globalRepoInfo', () => {
|
||||
const repoInfo = ref<repoInfoType>({});
|
||||
const access_level = ref<number>(0);
|
||||
|
||||
const setAccessLevel = (val: number) => {
|
||||
access_level.value = val;
|
||||
};
|
||||
|
||||
const setVisibility = (val: string) => {
|
||||
repoInfo.value = {
|
||||
...repoInfo.value,
|
||||
visibility: val
|
||||
};
|
||||
};
|
||||
|
||||
const isPrivate = computed(() => { // 是否私有
|
||||
return repoInfo.value?.visibility === 'private';
|
||||
});
|
||||
|
||||
const isArchived = computed(() => { // 是否归档
|
||||
return repoInfo.value?.archived;
|
||||
});
|
||||
|
||||
const isAdminOperate = computed(() => { // 操作权限(管理者且未归档,为了兼容未考虑归档时的权限)
|
||||
return access_level?.value >= admin && !repoInfo.value?.archived;
|
||||
});
|
||||
|
||||
const isDeveloperOperate = computed(() => { // 操作权限(开发者且未归档,为了兼容未考虑归档时的权限)
|
||||
return access_level?.value >= developer && !repoInfo.value?.archived;
|
||||
});
|
||||
|
||||
const isVisitorOperate = computed(() => { // 操作权限(浏览者且未归档,为了兼容未考虑归档时的权限)
|
||||
return access_level?.value >= visitor && !repoInfo.value?.archived;
|
||||
});
|
||||
|
||||
const isAdmin = computed(() => {
|
||||
return access_level?.value >= admin;
|
||||
});
|
||||
|
||||
const isDeveloper = computed(() => {
|
||||
return access_level?.value >= developer;
|
||||
});
|
||||
|
||||
const isVisitor = computed(() => {
|
||||
return access_level?.value >= visitor;
|
||||
});
|
||||
|
||||
const setRepoInfo = (data: repoInfoType) => {
|
||||
repoInfo.value = {
|
||||
...repoInfo.value,
|
||||
...data
|
||||
};
|
||||
};
|
||||
const setReleaseCount = (count: number) => {
|
||||
repoInfo.value.release_count = count;
|
||||
};
|
||||
const setTagsCount = (count: number) => {
|
||||
repoInfo.value.tag_count = count;
|
||||
};
|
||||
const setForkVisible = (visible: boolean)=> {
|
||||
repoInfo.value.module_setting?.modules.forEach((item)=> {
|
||||
if (item.key === 'FORK' && item.type === 'PROJECT_MODULE') {
|
||||
item.value = visible ? '1' : '0'
|
||||
}
|
||||
})
|
||||
}
|
||||
const getRepoInfo = async(namePath?: string) => {
|
||||
const res = await getRepo({ repoId: namePath || getRepoId(), statistics: true });
|
||||
if (!res.error) {
|
||||
const { data } = res.data;
|
||||
setRepoInfo(data);
|
||||
return data;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
return {
|
||||
isPrivate,
|
||||
isAdmin,
|
||||
isDeveloper,
|
||||
isVisitor,
|
||||
isArchived,
|
||||
isAdminOperate,
|
||||
isDeveloperOperate,
|
||||
isVisitorOperate,
|
||||
access_level,
|
||||
repoInfo,
|
||||
setRepoInfo,
|
||||
setVisibility,
|
||||
setAccessLevel,
|
||||
setReleaseCount,
|
||||
setTagsCount,
|
||||
setForkVisible,
|
||||
getRepoInfo
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user