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