From b858b35bc95d737b1ed2b5ef516d32fa649b6d2f Mon Sep 17 00:00:00 2001 From: Bunny <1319900154@qq.com> Date: Wed, 27 Nov 2024 23:14:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=9A=80=20=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E8=B4=A6=E5=8D=95=E4=BD=BF=E7=94=A8Excel=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E8=B4=A6=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/v1/files.ts | 5 ++ src/api/v1/financial/user/billUser.ts | 8 +++ src/store/financialUser/billUser.ts | 15 ++++- src/store/monitor/files.ts | 17 ++++- .../account-bill/bill/add-bull-by-excel.vue | 63 +++++++++++++++++++ .../account-bill/bill/bill-dialog.vue | 4 +- .../account-bill/bill/utils/hooks.ts | 36 +++++++++++ src/views/welcome/utils/hooks.tsx | 2 +- 8 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 src/views/financial-user/account-bill/bill/add-bull-by-excel.vue diff --git a/src/api/v1/files.ts b/src/api/v1/files.ts index 8ddd743..4d70608 100644 --- a/src/api/v1/files.ts +++ b/src/api/v1/files.ts @@ -16,6 +16,11 @@ export const downloadFilesByFilepath = (data: any) => { return http.request('get', `files/downloadFilesByFilepath`, { params: data, responseType: 'blob' }); }; +/** 系统文件管理---获取添加账单模板文件 */ +export const fetchGetAddBillTemplate = () => { + return http.request('get', `files/noManage/getAddBillTemplate`, { responseType: 'blob' }); +}; + /** 系统文件管理---获取所有文件类型 */ export const fetchGetAllMediaTypes = () => { return http.request>('get', `files/noManage/getAllMediaTypes`); diff --git a/src/api/v1/financial/user/billUser.ts b/src/api/v1/financial/user/billUser.ts index 49f4fa9..687c901 100644 --- a/src/api/v1/financial/user/billUser.ts +++ b/src/api/v1/financial/user/billUser.ts @@ -23,6 +23,14 @@ export const fetchGetExpendOrIncome = (data: any) => { }); }; +/** 账单信息---导出用户账单信息 */ +export const fetchImportBill = (data: any) => { + return http.request>('post', 'bill/noManage/importBill', { + data, + headers: { 'Content-Type': 'multipart/form-data' }, + }); +}; + /** 账单信息---导出用户账单信息 */ export const fetchExportBill = (data: any) => { return http.request>('post', 'bill/noManage/exportBill', { data, responseType: 'blob' }); diff --git a/src/store/financialUser/billUser.ts b/src/store/financialUser/billUser.ts index 288d849..49152c8 100644 --- a/src/store/financialUser/billUser.ts +++ b/src/store/financialUser/billUser.ts @@ -1,5 +1,12 @@ import { defineStore } from 'pinia'; -import { fetchAddUserBill, fetchDeleteUserBill, fetchExportBill, fetchGetUserBillList, fetchUpdateUserBill } from '@/api/v1/financial/user/billUser'; +import { + fetchAddUserBill, + fetchDeleteUserBill, + fetchExportBill, + fetchGetUserBillList, + fetchImportBill, + fetchUpdateUserBill, +} from '@/api/v1/financial/user/billUser'; import { pageSizes } from '@/enums/baseConstant'; import { storeMessage } from '@/utils/message'; import { storePagination } from '@/store/useStorePagination'; @@ -66,6 +73,12 @@ export const useBillUserStore = defineStore('billUserStore', { return pagination(result); }, + /** 导入账单*/ + async importBill(data: any) { + const result = await fetchImportBill(data); + return storeMessage(result); + }, + /** 导出账单*/ async exportBill(data: any) { data = { startDate: dayjs(data[0]).format('YYYY-MM-DD'), endDate: dayjs(data[1]).format('YYYY-MM-DD') }; diff --git a/src/store/monitor/files.ts b/src/store/monitor/files.ts index 7ca96d5..3edf72f 100644 --- a/src/store/monitor/files.ts +++ b/src/store/monitor/files.ts @@ -1,8 +1,17 @@ import { defineStore } from 'pinia'; -import { fetchAddFiles, fetchDeleteFiles, fetchGetAllFilesStoragePath, fetchGetAllMediaTypes, fetchGetFilesList, fetchUpdateFiles } from '@/api/v1/files'; +import { + fetchAddFiles, + fetchDeleteFiles, + fetchGetAddBillTemplate, + fetchGetAllFilesStoragePath, + fetchGetAllMediaTypes, + fetchGetFilesList, + fetchUpdateFiles, +} from '@/api/v1/files'; import { pageSizes } from '@/enums/baseConstant'; import { storeMessage } from '@/utils/message'; import { storePagination } from '@/store/useStorePagination'; +import { download } from '@/utils/sso'; /** * 系统文件表 Store @@ -64,6 +73,12 @@ export const useFilesStore = defineStore('filesStore', { } }, + /** 获取添加账单模板文件 */ + async getAddBillTemplate() { + const result = await fetchGetAddBillTemplate(); + download(result, `bill-add-excel.xlsx`); + }, + /** 获取所有文件类型 */ async getAllFilesStoragePath() { const result = await fetchGetAllFilesStoragePath(); diff --git a/src/views/financial-user/account-bill/bill/add-bull-by-excel.vue b/src/views/financial-user/account-bill/bill/add-bull-by-excel.vue new file mode 100644 index 0000000..1aca4c5 --- /dev/null +++ b/src/views/financial-user/account-bill/bill/add-bull-by-excel.vue @@ -0,0 +1,63 @@ + + + diff --git a/src/views/financial-user/account-bill/bill/bill-dialog.vue b/src/views/financial-user/account-bill/bill/bill-dialog.vue index 925693f..abc275a 100644 --- a/src/views/financial-user/account-bill/bill/bill-dialog.vue +++ b/src/views/financial-user/account-bill/bill/bill-dialog.vue @@ -73,8 +73,8 @@ defineExpose({ formRef }); - {{ item.categoryName }} - {{ item.categoryName }} + {{ item.categoryName }} + {{ item.categoryName }} diff --git a/src/views/financial-user/account-bill/bill/utils/hooks.ts b/src/views/financial-user/account-bill/bill/utils/hooks.ts index e9e4ca6..3213845 100644 --- a/src/views/financial-user/account-bill/bill/utils/hooks.ts +++ b/src/views/financial-user/account-bill/bill/utils/hooks.ts @@ -9,6 +9,8 @@ import DeleteBatchDialog from '@/components/Table/DeleteBatchDialog.vue'; import dayjs from 'dayjs'; import ExportBill from '@/views/financial-user/account-bill/bill/export-bill.vue'; import { currentMouth } from '@/enums/dateEnums'; +import AddBullByExcel from '@/views/financial-user/account-bill/bill/add-bull-by-excel.vue'; +import type { UploadRawFile } from 'element-plus'; export const formRef = ref(); // 删除ids @@ -70,6 +72,13 @@ export function onAdd() { }); }, }, + { + label: $t('fileImport'), + type: 'success', + text: true, + bg: true, + btnClick: () => addBillByExcel(), + }, { label: $t('continue_adding'), type: 'success', @@ -196,3 +205,30 @@ export const onExportBill = () => { }, }); }; + +/** 使用Excel文件导入 */ +export const addBillByExcel = () => { + const formImportBillRef = ref(); + addDialog({ + title: $t('addBillByExcel'), + width: '30%', + props: { formInline: { file: undefined } }, + draggable: true, + fullscreenIcon: true, + closeOnClickModal: false, + contentRenderer: () => h(AddBullByExcel, { ref: formImportBillRef }), + beforeSure: (done, { options }) => { + formImportBillRef.value.formRef.validate(async (valid: any) => { + if (!valid) return; + // 上传的文件 + const file = options.props.formInline.file[0] as UploadRawFile; + + // 添加到数据库 + const result = billStore.importBill({ file: file.raw }); + if (!result) return; + + done(); + }); + }, + }); +}; diff --git a/src/views/welcome/utils/hooks.tsx b/src/views/welcome/utils/hooks.tsx index 3eb2779..629595f 100644 --- a/src/views/welcome/utils/hooks.tsx +++ b/src/views/welcome/utils/hooks.tsx @@ -37,7 +37,7 @@ export const onSearch = async () => { .filter(item => item.type === 1) .map(item => { const transactionDate = item.transactionDate; - return `${dayjs(transactionDate).format('DD')} ${days[dayjs(transactionDate).day()]}`; + return `${dayjs(transactionDate).format('MM-DD')} ${days[dayjs(transactionDate).day()]}`; }); incomeData.value = result.data.homeOverview.filter(item => item.type === 1).map(item => item.amount); expendData.value = result.data.homeOverview.filter(item => item.type === -1).map(item => item.amount);