新增导出插件的可排序功能
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;
|
const baseUrl = import.meta.env.VITE_HISTORY_BASE_URL;
|
||||||
@@ -19,7 +19,10 @@ export const xlsxUrl = `${
|
|||||||
* console.log(res)
|
* 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 result = await fetch(`${xlsxUrl}/${lang}/${id}.xlsx`);
|
||||||
let fileBuffer = await result.arrayBuffer();
|
let fileBuffer = await result.arrayBuffer();
|
||||||
// 判断是否xlsx文件
|
// 判断是否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) {
|
if (data.length === 0) {
|
||||||
return new Blob([], { type: 'application/octet-stream' });
|
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(() => {
|
workSheet['!cols'] = Object.keys(data[0]).map(() => {
|
||||||
return { wch: 20 };
|
return { wch: 20 };
|
||||||
|
|||||||
@@ -630,6 +630,42 @@ function fnExportAll() {
|
|||||||
onOk() {
|
onOk() {
|
||||||
const key = 'exportAlarm';
|
const key = 'exportAlarm';
|
||||||
message.loading({ content: t('common.loading'), key });
|
message.loading({ content: t('common.loading'), key });
|
||||||
|
// 排序字段
|
||||||
|
const sortData = {
|
||||||
|
header: [
|
||||||
|
'id',
|
||||||
|
'neId',
|
||||||
|
'neName',
|
||||||
|
'neType',
|
||||||
|
'ackState',
|
||||||
|
'ackTime',
|
||||||
|
'ackUser',
|
||||||
|
'addInfo',
|
||||||
|
'alarmCode',
|
||||||
|
'alarmId',
|
||||||
|
'alarmSeq',
|
||||||
|
'alarmStatus',
|
||||||
|
'alarmTitle',
|
||||||
|
'alarmType',
|
||||||
|
'clearTime',
|
||||||
|
'clearType',
|
||||||
|
'clearUser',
|
||||||
|
'counter',
|
||||||
|
'eventTime',
|
||||||
|
'latestEventTime',
|
||||||
|
'locationInfo',
|
||||||
|
'objectName',
|
||||||
|
'objectType',
|
||||||
|
'objectUid',
|
||||||
|
'origSeverity',
|
||||||
|
'perceivedSeverity',
|
||||||
|
'province',
|
||||||
|
'pvFlag',
|
||||||
|
'specificProblem',
|
||||||
|
'specificProblemId',
|
||||||
|
'timestamp',
|
||||||
|
],
|
||||||
|
};
|
||||||
exportAll(queryParams).then(res => {
|
exportAll(queryParams).then(res => {
|
||||||
if (res.code === RESULT_CODE_SUCCESS) {
|
if (res.code === RESULT_CODE_SUCCESS) {
|
||||||
message.success({
|
message.success({
|
||||||
@@ -637,7 +673,7 @@ function fnExportAll() {
|
|||||||
key,
|
key,
|
||||||
duration: 3,
|
duration: 3,
|
||||||
});
|
});
|
||||||
writeSheet(res.data, 'alarm').then(fileBlob =>
|
writeSheet(res.data, 'alarm', sortData).then(fileBlob =>
|
||||||
saveAs(fileBlob, `alarm_${Date.now()}.xlsx`)
|
saveAs(fileBlob, `alarm_${Date.now()}.xlsx`)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ let dict: {
|
|||||||
/**记录开始结束时间 */
|
/**记录开始结束时间 */
|
||||||
let queryRangePicker = ref<[string, string]>(['', '']);
|
let queryRangePicker = ref<[string, string]>(['', '']);
|
||||||
|
|
||||||
|
/**表格字段列排序 */
|
||||||
|
let tableColumnsDnd = ref<ColumnsType>([]);
|
||||||
|
|
||||||
/**查询参数 */
|
/**查询参数 */
|
||||||
let queryParams = reactive({
|
let queryParams = reactive({
|
||||||
/**告警设备类型 */
|
/**告警设备类型 */
|
||||||
@@ -431,6 +434,42 @@ function fnExportAll() {
|
|||||||
onOk() {
|
onOk() {
|
||||||
const key = 'exportAlarmHis';
|
const key = 'exportAlarmHis';
|
||||||
message.loading({ content: t('common.loading'), key });
|
message.loading({ content: t('common.loading'), key });
|
||||||
|
// 排序字段
|
||||||
|
const sortData = {
|
||||||
|
header: [
|
||||||
|
'id',
|
||||||
|
'neId',
|
||||||
|
'neName',
|
||||||
|
'neType',
|
||||||
|
'ackState',
|
||||||
|
'ackTime',
|
||||||
|
'ackUser',
|
||||||
|
'addInfo',
|
||||||
|
'alarmCode',
|
||||||
|
'alarmId',
|
||||||
|
'alarmSeq',
|
||||||
|
'alarmStatus',
|
||||||
|
'alarmTitle',
|
||||||
|
'alarmType',
|
||||||
|
'clearTime',
|
||||||
|
'clearType',
|
||||||
|
'clearUser',
|
||||||
|
'counter',
|
||||||
|
'eventTime',
|
||||||
|
'latestEventTime',
|
||||||
|
'locationInfo',
|
||||||
|
'objectName',
|
||||||
|
'objectType',
|
||||||
|
'objectUid',
|
||||||
|
'origSeverity',
|
||||||
|
'perceivedSeverity',
|
||||||
|
'province',
|
||||||
|
'pvFlag',
|
||||||
|
'specificProblem',
|
||||||
|
'specificProblemId',
|
||||||
|
'timestamp',
|
||||||
|
],
|
||||||
|
};
|
||||||
exportAll(queryParams).then(res => {
|
exportAll(queryParams).then(res => {
|
||||||
if (res.code === RESULT_CODE_SUCCESS) {
|
if (res.code === RESULT_CODE_SUCCESS) {
|
||||||
message.success({
|
message.success({
|
||||||
@@ -438,7 +477,7 @@ function fnExportAll() {
|
|||||||
key,
|
key,
|
||||||
duration: 3,
|
duration: 3,
|
||||||
});
|
});
|
||||||
writeSheet(res.data, 'alarm').then(fileBlob =>
|
writeSheet(res.data, 'alarm',sortData).then(fileBlob =>
|
||||||
saveAs(fileBlob, `history-alarm_${Date.now()}.xlsx`)
|
saveAs(fileBlob, `history-alarm_${Date.now()}.xlsx`)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@@ -707,6 +746,10 @@ onMounted(() => {
|
|||||||
</template>
|
</template>
|
||||||
</a-dropdown>
|
</a-dropdown>
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
|
<TableColumnsDnd
|
||||||
|
:columns="tableColumns"
|
||||||
|
v-model:columns-dnd="tableColumnsDnd"
|
||||||
|
></TableColumnsDnd>
|
||||||
</a-space>
|
</a-space>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -714,7 +757,7 @@ onMounted(() => {
|
|||||||
<a-table
|
<a-table
|
||||||
class="table"
|
class="table"
|
||||||
row-key="id"
|
row-key="id"
|
||||||
:columns="tableColumns"
|
:columns="tableColumnsDnd"
|
||||||
:loading="tableState.loading"
|
:loading="tableState.loading"
|
||||||
:data-source="tableState.data"
|
:data-source="tableState.data"
|
||||||
:size="tableState.size"
|
:size="tableState.size"
|
||||||
|
|||||||
@@ -70,6 +70,11 @@ let tableColumns: ColumnsType = [
|
|||||||
dataIndex: 'version',
|
dataIndex: 'version',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: t('views.index.serialNum'),
|
||||||
|
dataIndex: 'serialNum',
|
||||||
|
align: 'center',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: t('views.index.ipAddress'),
|
title: t('views.index.ipAddress'),
|
||||||
dataIndex: 'ipAddress',
|
dataIndex: 'ipAddress',
|
||||||
@@ -400,9 +405,7 @@ onBeforeUnmount(() => {
|
|||||||
nfInfo.obj
|
nfInfo.obj
|
||||||
}}</a-descriptions-item>
|
}}</a-descriptions-item>
|
||||||
<template v-if="nfInfo.obj === 'OMC'">
|
<template v-if="nfInfo.obj === 'OMC'">
|
||||||
<a-descriptions-item :label="t('views.index.serialNum')">{{
|
|
||||||
nfInfo.serialNum
|
|
||||||
}}</a-descriptions-item>
|
|
||||||
<a-descriptions-item :label="t('views.index.versionNum')">{{
|
<a-descriptions-item :label="t('views.index.versionNum')">{{
|
||||||
nfInfo.version
|
nfInfo.version
|
||||||
}}</a-descriptions-item>
|
}}</a-descriptions-item>
|
||||||
|
|||||||
Reference in New Issue
Block a user