UploadControlView.vue 6.0 KB

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