UploadControlView.vue 6.0 KB

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