From f78ae93eedfe214008c3d071ca3d77c962137a64 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Mon, 5 Aug 2024 12:49:44 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BF=AE=E5=A4=8D=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95=E6=B2=A1=E6=9C=89=E5=88=A0?= =?UTF-8?q?=E9=99=A4log=E7=9A=84bug=EF=BC=8C=E6=96=B0=E5=A2=9Ehistory?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E9=A1=B5=E9=9D=A2=EF=BC=8C=E6=BC=94=E7=A4=BA?= =?UTF-8?q?=E7=AB=99=E7=82=B9=E5=90=AF=E5=8A=A8=E6=97=B6=E4=B8=8D=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=90=AF=E5=8A=A8=E9=9D=9E=E7=AE=A1=E7=90=86=E5=91=98?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=9A=84=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../certd-client/src/api/modules/api.basic.ts | 6 +- .../certd-client/src/api/modules/api.user.ts | 1 + .../src/router/source/modules/certd.ts | 9 + .../src/store/modules/settings.ts | 20 +-- .../ui/certd-client/src/store/modules/user.ts | 3 + .../src/views/certd/history/api.ts | 59 +++++++ .../src/views/certd/history/crud.tsx | 154 ++++++++++++++++++ .../src/views/certd/history/index.vue | 51 ++++++ .../src/views/certd/pipeline/crud.tsx | 21 ++- .../src/views/framework/login/index.vue | 25 ++- .../src/views/framework/register/index.vue | 14 +- .../src/views/sys/settings/api.ts | 17 +- .../src/views/sys/settings/index.vue | 32 +++- .../certd-server/src/basic/base-controller.ts | 2 +- .../certd-server/src/middleware/authority.ts | 14 +- .../modules/authority/service/auth-service.ts | 38 +++++ .../{pipeline => }/auto/auto-register-cron.ts | 9 +- .../pipeline/controller/history-controller.ts | 50 ++++-- .../controller/pipeline-controller.ts | 24 ++- .../src/modules/pipeline/entity/history.ts | 9 + .../pipeline/service/history-log-service.ts | 9 +- .../pipeline/service/history-service.ts | 24 ++- .../pipeline/service/pipeline-service.ts | 39 +++-- .../controller/sys-settings-controller.ts | 8 + .../src/modules/system/service/models.ts | 1 + 25 files changed, 562 insertions(+), 77 deletions(-) create mode 100644 packages/ui/certd-client/src/views/certd/history/api.ts create mode 100644 packages/ui/certd-client/src/views/certd/history/crud.tsx create mode 100644 packages/ui/certd-client/src/views/certd/history/index.vue create mode 100644 packages/ui/certd-server/src/modules/authority/service/auth-service.ts rename packages/ui/certd-server/src/modules/{pipeline => }/auto/auto-register-cron.ts (79%) diff --git a/packages/ui/certd-client/src/api/modules/api.basic.ts b/packages/ui/certd-client/src/api/modules/api.basic.ts index 9ace67f6..efc433d7 100644 --- a/packages/ui/certd-client/src/api/modules/api.basic.ts +++ b/packages/ui/certd-client/src/api/modules/api.basic.ts @@ -1,9 +1,9 @@ import { request } from "../service"; export type SysPublicSetting = { - registerEnabled:boolean -} - + registerEnabled: boolean; + managerOtherUserPipeline: boolean; +}; export async function getSysPublicSettings(): Promise { return await request({ diff --git a/packages/ui/certd-client/src/api/modules/api.user.ts b/packages/ui/certd-client/src/api/modules/api.user.ts index 0befb92d..6eccf47d 100644 --- a/packages/ui/certd-client/src/api/modules/api.user.ts +++ b/packages/ui/certd-client/src/api/modules/api.user.ts @@ -18,6 +18,7 @@ export interface UserInfoRes { id: string | number; username: string; nickName: string; + roles: number[]; } export interface LoginRes { diff --git a/packages/ui/certd-client/src/router/source/modules/certd.ts b/packages/ui/certd-client/src/router/source/modules/certd.ts index e14b7ad5..740e2bfe 100644 --- a/packages/ui/certd-client/src/router/source/modules/certd.ts +++ b/packages/ui/certd-client/src/router/source/modules/certd.ts @@ -27,6 +27,15 @@ export const certdResources = [ isMenu: false } }, + { + title: "执行历史记录", + name: "pipelineHistory", + path: "/certd/history", + component: "/certd/history/index.vue", + meta: { + icon: "ion:timer-outline" + } + }, { title: "授权管理", name: "access", diff --git a/packages/ui/certd-client/src/store/modules/settings.ts b/packages/ui/certd-client/src/store/modules/settings.ts index daed894e..7147dc9a 100644 --- a/packages/ui/certd-client/src/store/modules/settings.ts +++ b/packages/ui/certd-client/src/store/modules/settings.ts @@ -4,9 +4,8 @@ import _ from "lodash-es"; // @ts-ignore import { LocalStorage } from "/src/utils/util.storage"; +import * as basicApi from "/@/api/modules/api.basic"; import { SysPublicSetting } from "/@/api/modules/api.basic"; -import * as basicApi from '/@/api/modules/api.basic' -import _ from "lodash-es"; export type ThemeToken = { token: { @@ -21,7 +20,7 @@ export type ThemeConfig = { export interface SettingState { themeConfig?: ThemeConfig; themeToken: ThemeToken; - sysPublic?: SysPublicSetting + sysPublic?: SysPublicSetting; } const defaultThemeConfig = { @@ -38,21 +37,22 @@ export const useSettingStore = defineStore({ algorithm: theme.defaultAlgorithm }, sysPublic: { - registerEnabled: false + registerEnabled: false, + managerOtherUserPipeline: false } }), getters: { getThemeConfig(): any { return this.themeConfig || _.merge({}, defaultThemeConfig, LocalStorage.get(SETTING_THEME_KEY) || {}); }, - getSysPublic():SysPublicSetting{ - return this.sysPublic + getSysPublic(): SysPublicSetting { + return this.sysPublic; } }, actions: { - async loadSysSettings(){ - const settings = await basicApi.getSysPublicSettings() - _.merge(this.sysPublic,settings) + async loadSysSettings() { + const settings = await basicApi.getSysPublicSettings(); + _.merge(this.sysPublic, settings); }, persistThemeConfig() { LocalStorage.set(SETTING_THEME_KEY, this.getThemeConfig); @@ -92,7 +92,7 @@ export const useSettingStore = defineStore({ }, async init() { await this.setThemeConfig(this.getThemeConfig); - await this.loadSysSettings() + await this.loadSysSettings(); } } }); diff --git a/packages/ui/certd-client/src/store/modules/user.ts b/packages/ui/certd-client/src/store/modules/user.ts index 00115e8b..bf0092f2 100644 --- a/packages/ui/certd-client/src/store/modules/user.ts +++ b/packages/ui/certd-client/src/store/modules/user.ts @@ -34,6 +34,9 @@ export const useUserStore = defineStore({ }, getToken(): string { return this.token || LocalStorage.get(TOKEN_KEY); + }, + isAdmin(): boolean { + return this.getUserInfo?.id === 1; } }, actions: { diff --git a/packages/ui/certd-client/src/views/certd/history/api.ts b/packages/ui/certd-client/src/views/certd/history/api.ts new file mode 100644 index 00000000..bd6a11de --- /dev/null +++ b/packages/ui/certd-client/src/views/certd/history/api.ts @@ -0,0 +1,59 @@ +import { request } from "/src/api/service"; + +const apiPrefix = "/pi/history"; + +export function GetList(query: any) { + return request({ + url: apiPrefix + "/page", + method: "post", + data: query + }); +} + +export function AddObj(obj: any) { + return request({ + url: apiPrefix + "/add", + method: "post", + data: obj + }); +} + +export function UpdateObj(obj: any) { + return request({ + url: apiPrefix + "/update", + method: "post", + data: obj + }); +} + +export function DelObj(id: any) { + return request({ + url: apiPrefix + "/delete", + method: "post", + params: { id } + }); +} + +export function GetObj(id: any) { + return request({ + url: apiPrefix + "/info", + method: "post", + params: { id } + }); +} + +export function GetDetail(id: any) { + return request({ + url: apiPrefix + "/detail", + method: "post", + params: { id } + }); +} + +export function DeleteBatch(ids: any[]) { + return request({ + url: apiPrefix + "/deleteByIds", + method: "post", + data: { ids } + }); +} diff --git a/packages/ui/certd-client/src/views/certd/history/crud.tsx b/packages/ui/certd-client/src/views/certd/history/crud.tsx new file mode 100644 index 00000000..d2b0edca --- /dev/null +++ b/packages/ui/certd-client/src/views/certd/history/crud.tsx @@ -0,0 +1,154 @@ +import * as api from "./api"; +import { useI18n } from "vue-i18n"; +import { computed, Ref, ref } from "vue"; +import { useRouter } from "vue-router"; +import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, EditReq, UserPageQuery, UserPageRes, utils } from "@fast-crud/fast-crud"; +import { useUserStore } from "/@/store/modules/user"; +import { useSettingStore } from "/@/store/modules/settings"; + +export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet { + const router = useRouter(); + const { t } = useI18n(); + const pageRequest = async (query: UserPageQuery): Promise => { + return await api.GetList(query); + }; + const editRequest = async ({ form, row }: EditReq) => { + form.id = row.id; + const res = await api.UpdateObj(form); + return res; + }; + const delRequest = async ({ row }: DelReq) => { + return await api.DelObj(row.id); + }; + + const addRequest = async ({ form }: AddReq) => { + form.content = JSON.stringify({ + title: form.title + }); + const res = await api.AddObj(form); + return res; + }; + + const userStore = useUserStore(); + const settingStore = useSettingStore(); + const selectedRowKeys: Ref = ref([]); + context.selectedRowKeys = selectedRowKeys; + + return { + crudOptions: { + settings: { + plugins: { + //这里使用行选择插件,生成行选择crudOptions配置,最终会与crudOptions合并 + rowSelection: { + enabled: true, + order: -2, + before: true, + // handle: (pluginProps,useCrudProps)=>CrudOptions, + props: { + multiple: true, + crossPage: true, + selectedRowKeys + } + } + } + }, + request: { + pageRequest, + addRequest, + editRequest, + delRequest + }, + actionbar: { + buttons: { + add: { + show: false + } + } + }, + rowHandle: { + minWidth: 200, + fixed: "right", + buttons: { + edit: { + show: false + } + } + }, + columns: { + id: { + title: "ID", + key: "id", + type: "number", + column: { + width: 100 + }, + form: { + show: false + } + }, + userId: { + title: "用户Id", + type: "number", + search: { + show: computed(() => { + return userStore.isAdmin && settingStore.sysPublic.managerOtherUserPipeline; + }) + }, + form: { + show: false + }, + column: { + show: computed(() => { + return userStore.isAdmin && settingStore.sysPublic.managerOtherUserPipeline; + }) + } + }, + pipelineId: { + title: "流水线Id", + type: "number", + search: { + show: true + }, + form: { + show: false + } + }, + pipelineTitle: { + title: "流水线名称", + type: "link", + search: { + show: true, + component: { + name: "a-input" + } + }, + column: { + width: 200 + } + }, + createTime: { + title: "创建时间", + type: "datetime", + form: { + show: false + }, + column: { + sorter: true, + width: 125, + align: "center" + } + }, + updateTime: { + title: "更新时间", + type: "datetime", + form: { + show: false + }, + column: { + show: true + } + } + } + } + }; +} diff --git a/packages/ui/certd-client/src/views/certd/history/index.vue b/packages/ui/certd-client/src/views/certd/history/index.vue new file mode 100644 index 00000000..40f74b36 --- /dev/null +++ b/packages/ui/certd-client/src/views/certd/history/index.vue @@ -0,0 +1,51 @@ + + + + diff --git a/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx b/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx index f9cb7403..6d467fdb 100644 --- a/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx +++ b/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx @@ -1,6 +1,6 @@ import * as api from "./api"; import { useI18n } from "vue-i18n"; -import { ref } from "vue"; +import { computed, ref } from "vue"; import { useRouter } from "vue-router"; import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, dict, EditReq, UserPageQuery, UserPageRes } from "@fast-crud/fast-crud"; import { statusUtil } from "/@/views/certd/pipeline/pipeline/utils/util.status"; @@ -9,6 +9,7 @@ import { message, Modal } from "ant-design-vue"; import { env } from "/@/utils/util.env"; import { useUserStore } from "/@/store/modules/user"; import dayjs from "dayjs"; +import { useSettingStore } from "/@/store/modules/settings"; export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOptionsProps): CreateCrudOptionsRet { const router = useRouter(); @@ -94,6 +95,7 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp }); } const userStore = useUserStore(); + const settingStore = useSettingStore(); return { crudOptions: { request: { @@ -192,6 +194,23 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp show: false } }, + userId: { + title: "用户Id", + type: "number", + search: { + show: computed(() => { + return userStore.isAdmin && settingStore.sysPublic.managerOtherUserPipeline; + }) + }, + form: { + show: false + }, + column: { + show: computed(() => { + return userStore.isAdmin && settingStore.sysPublic.managerOtherUserPipeline; + }) + } + }, title: { title: "流水线名称", type: "link", diff --git a/packages/ui/certd-client/src/views/framework/login/index.vue b/packages/ui/certd-client/src/views/framework/login/index.vue index a5d31932..238b672b 100644 --- a/packages/ui/certd-client/src/views/framework/login/index.vue +++ b/packages/ui/certd-client/src/views/framework/login/index.vue @@ -1,6 +1,15 @@