diff --git a/apps/web-antd/src/components/upload/use-upload.ts b/apps/web-antd/src/components/upload/use-upload.ts index a11727c6e..7b9b4ca66 100644 --- a/apps/web-antd/src/components/upload/use-upload.ts +++ b/apps/web-antd/src/components/upload/use-upload.ts @@ -4,7 +4,7 @@ import type { AxiosProgressEvent, InfraFileApi } from '#/api/infra/file'; import { computed, unref } from 'vue'; import { $t } from '@vben/locales'; import CryptoJS from 'crypto-js' -import axios from 'axios' +import { baseRequestClient } from '#/api/request'; import { uploadFile, getFilePresignedUrl, createFile } from '#/api/infra/file'; export function useUploadType({ @@ -78,7 +78,7 @@ export const useUpload = () => { // 1.2 获取文件预签名地址 const presignedInfo = await getFilePresignedUrl(fileName) // 1.3 上传文件 - return axios + return baseRequestClient .put(presignedInfo.uploadUrl, file, { headers: { 'Content-Type': file.type diff --git a/apps/web-antd/src/views/system/dept/data.ts b/apps/web-antd/src/views/system/dept/data.ts index 1f3c3d691..ce12f4cd3 100644 --- a/apps/web-antd/src/views/system/dept/data.ts +++ b/apps/web-antd/src/views/system/dept/data.ts @@ -3,6 +3,7 @@ import type { VxeTableGridOptions } from '@vben/plugins/vxe-table'; import type { VbenFormSchema } from '#/adapter/form'; import type { OnActionClickFn } from '#/adapter/vxe-table'; import type { SystemDeptApi } from '#/api/system/dept'; +import type { SystemUserApi } from '#/api/system/user'; import { useAccess } from '@vben/access'; @@ -122,9 +123,9 @@ export function useFormSchema(): VbenFormSchema[] { } /** 列表的字段 */ -const userList = await getSimpleUserList(); export function useGridColumns( onActionClick?: OnActionClickFn, + getLeaderName?: (userId: number) => string | undefined, ): VxeTableGridOptions['columns'] { return [ { @@ -140,9 +141,7 @@ export function useGridColumns( title: '负责人', minWidth: 150, formatter: (row) => { - return ( - userList.find((user) => user.id === row.cellValue)?.nickname || '-' - ); + return getLeaderName?.(row.cellValue) || '-'; }, }, { diff --git a/apps/web-antd/src/views/system/dept/index.vue b/apps/web-antd/src/views/system/dept/index.vue index b790d2dec..f15cabd34 100644 --- a/apps/web-antd/src/views/system/dept/index.vue +++ b/apps/web-antd/src/views/system/dept/index.vue @@ -4,8 +4,9 @@ import type { VxeTableGridOptions, } from '#/adapter/vxe-table'; import type { SystemDeptApi } from '#/api/system/dept'; +import type { SystemUserApi } from '#/api/system/user'; -import { ref } from 'vue'; +import { onMounted, ref } from 'vue'; import { Page, useVbenModal } from '@vben/common-ui'; import { Plus } from '@vben/icons'; @@ -14,6 +15,7 @@ import { Button, message } from 'ant-design-vue'; import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { deleteDept, getDeptList } from '#/api/system/dept'; +import { getSimpleUserList } from '#/api/system/user'; import { $t } from '#/locales'; import { useGridColumns } from './data'; @@ -24,6 +26,13 @@ const [FormModal, formModalApi] = useVbenModal({ destroyOnClose: true, }); +const userList = ref([]); + +/** 获取负责人名称 */ +const getLeaderName = (userId: number) => { + return userList.value.find((user) => user.id === userId)?.nickname; +}; + /** 刷新表格 */ function onRefresh() { gridApi.query(); @@ -93,7 +102,7 @@ function onActionClick({ const [Grid, gridApi] = useVbenVxeGrid({ gridOptions: { - columns: useGridColumns(onActionClick), + columns: useGridColumns(onActionClick, getLeaderName), height: 'auto', keepSource: true, pagerConfig: { @@ -121,6 +130,11 @@ const [Grid, gridApi] = useVbenVxeGrid({ }, } as VxeTableGridOptions, }); + +/** 初始化 */ +onMounted(async () => { + userList.value = await getSimpleUserList(); +});