Compare commits

..

5 Commits

Author SHA1 Message Date
xiaojunnuo 316537eb4d fix: 修复偶尔下载证书报未授权的错误 2026-02-27 00:37:24 +08:00
xiaojunnuo b2c421600c chore: 首页数据统计项目显示 2026-02-27 00:14:53 +08:00
xiaojunnuo 787f6ef528 perf: 任务步骤页面增加串行执行提示说明 2026-02-27 00:06:44 +08:00
xiaojunnuo 8578547467 chore: project permission 2026-02-26 23:50:15 +08:00
xiaojunnuo 51ab6d6da1 perf: 【破坏性更新】错误返回信息msg字段名统一改成message,与成功的返回结构一致 2026-02-26 23:50:01 +08:00
38 changed files with 225 additions and 75 deletions
@@ -34,7 +34,7 @@ export abstract class BaseController {
fail(msg: string, code?: any) { fail(msg: string, code?: any) {
return { return {
code: code ? code : Constants.res.error.code, code: code ? code : Constants.res.error.code,
msg: msg ? msg : Constants.res.error.code, message: msg ? msg : Constants.res.error.code,
}; };
} }
@@ -4,7 +4,7 @@
export class BaseException extends Error { export class BaseException extends Error {
code: number; code: number;
data?:any data?:any
constructor(name, code, message,data?:any) { constructor(name: string, code: number, message: string ,data?:any) {
super(message); super(message);
this.name = name; this.name = name;
this.code = code; this.code = code;
+7 -7
View File
@@ -1,19 +1,19 @@
export class Result<T> { export class Result<T> {
code: number; code: number;
msg: string; message: string;
data: T; data: T;
constructor(code, msg, data?) { constructor(code, message, data?) {
this.code = code; this.code = code;
this.msg = msg; this.message = message;
this.data = data; this.data = data;
} }
static error(code = 1, msg, data?: any) { static error(code = 1, message, data?: any) {
return new Result(code, msg, data); return new Result(code, message, data);
} }
static success(msg, data?) { static success(message, data?) {
return new Result(0, msg, data); return new Result(0, message, data);
} }
} }
+8 -6
View File
@@ -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);
}, },
}; };
@@ -3,21 +3,25 @@
<template #overlay> <template #overlay>
<a-menu @click="handleMenuClick"> <a-menu @click="handleMenuClick">
<a-menu-item v-for="item in projectStore.myProjects" :key="item.id"> <a-menu-item v-for="item in projectStore.myProjects" :key="item.id">
{{ item.name }} <div class="flex items-center justify-between w-full">
<span class="mr-1">{{ item.name }}</span>
<fs-values-format :model-value="item.permission" :dict="projectPermissionDict"></fs-values-format>
</div>
</a-menu-item> </a-menu-item>
</a-menu> </a-menu>
</template> </template>
<div class="rounded pl-3 pr-3 px-2 py-1 flex-center flex pointer items-center bg-accent h-10 button-text" title="当前项目"> <div class="rounded pl-3 pr-3 px-2 py-1 flex-center flex pointer items-center bg-accent h-10 button-text" title="当前项目">
<fs-icon icon="ion:apps" class="mr-1"></fs-icon> <!-- <fs-icon icon="ion:apps" class="mr-1"></fs-icon> -->
当前项目{{ projectStore.currentProject?.name || "..." }} 当前项目{{ projectStore.currentProject?.name || "..." }}
<fs-icon icon="ion:chevron-down-outline" class="ml-1"></fs-icon> <fs-icon :icon="currentIcon" class="ml-5"></fs-icon>
</div> </div>
</a-dropdown> </a-dropdown>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { onMounted } from "vue"; import { computed, onMounted } from "vue";
import { useProjectStore } from "/@/store/project"; import { useProjectStore } from "/@/store/project";
import { useDicts } from "/@/views/certd/dicts";
defineOptions({ defineOptions({
name: "ProjectSelector", name: "ProjectSelector",
}); });
@@ -25,12 +29,18 @@ defineOptions({
const projectStore = useProjectStore(); const projectStore = useProjectStore();
onMounted(async () => { onMounted(async () => {
await projectStore.reload(); await projectStore.reload();
console.log(projectStore.myProjects);
}); });
function handleMenuClick({ key }: any) { function handleMenuClick({ key }: any) {
projectStore.changeCurrentProject(key); projectStore.changeCurrentProject(key);
window.location.reload(); window.location.reload();
} }
const { projectPermissionDict } = useDicts();
const currentIcon = computed(() => {
return projectPermissionDict.dataMap[projectStore.currentProject?.permission || ""]?.icon || "";
});
</script> </script>
<style lang="less"> <style lang="less">
.project-selector { .project-selector {
@@ -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> -->
当前项目{{ projectStore.currentProject?.name || "..." }}
<fs-icon :icon="currentIcon" class="ml-5"></fs-icon>
</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>
@@ -8,6 +8,7 @@ export type UseCrudPermissionExtraProps = {
export type UseCrudPermissionExtra = (props: UseCrudPermissionExtraProps) => any; export type UseCrudPermissionExtra = (props: UseCrudPermissionExtraProps) => any;
export type UseCrudPermissionCompProps = { export type UseCrudPermissionCompProps = {
isProjectPermission?: boolean; isProjectPermission?: boolean;
projectPermission?: string;
prefix?: string; prefix?: string;
extra?: UseCrudPermissionExtra; extra?: UseCrudPermissionExtra;
[key: string]: any; [key: string]: any;
@@ -69,17 +70,17 @@ export function useCrudPermission({ permission }: UseCrudPermissionProps) {
let addPermission = "add"; let addPermission = "add";
if (isProjectPermission) { if (isProjectPermission) {
addPermission = "write"; addPermission = per.projectPermission || "write";
} }
let editPermission = "edit"; let editPermission = "edit";
if (isProjectPermission) { if (isProjectPermission) {
editPermission = "write"; editPermission = per.projectPermission || "write";
} }
let removePermission = "remove"; let removePermission = "remove";
if (isProjectPermission) { if (isProjectPermission) {
removePermission = "write"; removePermission = per.projectPermission || "write";
} }
return LodashMerge( return LodashMerge(
{ {
@@ -241,6 +241,10 @@ export const certdResources = [
icon: "mi:user-check", icon: "mi:user-check",
auth: true, auth: true,
isMenu: true, isMenu: true,
show: () => {
const projectStore = useProjectStore();
return !projectStore.isEnterprise;
},
}, },
}, },
{ {
@@ -22,7 +22,10 @@ export default defineComponent({
setup() { setup() {
const api = createAddonApi({ from: "user", addonType: "" }); const api = createAddonApi({ from: "user", addonType: "" });
addonProvide(api); addonProvide(api);
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: { api } }); const { crudBinding, crudRef, crudExpose } = useFs({
createCrudOptions,
context: { api, permission: { isProjectPermission: true } },
});
// 页面打开后获取列表数据 // 页面打开后获取列表数据
onMounted(() => { onMounted(() => {
@@ -18,7 +18,12 @@ import createCrudOptions from "./crud";
export default defineComponent({ export default defineComponent({
name: "BasicGroupManager", name: "BasicGroupManager",
setup() { setup() {
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: {} }); const { crudBinding, crudRef, crudExpose } = useFs({
createCrudOptions,
context: {
permission: { isProjectPermission: true },
},
});
// 页面打开后获取列表数据 // 页面打开后获取列表数据
onMounted(() => { onMounted(() => {
@@ -8,6 +8,7 @@ import { useSettingStore } from "/@/store/settings";
import { message, Modal } from "ant-design-vue"; import { message, Modal } from "ant-design-vue";
import CnameTip from "/@/components/plugins/cert/domains-verify-plan-editor/cname-tip.vue"; import CnameTip from "/@/components/plugins/cert/domains-verify-plan-editor/cname-tip.vue";
import { useCnameImport } from "./use"; import { useCnameImport } from "./use";
import { useCrudPermission } from "/@/plugin/permission";
export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet { export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
const crudBinding = crudExpose.crudBinding; const crudBinding = crudExpose.crudBinding;
const router = useRouter(); const router = useRouter();
@@ -45,6 +46,8 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
{ label: t("certd.validation_timed_out"), value: "timeout", color: "red" }, { label: t("certd.validation_timed_out"), value: "timeout", color: "red" },
], ],
}); });
const { hasActionPermission } = useCrudPermission(context);
return { return {
crudOptions: { crudOptions: {
settings: { settings: {
@@ -75,6 +78,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
icon: "ion:add-circle-outline", icon: "ion:add-circle-outline",
}, },
import: { import: {
show: hasActionPermission("write"),
title: "导入CNAME记录", title: "导入CNAME记录",
type: "primary", type: "primary",
text: "批量导入", text: "批量导入",
@@ -12,7 +12,7 @@
</template> </template>
<fs-crud ref="crudRef" v-bind="crudBinding"> <fs-crud ref="crudRef" v-bind="crudBinding">
<template #pagination-left> <template #pagination-left>
<a-tooltip :title="t('certd.batch_delete')"> <a-tooltip v-if="hasActionPermission('write')" :title="t('certd.batch_delete')">
<fs-button icon="DeleteOutlined" @click="handleBatchDelete"></fs-button> <fs-button icon="DeleteOutlined" @click="handleBatchDelete"></fs-button>
</a-tooltip> </a-tooltip>
</template> </template>
@@ -27,13 +27,20 @@ import createCrudOptions from "./crud";
import { message, Modal } from "ant-design-vue"; import { message, Modal } from "ant-design-vue";
import { DeleteBatch } from "./api"; import { DeleteBatch } from "./api";
import { useI18n } from "/src/locales"; import { useI18n } from "/src/locales";
import { useCrudPermission } from "/@/plugin/permission";
const { t } = useI18n(); const { t } = useI18n();
defineOptions({ defineOptions({
name: "CnameRecord", name: "CnameRecord",
}); });
const { crudBinding, crudRef, crudExpose, context } = useFs({ createCrudOptions });
const context: any = {
permission: { isProjectPermission: true },
};
const { hasActionPermission } = useCrudPermission(context);
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context });
const selectedRowKeys = context.selectedRowKeys; const selectedRowKeys = context.selectedRowKeys;
const handleBatchDelete = () => { const handleBatchDelete = () => {
@@ -4,16 +4,22 @@ import { GetMyProjectList } from "./project/api";
const projectPermissionDict = dict({ const projectPermissionDict = dict({
data: [ data: [
{ {
label: "read", value: "read",
value: "只读", label: "只读",
color: "cyan",
icon: "material-symbols:folder-eye-outline-sharp",
}, },
{ {
label: "write", value: "write",
value: "读写", label: "读写",
color: "green",
icon: "material-symbols:edit-square-outline-rounded",
}, },
{ {
label: "admin", value: "admin",
value: "管理员", label: "管理员",
color: "orange",
icon: "material-symbols:manage-accounts-rounded",
}, },
], ],
}); });
@@ -5,7 +5,7 @@
</template> </template>
<fs-crud ref="crudRef" v-bind="crudBinding"> <fs-crud ref="crudRef" v-bind="crudBinding">
<template #pagination-left> <template #pagination-left>
<a-tooltip :title="t('certd.batchDelete')"> <a-tooltip v-if="hasActionPermission('write')" :title="t('certd.batchDelete')">
<fs-button icon="DeleteOutlined" @click="handleBatchDelete"></fs-button> <fs-button icon="DeleteOutlined" @click="handleBatchDelete"></fs-button>
</a-tooltip> </a-tooltip>
</template> </template>
@@ -20,13 +20,20 @@ import createCrudOptions from "./crud";
import { message, Modal } from "ant-design-vue"; import { message, Modal } from "ant-design-vue";
import { DeleteBatch } from "./api"; import { DeleteBatch } from "./api";
import { useI18n } from "/src/locales"; import { useI18n } from "/src/locales";
import { useCrudPermission } from "/@/plugin/permission";
const { t } = useI18n(); const { t } = useI18n();
defineOptions({ defineOptions({
name: "PipelineHistory", name: "PipelineHistory",
}); });
const { crudBinding, crudRef, crudExpose, context } = useFs({ createCrudOptions });
const context: any = {
permission: { isProjectPermission: true },
};
const { hasActionPermission } = useCrudPermission(context);
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context });
const selectedRowKeys = context.selectedRowKeys; const selectedRowKeys = context.selectedRowKeys;
const handleBatchDelete = () => { const handleBatchDelete = () => {
@@ -12,6 +12,7 @@ import { useCertUpload } from "/@/views/certd/pipeline/cert-upload/use";
import { useSettingStore } from "/@/store/settings"; import { useSettingStore } from "/@/store/settings";
import { useProjectStore } from "/@/store/project"; import { useProjectStore } from "/@/store/project";
import { useDicts } from "../../dicts"; import { useDicts } from "../../dicts";
import { useUserStore } from "/@/store/user";
export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet { export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
const { t } = useI18n(); const { t } = useI18n();
@@ -39,6 +40,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
const { myProjectDict } = useDicts(); const { myProjectDict } = useDicts();
const settingStore = useSettingStore(); const settingStore = useSettingStore();
const projectStore = useProjectStore(); const projectStore = useProjectStore();
const userStore = useUserStore();
const model = useModal(); const model = useModal();
const viewCert = async (row: any) => { const viewCert = async (row: any) => {
const cert = await api.GetCert(row.id); const cert = await api.GetCert(row.id);
@@ -140,7 +142,12 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
notification.error({ message: t("certd.certificateNotGenerated") }); notification.error({ message: t("certd.certificateNotGenerated") });
return; return;
} }
window.open("/api/monitor/cert/download?id=" + row.id); let url = "/api/monitor/cert/download?id=" + row.id;
if (projectStore.isEnterprise) {
url += `&projectId=${projectStore.currentProject?.id}`;
}
url += `&token=${userStore.getToken}`;
window.open(url);
}, },
}, },
}, },
@@ -21,7 +21,7 @@ const { t } = useI18n();
defineOptions({ defineOptions({
name: "CertStore", name: "CertStore",
}); });
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: {} }); const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: { permission: { isProjectPermission: true } } });
// 页面打开后获取列表数据 // 页面打开后获取列表数据
onMounted(() => { onMounted(() => {
@@ -37,7 +37,7 @@
<div class="helper">{{ t("monitor.setting.cronTrigger") }}</div> <div class="helper">{{ t("monitor.setting.cronTrigger") }}</div>
</a-form-item> </a-form-item>
<a-form-item label=" " :colon="false" :wrapper-col="{ span: 16 }"> <a-form-item label=" " :colon="false" :wrapper-col="{ span: 16 }">
<loading-button type="primary" html-type="button" :click="doSave">{{ t("certd.save") }}</loading-button> <loading-button type="primary" html-type="button" :click="doSave" :disabled="!hasActionPermission('write')">{{ t("certd.save") }}</loading-button>
</a-form-item> </a-form-item>
</a-form> </a-form>
</div> </div>
@@ -55,6 +55,7 @@ import { utils } from "/@/utils";
import NotificationSelector from "/@/views/certd/notification/notification-selector/index.vue"; import NotificationSelector from "/@/views/certd/notification/notification-selector/index.vue";
import { useI18n } from "/src/locales"; import { useI18n } from "/src/locales";
import { useSettingStore } from "/src/store/settings"; import { useSettingStore } from "/src/store/settings";
import { useCrudPermission } from "/@/plugin/permission";
const { t } = useI18n(); const { t } = useI18n();
@@ -73,6 +74,8 @@ async function loadUserSettings() {
merge(formState, data); merge(formState, data);
} }
const { hasActionPermission } = useCrudPermission({ permission: { isProjectPermission: true } });
loadUserSettings(); loadUserSettings();
const doSave = async (form: any) => { const doSave = async (form: any) => {
await utils.sleep(300); await utils.sleep(300);
@@ -22,7 +22,7 @@ export default defineComponent({
setup() { setup() {
const api = createNotificationApi(); const api = createNotificationApi();
notificationProvide(api); notificationProvide(api);
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: { api } }); const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: { api, permission: { isProjectPermission: true } } });
// 页面打开后获取列表数据 // 页面打开后获取列表数据
onMounted(() => { onMounted(() => {
@@ -19,7 +19,7 @@ import { OPEN_API_DOC } from "/@/views/certd/open/openkey/api";
defineOptions({ defineOptions({
name: "OpenKey", name: "OpenKey",
}); });
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: {} }); const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: { permission: { isProjectPermission: true } } });
// 页面打开后获取列表数据 // 页面打开后获取列表数据
onMounted(() => { onMounted(() => {
@@ -124,11 +124,11 @@ export default function ({ crudExpose, context: { selectedRowKeys, openCertApply
click() { click() {
openCertApplyDialog({ key: "CertApply" }); openCertApplyDialog({ key: "CertApply" });
}, },
show: hasActionPermission("add"), show: hasActionPermission("write"),
}, },
uploadCert: { uploadCert: {
order: 2, order: 2,
show: hasActionPermission("uploadCert"), show: hasActionPermission("write"),
text: t("certd.commercialCertHosting"), text: t("certd.commercialCertHosting"),
type: "primary", type: "primary",
tooltip: { tooltip: {
@@ -14,12 +14,16 @@
import { defineComponent, onActivated, onMounted } from "vue"; import { defineComponent, onActivated, onMounted } from "vue";
import { useFs } from "@fast-crud/fast-crud"; import { useFs } from "@fast-crud/fast-crud";
import createCrudOptions from "./crud"; import createCrudOptions from "./crud";
import { createApi } from "./api";
export default defineComponent({ export default defineComponent({
name: "PipelineGroupManager", name: "PipelineGroupManager",
setup() { setup() {
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: {} }); const { crudBinding, crudRef, crudExpose } = useFs({
createCrudOptions,
context: {
permission: { isProjectPermission: true },
},
});
// 页面打开后获取列表数据 // 页面打开后获取列表数据
onMounted(() => { onMounted(() => {
@@ -37,11 +37,11 @@
<div v-if="selectedRowKeys.length > 0" class="batch-actions"> <div v-if="selectedRowKeys.length > 0" class="batch-actions">
<div class="batch-actions-inner"> <div class="batch-actions-inner">
<span>{{ t("certd.selectedCount", { count: selectedRowKeys.length }) }}</span> <span>{{ t("certd.selectedCount", { count: selectedRowKeys.length }) }}</span>
<fs-button icon="ion:trash-outline" class="color-red" type="link" :text="t('certd.batchDelete')" @click="batchDelete"></fs-button> <fs-button v-if="hasActionPermission('write')" icon="ion:trash-outline" class="color-red" type="link" :text="t('certd.batchDelete')" @click="batchDelete"></fs-button>
<batch-rerun :selected-row-keys="selectedRowKeys" @change="batchFinished"></batch-rerun> <batch-rerun :selected-row-keys="selectedRowKeys" @change="batchFinished"></batch-rerun>
<change-group :selected-row-keys="selectedRowKeys" @change="batchFinished"></change-group> <change-group v-if="hasActionPermission('write')" :selected-row-keys="selectedRowKeys" @change="batchFinished"></change-group>
<change-notification :selected-row-keys="selectedRowKeys" @change="batchFinished"></change-notification> <change-notification v-if="hasActionPermission('write')" :selected-row-keys="selectedRowKeys" @change="batchFinished"></change-notification>
<change-trigger :selected-row-keys="selectedRowKeys" @change="batchFinished"></change-trigger> <change-trigger v-if="hasActionPermission('write')" :selected-row-keys="selectedRowKeys" @change="batchFinished"></change-trigger>
</div> </div>
</div> </div>
<template #form-bottom> <template #form-bottom>
@@ -49,6 +49,7 @@
</div> </div>
</template> </template>
</v-draggable> </v-draggable>
<div v-if="currentTask.steps?.length > 0" class="helper mt-6">任务步骤会串行执行如果前面步骤失败后面的步骤不会运行</div>
</a-form-item> </a-form-item>
</div> </div>
</a-form> </a-form>
@@ -17,7 +17,7 @@
</template> </template>
<fs-crud ref="crudRef" v-bind="crudBinding"> <fs-crud ref="crudRef" v-bind="crudBinding">
<template #pagination-left> <template #pagination-left>
<a-tooltip :title="t('certd.batchDelete')"> <a-tooltip v-if="hasActionPermission('write')" :title="t('certd.batchDelete')">
<fs-button icon="DeleteOutlined" @click="handleBatchDelete"></fs-button> <fs-button icon="DeleteOutlined" @click="handleBatchDelete"></fs-button>
</a-tooltip> </a-tooltip>
</template> </template>
@@ -32,13 +32,21 @@ import createCrudOptions from "./crud";
import { message, Modal } from "ant-design-vue"; import { message, Modal } from "ant-design-vue";
import { DeleteBatch } from "./api"; import { DeleteBatch } from "./api";
import { useI18n } from "/src/locales"; import { useI18n } from "/src/locales";
import { useCrudPermission } from "/@/plugin/permission";
const { t } = useI18n(); const { t } = useI18n();
defineOptions({ defineOptions({
name: "CnameRecord", name: "CnameRecord",
}); });
const { crudBinding, crudRef, crudExpose, context } = useFs({ createCrudOptions }); const context: any = {
permission: {
isProjectPermission: true,
},
};
const { hasActionPermission } = useCrudPermission({ permission: context.permission });
context.hasActionPermission = hasActionPermission;
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context });
const selectedRowKeys = context.selectedRowKeys; const selectedRowKeys = context.selectedRowKeys;
const handleBatchDelete = () => { const handleBatchDelete = () => {
@@ -3,8 +3,12 @@ import { notification } from "ant-design-vue";
import CertView from "/@/views/certd/pipeline/cert-view.vue"; import CertView from "/@/views/certd/pipeline/cert-view.vue";
import { env } from "/@/utils/util.env"; import { env } from "/@/utils/util.env";
import { useModal } from "/@/use/use-modal"; import { useModal } from "/@/use/use-modal";
import { useProjectStore } from "/@/store/project";
import { useUserStore } from "/@/store/user";
export function useCertViewer() { export function useCertViewer() {
const projectStore = useProjectStore();
const userStore = useUserStore();
const model = useModal(); const model = useModal();
const viewCert = async (id: number) => { const viewCert = async (id: number) => {
const cert = await api.GetCert(id); const cert = await api.GetCert(id);
@@ -33,7 +37,11 @@ export function useCertViewer() {
content: () => { content: () => {
const children = []; const children = [];
for (const file of files) { for (const file of files) {
const downloadUrl = `${env.API}/pi/history/download?pipelineId=${id}&fileId=${file.id}`; let downloadUrl = `${env.API}/pi/history/download?pipelineId=${id}&fileId=${file.id}`;
if (projectStore.isEnterprise) {
downloadUrl += `&projectId=${projectStore.currentProject?.id}`;
}
downloadUrl += `&token=${userStore.getToken}`;
children.push( children.push(
<div> <div>
<div class={"flex-o m-5"}> <div class={"flex-o m-5"}>
@@ -6,7 +6,7 @@ import * as api from "./api";
import { useSettingStore } from "/@/store/settings"; import { useSettingStore } from "/@/store/settings";
import { useUserStore } from "/@/store/user"; import { useUserStore } from "/@/store/user";
import { useI18n } from "/src/locales"; import { useI18n } from "/src/locales";
import { userDict } from "../../dicts"; import { useDicts } from "../../dicts";
export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet { export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
const router = useRouter(); const router = useRouter();
@@ -35,6 +35,8 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
const selectedRowKeys: Ref<any[]> = ref([]); const selectedRowKeys: Ref<any[]> = ref([]);
context.selectedRowKeys = selectedRowKeys; context.selectedRowKeys = selectedRowKeys;
const { userDict } = useDicts();
return { return {
crudOptions: { crudOptions: {
settings: { settings: {
@@ -30,7 +30,8 @@ const { t } = useI18n();
defineOptions({ defineOptions({
name: "MyProjectManager", name: "MyProjectManager",
}); });
const { crudBinding, crudRef, crudExpose, context } = useFs({ createCrudOptions }); const context: any = { permission: { isProjectPermission: true, projectPermission: "admin" } };
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context });
const selectedRowKeys = context.selectedRowKeys; const selectedRowKeys = context.selectedRowKeys;
const handleBatchDelete = () => { const handleBatchDelete = () => {
@@ -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>
@@ -40,9 +40,7 @@ export class LoginController extends BaseController {
} }
private writeTokenCookie(token: { expire: any; token: any }) { private writeTokenCookie(token: { expire: any; token: any }) {
this.ctx.cookies.set("certd_token", token.token, { // this.loginService.writeTokenCookie(this.ctx,token);
maxAge: 1000 * token.expire
});
} }
@Post('/loginBySms', { summary: Constants.per.guest }) @Post('/loginBySms', { summary: Constants.per.guest })
@@ -70,6 +70,8 @@ export class ConnectController extends BaseController {
}) })
return this.ok({ loginUrl, ticket }); return this.ok({ loginUrl, ticket });
} }
@Get('/callback/:type', { summary: Constants.per.guest }) @Get('/callback/:type', { summary: Constants.per.guest })
public async callback(@Param('type') type: string, @Query() query: Record<string, string>) { public async callback(@Param('type') type: string, @Query() query: Record<string, string>) {
@@ -154,10 +156,15 @@ export class ConnectController extends BaseController {
}); });
} }
this.writeTokenCookie(loginRes);
//返回登录成功token //返回登录成功token
return this.ok(loginRes); return this.ok(loginRes);
} }
private writeTokenCookie(token: { expire: any; token: any }) {
// this.loginService.writeTokenCookie(this.ctx,token);
}
@Post('/autoRegister', { summary: Constants.per.guest }) @Post('/autoRegister', { summary: Constants.per.guest })
public async autoRegister(@Body(ALL) body: { validationCode: string, type: string }) { public async autoRegister(@Body(ALL) body: { validationCode: string, type: string }) {
@@ -183,6 +190,7 @@ export class ConnectController extends BaseController {
}); });
const loginRes = await this.loginService.generateToken(newUser); const loginRes = await this.loginService.generateToken(newUser);
this.writeTokenCookie(loginRes);
return this.ok(loginRes); return this.ok(loginRes);
} }
@@ -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,
@@ -162,12 +162,15 @@ export class CertInfoController extends CrudController<CertInfoService> {
@Get('/download', { summary: Constants.per.authOnly }) @Get('/download', { summary: Constants.per.authOnly })
async download(@Query('id') id: number) { async download(@Query('id') id: number) {
await this.checkOwner(this.getService(),id,"read"); const {userId,projectId} =await this.checkOwner(this.getService(),id,"read");
const certInfo = await this.getService().info(id) const certInfo = await this.getService().info(id)
if (certInfo == null) { if (certInfo == null) {
throw new CommonException('file not found'); throw new CommonException('file not found');
} }
if (certInfo.userId !== this.getUserId()) { if (certInfo.userId !== userId) {
throw new CommonException('file not found');
}
if (projectId && certInfo.projectId !== projectId) {
throw new CommonException('file not found'); throw new CommonException('file not found');
} }
// koa send file // koa send file
@@ -241,7 +241,7 @@ export class HistoryController extends CrudController<HistoryService> {
history = await this.service.getLastHistory(pipelineId); history = await this.service.getLastHistory(pipelineId);
} }
if (history == null) { if (history == null) {
throw new CommonException('historyId is null'); throw new CommonException('流水线还未运行过');
} }
const {projectId} = await this.getProjectUserIdRead() const {projectId} = await this.getProjectUserIdRead()
if (projectId) { if (projectId) {
@@ -199,6 +199,12 @@ export class LoginService {
return this.generateToken(info); return this.generateToken(info);
} }
writeTokenCookie(ctx:any,token: { expire: any; token: any }) {
ctx.cookies.set("certd_token", token.token, {
maxAge: 1000 * token.expire
});
}
/** /**
* 生成token * 生成token
@@ -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,41 @@ 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,
isTemplate: false
}) })
.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,
isTemplate: false
}) })
.groupBy("disabled") .groupBy("disabled")
.getRawMany(); .getRawMany();
@@ -866,7 +872,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 +881,9 @@ export class PipelineService extends BaseService<PipelineEntity> {
}, },
where: { where: {
userId, userId,
disabled: false disabled: false,
projectId,
isTemplate: false
} }
}); });
await this.fillLastVars(list); await this.fillLastVars(list);
@@ -897,7 +905,8 @@ export class PipelineService extends BaseService<PipelineEntity> {
.addSelect("COUNT(1) AS count") .addSelect("COUNT(1) AS count")
.where({ .where({
// 0点 // 0点
createTime: MoreThan(todayEnd.add(-param.days, "day").toDate()) createTime: MoreThan(todayEnd.add(-param.days, "day").toDate()),
isTemplate: false
}) })
.groupBy("date") .groupBy("date")
.getRawMany(); .getRawMany();