UploadControl.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <!-- -->
  2. <template>
  3. <div class="Big-Book-prev-Textdes Tinydemo" v-if="curQue">
  4. <UploadView
  5. :changeFillId="changeFillId"
  6. :accept="accept"
  7. :filleNumber="1"
  8. :fileList="curQue.fileList"
  9. />
  10. <div class="dv" v-loading="loading">
  11. <div class="main">
  12. <div class="content">
  13. <template v-if="curQue.data">
  14. <template
  15. v-if="
  16. curQue.data.file_name.indexOf('png') != -1 ||
  17. curQue.data.file_name.indexOf('jpg') != -1
  18. "
  19. >
  20. <img :src="curQue.data.file_url" alt="" />
  21. </template>
  22. <template v-else-if="curQue.data.file_name.indexOf('pdf') != -1">
  23. <pdf
  24. ref="pdf"
  25. :src="curQue.data.fileRelativePath"
  26. v-for="i in curQue.data.numPages"
  27. :key="i"
  28. :page="i"
  29. >
  30. </pdf>
  31. </template>
  32. </template>
  33. </div>
  34. </div>
  35. <div class="remove" @click="remove">
  36. <img src="../../../assets/adult/red_remove.png" alt="" />
  37. </div>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. import UploadView from "../common/UploadView.vue";
  43. import pdf from "vue-pdf";
  44. export default {
  45. components: {
  46. UploadView,
  47. pdf,
  48. },
  49. props: ["curQue", "changeCurQue"],
  50. data() {
  51. return {
  52. uploadType: "",
  53. fileList: [],
  54. data: null,
  55. numPages: null,
  56. accept: ".png,.jpg,.pdf",
  57. data_structure: {
  58. type: "upload_control_chs",
  59. name: "上传控件",
  60. title: "",
  61. fileList: [],
  62. },
  63. loading: false,
  64. };
  65. },
  66. computed: {},
  67. watch: {},
  68. //方法集合
  69. methods: {
  70. remove() {
  71. this.data = null;
  72. this.curQue.data = null;
  73. this.curQue.fileList = [];
  74. this.$message.success("删除成功");
  75. },
  76. changeFillId(fileList, item, index) {
  77. this.curQue.fileList = fileList;
  78. this.curQue.data = fileList[0].response.file_info_list[0];
  79. if (this.curQue.data.file_name.indexOf("pdf" != -1)) {
  80. this.curQue.data = fileList[0].response.file_info_list[0];
  81. this.curQue.data.fileRelativePath =
  82. process.env.VUE_APP_BASE_API + this.curQue.data.file_relative_path;
  83. this.getNumPages();
  84. }
  85. },
  86. // 获取pdf的页数
  87. getNumPages() {
  88. let _this = this;
  89. let loadingTask = pdf.createLoadingTask(
  90. _this.curQue.data.fileRelativePath
  91. );
  92. loadingTask.promise
  93. .then((pdff) => {
  94. _this.numPages = pdff.numPages;
  95. _this.curQue.data.numPages = pdff.numPages;
  96. this.$forceUpdate();
  97. })
  98. .catch((err) => {
  99. this.$message.success("pdf 加载失败", err);
  100. this.data = null;
  101. this.curQue.data = null;
  102. this.curQue.fileList = [];
  103. });
  104. },
  105. initcurQue() {
  106. let data = JSON.parse(JSON.stringify(this.data_structure));
  107. this.changeCurQue(data);
  108. },
  109. },
  110. //生命周期 - 创建完成(可以访问当前this实例)
  111. created() {
  112. if (!this.curQue) {
  113. this.initcurQue();
  114. } else {
  115. }
  116. },
  117. //生命周期 - 挂载完成(可以访问DOM元素)
  118. mounted() {},
  119. beforeCreate() {}, //生命周期 - 创建之前
  120. beforeMount() {}, //生命周期 - 挂载之前
  121. beforeUpdate() {}, //生命周期 - 更新之前
  122. updated() {}, //生命周期 - 更新之后
  123. beforeDestroy() {}, //生命周期 - 销毁之前
  124. destroyed() {}, //生命周期 - 销毁完成
  125. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  126. };
  127. </script>
  128. <style lang='scss' scoped>
  129. //@import url(); 引入公共css类
  130. .Big-Book-prev-Textdes {
  131. padding: 24px 0 24px 24px;
  132. background: #f7f7f7;
  133. border: 1px solid rgba(0, 0, 0, 0.1);
  134. .dv {
  135. display: flex;
  136. align-items: center;
  137. .remove {
  138. width: 40px;
  139. height: 39px;
  140. background: #ffffff;
  141. border: 1px solid rgba(0, 0, 0, 0.1);
  142. box-sizing: border-box;
  143. border-radius: 8px;
  144. display: flex;
  145. align-items: center;
  146. justify-content: center;
  147. margin-left: 32px;
  148. cursor: pointer;
  149. img {
  150. width: 24px;
  151. height: 24px;
  152. }
  153. }
  154. }
  155. .main {
  156. margin-top: 23px;
  157. width: 477px;
  158. height: 292px;
  159. background: #ffffff;
  160. border: 1px solid rgba(0, 0, 0, 0.1);
  161. box-sizing: border-box;
  162. border-radius: 8px;
  163. display: flex;
  164. align-items: center;
  165. justify-content: center;
  166. .content {
  167. width: 445px;
  168. height: 260px;
  169. border-radius: 4px;
  170. box-sizing: border-box;
  171. background: linear-gradient(0deg, #ebebeb, #ebebeb);
  172. overflow-y: scroll;
  173. img {
  174. max-width: 100%;
  175. max-height: 100%;
  176. }
  177. }
  178. }
  179. }
  180. </style>