From 75f705dcf8717c758c55735fc0b68a70e4c4b432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=A1=E5=A4=8D=E4=B9=A0?= <2353956224@qq.com> Date: Fri, 16 Jan 2026 21:11:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E5=93=A5=E7=9A=84=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=89=8D=E7=AB=AF=E5=AF=BC=E5=87=BA=EF=BC=8C?= =?UTF-8?q?=E4=BF=9D=E7=95=99=E5=90=8E=E7=AB=AF=E5=AF=BC=E5=87=BA=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/locales/en.ts | 4 +- src/locales/zh-CN.ts | 4 +- src/views/server/bigbrother/index.vue | 78 ++++++++++++++++++++++++++- src/views/server/newhosts/index.vue | 5 +- 4 files changed, 86 insertions(+), 5 deletions(-) diff --git a/src/locales/en.ts b/src/locales/en.ts index 9854101..9ffbfe8 100644 --- a/src/locales/en.ts +++ b/src/locales/en.ts @@ -670,7 +670,9 @@ export default { placeTotalGiftCoins: 'Please enter total gift coins', placeHostDisplayId: 'Please enter host display_id', placeOwnerId: 'Please enter owner id', - displayIdRequired: 'Display ID is required' + displayIdRequired: 'Display ID is required', + exportFileName: 'BigBrother_Data', + exportSuccess: 'Export successful' }, system: { user: { diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts index 5b379fe..76f1437 100644 --- a/src/locales/zh-CN.ts +++ b/src/locales/zh-CN.ts @@ -671,7 +671,9 @@ export default { placeTotalGiftCoins: '请输入大哥历史打赏金币总和', placeHostDisplayId: '请输入大哥所在的直播间的主播display_id', placeOwnerId: '请输入该数据所属的账号id', - displayIdRequired: '大哥的display_id不能为空' + displayIdRequired: '大哥的display_id不能为空', + exportFileName: '大哥数据', + exportSuccess: '导出成功' }, system: { user: { diff --git a/src/views/server/bigbrother/index.vue b/src/views/server/bigbrother/index.vue index 99e9a76..8a40267 100644 --- a/src/views/server/bigbrother/index.vue +++ b/src/views/server/bigbrother/index.vue @@ -146,7 +146,11 @@ - + + + @@ -218,7 +222,10 @@ import { getAllocation, getSimpleUserList, getSimpleUserListPage } from '@/api/s import { useCache } from '@/hooks/web/useCache' import BigBrotherForm from './BigBrotherForm.vue' import { useDictStore } from '@/store/modules/dict' // 如果你项目里有字典 store +import { useLocaleStoreWithOut } from '@/store/modules/locale' const dictStore = useDictStore?.() // 有就用;没有的话把 dictStore 相关行删掉 +const localeStore = useLocaleStoreWithOut() +const currentLang = computed(() => localeStore.getCurrentLocale.lang) // 统一用字符串比较,自动识别并翻译 i18n key function dictLabelI18n(type: string, val: any) { @@ -351,8 +358,74 @@ const handleDelete = async (id: number) => { } catch { } } -/** 导出按钮操作 */ +/** 导出按钮操作 - 前端导出当前页数据 */ const handleExport = async () => { + try { + exportLoading.value = true + + // 定义表头(根据表格列顺序) + const headers = [ + t('bigBrother.displayId'), + t('bigBrother.uid'), + t('bigBrother.nickname'), + t('bigBrother.level'), + t('bigBrother.fansLevel'), + t('bigBrother.hostCoins'), + t('bigBrother.followerCount'), + t('bigBrother.followingCount'), + t('bigBrother.region'), + t('bigBrother.historicHighCoins'), + t('bigBrother.totalGiftCoins'), + t('bigBrother.hostDisplayId'), + t('bigBrother.ownerId'), + t('newHosts.isAssigned'), + t('newHosts.createTime') + ] + + // 将当前页数据转换为 CSV 行 + const rows = list.value.map(row => [ + row.displayId || '', + row.userIdStr || '', + row.nickname || '', + row.level || '', + row.fansLevel || '', + row.hostcoins || '', + row.followerCount || '', + row.followingCount || '', + currentLang.value === 'zh-CN' ? (row.region || '') : (row.regionEng || row.region || ''), + row.historicHighCoins || '', + row.totalGiftCoins || '', + row.hostDisplayId || '', + row.ownerId || '', + row.isAssigned == 1 ? (currentLang.value === 'zh-CN' ? '是' : 'Yes') : (currentLang.value === 'zh-CN' ? '否' : 'No'), + row.createTime ? new Date(row.createTime).toLocaleString(currentLang.value === 'zh-CN' ? 'zh-CN' : 'en-US') : '' + ]) + + // 组装 CSV 内容(添加 BOM 以支持 Excel 正确显示中文) + const BOM = '\uFEFF' + const csvContent = BOM + [headers, ...rows] + .map(row => row.map(cell => `"${String(cell).replace(/"/g, '""')}"`).join(',')) + .join('\n') + + // 创建 Blob 并下载 + const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' }) + const url = URL.createObjectURL(blob) + const link = document.createElement('a') + link.href = url + link.download = `${t('bigBrother.exportFileName')}_${new Date().toISOString().split('T')[0]}.csv` + link.click() + URL.revokeObjectURL(url) + + message.success(t('bigBrother.exportSuccess')) + } catch (error) { + console.error('导出失败:', error) + } finally { + exportLoading.value = false + } +} + +/* ======== 后端导出代码(已注释,保留备用)======== +const handleExportBackend = async () => { try { // 先确认是否删除导出的数据 @@ -385,6 +458,7 @@ const handleExport = async () => { exportLoading.value = false } } +======== 后端导出代码结束 ======== */ /** 查询员工 */ const getAllocationList = async () => { loading.value = true diff --git a/src/views/server/newhosts/index.vue b/src/views/server/newhosts/index.vue index bbe42c1..100ccf9 100644 --- a/src/views/server/newhosts/index.vue +++ b/src/views/server/newhosts/index.vue @@ -220,7 +220,7 @@ @@ -302,7 +302,10 @@ import { ElMessageBox } from 'element-plus' import { func } from 'vue-types' import { useDictStore } from '@/store/modules/dict' // 如果你项目里有字典 store +import { useLocaleStoreWithOut } from '@/store/modules/locale' const dictStore = useDictStore?.() // 有就用;没有的话把 dictStore 相关行删掉 +const localeStore = useLocaleStoreWithOut() +const currentLang = computed(() => localeStore.getCurrentLocale.lang) // 统一用字符串比较,自动识别并翻译 i18n key function dictLabelI18n(type: string, val: any) {