UploadControlView.vue 6.8 KB

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