2023-12-18 14:29:28 +08:00
|
|
|
import * as XLSX from "xlsx"
|
|
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
2023-12-21 11:58:50 +08:00
|
|
|
import { dateFormater } from '@/utils/date-util'
|
2023-12-18 14:29:28 +08:00
|
|
|
|
|
|
|
export const tableRemoveRow = (params: any, callback: (res: boolean) => void) => {
|
|
|
|
if (!params.data) params.data = []
|
|
|
|
if (Array.isArray(params.data)) {
|
|
|
|
if (params.data.length < 1) {
|
2023-12-28 10:18:10 +08:00
|
|
|
ElMessageBox.alert('请至少选择一条数据进行删除', '系统提醒', { type: 'warning', draggable: true })
|
2023-12-18 14:29:28 +08:00
|
|
|
return callback(false)
|
|
|
|
}
|
|
|
|
ElMessageBox.confirm(
|
|
|
|
params.batchRemoveTip || '是否确认删除选中的' + params.data.length + '条数据?此操作将永久删除',
|
|
|
|
'系统提醒',
|
|
|
|
{
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
type: 'warning',
|
2023-12-28 10:18:10 +08:00
|
|
|
draggable: true
|
2023-12-18 14:29:28 +08:00
|
|
|
}
|
|
|
|
).then(() => {
|
|
|
|
ElMessage.success('删除成功!')
|
|
|
|
callback(true)
|
|
|
|
}).catch(() => {
|
|
|
|
callback(false)
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
ElMessageBox.confirm(
|
|
|
|
params.removeTip || '此操作将永久删除',
|
|
|
|
'系统提醒',
|
|
|
|
{
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
type: 'warning',
|
2023-12-28 10:18:10 +08:00
|
|
|
draggable: true
|
2023-12-18 14:29:28 +08:00
|
|
|
}
|
|
|
|
).then(() => {
|
|
|
|
ElMessage.success('删除成功!')
|
|
|
|
callback(true)
|
|
|
|
}).catch(() => {
|
|
|
|
callback(false)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const exportData = (fileName: string, data: Array<any>) => {
|
2023-12-21 11:58:50 +08:00
|
|
|
if(data.length < 1) return
|
2023-12-18 14:29:28 +08:00
|
|
|
const wb = XLSX.utils.book_new();
|
|
|
|
XLSX.utils.book_append_sheet(
|
|
|
|
wb,
|
|
|
|
XLSX.utils.json_to_sheet(data)
|
2023-12-21 11:58:50 +08:00
|
|
|
)
|
|
|
|
XLSX.writeFile(wb, fileName + '.xls'); // 导出Excel
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param fileName
|
|
|
|
* @param data
|
|
|
|
* @param sheetNameKey data中的键名 对应表页名称
|
|
|
|
* @param sheetDataKey data中的键名 对应表数据
|
|
|
|
*/
|
|
|
|
export const exportMultiData = (fileName: string, data: Array<any>, sheetNameKey: string, sheetDataKey: string) => {
|
|
|
|
if(data.length < 1) return
|
|
|
|
const wb = XLSX.utils.book_new();
|
|
|
|
data.forEach(item => {
|
|
|
|
XLSX.utils.book_append_sheet(
|
|
|
|
wb,
|
|
|
|
XLSX.utils.json_to_sheet(item[sheetDataKey]),
|
|
|
|
item[sheetNameKey] instanceof Date ? dateFormater('yyyy-MM-dd HH:mm:ss', item[sheetNameKey]) : item[sheetNameKey]
|
|
|
|
)
|
|
|
|
})
|
2023-12-18 14:29:28 +08:00
|
|
|
XLSX.writeFile(wb, fileName + '.xls'); // 导出Excel
|
|
|
|
}
|