跟新
This commit is contained in:
@@ -370,6 +370,15 @@ export function downloadFileById(fileId: string) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function previewFileById(fileId: string) {
|
||||||
|
return request({
|
||||||
|
url: '/purchase/purchasingfiles/previewById',
|
||||||
|
method: 'get',
|
||||||
|
params: { fileId },
|
||||||
|
responseType: 'blob'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量获取文件下载地址列表
|
* 批量获取文件下载地址列表
|
||||||
* @param purchaseId 采购申请ID
|
* @param purchaseId 采购申请ID
|
||||||
|
|||||||
@@ -98,10 +98,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed } from 'vue'
|
import { ref, computed, onUnmounted } from 'vue'
|
||||||
import { FolderOpened, Download, Document } from '@element-plus/icons-vue'
|
import { FolderOpened, Download, Document } from '@element-plus/icons-vue'
|
||||||
import { useMessage } from '/@/hooks/message'
|
import { useMessage } from '/@/hooks/message'
|
||||||
import { listDownloadUrls, getArchiveDownloadUrl } from '/@/api/purchase/purchasingrequisition'
|
import { listDownloadUrls, getArchiveDownloadUrl, downloadFileById, previewFileById } from '/@/api/purchase/purchasingrequisition'
|
||||||
import other from '/@/utils/other'
|
import other from '/@/utils/other'
|
||||||
|
|
||||||
interface FileItem {
|
interface FileItem {
|
||||||
@@ -117,6 +117,7 @@ const loading = ref(false)
|
|||||||
const downloading = ref(false)
|
const downloading = ref(false)
|
||||||
const previewVisible = ref(false)
|
const previewVisible = ref(false)
|
||||||
const previewUrl = ref('')
|
const previewUrl = ref('')
|
||||||
|
const previewLoading = ref(false)
|
||||||
const purchaseId = ref('')
|
const purchaseId = ref('')
|
||||||
const purchaseNo = ref('')
|
const purchaseNo = ref('')
|
||||||
const fileList = ref<FileItem[]>([])
|
const fileList = ref<FileItem[]>([])
|
||||||
@@ -155,9 +156,9 @@ const isPdfFile = (fileName: string): boolean => {
|
|||||||
return ext === 'pdf'
|
return ext === 'pdf'
|
||||||
}
|
}
|
||||||
|
|
||||||
const handlePreview = (row: FileItem) => {
|
const handlePreview = async (row: FileItem) => {
|
||||||
if (!row.downloadUrl) {
|
if (!row.id) {
|
||||||
useMessage().warning('文件预览地址不存在')
|
useMessage().warning('文件ID不存在')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,16 +168,41 @@ const handlePreview = (row: FileItem) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用iframe预览PDF(通过后端下载接口获取文件流)
|
previewLoading.value = true
|
||||||
previewUrl.value = row.downloadUrl
|
|
||||||
previewVisible.value = true
|
previewVisible.value = true
|
||||||
|
previewUrl.value = ''
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await previewFileById(row.id)
|
||||||
|
const blob = res as unknown as Blob
|
||||||
|
const url = window.URL.createObjectURL(blob)
|
||||||
|
previewUrl.value = url
|
||||||
|
} catch (err: any) {
|
||||||
|
useMessage().error(err?.msg || '预览失败')
|
||||||
|
previewVisible.value = false
|
||||||
|
} finally {
|
||||||
|
previewLoading.value = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleDownloadFile = (row: FileItem) => {
|
const handleDownloadFile = async (row: FileItem) => {
|
||||||
if (row.downloadUrl) {
|
if (!row.id) {
|
||||||
window.open(row.downloadUrl, '_blank')
|
useMessage().warning('文件ID不存在')
|
||||||
} else {
|
return
|
||||||
useMessage().warning('文件下载地址不存在')
|
}
|
||||||
|
try {
|
||||||
|
const res = await downloadFileById(row.id)
|
||||||
|
const blob = res as unknown as Blob
|
||||||
|
const url = window.URL.createObjectURL(blob)
|
||||||
|
const link = document.createElement('a')
|
||||||
|
link.href = url
|
||||||
|
link.download = row.fileTitle || 'download'
|
||||||
|
document.body.appendChild(link)
|
||||||
|
link.click()
|
||||||
|
document.body.removeChild(link)
|
||||||
|
window.URL.revokeObjectURL(url)
|
||||||
|
} catch (err: any) {
|
||||||
|
useMessage().error(err?.msg || '下载失败')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,6 +223,12 @@ const handleDownloadAll = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
if (previewUrl.value) {
|
||||||
|
window.URL.revokeObjectURL(previewUrl.value)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
open
|
open
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -261,7 +261,7 @@
|
|||||||
<!-- 需求部门/内审部门操作按钮 -->
|
<!-- 需求部门/内审部门操作按钮 -->
|
||||||
<el-button v-if="canSubmitToAsset" type="primary" @click="handleSubmitToAsset">提交至资产管理处</el-button>
|
<el-button v-if="canSubmitToAsset" type="primary" @click="handleSubmitToAsset">提交至资产管理处</el-button>
|
||||||
<!-- 通用操作按钮 -->
|
<!-- 通用操作按钮 -->
|
||||||
<el-button v-if="canReturn" type="warning" @click="handleReturn">退回修改</el-button>
|
<el-button v-if="canReturn" type="primary" @click="handleReturn">提交招标代理</el-button>
|
||||||
<el-button v-if="canComplete" type="success" @click="handleComplete">确认流程结束</el-button>
|
<el-button v-if="canComplete" type="success" @click="handleComplete">确认流程结束</el-button>
|
||||||
<el-button @click="handleClose">关闭</el-button>
|
<el-button @click="handleClose">关闭</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user