PreviewAnswer.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. <!-- -->
  2. <template>
  3. <div class="Book_questionBox_answer">
  4. <template v-if="contextData">
  5. <div v-if="contextData.content.guide" class="guide" v-html="contextData.content.guide" />
  6. <div v-if="contextData.content.article_pdf_file_url" class="pdf">
  7. <pdf
  8. v-for="i in article_pdf_file_numPages"
  9. :key="i"
  10. ref="pdf"
  11. :page="i"
  12. :src="article_pdf_file_id"
  13. />
  14. </div>
  15. <div
  16. v-if="contextData.content.article"
  17. class="article"
  18. @click="chinaDict"
  19. v-html="contextData.content.article"
  20. />
  21. <template v-if="contextData.content.question">
  22. <div :class="['question', screenClass]">
  23. <component
  24. :is="getViewCom"
  25. :answer="answer"
  26. :bookClientWidth="bookClientWidth"
  27. :cur="cur"
  28. :getAnswer="getAnswer"
  29. :handleChildSrcList="handleChildSrcList"
  30. :moduleType="moduleType"
  31. :previewSrcList="previewSrcList"
  32. :queIndex="queIndex"
  33. :uiType="uiType"
  34. :watchIndex="watchIndex"
  35. :bookTaskModel="bookTaskModel"
  36. :bookAnswerShowFlag="bookAnswerShowFlag"
  37. :bookExamAnswer="bookExamAnswer"
  38. :BookWavAnswerWav="BookWavAnswerWav"
  39. @downloadBookWrite="downloadBookWrite"
  40. />
  41. <a class="btn-prev-big" @click="handlePrev" />
  42. <a class="btn-next-big" @click="handleNext" />
  43. </div>
  44. </template>
  45. </template>
  46. <div v-if="articleSrc" class="bookPreviewList">
  47. <i class="el-icon-circle-close" @click="closeBookPreview" />
  48. <!-- <i
  49. @click="handleBookPreviewLeft"
  50. class="el-icon-arrow-left"
  51. v-if="previewSrcListIndex!=0"
  52. ></i>
  53. <i
  54. @click="handleBookPreviewRight"
  55. class="el-icon-arrow-right"
  56. v-if="previewSrcListIndex!=previewSrcList.length - 1"
  57. ></i>-->
  58. <div class="bookPreviewList-inner">
  59. <img :src="articleSrc" class="previewImg">
  60. </div>
  61. </div>
  62. </div>
  63. </template>
  64. <script>
  65. import pdf from 'vue-pdf'
  66. import Cookies from 'js-cookie'
  67. import Single from './SingleAnswer/index' // 选择
  68. import Record from './dialogueAnswer/index' // 录音题
  69. import Blank from './BlankAnswer/index' // 选择
  70. import Match from './MatchAnswer/index' // 匹配题
  71. import Sort from './SortAnswer/index' // 匹配题
  72. import Write from './WriteAnswer/index' // 手写题
  73. import Judge from './JudgeAnswer/index' // 判断题
  74. import Checkoutbox from './CheckoutBoxAnswer/index' // 多选题
  75. import Writing from './WritingAnswer/index' // 写作题
  76. import { getContentFile } from "@/api/ajax";
  77. import { getToken } from '@/utils/auth'
  78. export default {
  79. name: 'QuestionAnswer',
  80. components: {
  81. pdf,
  82. Single,
  83. Record,
  84. Blank,
  85. // Drag,
  86. // SelectCorrect,
  87. Match,
  88. Sort,
  89. Write,
  90. Judge,
  91. Checkoutbox,
  92. Writing
  93. },
  94. props: {
  95. context: {
  96. type: Object,
  97. default: null
  98. },
  99. bookClientWidth: {
  100. type: Number,
  101. default: 800
  102. },
  103. bookAnswerContent: {
  104. type: String,
  105. default: ''
  106. }
  107. },
  108. data() {
  109. return {
  110. contextData: null,
  111. answer: [],
  112. queType: '', // 题型的类型
  113. moduleType: '', // 模版的类型
  114. queList: [], // 题目数组
  115. queTotal: [], // 题目总数
  116. queIndex: -1, // 题目的索引
  117. cur: [], // 当前的题目
  118. uiType: '', // 题型+模板
  119. watchIndex: -1, // 监听的值
  120. previewSrcList: [],
  121. replaceList: [],
  122. articleSrc: '',
  123. previewSrcListIndex: 0, // 点击放大照片index
  124. screenClass: '', // 不同尺寸屏幕宽度对应的class
  125. article_pdf_file_id: '', // pdf地址
  126. article_pdf_file_numPages: null, // pdf页数
  127. // bookClientWidth: 800,// 写死的值记得去掉
  128. bookTaskModel: 'EXAMRESULT', // 当前答题模式
  129. bookAnswerShowFlag: null, // 是否显示标准答案
  130. // bookExamAnswer:localStorage.getItem('exam_answer')?JSON.parse(localStorage.getItem('exam_answer')):[], // 用户答题答案
  131. bookExamAnswer: [], // 用户答题答案
  132. BookWavAnswerWav:[]
  133. }
  134. },
  135. computed: {
  136. getViewCom() {
  137. switch (this.queType) {
  138. case 'SINGLE':
  139. return Single
  140. case 'JUDGE':
  141. return Judge
  142. case 'RECORD':
  143. return Record
  144. case 'BLANK':
  145. return Blank
  146. case 'CHECKOUTBOX':
  147. return Checkoutbox
  148. case 'DRAG':
  149. return Drag
  150. case 'MATCH':
  151. return Match
  152. case 'SORT':
  153. return Sort
  154. case 'WRITE':
  155. return Write
  156. case 'WRITING':
  157. return Writing
  158. }
  159. }
  160. },
  161. watch: {
  162. context: {
  163. handler: function(val, oldVal) {
  164. const _this = this
  165. if (val) {
  166. _this.initContextData()
  167. }
  168. },
  169. // 深度观察监听
  170. deep: true
  171. }
  172. },
  173. // 生命周期 - 创建完成(可以访问当前this实例)
  174. created() { },
  175. // 生命周期 - 挂载完成(可以访问DOM元素)
  176. mounted() {
  177. const _this = this
  178. if (_this.context) {
  179. _this.initContextData()
  180. }
  181. window.onresize = () => {
  182. _this.handleClientwidth()
  183. }
  184. },
  185. beforeCreate() { }, // 生命周期 - 创建之前
  186. beforeMount() { }, // 生命周期 - 挂载之前
  187. beforeUpdate() { }, // 生命周期 - 更新之前
  188. updated() { }, // 生命周期 - 更新之后
  189. beforeDestroy() { }, // 生命周期 - 销毁之前
  190. destroyed() { }, // 生命周期 - 销毁完成
  191. activated() { },
  192. // 方法集合
  193. methods: {
  194. chinaDict(e) {
  195. if (e.target.nodeName === 'SPAN') {
  196. const val = e.target.innerHtml()
  197. } else if (e.target.tagName == 'IMG') {
  198. // 图片地址 e.target.attributes[0].nodeValue
  199. this.articleSrc = e.target.attributes[0].nodeValue
  200. // this.handleSrcListIndex()
  201. }
  202. },
  203. // 子组件调用父级查看图片
  204. handleChildSrcList(src) {
  205. this.articleSrc = src
  206. // this.handleSrcListIndex()
  207. },
  208. // 点击查看图片index
  209. handleSrcListIndex() {
  210. for (let i = 0; i < this.previewSrcList.length; i++) {
  211. if (this.previewSrcList[i] === this.articleSrc) {
  212. this.previewSrcListIndex = i
  213. return false
  214. }
  215. }
  216. },
  217. handleBookPreviewLeft() {
  218. if (this.previewSrcListIndex > 0) {
  219. this.previewSrcListIndex--
  220. this.articleSrc = this.previewSrcList[this.previewSrcListIndex]
  221. }
  222. },
  223. handleBookPreviewRight() {
  224. if (this.previewSrcListIndex < this.previewSrcList.length - 1) {
  225. this.previewSrcListIndex++
  226. this.articleSrc = this.previewSrcList[this.previewSrcListIndex]
  227. }
  228. },
  229. getAnswer() {
  230. const _this = this
  231. _this.$emit('getData', _this.cur)
  232. },
  233. handlePrev() {
  234. const _this = this
  235. if (_this.queIndex == 0) {
  236. this.$message({
  237. message: '已经是第一题',
  238. type: 'success'
  239. })
  240. } else {
  241. _this.queIndex = _this.queIndex - 1
  242. _this.watchIndex = _this.queIndex + new Date().getTime()
  243. _this.cur = _this.queList[_this.queIndex]
  244. }
  245. },
  246. handleNext() {
  247. const _this = this
  248. // if (_this.cur) {
  249. // const answer = _this.cur.Bookanswer
  250. // _this.getAnswer(answer)
  251. // }
  252. if (_this.queIndex == _this.queTotal - 1) {
  253. this.$message({
  254. message: '已经是最后一题',
  255. type: 'success'
  256. })
  257. } else {
  258. _this.queIndex = _this.queIndex + 1
  259. _this.watchIndex = _this.queIndex + new Date().getTime()
  260. _this.cur = _this.queList[_this.queIndex]
  261. }
  262. },
  263. initContextData() {
  264. const _this = this
  265. _this.contextData = JSON.parse(JSON.stringify(_this.context))
  266. _this.bookExamAnswer = JSON.parse(_this.bookAnswerContent)
  267. _this.previewSrcList = []
  268. _this.handlePreImg()
  269. _this.queIndex = 0
  270. _this.watchIndex = _this.queIndex + new Date().getTime()
  271. if (_this.contextData && _this.contextData.ui_type) {
  272. const queType = _this.contextData.ui_type.split('_')
  273. _this.uiType = _this.contextData.ui_type
  274. _this.queType = queType[0]
  275. _this.moduleType = queType[1]
  276. }
  277. if (_this.contextData && _this.contextData.content.question) {
  278. const list = _this.contextData.content.question.data_list
  279. if (list && list.length > 0) {
  280. _this.queList = list
  281. _this.cur = list[_this.queIndex]
  282. _this.queTotal = list.length
  283. }
  284. }
  285. _this.handleClientwidth()
  286. _this.article_pdf_file_id = process.env.VUE_APP_BASE_API + _this.contextData.content.article_pdf_file_url
  287. if (_this.article_pdf_file_id) _this.getPdfNumPages()
  288. },
  289. // 富文本img的地址以及替换img标签
  290. handlePreImg() {
  291. const _this = this
  292. const content = _this.contextData.content.article.replace(
  293. /<img [^>]*src=['"]([^'"]+)[^>]*>/g,
  294. function(match, capture) {
  295. _this.previewSrcList.push(capture)
  296. }
  297. )
  298. },
  299. // 关闭预览图片
  300. closeBookPreview() {
  301. this.articleSrc = ''
  302. },
  303. // 根据不同尺寸的宽设定不同的class
  304. handleClientwidth() {
  305. const clientWidth = this.bookClientWidth ? this.bookClientWidth : document.documentElement.clientWidth
  306. if (clientWidth < 1000) {
  307. this.screenClass = 'questionSmall'
  308. } else if (clientWidth >= 1000 && clientWidth < 1460) {
  309. this.screenClass = 'questionMiddle'
  310. } else {
  311. this.screenClass = ''
  312. }
  313. },
  314. // 获取pdf的页数
  315. getPdfNumPages() {
  316. const _this = this
  317. const loadingTask = pdf.createLoadingTask(_this.article_pdf_file_id)
  318. loadingTask.promise
  319. .then((pdf) => {
  320. _this.article_pdf_file_numPages = pdf._pdfInfo.numPages
  321. })
  322. .catch((err) => {
  323. })
  324. },
  325. // 是否显示标准答案
  326. bookAnswerShow(flag) {
  327. this.bookAnswerShowFlag = flag
  328. },
  329. downloadBookWrite(idList){
  330. debugger
  331. let MethodName = "file_store_manager-StartCreateFileCompressPack"
  332. let data = {
  333. file_id_list:JSON.parse(idList)
  334. }
  335. getContentFile(MethodName, data)
  336. .then((res) => {
  337. let id = res.file_compress_task_id
  338. let _this = this
  339. this.bookDownTimer = setInterval(()=>{_this.checkTaskProgress(id)}, 2000);
  340. })
  341. .catch((error) => {
  342. });
  343. },
  344. //成功后调用打包进度
  345. checkTaskProgress(taskId){
  346. let userInfor = getToken();
  347. let UserCode = '',
  348. UserType = '',
  349. SessionID = ''
  350. if (userInfor) {
  351. let user = JSON.parse(getToken());
  352. UserCode = user.user_code;
  353. UserType = user.user_type;
  354. SessionID = user.session_id;
  355. }
  356. let MethodName = "file_store_manager-GetFileCompressTaskProgress"
  357. let data = {
  358. file_compress_task_id:taskId
  359. }
  360. getContentFile(MethodName, data)
  361. .then((res) => {
  362. if(res.is_finish=='true'){
  363. clearInterval(this.bookDownTimer)
  364. window.open(process.env.VUE_APP_BASE_API +
  365. `/GCLSFileServer/WebFileDownload?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}&FileID=${res.compress_pack_file_id}`)
  366. }
  367. })
  368. .catch((error) => {
  369. });
  370. },
  371. } // 如果页面有keep-alive缓存功能,这个函数会触发
  372. }
  373. </script>
  374. <style lang='scss' scoped>
  375. .Book_questionBox_answer {
  376. width: 100%;
  377. height: 100%;
  378. .guide {
  379. font-size: 20px;
  380. margin-bottom: 10px;
  381. }
  382. .article {
  383. margin-bottom: 10px;
  384. img {
  385. cursor: pointer;
  386. }
  387. }
  388. .question {
  389. position: relative;
  390. width: 1440px;
  391. // height: 100%;
  392. margin:0 auto;
  393. background: #ffd66b url('../assets/single/bg.png') center no-repeat;
  394. background-size: 100% 100%;
  395. padding: 20px 0px 0 0;
  396. &.questionMiddle {
  397. width: 960px;
  398. > div {
  399. padding: 0 30px;
  400. height: 600px;
  401. overflow-y: auto;
  402. }
  403. .btn-prev-big,
  404. .btn-next-big {
  405. width: 48px;
  406. height: 116px;
  407. margin-top: -58px;
  408. }
  409. }
  410. &.questionSmall {
  411. width: 720px;
  412. > div {
  413. padding: 0 20px;
  414. height: 450px;
  415. overflow-y: auto;
  416. }
  417. .btn-prev-big,
  418. .btn-next-big {
  419. width: 36px;
  420. height: 87px;
  421. margin-top: -44px;
  422. }
  423. }
  424. > div {
  425. padding: 0 40px;
  426. height: 900px;
  427. overflow-y: auto;
  428. }
  429. .btn-prev-big,
  430. .btn-next-big {
  431. width: 72px;
  432. height: 174px;
  433. position: absolute;
  434. left: 0;
  435. top: 50%;
  436. margin-top: -87px;
  437. background: url('../assets/single/btn-prev.png') center no-repeat;
  438. background-size: 100% 100%;
  439. }
  440. .btn-next-big {
  441. right: 0;
  442. left: auto;
  443. background: url('../assets/single/btn-next.png') center no-repeat;
  444. background-size: 100% 100%;
  445. }
  446. .btn-prev-big:active {
  447. background: url('../assets/single/btn-prev-click.png') center
  448. no-repeat;
  449. background-size: 100% 100%;
  450. }
  451. .btn-next-big:active {
  452. background: url('../assets/single/btn-next-click.png') center
  453. no-repeat;
  454. background-size: 100% 100%;
  455. }
  456. }
  457. .bookPreviewList {
  458. position: fixed;
  459. top: 0;
  460. left: 0;
  461. width: 100%;
  462. height: 100%;
  463. background: rgba(44, 44, 44, 0.7);
  464. z-index: 999;
  465. .el-icon-circle-close {
  466. cursor: pointer;
  467. position: absolute;
  468. right: 40px;
  469. top: 40px;
  470. &:before {
  471. font-size: 40px;
  472. color: rgba(255, 255, 255, 1);
  473. font-weight: blod;
  474. }
  475. }
  476. .el-icon-arrow-left {
  477. cursor: pointer;
  478. position: absolute;
  479. left: 40px;
  480. top: 50%;
  481. margin-top: -40px;
  482. &:before {
  483. font-size: 80px;
  484. color: rgba(255, 255, 255, 1);
  485. font-weight: blod;
  486. }
  487. }
  488. .el-icon-arrow-right {
  489. cursor: pointer;
  490. position: absolute;
  491. right: 40px;
  492. top: 50%;
  493. margin-top: -40px;
  494. &:before {
  495. font-size: 80px;
  496. color: rgba(255, 255, 255, 1);
  497. font-weight: blod;
  498. }
  499. }
  500. .bookPreviewList-inner {
  501. width: 100%;
  502. height: 100%;
  503. display: flex;
  504. justify-content: center;
  505. align-items: center;
  506. }
  507. img.previewImg {
  508. max-width: 100%;
  509. max-height: 100%;
  510. }
  511. }
  512. }
  513. </style>