lookDocumentListDialog.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <!--
  2. 查看多个文档
  3. import lookDocumentListDialog from '@/components/lookDocumentDialog/lookDocumentListDialog.vue'
  4. components: {
  5. lookDocumentListDialog
  6. },
  7. <lookDocumentListDialog v-if="lookDocumentListType" :propsLookDocumentListData="propsLookDocumentListData"></lookDocumentListDialog>
  8. //查看多个文档
  9. lookDocumentListButton(type){
  10. if(type==1){
  11. this.$set(this,'propsLookDocumentListData',{
  12. title:"查看附件",
  13. list:this.addForm.data7
  14. });
  15. this.$set(this,'lookDocumentListType',true);
  16. }else{
  17. this.$set(this,'lookDocumentListType',false);
  18. }
  19. },
  20. -->
  21. <template>
  22. <el-dialog class="lookDocumentListDialog" :title="lookDocumentListTitle"
  23. :visible.sync="lookDocumentListType" v-if="lookDocumentListType"
  24. @close="outLook"
  25. width="1500px" height="700" append-to-body>
  26. <div class="lookDocumentListDialog-page">
  27. <div class="left-box">
  28. <div class="left-title-box">
  29. <img src="@/assets/ZDimages/safetyCheck/icon_dr_wj.png">
  30. <p>材料附件</p>
  31. <p class="button-p" @click="allDownloadButton">全部下载</p>
  32. </div>
  33. <div class="left-for-box scrollbar-box">
  34. <p class="left-for-p" v-for="(iframeItem,iframeIndex) in lookDocumentList" :key="iframeIndex"
  35. @click="lookDocumentListCheck(iframeIndex)"
  36. :class="lookDocumentListIndex == iframeIndex?'check-p':''">{{iframeItem.name}}</p>
  37. </div>
  38. </div>
  39. <div class="center-border"></div>
  40. <div class="right-box">
  41. <vue-office-docx
  42. style="width:1030px;"
  43. v-if="officeType === 'docx'&&!officeNullType"
  44. :src="lookUrl"
  45. @rendered="renderedHandler"
  46. @error="errorHandler"
  47. />
  48. <vue-office-excel
  49. style="width:1030px;"
  50. v-if="officeType === 'excel'&&!officeNullType"
  51. :src="lookUrl"
  52. @rendered="renderedHandler"
  53. @error="errorHandler"
  54. />
  55. <vue-office-pdf
  56. style="width:1030px;"
  57. v-if="officeType === 'pdf'&&!officeNullType"
  58. :src="lookUrl"
  59. @rendered="renderedHandler"
  60. @error="errorHandler"
  61. />
  62. <p v-if="officeNullType" class="office-null-text">加载失败...</p>
  63. </div>
  64. </div>
  65. <div slot="footer" class="dialog-footer dialog-footer-box" style="display: flex">
  66. <p class="dialog-footer-button-null"></p>
  67. <p class="dialog-footer-button-info" @click="outLook">取消</p>
  68. <p class="dialog-footer-button-primary" @click="downloadButton">下载</p>
  69. <p class="dialog-footer-button-null"></p>
  70. </div>
  71. </el-dialog>
  72. </template>
  73. <script>
  74. //引入VueOfficeDocx组件
  75. import VueOfficeDocx from '@vue-office/docx'
  76. import '@vue-office/docx/lib/index.css'
  77. //引入VueOfficeExcel组件
  78. import VueOfficeExcel from '@vue-office/excel'
  79. import '@vue-office/excel/lib/index.css'
  80. //引入VueOfficePdf组件
  81. import VueOfficePdf from '@vue-office/pdf'
  82. import axios from 'axios'
  83. import saveAs from 'file-saver'
  84. import JSZip from 'jszip'
  85. export default {
  86. name: 'lookDocumentListDialog',
  87. props:{
  88. propsLookDocumentListData:{},
  89. },
  90. components: {
  91. VueOfficeDocx,
  92. VueOfficeExcel,
  93. VueOfficePdf
  94. },
  95. data(){
  96. return{
  97. lookDocumentListType:true,
  98. lookDocumentListTitle:"",
  99. lookDocumentList:[],
  100. lookDocumentSrc:"",
  101. lookDocumentListIndex:0,
  102. //文档类型
  103. officeType:null,
  104. //开关
  105. officeNullType:true,
  106. //文档地址
  107. lookUrl:"",
  108. fileBrowseEnvironment:localStorage.getItem('fileBrowseEnvironment'),
  109. }
  110. },
  111. created(){
  112. this.$set(this,'lookDocumentListTitle',this.propsLookDocumentListData.title);
  113. this.$set(this,'lookDocumentList',this.propsLookDocumentListData.list);
  114. this.lookDocumentListCheck(0);
  115. },
  116. mounted(){
  117. },
  118. methods:{
  119. //全部下载
  120. allDownloadButton(){
  121. // 初始化一个zip打包对象
  122. let zip = new JSZip()
  123. var promises = [];
  124. this.lookDocumentList.forEach(item => {
  125. const promise = this.getFile(item.url).then(data => {
  126. console.log(data)
  127. zip.file(item.name, data, { binary: true });
  128. });
  129. promises.push(promise);
  130. });
  131. Promise.all(promises).then(() => {
  132. zip.generateAsync({ type: "blob" }).then(content => {
  133. // 生成二进制流
  134. saveAs(content, '材料附件.zip')
  135. this.msgSuccess('操作成功')
  136. });
  137. });
  138. },
  139. getFile(url){
  140. return new Promise((resolve, reject) => {
  141. axios({
  142. method: "get",
  143. url:this.fileBrowseEnvironment+url,
  144. responseType: "blob"
  145. })
  146. .then(data => {
  147. resolve(data.data);
  148. })
  149. .catch(error => {
  150. reject(error.toString());
  151. });
  152. });
  153. },
  154. // 切换按钮
  155. lookDocumentListCheck(val){
  156. let type = '';
  157. if(this.lookDocumentList[val].url.split('.')[1] == 'docx'){
  158. type = 'docx'
  159. }else if(this.lookDocumentList[val].url.split('.')[1] == 'xlsx'){
  160. type = 'excel'
  161. }else if(this.lookDocumentList[val].url.split('.')[1] == 'pdf'){
  162. type = 'pdf'
  163. }
  164. let url = this.fileBrowseEnvironment + this.lookDocumentList[val].url;
  165. this.$set(this,'lookUrl',url);
  166. this.$set(this,'lookDocumentListIndex',val);
  167. this.$set(this,'officeType',type);
  168. this.$set(this,'officeNullType',false);
  169. },
  170. // 返回按钮
  171. outLook(){
  172. this.$parent.lookDocumentListButton(2)
  173. },
  174. // 下载按钮
  175. downloadButton(){
  176. let name = this.lookDocumentList[this.lookDocumentListIndex].name.split('.')[0];
  177. let type = this.lookDocumentList[this.lookDocumentListIndex].name.split('.')[1];
  178. let url = this.fileBrowseEnvironment + this.lookDocumentList[this.lookDocumentListIndex].url;
  179. const oReq = new XMLHttpRequest()
  180. oReq.open('GET', url, true)// URL 为下载的URL地址
  181. oReq.responseType = 'blob'
  182. oReq.onload = function() {
  183. const file = new Blob([oReq.response], {
  184. type: 'blob'
  185. })
  186. saveAs(file, name+'.'+type) // fileName为文件名
  187. }
  188. oReq.send()
  189. },
  190. //文件加载成功
  191. renderedHandler() {
  192. console.log("渲染完成")
  193. this.$set(this,'officeNullType',false);
  194. },
  195. //文件加载失败
  196. errorHandler() {
  197. console.log("渲染失败")
  198. this.$set(this,'officeNullType',true);
  199. },
  200. }
  201. }
  202. </script>
  203. <style scoped lang="scss">
  204. .lookDocumentListDialog{
  205. .lookDocumentListDialog-page{
  206. display: flex;
  207. flex:1;
  208. height:645px;
  209. overflow: hidden;
  210. padding:0 50px;
  211. .left-box{
  212. display: flex;
  213. flex-direction: column;
  214. overflow: hidden;
  215. width:265px;
  216. .left-title-box{
  217. padding-bottom:20px;
  218. display: flex;
  219. width:230px;
  220. border-bottom:1px dashed #D8D8D8;
  221. img{
  222. width:16px;
  223. height:13px;
  224. margin:13px 15px 13px 0;
  225. }
  226. p:nth-child(2){
  227. flex:1;
  228. line-height:40px;
  229. font-size:16px;
  230. color:#0183FA;
  231. }
  232. .button-p{
  233. padding:0 10px;
  234. margin-top:5px;
  235. height:30px;
  236. line-height:30px;
  237. font-size:14px;
  238. color:#0183FA;
  239. border:1px solid #0183FA;
  240. border-radius:4px;
  241. cursor: pointer;
  242. }
  243. .button-p:hover{
  244. color:#fff;
  245. border:1px solid #0183FA;
  246. background-color: #0183FA;
  247. }
  248. }
  249. .left-for-box{
  250. flex:1;
  251. .left-for-p{
  252. padding:0 10px;
  253. width:230px;
  254. line-height:40px;
  255. margin-top:10px;
  256. font-size:16px;
  257. color:#333;
  258. display:block;
  259. overflow:hidden;
  260. text-overflow:ellipsis;
  261. white-space:nowrap;
  262. cursor: pointer;
  263. }
  264. .check-p{
  265. background-color:rgba(1,131,250,0.2);
  266. color:#0183FA;
  267. }
  268. }
  269. }
  270. .center-border{
  271. border-right:1px dashed #D8D8D8;
  272. }
  273. .right-box{
  274. flex:1;
  275. display: flex;
  276. margin-left:57px;
  277. position: relative;
  278. .positionButton{
  279. position: absolute;
  280. top:15px;
  281. right: 35px;
  282. border:1px solid #0183fa;
  283. border-radius:4px;
  284. line-height:30px;
  285. width:60px;
  286. text-align: center;
  287. cursor: pointer;
  288. color:#0183fa;
  289. background-color: #fff;
  290. }
  291. .iframe{
  292. flex:1;
  293. }
  294. }
  295. .out-button{
  296. width:60px;
  297. line-height:30px;
  298. color:#999;
  299. background-color: #dedede;
  300. border-radius:4px;
  301. text-align: center;
  302. cursor: pointer;
  303. position: absolute;
  304. top:17px;
  305. right:17px;
  306. z-index:99999;
  307. }
  308. }
  309. }
  310. </style>