Commit 1d57f3ea authored by 何远江's avatar 何远江

excel浏览添加下载

parent 442f3b3a
<template> <template>
<div id="preview-excel"></div> <div id="preview-excel"></div>
<el-button class="download-file" @click.stop="downloadFile" size="large" circle type="primary">
<el-icon><Download /></el-icon>
</el-button>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { Download } from '@element-plus/icons-vue'
import { onMounted, onUnmounted, ref, watch } from 'vue' import { onMounted, onUnmounted, ref, watch } from 'vue'
import LuckyExcel from 'luckyexcel' import LuckyExcel from 'luckyexcel'
import { getOrderFileById } from '@/api/order' import { getOrderFileById } from '@/api/order'
...@@ -15,6 +20,7 @@ import { ...@@ -15,6 +20,7 @@ import {
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import { isFunction } from '@/utils/is' import { isFunction } from '@/utils/is'
const filePath = ref('')
const props = defineProps(['fileId']) const props = defineProps(['fileId'])
const luckysheet = (window as any).luckysheet const luckysheet = (window as any).luckysheet
const loading = ref(false) const loading = ref(false)
...@@ -22,6 +28,8 @@ const route = useRoute() ...@@ -22,6 +28,8 @@ const route = useRoute()
/**生成excel */ /**生成excel */
const generateExcel = (path: string) => { const generateExcel = (path: string) => {
// 保存浏览文件的地址
filePath.value = path
LuckyExcel.transformExcelToLuckyByUrl( LuckyExcel.transformExcelToLuckyByUrl(
'/api/sys/static/' + path, '/api/sys/static/' + path,
new Date().getTime() + '.xlsx', new Date().getTime() + '.xlsx',
...@@ -43,6 +51,10 @@ const generateExcel = (path: string) => { ...@@ -43,6 +51,10 @@ const generateExcel = (path: string) => {
) )
} }
const downloadFile = () => {
window.open('/api/sys/static/' + filePath.value, '_blank')
}
/**获取文件路径 */ /**获取文件路径 */
const getFilePath = async () => { const getFilePath = async () => {
try { try {
...@@ -71,10 +83,6 @@ watch( ...@@ -71,10 +83,6 @@ watch(
) )
onMounted(() => { onMounted(() => {
// luckysheet.create({
// container: 'preview-excel'
// })
getFilePath() getFilePath()
}) })
onUnmounted(() => { onUnmounted(() => {
...@@ -86,4 +94,10 @@ onUnmounted(() => { ...@@ -86,4 +94,10 @@ onUnmounted(() => {
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
.download-file {
position: fixed;
bottom: 30px;
right: 20px;
z-index: 3000;
}
</style> </style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment