UploadControlView.vue 6.7 KB

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