UploadControlView.vue 11 KB

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