From bd38076d402f259650e1b9a8ce6887d075446332 Mon Sep 17 00:00:00 2001 From: ziye <278898052@qq.com> Date: Tue, 6 May 2025 21:07:31 +0800 Subject: [PATCH 1/8] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=88=86=E7=BB=84=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/api/bpm/userGroup/index.ts | 53 ++++++ apps/web-antd/src/views/bpm/group/data.ts | 171 ++++++++++++++++++ apps/web-antd/src/views/bpm/group/index.vue | 159 +++++++++++++--- .../src/views/bpm/group/modules/form.vue | 91 ++++++++++ 4 files changed, 451 insertions(+), 23 deletions(-) create mode 100644 apps/web-antd/src/api/bpm/userGroup/index.ts create mode 100644 apps/web-antd/src/views/bpm/group/data.ts create mode 100644 apps/web-antd/src/views/bpm/group/modules/form.vue diff --git a/apps/web-antd/src/api/bpm/userGroup/index.ts b/apps/web-antd/src/api/bpm/userGroup/index.ts new file mode 100644 index 00000000..f4c50f8b --- /dev/null +++ b/apps/web-antd/src/api/bpm/userGroup/index.ts @@ -0,0 +1,53 @@ +import type { PageParam, PageResult } from '@vben/request'; + +import { requestClient } from '#/api/request'; + +export namespace BpmUserGroupApi { + /** BPM 用户组 VO */ + export interface UserGroupVO { + id: number; + name: string; + description: string; + userIds: number[]; + status: number; + remark: string; + createTime: string; + } +} + +/** 查询用户组分页 */ +export async function getUserGroupPage(params: PageParam) { + return requestClient.get>( + '/bpm/user-group/page', + { params }, + ); +} + +/** 查询用户组详情 */ +export async function getUserGroup(id: number) { + return requestClient.get( + `/bpm/user-group/get?id=${id}`, + ); +} + +/** 新增用户组 */ +export async function createUserGroup(data: BpmUserGroupApi.UserGroupVO) { + return requestClient.post('/bpm/user-group/create', data); +} + +/** 修改用户组 */ +export async function updateUserGroup(data: BpmUserGroupApi.UserGroupVO) { + return requestClient.put('/bpm/user-group/update', data); +} + +/** 删除用户组 */ +export async function deleteUserGroup(id: number) { + return requestClient.delete(`/bpm/user-group/delete?id=${id}`); +} + +/** 查询用户组列表 */ +export async function getUserGroupSimpleList() { + return requestClient.get( + `/bpm/user-group/simple-list`, + ); +} diff --git a/apps/web-antd/src/views/bpm/group/data.ts b/apps/web-antd/src/views/bpm/group/data.ts new file mode 100644 index 00000000..58c0b928 --- /dev/null +++ b/apps/web-antd/src/views/bpm/group/data.ts @@ -0,0 +1,171 @@ +import type { VbenFormSchema } from '#/adapter/form'; +import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; +import type { BpmCategoryApi } from '#/api/bpm/category'; + +import { useAccess } from '@vben/access'; + +import { z } from '#/adapter/form'; +import { getSimpleUserList } from '#/api/system/user'; +import { CommonStatusEnum } from '#/utils/constants'; +import { DICT_TYPE, getDictOptions } from '#/utils/dict'; + +const { hasAccessByCodes } = useAccess(); +/** 新增/修改的表单 */ +export function useFormSchema(): VbenFormSchema[] { + return [ + { + fieldName: 'id', + component: 'Input', + dependencies: { + triggerFields: [''], + show: () => false, + }, + }, + { + fieldName: 'name', + label: '组名', + component: 'Input', + componentProps: { + placeholder: '请输入组名', + }, + rules: 'required', + }, + { + fieldName: 'description', + label: '描述', + component: 'Textarea', + componentProps: { + placeholder: '请输入描述', + }, + }, + { + fieldName: 'userIds', + label: '成员', + component: 'ApiSelect', + componentProps: { + placeholder: '请选择成员', + api: getSimpleUserList, + labelField: 'nickname', + valueField: 'id', + mode: 'tags', + }, + rules: z.array(z.number()).min(1, '请选择成员').default([]), + }, + { + fieldName: 'status', + label: '状态', + component: 'RadioGroup', + componentProps: { + options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), + buttonStyle: 'solid', + optionType: 'button', + }, + rules: z.number().default(CommonStatusEnum.ENABLE), + }, + ]; +} + +/** 列表的搜索表单 */ +export function useGridFormSchema(): VbenFormSchema[] { + return [ + { + fieldName: 'name', + label: '组名', + component: 'Input', + componentProps: { + placeholder: '请输入组名', + allowClear: true, + }, + }, + { + fieldName: 'status', + label: '状态', + component: 'Select', + componentProps: { + placeholder: '请选择状态', + options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), + allowClear: true, + }, + }, + { + fieldName: 'createTime', + label: '创建时间', + component: 'RangePicker', + componentProps: { + placeholder: ['开始时间', '结束时间'], + allowClear: true, + }, + }, + ]; +} + +/** 列表的字段 */ +export function useGridColumns( + onActionClick: OnActionClickFn, +): VxeTableGridOptions['columns'] { + return [ + { + field: 'id', + title: '分类编号', + minWidth: 100, + }, + { + field: 'name', + title: '组名', + minWidth: 200, + }, + { + field: 'description', + title: '描述', + minWidth: 200, + }, + { + field: 'userIds', + title: '成员', + minWidth: 200, + slots: { + default: 'userIds-cell', + }, + }, + { + field: 'status', + title: '状态', + minWidth: 100, + cellRender: { + name: 'CellDict', + props: { type: DICT_TYPE.COMMON_STATUS }, + }, + }, + { + field: 'createTime', + title: '创建时间', + minWidth: 180, + formatter: 'formatDateTime', + }, + { + field: 'operation', + title: '操作', + minWidth: 180, + align: 'center', + fixed: 'right', + cellRender: { + attrs: { + nameField: 'name', + nameTitle: '用户分组', + onClick: onActionClick, + }, + name: 'CellOperation', + options: [ + { + code: 'edit', + show: hasAccessByCodes(['bpm:user-group:update']), + }, + { + code: 'delete', + show: hasAccessByCodes(['bpm:user-group:delete']), + }, + ], + }, + }, + ]; +} diff --git a/apps/web-antd/src/views/bpm/group/index.vue b/apps/web-antd/src/views/bpm/group/index.vue index 98675eed..85d63697 100644 --- a/apps/web-antd/src/views/bpm/group/index.vue +++ b/apps/web-antd/src/views/bpm/group/index.vue @@ -1,31 +1,144 @@ diff --git a/apps/web-antd/src/views/bpm/group/modules/form.vue b/apps/web-antd/src/views/bpm/group/modules/form.vue new file mode 100644 index 00000000..374d43ef --- /dev/null +++ b/apps/web-antd/src/views/bpm/group/modules/form.vue @@ -0,0 +1,91 @@ + + + From 413ed3526d968567029410c844d7005c9c4052c4 Mon Sep 17 00:00:00 2001 From: ziye <278898052@qq.com> Date: Tue, 6 May 2025 21:15:14 +0800 Subject: [PATCH 2/8] =?UTF-8?q?refactor:=20=E4=BF=AE=E6=94=B9=E5=88=86?= =?UTF-8?q?=E7=B1=BB=E7=BC=96=E5=8F=B7=E6=A0=87=E9=A2=98=E4=B8=BA=E2=80=9C?= =?UTF-8?q?=E7=BC=96=E5=8F=B7=E2=80=9D=E4=BB=A5=E6=8F=90=E5=8D=87=E4=B8=80?= =?UTF-8?q?=E8=87=B4=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/views/bpm/group/data.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web-antd/src/views/bpm/group/data.ts b/apps/web-antd/src/views/bpm/group/data.ts index 58c0b928..58da1944 100644 --- a/apps/web-antd/src/views/bpm/group/data.ts +++ b/apps/web-antd/src/views/bpm/group/data.ts @@ -106,7 +106,7 @@ export function useGridColumns( return [ { field: 'id', - title: '分类编号', + title: '编号', minWidth: 100, }, { From b724ca2917856c81221dfcd06fbe46a0a2d943b2 Mon Sep 17 00:00:00 2001 From: xingyu4j Date: Tue, 6 May 2025 21:35:10 +0800 Subject: [PATCH 3/8] =?UTF-8?q?feat:=20=E5=88=A0=E9=99=A4=E5=B7=B2?= =?UTF-8?q?=E7=BB=8F=E8=BF=81=E7=A7=BBvben/utils=20=E4=B8=8B=E7=9A=84?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/utils/TimeUtils.ts | 47 ---------- apps/web-antd/src/utils/date.ts | 42 --------- apps/web-antd/src/utils/download.ts | 127 --------------------------- apps/web-antd/src/utils/tree.ts | 71 --------------- 4 files changed, 287 deletions(-) delete mode 100644 apps/web-antd/src/utils/TimeUtils.ts delete mode 100644 apps/web-antd/src/utils/date.ts delete mode 100644 apps/web-antd/src/utils/download.ts delete mode 100644 apps/web-antd/src/utils/tree.ts diff --git a/apps/web-antd/src/utils/TimeUtils.ts b/apps/web-antd/src/utils/TimeUtils.ts deleted file mode 100644 index 8c45beda..00000000 --- a/apps/web-antd/src/utils/TimeUtils.ts +++ /dev/null @@ -1,47 +0,0 @@ -// 迁移至 packages/@core/base/shared/src/utils/time.ts -import dayjs from 'dayjs'; - -/** 时间段选择器拓展 */ -export const rangePickerExtend = () => { - return { - showTime: { - format: 'HH:mm:ss', - defaultValue: [ - dayjs('00:00:00', 'HH:mm:ss'), - dayjs('23:59:59', 'HH:mm:ss'), - ], - }, - // 如果需要10位时间戳(秒级)可以使用 valueFormat: 'X' - valueFormat: 'YYYY-MM-DD HH:mm:ss', - format: 'YYYY-MM-DD HH:mm:ss', // 显示格式 - placeholder: ['开始时间', '结束时间'], - ranges: { - 今天: [dayjs().startOf('day'), dayjs().endOf('day')], - - 昨天: [ - dayjs().subtract(1, 'day').startOf('day'), - dayjs().subtract(1, 'day').endOf('day'), - ], - - 本周: [dayjs().startOf('week'), dayjs().endOf('day')], - - 本月: [dayjs().startOf('month'), dayjs().endOf('day')], - - 最近7天: [ - dayjs().subtract(7, 'day').startOf('day'), - dayjs().endOf('day'), - ], - - 最近30天: [ - dayjs().subtract(30, 'day').startOf('day'), - dayjs().endOf('day'), - ], - }, - transformDateFunc: (dates: any) => { - if (dates && dates.length === 2) { - return [dates.createTime[0], dates.createTime[1]].join(','); // 格式化为后台支持的时间格式 - } - return {}; - }, - }; -}; diff --git a/apps/web-antd/src/utils/date.ts b/apps/web-antd/src/utils/date.ts deleted file mode 100644 index 227cf762..00000000 --- a/apps/web-antd/src/utils/date.ts +++ /dev/null @@ -1,42 +0,0 @@ -import dayjs from 'dayjs'; - -// TODO @芋艿:后续整理下 迁移至 packages/core/base/shared/src/utils/date.ts,后续删除 使用 @vben/utils 的 getRangePickerDefaultProps - -/** 时间段选择器拓展 */ -export function getRangePickerDefaultProps(): any { - return { - showTime: { - format: 'HH:mm:ss', - defaultValue: [ - dayjs('00:00:00', 'HH:mm:ss'), - dayjs('23:59:59', 'HH:mm:ss'), - ], - }, - valueFormat: 'YYYY-MM-DD HH:mm:ss', - format: 'YYYY-MM-DD HH:mm:ss', - placeholder: ['开始时间', '结束时间'], - ranges: { - 今天: [dayjs().startOf('day'), dayjs().endOf('day')], - 昨天: [ - dayjs().subtract(1, 'day').startOf('day'), - dayjs().subtract(1, 'day').endOf('day'), - ], - 本周: [dayjs().startOf('week'), dayjs().endOf('day')], - 本月: [dayjs().startOf('month'), dayjs().endOf('day')], - '最近 7 天': [ - dayjs().subtract(7, 'day').startOf('day'), - dayjs().endOf('day'), - ], - '最近 30 天': [ - dayjs().subtract(30, 'day').startOf('day'), - dayjs().endOf('day'), - ], - }, - transformDateFunc: (dates: any) => { - if (dates && dates.length === 2) { - return [dates.createTime[0], dates.createTime[1]].join(','); // 格式化为后台支持的时间格式 - } - return {}; - }, - }; -} diff --git a/apps/web-antd/src/utils/download.ts b/apps/web-antd/src/utils/download.ts deleted file mode 100644 index 2fc2989b..00000000 --- a/apps/web-antd/src/utils/download.ts +++ /dev/null @@ -1,127 +0,0 @@ -// TODO @芋艿:需要优化下每个方法 -// TODO @芋艿:是不是可以共用么? -// 后续使用 packages/core/base/shared/src/utils/download.ts 下的方法 -import { dataURLtoBlob, urlToBase64 } from './base64Conver'; - -/** - * Download online pictures - * @param url - * @param filename - * @param mime - * @param bom - */ -export function downloadByOnlineUrl( - url: string, - filename: string, - mime?: string, - bom?: BlobPart, -) { - urlToBase64(url).then((base64) => { - downloadByBase64(base64, filename, mime, bom); - }); -} - -/** - * Download pictures based on base64 - * @param buf - * @param filename - * @param mime - * @param bom - */ -export function downloadByBase64( - buf: string, - filename: string, - mime?: string, - bom?: BlobPart, -) { - const base64Buf = dataURLtoBlob(buf); - downloadByData(base64Buf, filename, mime, bom); -} - -/** - * Download according to the background interface file stream - * @param {*} data - * @param {*} filename - * @param {*} mime - * @param {*} bom - */ -export function downloadByData( - data: BlobPart, - filename: string, - mime?: string, - bom?: BlobPart, -) { - const blobData = bom === undefined ? [data] : [bom, data]; - const blob = new Blob(blobData, { type: mime || 'application/octet-stream' }); - - const blobURL = window.URL.createObjectURL(blob); - const tempLink = document.createElement('a'); - tempLink.style.display = 'none'; - tempLink.href = blobURL; - tempLink.setAttribute('download', filename); - if (tempLink.download === undefined) - tempLink.setAttribute('target', '_blank'); - - document.body.append(tempLink); - tempLink.click(); - tempLink.remove(); - window.URL.revokeObjectURL(blobURL); -} - -/** - * Download file according to file address - * @param {*} sUrl - */ -export function downloadByUrl({ - url, - target = '_blank', - fileName, -}: { - fileName?: string; - target?: '_blank' | '_self'; - url: string; -}): boolean { - const isChrome = window.navigator.userAgent.toLowerCase().includes('chrome'); - const isSafari = window.navigator.userAgent.toLowerCase().includes('safari'); - - if (/iP/.test(window.navigator.userAgent)) { - console.error('Your browser does not support download!'); - return false; - } - if (isChrome || isSafari) { - const link = document.createElement('a'); - link.href = url; - link.target = target; - - if (link.download !== undefined) - link.download = fileName || url.slice(url.lastIndexOf('/') + 1); - - if (document.createEvent) { - const e = document.createEvent('MouseEvents'); - e.initEvent('click', true, true); - link.dispatchEvent(e); - return true; - } - } - if (!url.includes('?')) url += '?download'; - - openWindow(url, { target }); - return true; -} - -export function openWindow( - url: string, - opt?: { - noopener?: boolean; - noreferrer?: boolean; - target?: '_blank' | '_self' | string; - }, -) { - const { noopener = true, noreferrer = true, target = '__blank' } = opt || {}; - const feature: string[] = []; - - noopener && feature.push('noopener=yes'); - noreferrer && feature.push('noreferrer=yes'); - - window.open(url, target, feature.join(',')); -} diff --git a/apps/web-antd/src/utils/tree.ts b/apps/web-antd/src/utils/tree.ts deleted file mode 100644 index 3dda8965..00000000 --- a/apps/web-antd/src/utils/tree.ts +++ /dev/null @@ -1,71 +0,0 @@ -// todo @芋艿:公用逻辑 -// 已迁移,后续使用 packages/core/base/shared/src/utils/tree.ts 下的方法 -interface TreeNode { - [key: string]: any; - children?: TreeNode[]; -} - -/** - * 构造树型结构数据 - * - * @param {*} data 数据源 - * @param {*} id id字段 默认 'id' - * @param {*} parentId 父节点字段 默认 'parentId' - * @param {*} children 孩子节点字段 默认 'children' - */ -export const handleTree = ( - data: TreeNode[], - id: string = 'id', - parentId: string = 'parentId', - children: string = 'children', -): TreeNode[] => { - if (!Array.isArray(data)) { - console.warn('data must be an array'); - return []; - } - const config = { - id, - parentId, - childrenList: children, - }; - const childrenListMap: Record = {}; - const nodeIds: Record = {}; - const tree: TreeNode[] = []; - - // 1. 数据预处理 - // 1.1 第一次遍历,生成 childrenListMap 和 nodeIds 映射 - for (const d of data) { - const pId = d[config.parentId]; - if (childrenListMap[pId] === undefined) { - childrenListMap[pId] = []; - } - nodeIds[d[config.id]] = d; - childrenListMap[pId].push(d); - } - // 1.2 第二次遍历,找出根节点 - for (const d of data) { - const pId = d[config.parentId]; - if (nodeIds[pId] === undefined) { - tree.push(d); - } - } - - // 2. 构建树结:递归构建子节点 - const adaptToChildrenList = (node: TreeNode): void => { - const nodeId = node[config.id]; - if (childrenListMap[nodeId]) { - node[config.childrenList] = childrenListMap[nodeId]; - // 递归处理子节点 - for (const child of node[config.childrenList]) { - adaptToChildrenList(child); - } - } - }; - - // 3. 从根节点开始构建完整树 - for (const rootNode of tree) { - adaptToChildrenList(rootNode); - } - - return tree; -}; From d92972ba3eead714d65fbbf2cf4a67ff51083547 Mon Sep 17 00:00:00 2001 From: xingyu4j Date: Tue, 6 May 2025 21:38:46 +0800 Subject: [PATCH 4/8] =?UTF-8?q?perf:=20=E4=BD=BF=E7=94=A8=E5=B0=81?= =?UTF-8?q?=E8=A3=85=E7=9A=84=20confirm=20=E6=9B=BF=E6=8D=A2=20Modal.confi?= =?UTF-8?q?rm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_core/profile/modules/user-social.vue | 22 +++++----- .../src/views/infra/apiErrorLog/index.vue | 21 ++++------ apps/web-antd/src/views/infra/file/index.vue | 3 +- .../src/views/infra/fileConfig/index.vue | 14 +++---- apps/web-antd/src/views/infra/job/index.vue | 34 ++++++---------- apps/web-antd/src/views/system/user/index.vue | 40 ++++++++----------- 6 files changed, 56 insertions(+), 78 deletions(-) diff --git a/apps/web-antd/src/views/_core/profile/modules/user-social.vue b/apps/web-antd/src/views/_core/profile/modules/user-social.vue index b44317af..62f3669a 100644 --- a/apps/web-antd/src/views/_core/profile/modules/user-social.vue +++ b/apps/web-antd/src/views/_core/profile/modules/user-social.vue @@ -5,7 +5,9 @@ import type { SystemSocialUserApi } from '#/api/system/social/user'; import { computed, onMounted, ref } from 'vue'; import { useRoute } from 'vue-router'; -import { Button, Card, Image, message, Modal } from 'ant-design-vue'; +import { confirm } from '@vben/common-ui'; + +import { Button, Card, Image, message } from 'ant-design-vue'; import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { socialAuthRedirect } from '#/api/core/auth'; @@ -102,19 +104,13 @@ const [Grid, gridApi] = useVbenVxeGrid({ /** 解绑账号 */ function onUnbind(row: SystemSocialUserApi.SocialUser) { - Modal.confirm({ - type: 'warning', - title: '提示', + confirm({ content: `确定解绑[${getDictLabel(DICT_TYPE.SYSTEM_SOCIAL_TYPE, row.type)}]平台的[${row.openid}]账号吗?`, - async onOk() { - await socialUnbind({ type: row.type, openid: row.openid }); - // 提示成功 - message.success({ - content: $t('ui.actionMessage.operationSuccess'), - key: 'action_process_msg', - }); - await gridApi.reload(); - }, + }).then(async () => { + await socialUnbind({ type: row.type, openid: row.openid }); + // 提示成功 + message.success($t('ui.actionMessage.operationSuccess')); + await gridApi.reload(); }); } diff --git a/apps/web-antd/src/views/infra/apiErrorLog/index.vue b/apps/web-antd/src/views/infra/apiErrorLog/index.vue index c649090d..c8ee3736 100644 --- a/apps/web-antd/src/views/infra/apiErrorLog/index.vue +++ b/apps/web-antd/src/views/infra/apiErrorLog/index.vue @@ -5,11 +5,11 @@ import type { } from '#/adapter/vxe-table'; import type { InfraApiErrorLogApi } from '#/api/infra/api-error-log'; -import { Page, useVbenModal } from '@vben/common-ui'; +import { confirm, Page, useVbenModal } from '@vben/common-ui'; import { Download } from '@vben/icons'; import { downloadFileFromBlobPart } from '@vben/utils'; -import { Button, message, Modal } from 'ant-design-vue'; +import { Button, message } from 'ant-design-vue'; import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { @@ -47,18 +47,13 @@ function onDetail(row: InfraApiErrorLogApi.ApiErrorLog) { /** 处理已处理 / 已忽略的操作 */ async function onProcess(id: number, processStatus: number) { - Modal.confirm({ - title: '确认操作', + confirm({ content: `确认标记为${InfraApiErrorLogProcessStatusEnum.DONE ? '已处理' : '已忽略'}?`, - onOk: async () => { - await updateApiErrorLogStatus(id, processStatus); - // 关闭并提示 - message.success({ - content: $t('ui.actionMessage.operationSuccess'), - key: 'action_process_msg', - }); - onRefresh(); - }, + }).then(async () => { + await updateApiErrorLogStatus(id, processStatus); + // 关闭并提示 + message.success($t('ui.actionMessage.operationSuccess')); + onRefresh(); }); } diff --git a/apps/web-antd/src/views/infra/file/index.vue b/apps/web-antd/src/views/infra/file/index.vue index ac0ff543..5383a4dc 100644 --- a/apps/web-antd/src/views/infra/file/index.vue +++ b/apps/web-antd/src/views/infra/file/index.vue @@ -7,6 +7,7 @@ import type { InfraFileApi } from '#/api/infra/file'; import { Page, useVbenModal } from '@vben/common-ui'; import { Upload } from '@vben/icons'; +import { openWindow } from '@vben/utils'; import { useClipboard } from '@vueuse/core'; import { Button, Image, message } from 'ant-design-vue'; @@ -52,7 +53,7 @@ async function onCopyUrl(row: InfraFileApi.File) { /** 打开 URL */ function openUrl(url?: string) { if (url) { - window.open(url, '_blank'); + openWindow(url); } } diff --git a/apps/web-antd/src/views/infra/fileConfig/index.vue b/apps/web-antd/src/views/infra/fileConfig/index.vue index 5c8921ec..1db98faa 100644 --- a/apps/web-antd/src/views/infra/fileConfig/index.vue +++ b/apps/web-antd/src/views/infra/fileConfig/index.vue @@ -5,10 +5,11 @@ import type { } from '#/adapter/vxe-table'; import type { InfraFileConfigApi } from '#/api/infra/file-config'; -import { Page, useVbenModal } from '@vben/common-ui'; +import { confirm, Page, useVbenModal } from '@vben/common-ui'; import { Plus } from '@vben/icons'; +import { openWindow } from '@vben/utils'; -import { Button, message, Modal } from 'ant-design-vue'; +import { Button, message } from 'ant-design-vue'; import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { @@ -72,14 +73,13 @@ async function onTest(row: InfraFileConfigApi.FileConfig) { const response = await testFileConfig(row.id as number); hideLoading(); // 确认是否访问该文件 - Modal.confirm({ + confirm({ title: '测试上传成功', content: '是否要访问该文件?', - okText: '访问', + confirmText: '访问', cancelText: '取消', - onOk: () => { - window.open(response, '_blank'); - }, + }).then(() => { + openWindow(response); }); } catch { hideLoading(); diff --git a/apps/web-antd/src/views/infra/job/index.vue b/apps/web-antd/src/views/infra/job/index.vue index 33036fc4..5d76addb 100644 --- a/apps/web-antd/src/views/infra/job/index.vue +++ b/apps/web-antd/src/views/infra/job/index.vue @@ -7,11 +7,11 @@ import type { InfraJobApi } from '#/api/infra/job'; import { useRouter } from 'vue-router'; -import { Page, useVbenModal } from '@vben/common-ui'; +import { confirm, Page, useVbenModal } from '@vben/common-ui'; import { Download, History, Plus } from '@vben/icons'; import { downloadFileFromBlobPart } from '@vben/utils'; -import { Button, message, Modal } from 'ant-design-vue'; +import { Button, message } from 'ant-design-vue'; import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { @@ -74,32 +74,24 @@ async function onUpdateStatus(row: InfraJobApi.Job) { ? InfraJobStatusEnum.NORMAL : InfraJobStatusEnum.STOP; const statusText = status === InfraJobStatusEnum.NORMAL ? '启用' : '停用'; - Modal.confirm({ - title: '确认操作', + + confirm({ content: `确定${statusText} ${row.name} 吗?`, - onOk: async () => { - await updateJobStatus(row.id as number, status); - message.success({ - content: $t('ui.actionMessage.operationSuccess'), - key: 'action_process_msg', - }); - onRefresh(); - }, + }).then(async () => { + await updateJobStatus(row.id as number, status); + // 提示成功 + message.success($t('ui.actionMessage.operationSuccess')); + onRefresh(); }); } /** 执行一次任务 */ async function onTrigger(row: InfraJobApi.Job) { - Modal.confirm({ - title: '确认操作', + confirm({ content: `确定执行一次 ${row.name} 吗?`, - onOk: async () => { - await runJob(row.id as number); - message.success({ - content: $t('ui.actionMessage.operationSuccess'), - key: 'action_process_msg', - }); - }, + }).then(async () => { + await runJob(row.id as number); + message.success($t('ui.actionMessage.operationSuccess')); }); } diff --git a/apps/web-antd/src/views/system/user/index.vue b/apps/web-antd/src/views/system/user/index.vue index 1609b4bc..90dc7bd9 100644 --- a/apps/web-antd/src/views/system/user/index.vue +++ b/apps/web-antd/src/views/system/user/index.vue @@ -8,11 +8,11 @@ import type { SystemUserApi } from '#/api/system/user'; import { ref } from 'vue'; -import { Page, useVbenModal } from '@vben/common-ui'; +import { confirm, Page, useVbenModal } from '@vben/common-ui'; import { Download, Plus, Upload } from '@vben/icons'; import { downloadFileFromBlobPart } from '@vben/utils'; -import { Button, message, Modal } from 'ant-design-vue'; +import { Button, message } from 'ant-design-vue'; import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { @@ -114,35 +114,29 @@ function onAssignRole(row: SystemUserApi.User) { assignRoleModalApi.setData(row).open(); } -// TODO @芋艿:后续怎么简化一下 confirm 的实现。 /** 更新用户状态 */ async function onStatusChange( newStatus: number, row: SystemUserApi.User, ): Promise { return new Promise((resolve, reject) => { - Modal.confirm({ - title: '切换状态', + confirm({ content: `你要将${row.username}的状态切换为【${getDictLabel(DICT_TYPE.COMMON_STATUS, newStatus)}】吗?`, - onCancel() { - reject(new Error('已取消')); - }, - onOk() { + }) + .then(async () => { // 更新用户状态 - updateUserStatus(row.id as number, newStatus) - .then(() => { - // 提示并返回成功 - message.success({ - content: $t('ui.actionMessage.operationSuccess'), - key: 'action_process_msg', - }); - resolve(true); - }) - .catch((error) => { - reject(error); - }); - }, - }); + const res = await updateUserStatus(row.id as number, newStatus); + if (res) { + // 提示并返回成功 + message.success($t('ui.actionMessage.operationSuccess')); + resolve(true); + } else { + reject(new Error('更新失败')); + } + }) + .catch(() => { + reject(new Error('取消操作')); + }); }); } From 60bd4a13b18c315705149b79a1f40155bae71ba7 Mon Sep 17 00:00:00 2001 From: xingyu4j Date: Tue, 6 May 2025 21:39:25 +0800 Subject: [PATCH 5/8] =?UTF-8?q?perf:=20=E4=BD=BF=E7=94=A8=E5=B0=81?= =?UTF-8?q?=E8=A3=85=E7=9A=84vben/utils=E5=B7=A5=E5=85=B7=E7=B1=BB=20?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=20windows.open?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/components/doc-alert/doc-alert.vue | 3 ++- apps/web-antd/src/layouts/components/help.vue | 5 +---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/apps/web-antd/src/components/doc-alert/doc-alert.vue b/apps/web-antd/src/components/doc-alert/doc-alert.vue index d44d557f..8df45454 100644 --- a/apps/web-antd/src/components/doc-alert/doc-alert.vue +++ b/apps/web-antd/src/components/doc-alert/doc-alert.vue @@ -1,5 +1,6 @@ diff --git a/apps/web-antd/src/layouts/components/help.vue b/apps/web-antd/src/layouts/components/help.vue index 5e4647d8..dea84d5f 100644 --- a/apps/web-antd/src/layouts/components/help.vue +++ b/apps/web-antd/src/layouts/components/help.vue @@ -1,5 +1,6 @@