UploadControlView.vue 9.3 KB

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