华西海圻ELN前端工程
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.

176 lines
3.9 KiB

  1. <template>
  2. <div>
  3. <div class="edit-container">
  4. <div class="edit-top">
  5. <div class="left-top">
  6. <img src="@/assets/images/back.png" @click="cancel()" />
  7. <div class="left-title"></div>
  8. </div>
  9. <div class="center-top">
  10. </div>
  11. <div class="right-top">
  12. <el-button @click="cancel()">{{ $t('form.cancel') }}</el-button>
  13. <el-button type="primary" @click="yuedu" v-if="form.zt == 0">{{
  14. $t('page.business.study.studyMethod.yuedu') }}</el-button>
  15. </div>
  16. </div>
  17. <div class="edit-content ">
  18. <div class="pdf-layout">
  19. <div class="pdf-content">
  20. <pdf id="pdfBox" :page="pageNum" :src="pdfSrc" @progress="loadedRatio = $event"
  21. @num-pages="totalPages = $event"></pdf>
  22. </div>
  23. <div class="btn-layout" v-if="totalPages">
  24. <div class="pageNum">{{ pageNum }} / {{ totalPages }}</div>
  25. <el-button-group>
  26. <el-button round plain type="primary" icon="el-icon-arrow-left" size="mini"
  27. @click="prePage">上一页</el-button>
  28. <el-button round plain type="primary" size="mini" @click="nextPage">下一页<i
  29. class="el-icon-arrow-right el-icon--right"></i></el-button>
  30. </el-button-group>
  31. </div>
  32. </div>
  33. </div>
  34. </div>
  35. <Yd ref="Yd" @callback="closeYd"/>
  36. </div>
  37. </template>
  38. <script>
  39. import { mapGetters } from 'vuex'
  40. import pdf from 'vue-pdf'
  41. import Yd from './Yd.vue'
  42. export default {
  43. name: "Xq",
  44. components: { pdf, Yd },
  45. data() {
  46. return {
  47. pdfSrc: '',
  48. open: false,
  49. pageNum: 1,
  50. loadedRatio: 0, // 当前页面的加载进度,范围是0-1 ,等于1的时候代表当前页已经完全加载完成了
  51. totalPages: 0, //pdf总页数
  52. form: {},
  53. }
  54. },
  55. computed: {
  56. ...mapGetters([
  57. 'nickName'
  58. ]),
  59. },
  60. created() {
  61. },
  62. methods: {
  63. yuedu() {
  64. this.$refs.Yd.show(this.form)
  65. },
  66. cancel() {
  67. this.$emit('close')
  68. },
  69. show(row) {
  70. this.open = true
  71. this.form = row
  72. this.pdfSrc = process.env.VUE_APP_FILE_DOMAIN + row.fileUrl
  73. this.getPageNum()
  74. },
  75. // 获取PDF总页数
  76. getPageNum() {
  77. let loadingTask = pdf.createLoadingTask(this.fileUrl);
  78. loadingTask.promise
  79. .then((pdf) => {
  80. this.totalPages = pdf.numPages;
  81. this.$nextTick(() => {
  82. this.setWatermarkContent();
  83. });
  84. })
  85. .catch((err) => {
  86. this.$message.warning("pdf加载失败");
  87. });
  88. },
  89. // 上一页
  90. prePage() {
  91. let page = this.pageNum;
  92. page = page > 1 ? page - 1 : this.totalPages;
  93. this.pageNum = page;
  94. window.scrollTo(0, 0);
  95. },
  96. // 下一页
  97. nextPage() {
  98. let page = this.pageNum;
  99. page = page < this.totalPages ? page + 1 : 1;
  100. this.pageNum = page;
  101. window.scrollTo(0, 0);
  102. },
  103. closeYd(val) {
  104. this.form.zt = val
  105. }
  106. }
  107. }
  108. </script>
  109. <style lang="scss">
  110. .pdf-layout {
  111. display: flex;
  112. flex-direction: column;
  113. align-items: center;
  114. }
  115. .pdf-content {
  116. min-width: 1000px;
  117. min-height: 550px;
  118. position: relative;
  119. margin: 0 auto
  120. }
  121. .btn-layout {
  122. display: flex;
  123. flex-direction: column;
  124. align-items: center;
  125. }
  126. .content-edit {
  127. background: #f5f5f5;
  128. padding: 0;
  129. .edit-top {
  130. background: #fff;
  131. padding: 10px 20px;
  132. margin-bottom: 10px;
  133. display: flex;
  134. flex-direction: row;
  135. align-items: center;
  136. justify-content: space-between;
  137. .left-top {
  138. flex-shrink: 0;
  139. display: flex;
  140. flex-direction: row;
  141. align-items: center;
  142. img {
  143. height: 16px;
  144. margin-right: 20px;
  145. cursor: pointer;
  146. }
  147. .right-top {}
  148. }
  149. }
  150. .edit-content {
  151. background: #fff;
  152. padding: 20px;
  153. min-height: 500px;
  154. .edit-form {
  155. width: 800px;
  156. margin: 0 auto;
  157. }
  158. }
  159. }
  160. </style>