UploadControl.vue 5.7 KB

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