阅行客电子档案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

568 lines
18 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 weeks ago
2 years ago
2 years ago
3 weeks ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 weeks ago
3 weeks ago
2 years ago
2 years ago
3 weeks ago
2 years ago
2 years ago
2 years ago
2 years ago
3 weeks ago
2 years ago
3 weeks ago
3 weeks ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <div class="preview-wrapper">
  3. <div class="collect-header" style="justify-content: flex-start; border-top: none; ">
  4. <h4 class="is-file" style="flex:none; width: 120px;">原文</h4>
  5. <span style="font-size: 12px; flex: 1; line-height: 42px;">所属文件{{ parentArchiveNo }}</span>
  6. </div>
  7. <!-- <div class="top-container">
  8. <div class="top-left">
  9. <input
  10. class="file-select"
  11. type="file"
  12. @change="handleChange"
  13. >
  14. </div>
  15. <div class="top-middle">
  16. 文件预览
  17. </div>
  18. <div class="top-right">
  19. <el-button @click="printWindow">
  20. <i class="el-icon-printer" />window
  21. </el-button>
  22. <el-button v-print="printObj">vue-print打印</el-button>
  23. <el-button type="primary" @click="toImg">转图片打印</el-button>
  24. </div>
  25. </div> -->
  26. <div class="main-content">
  27. <div class="content-list">
  28. <h4 class="arc-title">原文列表</h4>
  29. <ul v-if="allFileTables.length!==0" class="file-list">
  30. <li v-for="(item,index) in allFileTables" :key="index" :class="{'active-file': item.id == fileCurrent.id}" @click="selectFile(item)">
  31. <span>{{ item.file_name }}</span>
  32. <i class="iconfont icon-attachment" />
  33. </li>
  34. </ul>
  35. <el-empty v-else :image-size="100" />
  36. </div>
  37. <div v-loading="loading" element-loading-text="文件加载中" class="content-right">
  38. <div class="preview-info">
  39. <ul>
  40. <li>创建时间{{ fileCurrent && fileCurrent.create_time }}</li>
  41. <li>大小{{ getFileSize(fileCurrent && fileCurrent.file_size) }}</li>
  42. <li>尺寸{{ (!(fileCurrent && fileCurrent.file_dpi) || (fileCurrent && fileCurrent.file_dpi === 'null')) ? '-' : fileCurrent.file_dpi }}</li>
  43. </ul>
  44. <div class="preview-btn">
  45. <el-button :loading="downloading" class="iconfont icon-xiazai" @click="downloadFile(fileCurrent)">下载</el-button>
  46. <el-button v-print="printObj" class="iconfont icon-dayin">打印</el-button>
  47. </div>
  48. </div>
  49. <div id="printArea" ref="output" class="well-box" :style="{overflowY : !loading ? 'auto' : 'hidden'}" />
  50. <div class="water-mask" />
  51. </div>
  52. </div>
  53. </div>
  54. </template>
  55. <script>
  56. import { FetchMinioReDocumentBase64ByFileId } from '@/api/prearchiveLibrary/prearchiveLibrary'
  57. import { FetchBase64ByFileId } from '@/api/archivesManage/library'
  58. import { getExtend, readBuffer, render } from '@/components/util'
  59. import { parse } from 'qs'
  60. import { watermark } from '@/utils/waterMark'
  61. import { getInitWatermark } from '@/api/system/waterMask'
  62. import { downloadFile } from '@/utils/index'
  63. import { mapGetters } from 'vuex'
  64. import html2canvas from 'html2canvas' // 转图片打印需要先安装html2Canvas和print-js
  65. import printJS from 'print-js'
  66. import { getToken } from '@/utils/auth'
  67. export default {
  68. name: 'Preview',
  69. components: {
  70. },
  71. props: {
  72. msg: {
  73. type: String,
  74. default: ''
  75. }
  76. },
  77. data() {
  78. return {
  79. downloading: false,
  80. src: '',
  81. logo: require('../../assets/images/logo.png'),
  82. // 加载状态跟踪
  83. loading: false,
  84. // 上个渲染实例
  85. last: null,
  86. // 隐藏头部,当基于消息机制渲染,将隐藏
  87. hidden: false,
  88. printObj: {
  89. id: 'printArea',
  90. preview: true, // 是否启动预览模式,默认是false
  91. previewTitle: '电子原文预览', // 打印预览的标题
  92. previewPrintBtnLabel: '预览结束,开始打印',
  93. zIndex: 20002, // 预览窗口的z-index,默认是20002,最好比默认值更高
  94. extraCss: '', // 打印可引入外部的一个css文件
  95. extraHead: '<meta http-equiv="Content-Language"content="zh-cn"/>,<style> #printArea { height: auto !important; } <style>', // 打印头部文字
  96. previewBeforeOpenCallback() { console.log('正在加载预览窗口!') }, // 预览窗口打开之前的callback
  97. previewOpenCallback() { console.log('已经加载完预览窗口,预览打开了!') }, // 预览窗口打开时的callback
  98. beforeOpenCallback() { console.log('开始打印之前!') }, // 开始打印之前的callback
  99. openCallback() { console.log('执行打印了!') }, // 调用打印时的callback
  100. closeCallback() { console.log('关闭了打印工具!') }, // 关闭打印的callback(无法区分确认or取消)
  101. clickMounted() { console.log('点击v-print绑定的按钮了!') },
  102. // url: 'http://192.168.99.67:11100/downloadFile/category/AE8B188F0C0314F9BE31B8/82FBCAE96CBC9F50809838/7f3df862-f36d-4061-9c3e-e81556420742.pdf', // 打印指定的URL,确保同源策略相同
  103. // asyncUrl (reslove) {
  104. // setTimeout(() => {
  105. // reslove('http://localhost:8080/')
  106. // }, 2000)
  107. // },
  108. standard: '',
  109. extarCss: ''
  110. },
  111. watermarkInfo: null,
  112. timer: null,
  113. parentArchiveNo: null,
  114. allFileTables: [],
  115. toFile: null,
  116. fileCurrent: null,
  117. fileParentInfo: null,
  118. pdfsArray: [],
  119. documentId: null
  120. }
  121. },
  122. computed: {
  123. ...mapGetters([
  124. 'baseApi'
  125. ])
  126. },
  127. created() {
  128. // 允许使用预留的消息机制发送二进制数据,必须在url后添加?name=xxx.xxx&from=xxx
  129. const { from, name } = parse(location.search.substr(1))
  130. if (from) {
  131. window.addEventListener('message', (event) => {
  132. const { origin, data: blob } = event
  133. if (origin === from && blob instanceof Blob) {
  134. // 构造响应,自动渲染
  135. const file = new File([blob], name, {})
  136. this.hidden = true
  137. this.handleChange({ target: { files: [file] }})
  138. }
  139. })
  140. }
  141. },
  142. mounted() {
  143. if (this.$route.query.archiveNo) {
  144. this.parentArchiveNo = this.$route.query.archiveNo
  145. }
  146. if (localStorage.getItem('documentId')) {
  147. this.documentId = JSON.parse(localStorage.getItem('documentId'))
  148. }
  149. if (localStorage.getItem('fileParentInfo')) {
  150. this.fileParentInfo = JSON.parse(localStorage.getItem('fileTables'))
  151. }
  152. if (localStorage.getItem('fileTables')) {
  153. this.allFileTables = JSON.parse(localStorage.getItem('fileTables'))
  154. }
  155. if (localStorage.getItem('fileCurrent')) {
  156. this.fileCurrent = JSON.parse(localStorage.getItem('fileCurrent'))
  157. }
  158. this.getBase64ByFileId()
  159. },
  160. methods: {
  161. getFileSize(fileSize) {
  162. const fileSizeInKB = (fileSize / 1024).toFixed(2) + 'kB'
  163. const fileSizeInB = fileSize + 'B'
  164. return (fileSize / 1024) <= 0.01 ? fileSizeInB : fileSizeInKB
  165. },
  166. // 下载附件
  167. downloadFile(row) {
  168. // filePath 保存的文件路径
  169. // bucketType 1预归档 2档案
  170. this.downloading = true
  171. let bucketType = null
  172. if (this.documentId) {
  173. bucketType = 1
  174. } else {
  175. bucketType = 2
  176. }
  177. const url = this.baseApi + '/api/minioUpload/getFile?filePath=' + row.file_path + '&bucketType=' + bucketType
  178. const fetchOptions = {
  179. method: 'GET',
  180. headers: {
  181. 'Authorization': getToken()
  182. }
  183. }
  184. fetch(url, fetchOptions).then(res => res.blob()).then(blob => {
  185. downloadFile(blob, row.file_name.split('.')[0], row.file_type)
  186. this.downloading = false
  187. }).catch(() => {
  188. this.$message({ message: '下载文件失败', type: 'error', offset: 8 })
  189. this.downloading = false
  190. })
  191. },
  192. selectFile(item) {
  193. this.fileCurrent = item
  194. this.getBase64ByFileId()
  195. },
  196. getBase64ByFileId() {
  197. this.loading = true
  198. if (this.documentId) {
  199. const params = {
  200. 'filePath': this.fileCurrent.file_path,
  201. 'bucketType': 1
  202. }
  203. FetchMinioReDocumentBase64ByFileId(params).then(res => {
  204. var base64String = res
  205. var fileName = this.fileCurrent && this.fileCurrent.file_name
  206. var mimeType = this.fileCurrent && this.fileCurrent.file_type
  207. this.toFile = this.base64ToFile(base64String, fileName, mimeType)
  208. if (this.toFile) {
  209. this.handleChange()
  210. }
  211. })
  212. } else {
  213. const params = {
  214. 'fileId': this.fileCurrent ? this.fileCurrent.id : this.allFileTables[0].id,
  215. 'bucketType': 2
  216. }
  217. FetchBase64ByFileId(params).then(res => {
  218. console.log('res', res)
  219. var base64String = res
  220. var fileName = this.fileCurrent && this.fileCurrent.file_name
  221. var mimeType = this.fileCurrent && this.fileCurrent.file_type
  222. this.toFile = this.base64ToFile(base64String, fileName, mimeType)
  223. if (this.toFile) {
  224. this.handleChange()
  225. }
  226. })
  227. }
  228. },
  229. base64ToFile(base64String, fileName, mimeType) {
  230. var byteCharacters = atob(base64String)
  231. var byteArrays = []
  232. for (var offset = 0; offset < byteCharacters.length; offset += 512) {
  233. var slice = byteCharacters.slice(offset, offset + 512)
  234. var byteNumbers = new Array(slice.length)
  235. for (var i = 0; i < slice.length; i++) {
  236. byteNumbers[i] = slice.charCodeAt(i)
  237. }
  238. var byteArray = new Uint8Array(byteNumbers)
  239. byteArrays.push(byteArray)
  240. }
  241. var file = new Blob(byteArrays, { type: mimeType })
  242. file.name = fileName
  243. return file
  244. },
  245. toImg() { // 转图片打印
  246. html2canvas(this.$refs.output, {
  247. backgroundColor: null,
  248. useCORS: true,
  249. windowHeight: document.body.scrollHeight
  250. }).then((canvas) => {
  251. // let url = canvas.toDataURL('image/jpeg', 1.0)
  252. const url = canvas.toDataURL()
  253. this.img = url
  254. printJS({
  255. printable: url,
  256. type: 'image',
  257. documentTitle: '打印图片'
  258. })
  259. })
  260. },
  261. getWatermark() {
  262. getInitWatermark().then((res) => {
  263. this.watermarkInfo = res
  264. // this.isEnable = this.watermarkInfo.isEnable
  265. if (res.watermarkType === '1') {
  266. watermark({
  267. watermark_txt: this.watermarkInfo.context,
  268. watermark_alpha: parseFloat(this.watermarkInfo.transparency) / 100
  269. }, 'water-mask', 'img')
  270. } else if (res.watermarkType === '0') {
  271. // if (parent.length > 0) {
  272. // for (let i = 0; i < parent.length; i++) {
  273. // const childImg = parent[i].getElementsByClassName('weterbox')
  274. // if (childImg.length > 0) {
  275. // for (let i = 0; i < childImg.length; i++) {
  276. // parent[i].removeChild(childImg[i])
  277. // }
  278. // }
  279. // }
  280. // }
  281. watermark({
  282. watermark_txt: this.watermarkInfo.context,
  283. watermark_color: this.watermarkInfo.transparency,
  284. watermark_fontsize: this.watermarkInfo.watermarkFont + 'px'
  285. }, 'water-mask', 'text')
  286. }
  287. if (document.getElementById('error-tip')) {
  288. document.getElementsByClassName('water-mask')[0].innerHTML = ''
  289. }
  290. }).catch(err => {
  291. console.log(err)
  292. })
  293. },
  294. async handleChange(e) {
  295. try {
  296. clearTimeout(this.timer)
  297. // const [file] = e.target.files
  298. // console.log('file', file)
  299. const fileReader = new FileReader()
  300. fileReader.readAsArrayBuffer(this.toFile)
  301. fileReader.onload = () => {
  302. this.src = fileReader.result
  303. }
  304. const arrayBuffer = await readBuffer(this.toFile)
  305. this.last = await this.displayResult(arrayBuffer, this.toFile)
  306. this.$nextTick(() => {
  307. // 取得扩展名
  308. const extend = getExtend(this.toFile.name)
  309. // 加水印
  310. const maskDiv = document.getElementsByClassName('mask_div')
  311. const imgMaskDiv = document.getElementsByClassName('weterbox')
  312. if (imgMaskDiv.length === 1) {
  313. document.getElementsByClassName('water-mask')[0].removeChild(imgMaskDiv[0])
  314. }
  315. // docx-wrapper docx
  316. for (var j = maskDiv.length - 1; j >= 0; j--) {
  317. document.getElementsByClassName('water-mask')[0].removeChild(maskDiv[j])
  318. }
  319. if (!extend.includes('pdf')) {
  320. this.getWatermark()
  321. }
  322. })
  323. } catch (e) {
  324. console.error(e)
  325. } finally {
  326. this.timer = setTimeout(() => {
  327. this.loading = false
  328. }, 1000)
  329. }
  330. },
  331. displayResult(buffer, file) {
  332. // 取得文件名
  333. const { name } = file
  334. // 取得扩展名
  335. const extend = getExtend(name)
  336. // 输出目的地
  337. const { output } = this.$refs
  338. // 生成新的dom
  339. const node = document.createElement('div')
  340. // 添加孩子,防止vue实例替换dom元素
  341. if (this.last) {
  342. output.removeChild(this.last.$el)
  343. this.last.$destroy()
  344. }
  345. const child = output.appendChild(node)
  346. // 调用渲染方法进行渲染
  347. return new Promise((resolve, reject) =>
  348. render(buffer, extend, child).then(resolve).catch(reject)
  349. )
  350. },
  351. // 打印ofd文件
  352. async printWindow() {
  353. /* if (this.showScale !== 0) {
  354. this.showScale = 0;
  355. const divs = renderOfd(this.domWidth, this.ofdObj);
  356. await this.displayOfdDiv(divs);
  357. }*/
  358. const childs = this.$refs.output.children
  359. const list = []
  360. for (const page of childs) {
  361. list.push(page.cloneNode(true))
  362. }
  363. if (list.length > 0) {
  364. const printWindow = window.open('打印窗口', '_blank')
  365. // 给新打开的标签页添加画布内容
  366. const documentBody = printWindow.document.body
  367. // 需要给新打开的标签页添加样式,否则打印出来的内容会很错位
  368. documentBody.style.marginTop = '20px'
  369. for (const page of list) {
  370. // 为了让打印的内容不会太靠上,所以给每一页都添加一个marginBottom
  371. page.style.marginBottom = '20px'
  372. documentBody.appendChild(page)
  373. }
  374. // 焦点移到新打开的标签页
  375. printWindow.focus()
  376. // 执行打印的方法(注意打印方法是打印的当前窗口内的元素,所以前面才新建一个窗口:print()--打印当前窗口的内容。)
  377. printWindow.print()
  378. // 操作完成之后关闭当前标签页(点击确定或者取消都会关闭)
  379. printWindow.close()
  380. }
  381. }
  382. }
  383. }
  384. </script>
  385. <style media="print" lang="scss">
  386. @page {
  387. size: auto;
  388. margin: 3mm;
  389. }
  390. @media print {
  391. html {
  392. background-color: #ffffff;
  393. height: auto;
  394. margin: 0px;
  395. }
  396. body {
  397. border: solid 1px #ffffff;
  398. margin: 10mm 15mm 10mm 15mm;
  399. }
  400. table {
  401. table-layout: auto !important;
  402. }
  403. .el-table__header-wrapper .el-table__header {
  404. width: 100% !important;
  405. border: solid 1px #f2f2f2;
  406. }
  407. .el-table__body-wrapper .el-table__body {
  408. width: 100% !important;
  409. }
  410. #pagetable table {
  411. table-layout: fixed !important;
  412. }
  413. }
  414. </style>
  415. <style lang="scss" scoped>
  416. .preview-wrapper{
  417. background-color: #f6f8fc;
  418. .collect-header{
  419. background-color: #fff;
  420. border-bottom: 1px solid #edeff3;
  421. }
  422. }
  423. .top-container{
  424. display: flex;
  425. justify-content: space-between;
  426. padding: 0 20px;
  427. height: 50px;
  428. line-height: 50px;
  429. overflow: hidden;
  430. text-align: center;
  431. align-items: center;
  432. color: #000;
  433. .top-middle{
  434. flex:1;
  435. text-align: center;
  436. font-size: 20px;
  437. font-weight: bold;
  438. }
  439. .top-right{
  440. text-align: center;
  441. align-items: center;
  442. display:flex;
  443. justify-content: flex-end;
  444. .el-button{
  445. padding: 0 4px;
  446. height: 30px;
  447. line-height: 30px;
  448. }
  449. }
  450. }
  451. .main-content{
  452. display: flex;
  453. justify-content: space-between;
  454. width: calc(100%);
  455. height: calc(100vh - 75px);
  456. background-color: #fff;
  457. .content-list{
  458. width: 300px;
  459. .arc-title{
  460. height: 48px;
  461. line-height: 48px;
  462. text-align: center;
  463. font-size: 16px;
  464. color: #0c0e1e;
  465. background-color: #f3f5f8;
  466. }
  467. .file-list{
  468. height: calc(100% - 48px);
  469. padding: 10px 0;
  470. font-size: 12px;
  471. overflow: hidden;
  472. overflow-y: scroll;
  473. li{
  474. display: flex;
  475. justify-content: space-between;
  476. padding: 0 10px 0 20px;
  477. line-height: 26px;
  478. margin-bottom: 4px;
  479. cursor:default;
  480. &.active-file{
  481. background-color: #e8f2ff;
  482. color: #0c0e1e;
  483. }
  484. & span{
  485. display: block;
  486. margin-right: 4px;
  487. }
  488. &:hover{
  489. background-color: #e8f2ff;
  490. color: #0c0e1e;
  491. }
  492. }
  493. }
  494. }
  495. .content-right{
  496. position: relative;
  497. width: calc(100% - 300px);
  498. border: 1px solid #edeff3;
  499. border-top: none;
  500. border-bottom: none;
  501. // overflow-y: auto;
  502. }
  503. }
  504. .well-box{
  505. position: relative;
  506. border: 1px solid #edeff3;
  507. background-color: #f6f8fc;
  508. height: calc(100vh - 150px);
  509. margin: 0 10px;
  510. overflow: hidden;
  511. }
  512. .water-mask{
  513. position: fixed;
  514. left: 300px;
  515. top: 150px;
  516. bottom: 10px;
  517. right: 10px;
  518. width:100%;
  519. z-index:99;
  520. pointer-events: none;
  521. }
  522. .preview-info{
  523. display: flex;
  524. justify-content: space-between;
  525. padding: 15px;
  526. ul{
  527. display: flex;
  528. justify-content: flex-start;
  529. font-size: 14px;
  530. li{
  531. margin-right: 10px;
  532. height: 30px;
  533. line-height: 30px
  534. }
  535. }
  536. .preview-btn{
  537. .el-button.icon-dayin{
  538. &::before{
  539. font-size: 16px;
  540. }
  541. }
  542. }
  543. }
  544. </style>
  545. <style>
  546. .pptx-wrapper {
  547. max-width: 1000px;
  548. margin: 0 auto;
  549. }
  550. .el-loading-mask{
  551. position: fixed;
  552. left: 300px;
  553. top: 75px;
  554. }
  555. </style>