大哥的导出改为前端导出,保留后端导出代码
This commit is contained in:
@@ -146,7 +146,11 @@
|
||||
<el-table-column :label="t('bigBrother.hostCoins')" align="center" prop="hostcoins" />
|
||||
<el-table-column :label="t('bigBrother.followerCount')" align="center" prop="followerCount" />
|
||||
<el-table-column :label="t('bigBrother.followingCount')" align="center" prop="followingCount" />
|
||||
<el-table-column :label="t('bigBrother.region')" align="center" prop="region" />
|
||||
<el-table-column :label="t('bigBrother.region')" align="center" prop="region">
|
||||
<template #default="scope">
|
||||
{{ currentLang === 'zh-CN' ? scope.row.region : (scope.row.regionEng || scope.row.region) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="t('bigBrother.historicHighCoins')" align="center" prop="historicHighCoins" />
|
||||
<el-table-column :label="t('bigBrother.totalGiftCoins')" align="center" prop="totalGiftCoins" />
|
||||
<el-table-column :label="t('bigBrother.hostDisplayId')" align="center" prop="hostDisplayId">
|
||||
@@ -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
|
||||
|
||||
@@ -220,7 +220,7 @@
|
||||
<el-table-column :label="t('newHosts.yesterdayCoins')" sortable align="center" prop="yesterdayCoins" />
|
||||
<el-table-column :label="t('newHosts.hostsCountry')" align="center" prop="country">
|
||||
<template #default="scope">
|
||||
{{ t('newHosts.min') == '最小值' ? scope.row.country : scope.row.countryEng }}
|
||||
{{ currentLang === 'zh-CN' ? scope.row.country : (scope.row.countryEng || scope.row.country) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="t('newHosts.hostsKind')" align="center" prop="hostsKind" />
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user