新增导出插件的可排序功能
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { read, utils, write } from 'xlsx';
|
||||
import { JSON2SheetOpts, read, utils, write } from 'xlsx';
|
||||
|
||||
// 静态资源路径
|
||||
const baseUrl = import.meta.env.VITE_HISTORY_BASE_URL;
|
||||
@@ -19,7 +19,10 @@ export const xlsxUrl = `${
|
||||
* console.log(res)
|
||||
* });
|
||||
*/
|
||||
export async function readLoalXlsx(lang:string,id: string): Promise<Record<string, any>[]> {
|
||||
export async function readLoalXlsx(
|
||||
lang: string,
|
||||
id: string
|
||||
): Promise<Record<string, any>[]> {
|
||||
let result = await fetch(`${xlsxUrl}/${lang}/${id}.xlsx`);
|
||||
let fileBuffer = await result.arrayBuffer();
|
||||
// 判断是否xlsx文件
|
||||
@@ -62,11 +65,18 @@ export async function readSheet(
|
||||
* );
|
||||
*
|
||||
*/
|
||||
export async function writeSheet(data: any[], sheetName: string) {
|
||||
export async function writeSheet(
|
||||
data: any[],
|
||||
sheetName: string,
|
||||
opts?: JSON2SheetOpts
|
||||
) {
|
||||
if (data.length === 0) {
|
||||
return new Blob([], { type: 'application/octet-stream' });
|
||||
}
|
||||
const workSheet = utils.json_to_sheet(data);
|
||||
|
||||
const workSheet = utils.json_to_sheet(data, opts);
|
||||
console.log(workSheet);
|
||||
|
||||
// 设置列宽度,单位厘米
|
||||
workSheet['!cols'] = Object.keys(data[0]).map(() => {
|
||||
return { wch: 20 };
|
||||
|
||||
Reference in New Issue
Block a user