报表修改

This commit is contained in:
stt
2025-11-24 14:53:07 +08:00
parent 0249ccac48
commit 704f735744

View File

@@ -3,18 +3,28 @@
<!--治理效果报表 --> <!--治理效果报表 -->
<TableHeader :showReset="false" datePicker @selectChange="selectChange" v-if="fullscreen"> <TableHeader :showReset="false" datePicker @selectChange="selectChange" v-if="fullscreen">
<template v-slot:select> <template v-slot:select>
<el-form-item label="治理对象"> <el-form-item label="报表模板">
<el-select <el-select
v-model="tableStore.table.params.power" v-model="tableStore.table.params.tempId"
placeholder="请选择治理对象" placeholder="请选择报表模板"
clearable
style="width: 130px"
>
<el-option v-for="item in templateList" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
</el-form-item>
<el-form-item label="监测对象">
<el-select
v-model="tableStore.table.params.sensitiveUserId"
placeholder="请选择监测对象"
clearable clearable
style="width: 130px" style="width: 130px"
> >
<el-option <el-option
v-for="item in powerList" v-for="item in idList"
:key="item.value" :key="item.id"
:label="item.label" :label="item.name"
:value="item.value" :value="item.id"
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
@@ -23,13 +33,22 @@
<el-button @click="downloadExcel" class="" type="primary" icon="el-icon-Download">导出excel</el-button> <el-button @click="downloadExcel" class="" type="primary" icon="el-icon-Download">导出excel</el-button>
</template> </template>
</TableHeader> </TableHeader>
<div style="display: flex"> <div style="display: flex; border: red solid 1px">
<div <div
id="luckysheet" id="luckysheet-before"
:style="{ :style="{
width: `calc(${prop.width} )`, width: `calc(${prop.width} / 2 - 10px)`,
height: `calc(${prop.height} - 57px + ${fullscreen ? 0 : 56}px)` height: `calc(${prop.height} - 57px + ${fullscreen ? 0 : 56}px)`
}" }"
style="border: yellow solid 1px"
></div>
<div
id="luckysheet-after"
:style="{
width: `calc(${prop.width} / 2 - 10px)`,
height: `calc(${prop.height} - 57px + ${fullscreen ? 0 : 56}px)`,
marginLeft: '10px'
}"
></div> ></div>
</div> </div>
</div> </div>
@@ -39,18 +58,18 @@ import { ref, onMounted, provide, reactive, watch, h, computed } from 'vue'
import TableStore from '@/utils/tableStore' import TableStore from '@/utils/tableStore'
import { exportExcel } from '@/views/govern/reportForms/export.js' import { exportExcel } from '@/views/govern/reportForms/export.js'
import TableHeader from '@/components/table/header/index.vue' import TableHeader from '@/components/table/header/index.vue'
import { getTimeOfTheMonth } from '@/utils/formatTime'
import { useConfig } from '@/stores/config' import { useConfig } from '@/stores/config'
import Json from './index.json' import Json from './index.json'
import { useRoute } from 'vue-router' import JsonAfter from './index.json'
import { useTimeCacheStore } from '@/stores/timeCache' import { getTemplateList } from '@/api/harmonic-boot/luckyexcel'
import { getListByIds } from '@/api/harmonic-boot/cockpit/cockpit'
const prop = defineProps({ const prop = defineProps({
w: { type: [String, Number]}, w: { type: [String, Number] },
h: { type: [String, Number]}, h: { type: [String, Number] },
width: { type: [String, Number]}, width: { type: [String, Number] },
height: { type: [String, Number]}, height: { type: [String, Number] },
timeKey: { type: [String, Number]}, timeKey: { type: [String, Number] },
timeValue: { type: Object } timeValue: { type: Object }
}) })
const config = useConfig() const config = useConfig()
@@ -65,9 +84,6 @@ const powerList: any = ref([
} }
]) ])
const route = useRoute()
const timeCacheStore = useTimeCacheStore()
const tableStore: any = new TableStore({ const tableStore: any = new TableStore({
url: '/user-boot/role/selectRoleDetail?id=0', url: '/user-boot/role/selectRoleDetail?id=0',
method: 'POST', method: 'POST',
@@ -87,27 +103,115 @@ provide('tableRef', tableRef)
tableStore.table.params.power = '1' tableStore.table.params.power = '1'
provide('tableStore', tableStore) provide('tableStore', tableStore)
// 报表模板列表
const templateList = ref([])
// 监测对象
const idList = ref()
// 监测对象
const initListByIds = () => {
getListByIds({}).then((res: any) => {
if (res.data.length > 0) {
idList.value = res.data
if (!tableStore.table.params.sensitiveUserId && idList.value?.length > 0) {
tableStore.table.params.sensitiveUserId = idList.value[0].id
}
}
})
}
const templateListData = () => {
getTemplateList({}).then(res => {
templateList.value = res.data
if (!tableStore.table.params.tempId && templateList.value?.length > 0) {
tableStore.table.params.tempId = res.data[0].id
}
})
}
// 治理前和治理后的Luckysheet实例
let luckysheetBefore: any
let luckysheetAfter: any
onMounted(() => {
templateListData()
// 等待DOM更新完成后再创建Luckysheet实例
nextTick(() => {
setTimeout(() => {
createLuckysheets()
}, 100)
})
})
// 下载表格 // 下载表格
const downloadExcel = () => { const downloadExcel = () => {
exportExcel(luckysheet.getAllSheets(), '治理效果报表') // 可以选择导出治理前、治理后或两个报表
const beforeSheets = luckysheetBefore.getAllSheets()
const afterSheets = luckysheetAfter.getAllSheets()
exportExcel([...beforeSheets, ...afterSheets], '治理效果对比报表')
} }
onMounted(() => { onMounted(() => {
luckysheet.create({ templateListData()
container: 'luckysheet', initListByIds()
title: '', // 表 头名 nextTick(() => {
lang: 'zh', // 中文 setTimeout(() => {
showtoolbar: false, // 是否显示工具栏 createLuckysheets()
showinfobar: false, // 是否显示顶部信息栏 }, 100)
showsheetbar: true, // 是否显示底部sheet按钮 })
allowEdit: false, // 禁止所有编辑操作(必填) })
data: Json
const createLuckysheets = () => {
try {
// 检查容器
const beforeContainer = document.getElementById('luckysheet-before')
const afterContainer = document.getElementById('luckysheet-after')
if (!beforeContainer) {
return
}
if (!afterContainer) {
return
}
// 验证并准备数据
const beforeData = Json && Array.isArray(Json) ? Json : []
const afterData = JsonAfter && Array.isArray(JsonAfter) ? JsonAfter : []
// 创建治理前报表
luckysheetBefore = luckysheet.create({
container: 'luckysheet-before',
title: '治理前',
lang: 'zh',
showtoolbar: false,
showinfobar: false,
showsheetbar: true,
allowEdit: false,
data: beforeData
})
// 创建治理后报表
luckysheetAfter = luckysheet.create({
container: 'luckysheet-after',
title: '治理后',
lang: 'zh',
showtoolbar: false,
showinfobar: false,
showsheetbar: true,
allowEdit: false,
data: afterData
}) })
tableStore.index() tableStore.index()
}) } catch (error) {
console.error('创建Luckysheet实例时发生错误:', error)
}
}
const selectChange = (showSelect: any, height: any, datePickerValue?: any) => { const selectChange = (showSelect: any, height: any, datePickerValue?: any) => {
if (datePickerValue && datePickerValue.timeValue) { if (datePickerValue && datePickerValue.timeValue) {
// 更新时间参数 // 更新时间参数
tableStore.table.params.searchBeginTime = datePickerValue.timeValue[0] tableStore.table.params.searchBeginTime = datePickerValue.timeValue[0]
@@ -146,11 +250,9 @@ watch(
deep: true deep: true
} }
) )
const addMenu = () => {}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
:deep(.el-select) { // :deep(.el-select) {
min-width: 80px; // min-width: 80px;
} // }
</style> </style>