|
|
@@ -0,0 +1,147 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <el-dialog v-model="visible" title="报告模板" width="500" :before-close="handleClose">
|
|
|
+ <el-table
|
|
|
+ ref="singleTableRef"
|
|
|
+ highlight-current-row
|
|
|
+ :data="tableData"
|
|
|
+ style="width: 100%"
|
|
|
+ @current-change="handleCurrentChange"
|
|
|
+ >
|
|
|
+ <el-table-column type="index" label="序号" width="80">
|
|
|
+ <template #default="scope">
|
|
|
+ <div>
|
|
|
+ <el-radio-group v-model="templateId">
|
|
|
+ <el-radio :value="scope.row.id" size="large">{{ scope.$index + 1 }}</el-radio>
|
|
|
+ </el-radio-group>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column property="templateName" label="模板名称"></el-table-column>
|
|
|
+ </el-table>
|
|
|
+ <template #footer>
|
|
|
+ <div class="dialog-footer">
|
|
|
+ <el-button @click="handleClose">取 消</el-button>
|
|
|
+ <el-button type="primary" @click="submit" :loading="btnLoading"> 确 认 </el-button>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </el-dialog>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+<script setup lang="ts">
|
|
|
+import { ref } from 'vue'
|
|
|
+import { ElMessage } from 'element-plus'
|
|
|
+import type { TableInstance } from 'element-plus'
|
|
|
+const currentRow = ref()
|
|
|
+const singleTableRef = ref<TableInstance>()
|
|
|
+import { reportApi } from '@/services/api'
|
|
|
+
|
|
|
+const visible = ref(false)
|
|
|
+interface reportTemplate {
|
|
|
+ id: number
|
|
|
+ templateName: string
|
|
|
+ templatePath: string
|
|
|
+ createId: number
|
|
|
+ createTime: Date
|
|
|
+}
|
|
|
+const tableData = ref<reportTemplate[]>([])
|
|
|
+const templateId = ref()
|
|
|
+const btnLoading = ref(false)
|
|
|
+
|
|
|
+const handleClose = () => {
|
|
|
+ currentRow.value = null
|
|
|
+ singleTableRef.value?.setCurrentRow(null)
|
|
|
+ templateId.value = null
|
|
|
+ visible.value = false
|
|
|
+}
|
|
|
+
|
|
|
+const parentParams = ref({})
|
|
|
+
|
|
|
+const handleCurrentChange = (val: reportTemplate | undefined) => {
|
|
|
+ currentRow.value = val
|
|
|
+ if (val) {
|
|
|
+ templateId.value = val.id
|
|
|
+ } else {
|
|
|
+ templateId.value = null
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const open = (obj: object | null) => {
|
|
|
+ parentParams.value = obj || {}
|
|
|
+ if (!tableData.value.length) {
|
|
|
+ getTemplateList()
|
|
|
+ }
|
|
|
+ visible.value = true
|
|
|
+}
|
|
|
+
|
|
|
+const downLoad2 = (guid: string, fileName = 'download') => {
|
|
|
+ //获取下载地址
|
|
|
+ const href = getDownloadPath(guid)
|
|
|
+ if (!href) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const anchor = document.createElement('a')
|
|
|
+ if ('download' in anchor) {
|
|
|
+ anchor.href = href
|
|
|
+ anchor.setAttribute('download', fileName)
|
|
|
+ anchor.className = 'download-js-link'
|
|
|
+ anchor.innerHTML = 'downloading...'
|
|
|
+ anchor.style.display = 'none'
|
|
|
+ document.body.appendChild(anchor)
|
|
|
+ setTimeout(function () {
|
|
|
+ anchor.click()
|
|
|
+ document.body.removeChild(anchor)
|
|
|
+ }, 66)
|
|
|
+ return true
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//获取下载地址
|
|
|
+const getDownloadPath = (guid: string) => {
|
|
|
+ if (!guid) {
|
|
|
+ return ''
|
|
|
+ }
|
|
|
+ return `/api/fileManager/downloadFile?fileId=${guid}`
|
|
|
+}
|
|
|
+
|
|
|
+const submit = async () => {
|
|
|
+ if (!templateId.value) {
|
|
|
+ ElMessage.warning('请选择一个模板')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ const params = {
|
|
|
+ ...parentParams.value,
|
|
|
+ templateId: templateId.value,
|
|
|
+ }
|
|
|
+ btnLoading.value = true
|
|
|
+ const response = await reportApi.exportReportInfo(params)
|
|
|
+ ElMessage.success('导出报告成功')
|
|
|
+ if (response.code == 200) {
|
|
|
+ const guid = response.data
|
|
|
+ //执行下载
|
|
|
+ downLoad2(guid, parentParams.value.reportName)
|
|
|
+ btnLoading.value = true
|
|
|
+ handleClose()
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ ElMessage.error('导出报告失败')
|
|
|
+ btnLoading.value = true
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const getTemplateList = async () => {
|
|
|
+ try {
|
|
|
+ const response = await reportApi.getReportTemplate()
|
|
|
+ if (response.code == 200) {
|
|
|
+ tableData.value = response.data || []
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ ElMessage.error('获取报告模板失败')
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+defineExpose({
|
|
|
+ open,
|
|
|
+})
|
|
|
+</script>
|