瀏覽代碼

[update] 待办接口请求失败清除轮询,优化润乾预览代码

cfort 2 年之前
父節點
當前提交
3885538000
共有 2 個文件被更改,包括 40 次插入52 次删除
  1. 38 52
      src/business/platform/form/utils/custom/pintText.js
  2. 2 0
      src/views/system/dashboard/components/new-home.vue

+ 38 - 52
src/business/platform/form/utils/custom/pintText.js

@@ -1,12 +1,11 @@
 import dialog from '@/utils/dialog'
-import Pdfh5 from "pdfh5";
-import "pdfh5/css/pdfh5.css";
-import { snapshoot } from '@/api/platform/file/attachment' //印章,快照
-import { download } from '@/api/platform/file/attachment'
+import Pdfh5 from 'pdfh5'
+import 'pdfh5/css/pdfh5.css'
+import { snapshoot, download } from '@/api/platform/file/attachment' // 印章,快照
 import ActionUtils from '@/utils/action'
 import store from '@/store'
 
-const getPint = (tableForm, srcUrl) => {
+const getPint = (tableForm, url) => {
     let isMobile = false
     if (/Mobi|Android|iPhone|iPad/i.test(navigator.userAgent)) {
         isMobile = true
@@ -20,11 +19,8 @@ const getPint = (tableForm, srcUrl) => {
                         data: ''
                     }
                 },
-                template: `
-                    <div style="height:100%">
-                        <iframe src="${srcUrl}" id="myiframe" frameborder="0" scrolling="no" height="100%" width="100%"></iframe>
-                    </div>
-                `,
+
+                template: `<div style="height:100%"><iframe src="${url}" id="myiframe" frameborder="0" scrolling="no" height="100%" width="100%"></iframe></div>`
             },
             {
                 dialog: {
@@ -62,78 +58,69 @@ const getPint = (tableForm, srcUrl) => {
     } else {
         dialog(
             {
-                data() {
+                data () {
                     return {
                         readonly: false,
                         data: '',
                         pdfh5: null,
                         name: '',
-                        url: ``
+                        url: ''
                     }
                 },
-                mounted() {
-                    this.getYab()
+                mounted () {
+                    this.getFile()
                 },
                 methods: {
-                    getYab() {
-                        let srcUrl1 = srcUrl.split('rpx=')[1]
-                        let srcUrlList = srcUrl1.split('.rpx&id_=')
-                        let name = srcUrlList[0].split('/')
-
-                        let url = tableForm.$getReportFile(srcUrlList[0], `id_=${srcUrlList[1]}`)
-                        this.name = name[name.length - 1] + '.pdf'
-                        let params = {
-                            url: url,
-                            name: name[name.length - 1] || '暂无',
+                    getFile () {
+                        const urlList = url.split('rpx=')[1].split('.rpx&id_=')
+                        const name = urlList[0].split('/')
+                        this.name = name[name.length - 1] || '未命名'
+                        const params = {
+                            url: tableForm.$getReportFile(urlList[0], `id_=${urlList[1]}`),
+                            name: this.name,
                             type: 'pdf'
                         }
                         snapshoot(params).then(res => {
-                            if (res.state == 200) {
-                                const data = res.data
-                                this.getDownload(data.id)
+                            const { data = null } = res
+                            if (!data) {
+                                tableForm.$message.error('获取文件信息失败!')
+                                return
                             }
+                            this.getDownload(data.id)
                         })
                     },
-                    getDownload(id) {
-                        download({
-                            attachmentId: id
-                        }).then(res => {
-                            this.getMet(res.data)
+                    getDownload (id) {
+                        download({ attachmentId: id }).then(res => {
+                            this.render(res.data)
                             this.url = res.data
-                        }).catch(() => {
                         })
                     },
-                    getMet(url) {
-                        let that = this
-                        // //实例化1
-                        that.$nextTick(() => {
-                            that.pdfh5 = new Pdfh5("#demo", {
+                    render (url) {
+                        this.$nextTick(() => {
+                            this.pdfh5 = new Pdfh5('#demo', {
                                 // pdfurl: window.location.origin + '/' + url,
-                                data: url,
+                                data: url
                                 // lazy: true
                             })
-                            that.pdfh5.on("complete", function (status, msg, time) {
+                            this.pdfh5.on('complete', (status, msg, time) => {
                                 // console.log(status, msg, time)
                             })
-                        });
+                        })
                     },
-                    finish() {
-                        this.visible = false
+                    close () {
                         tableForm.dialogTemplate = null
+                        this.visible = false
                     },
-                    xiazan() {
-                        ActionUtils.exportFile(
-                            this.url,
-                            this.name
-                        )
+                    downloadFile () {
+                        ActionUtils.exportFile(this.url, `${this.name}.pdf`)
                     }
                 },
                 template:
-                    `<div style="height:100%">
+                `<div style="height:100%">
                     <div id="demo"></div>
                     <div style="position:absolute;right: 17px;top: 15px;" >
-                        <i class="el-icon-download" style="font-size: 24px;margin-right:15px" @click="xiazan"></i>
-                        <i class="el-icon-close" style="font-size: 24px;" @click="finish"></i>
+                        <i class="el-icon-download" style="font-size: 24px;margin-right:15px" @click="downloadFile"></i>
+                        <i class="el-icon-close" style="font-size: 24px;" @click="close"></i>
                     </div>
                 </div>`
             },
@@ -154,6 +141,5 @@ const getPint = (tableForm, srcUrl) => {
             tableForm.dialogTemplate = null
         })
     }
-
 }
 export default getPint

+ 2 - 0
src/views/system/dashboard/components/new-home.vue

@@ -478,6 +478,8 @@
                     this.loading = false
                 }).catch(() => {
                     this.loading = false
+                    // 请求出错清除轮询
+                    clearInterval(this.timer)
                 })
             },
             // 延迟更新列表数据