mirror of
https://github.com/certd/certd.git
synced 2026-04-16 05:50:50 +08:00
chore: 首页数据统计项目显示
This commit is contained in:
@@ -136,27 +136,29 @@ function createService() {
|
||||
*/
|
||||
function createRequestFunction(service: any) {
|
||||
return function (config: any) {
|
||||
const configDefault = {
|
||||
const configDefault: any = {
|
||||
headers: {
|
||||
"Content-Type": get(config, "headers.Content-Type", "application/json"),
|
||||
} as any,
|
||||
timeout: 30000,
|
||||
baseURL: env.API,
|
||||
data: {},
|
||||
params: {},
|
||||
};
|
||||
const projectStore = useProjectStore();
|
||||
|
||||
if (projectStore.isEnterprise && !config.url.startsWith("/sys") && !config.url.startsWith("http")) {
|
||||
configDefault.headers["project-id"] = projectStore.currentProjectId;
|
||||
}
|
||||
|
||||
const userStore = useUserStore();
|
||||
const token = userStore.getToken;
|
||||
if (token != null) {
|
||||
// @ts-ignore
|
||||
configDefault.headers.Authorization = token;
|
||||
}
|
||||
return service(Object.assign(configDefault, config));
|
||||
Object.assign(configDefault, config);
|
||||
|
||||
if (projectStore.isEnterprise && !config.url.startsWith("/sys") && !config.url.startsWith("http")) {
|
||||
configDefault.params.projectId = projectStore.currentProjectId;
|
||||
}
|
||||
return service(configDefault);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ import NotificationSelector from "../views/certd/notification/notification-selec
|
||||
import EmailSelector from "./email-selector/index.vue";
|
||||
import ValidTimeFormat from "./valid-time-format.vue";
|
||||
import ProjectSelector from "./project-selector/index.vue";
|
||||
import ProjectCurrent from "./project-selector/project-current.vue";
|
||||
|
||||
export default {
|
||||
install(app: any) {
|
||||
app.component(
|
||||
@@ -47,5 +49,6 @@ export default {
|
||||
app.use(vip);
|
||||
app.use(Plugins);
|
||||
app.component("ProjectSelector", ProjectSelector);
|
||||
app.component("ProjectCurrent", ProjectCurrent);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<template>
|
||||
<a-tag color="green" class="flex-center flex pointer items-center button-text" title="当前项目">
|
||||
<!-- <fs-icon icon="ion:apps" class="mr-1"></fs-icon> -->
|
||||
<fs-icon :icon="currentIcon" class="mr-5"></fs-icon>
|
||||
当前项目:{{ projectStore.currentProject?.name || "..." }}
|
||||
</a-tag>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, onMounted } from "vue";
|
||||
import { useProjectStore } from "/@/store/project";
|
||||
import { useDicts } from "/@/views/certd/dicts";
|
||||
defineOptions({
|
||||
name: "ProjectCurrent",
|
||||
});
|
||||
|
||||
const projectStore = useProjectStore();
|
||||
// onMounted(async () => {
|
||||
// await projectStore.reload();
|
||||
// });
|
||||
|
||||
const { projectPermissionDict } = useDicts();
|
||||
|
||||
const currentIcon = computed(() => {
|
||||
return projectPermissionDict.dataMap[projectStore.currentProject?.permission || ""]?.icon || "";
|
||||
});
|
||||
</script>
|
||||
<style lang="less"></style>
|
||||
@@ -35,6 +35,11 @@
|
||||
<a-divider type="vertical" />
|
||||
<vip-button mode="nav" style="font-size: 12px"></vip-button>
|
||||
</template>
|
||||
|
||||
<template v-if="settingsStore.isEnterprise">
|
||||
<a-divider type="vertical" />
|
||||
<project-current></project-current>
|
||||
</template>
|
||||
<template v-if="settingsStore.isComm">
|
||||
<a-divider type="vertical" />
|
||||
<suite-card class="m-0"></suite-card>
|
||||
|
||||
@@ -46,14 +46,15 @@ export class StatisticController extends BaseController {
|
||||
|
||||
@Post('/count', { summary: Constants.per.authOnly })
|
||||
public async count() {
|
||||
const pipelineCount = await this.pipelineService.count({ userId: this.getUserId() });
|
||||
const pipelineStatusCount = await this.pipelineService.statusCount({ userId: this.getUserId() });
|
||||
const pipelineEnableCount = await this.pipelineService.enableCount({ userId: this.getUserId() });
|
||||
const {userId,projectId} = await this.getProjectUserIdRead();
|
||||
const pipelineCount = await this.pipelineService.count({ userId,projectId });
|
||||
const pipelineStatusCount = await this.pipelineService.statusCount({ userId,projectId });
|
||||
const pipelineEnableCount = await this.pipelineService.enableCount({ userId,projectId });
|
||||
|
||||
const historyCount = await this.historyService.countPerDay({ userId: this.getUserId(), days: 7 });
|
||||
const expiringList = await this.pipelineService.latestExpiringList({ userId: this.getUserId(), count: 5 });
|
||||
const historyCount = await this.historyService.countPerDay({ userId,projectId, days: 7 });
|
||||
const expiringList = await this.pipelineService.latestExpiringList({ userId,projectId, count: 5 });
|
||||
|
||||
const certCount = await this.certInfoService.count({ userId: this.getUserId() });
|
||||
const certCount = await this.certInfoService.count({ userId,projectId });
|
||||
|
||||
const count: UserStatisticCount = {
|
||||
pipelineCount,
|
||||
|
||||
@@ -191,11 +191,12 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
|
||||
});
|
||||
}
|
||||
|
||||
async count({ userId }: { userId: number }) {
|
||||
async count({ userId,projectId }: { userId: number,projectId?:number }) {
|
||||
const total = await this.repository.count({
|
||||
where: {
|
||||
userId,
|
||||
expiresTime: Not(IsNull()),
|
||||
projectId,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -203,6 +204,7 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
|
||||
where: {
|
||||
userId,
|
||||
expiresTime: LessThan(new Date().getTime()),
|
||||
projectId,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -210,6 +212,7 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
|
||||
where: {
|
||||
userId,
|
||||
expiresTime: Between(new Date().getTime(), new Date().getTime() + 15 * 24 * 60 * 60 * 1000),
|
||||
projectId,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -183,7 +183,7 @@ export class HistoryService extends BaseService<HistoryEntity> {
|
||||
}
|
||||
}
|
||||
|
||||
async countPerDay(param: { days: number; userId?: any }) {
|
||||
async countPerDay(param: { days: number; userId?: any,projectId?:number }) {
|
||||
const todayEnd = dayjs().endOf('day');
|
||||
const where: any = {
|
||||
createTime: MoreThan(todayEnd.add(-param.days, 'day').toDate()),
|
||||
@@ -191,6 +191,9 @@ export class HistoryService extends BaseService<HistoryEntity> {
|
||||
if (param.userId > 0) {
|
||||
where.userId = param.userId;
|
||||
}
|
||||
if (param.projectId > 0) {
|
||||
where.projectId = param.projectId;
|
||||
}
|
||||
const result = await this.getRepository()
|
||||
.createQueryBuilder('main')
|
||||
.select(`${this.dbAdapter.date('main.createTime')} AS date`) // 将UNIX时间戳转换为日期
|
||||
|
||||
@@ -824,35 +824,39 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
await this.historyLogService.addOrUpdate(logEntity);
|
||||
}
|
||||
|
||||
async count(param: { userId?: any }) {
|
||||
async count(param: { userId?: any,projectId?:number }) {
|
||||
const count = await this.repository.count({
|
||||
where: {
|
||||
userId: param.userId
|
||||
userId: param.userId,
|
||||
projectId: param.projectId,
|
||||
isTemplate: false
|
||||
}
|
||||
});
|
||||
return count;
|
||||
}
|
||||
|
||||
async statusCount(param: { userId?: any } = {}) {
|
||||
async statusCount(param: { userId?: any,projectId?:number } = {}) {
|
||||
const statusCount = await this.repository
|
||||
.createQueryBuilder()
|
||||
.select("status")
|
||||
.addSelect("count(1)", "count")
|
||||
.where({
|
||||
userId: param.userId
|
||||
userId: param.userId,
|
||||
projectId: param.projectId
|
||||
})
|
||||
.groupBy("status")
|
||||
.getRawMany();
|
||||
return statusCount;
|
||||
}
|
||||
|
||||
async enableCount(param: { userId?: any } = {}) {
|
||||
async enableCount(param: { userId?: any,projectId?:number } = {}) {
|
||||
const statusCount = await this.repository
|
||||
.createQueryBuilder()
|
||||
.select("disabled")
|
||||
.addSelect("count(1)", "count")
|
||||
.where({
|
||||
userId: param.userId
|
||||
userId: param.userId,
|
||||
projectId: param.projectId
|
||||
})
|
||||
.groupBy("disabled")
|
||||
.getRawMany();
|
||||
@@ -866,7 +870,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
return result;
|
||||
}
|
||||
|
||||
async latestExpiringList({ userId }: any) {
|
||||
async latestExpiringList({ userId,projectId }: any) {
|
||||
let list = await this.repository.find({
|
||||
select: {
|
||||
id: true,
|
||||
@@ -875,7 +879,8 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
},
|
||||
where: {
|
||||
userId,
|
||||
disabled: false
|
||||
disabled: false,
|
||||
projectId
|
||||
}
|
||||
});
|
||||
await this.fillLastVars(list);
|
||||
|
||||
Reference in New Issue
Block a user