word-dictation-question.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. <template>
  2. <view class="word-dictation-area" v-model="questionData">
  3. <view class="question_title">
  4. <text class="question_number">
  5. {{ questionNumberEndIsBracket(questionData.property.question_number) }}
  6. </text>
  7. <text class="question_stem" v-html="sanitizeHTML(questionData.stem)"
  8. :ref="'richText-1-1'+questionData.question_id"
  9. @longpress="previewByRichTextImg(-1,-1,questionData.question_id)"></text>
  10. </view>
  11. <view class="description"
  12. v-if="isEnable(questionData.property.is_enable_description)&&questionData.description.length > 0"
  13. v-html="sanitizeHTML(questionData.description)" :ref="'richText-2-2'+questionData.question_id"
  14. @longpress="previewByRichTextImg(-2,-2,questionData.question_id)">
  15. </view>
  16. <scroll-view v-if="isShow" class="words-box" scroll-x :scroll-into-view="tabCurrent">
  17. <view v-for="(item, index) in questionData.option_list" :key="index" @click="swichMenu(index)"
  18. :id="'tabNum'+index" :class="['words-item',currentTab===index ? 'menu-topic-active' : '']">
  19. <view class="dictation-box">
  20. <text class="serial">{{computedQuestionNumber(index,questionData.option_number_show_mode)}}</text>
  21. <!-- <text>{{item.pinyin}}</text> -->
  22. <AudioPlay v-if="item.audio_file_id" :file-id="item.audio_file_id" :isPlaying="item.isPlaying" />
  23. </view>
  24. </view>
  25. </scroll-view>
  26. <view class="title-split"></view>
  27. <!-- 内容 -->
  28. <swiper v-if="isShowC" class="swiper-box" :current="currentTab" disable-touch
  29. :style="`height: ${contentRealHeight}px`">
  30. <swiper-item class="swiper-topic-list" v-for="(item, index) in questionData.option_list" :key="index">
  31. <view class="swiper-topic-area">
  32. <view class="dictation-content-box" v-for="(itemI,indexI) in item.pinyin_item_list" :key="indexI">
  33. <text class="pinyin-text">{{item.pinyin.trim().split(' ')[indexI]}}</text>
  34. <view class="hanzi-writer-area"
  35. @click="showHanziWritePop('dictation',questionData.question_id+'_'+item.mark+indexI,item.mark,item.pinyin.trim().split(' ')[indexI],indexI)">
  36. <SvgIcon class="character-target-bg" icon-class="hanzi-writer-bg" :size="72" />
  37. <img class="hanzi-writer-img" :ref="'con_'+questionData.question_id+'_'+item.mark+indexI"
  38. :src="imgList[item.mark+indexI]" />
  39. </view>
  40. </view>
  41. </view>
  42. <view class="reference" v-if="answer_control[questionData.question_id].isViewRightAnswer">
  43. <text class="reference-title">参考答案</text>
  44. <view class="pinyin-box">
  45. <text class="pinyin-text" v-for="(itemI,indexI) in item.pinyin_item_list"
  46. :key="indexI">{{item.pinyin.trim().split(' ')[indexI]}}</text>
  47. </view>
  48. <view class="strock-chinese-box">
  49. <Strockplayredline v-for="(word,indexW) in item.hz_strokes_list" :key="indexW" strokeColor="#000000"
  50. :class="['strock-chinese']" :play-storkes="true" :book-text="word.hz"
  51. :target-view="questionData.question_id+'_' + index +'_'+ indexW" :book-strokes="word.strokes" />
  52. </view>
  53. </view>
  54. </swiper-item>
  55. </swiper>
  56. <uni-popup ref="parentPopup" :mask-click="true">
  57. <view class="popup-box">
  58. <FreeWrite :class="['con-box']" :canvasId="'pop_'+canvas_id" :mark="item_mark" :answerIndex="answer_index"
  59. @saveStrock="saveStrock" :userAnswerList="returnUserAnswerList" :pinyin="pinyin_item"
  60. :disabled="answer_control[questionData.question_id].isReadOnly" />
  61. </view>
  62. </uni-popup>
  63. <view class="reference" v-if="isViewAnalysis&&answer_control[questionData.question_id].isViewRightAnswer">
  64. <text class="reference-title">解析</text>
  65. <text class="reference-answer" v-html="sanitizeHTML(questionData.analysis)"
  66. :ref="'richText-3-3'+questionData.question_id"
  67. @longpress="previewByRichTextImg(-3,-3,questionData.question_id)">
  68. </text>
  69. </view>
  70. </view>
  71. </template>
  72. <script>
  73. import {
  74. questionData,
  75. sanitizeHTML,
  76. isEnable,
  77. computedQuestionNumber,
  78. answer_control,
  79. } from '@/pages/answer_question/common/data/common.js';
  80. import {
  81. GetFileStoreInfo,
  82. GetStaticResources,
  83. GetFileURLMap
  84. } from '@/api/api.js';
  85. import FreeWrite from '@/components/FreeWrite/FreeWrite.vue';
  86. import AudioPlay from '@/components/AudioPlay/AudioPlay.vue';
  87. import AnswerControlMixin from '@/pages/answer_question/common/data/AnswerControlMixin.js';
  88. export default {
  89. name: "word-dictation-question",
  90. mixins: [AnswerControlMixin],
  91. components: {
  92. FreeWrite,
  93. AudioPlay
  94. },
  95. props: {
  96. questionData: questionData,
  97. },
  98. data() {
  99. return {
  100. isEnable,
  101. sanitizeHTML,
  102. computedQuestionNumber,
  103. answer_control,
  104. currentTab: 0, //当前标签
  105. prevTab: 0, //上一次点击的标签
  106. tabCurrent: 'tabNum0', //当前标签对应页
  107. currentPager: 0, //当前书写汉字格
  108. hanzi_color: '#404040', // 描红汉字底色
  109. answer_list: {
  110. write_model: {},
  111. }, // 用户答题数据
  112. isShow: true,
  113. isShowC: true,
  114. userAnswerList: [],
  115. returnUserAnswerList: [], //用
  116. strokesList: {}, //用于临时存储笔画
  117. imgList: [],
  118. canvas_id: '',
  119. item_mark: '',
  120. pinyin_item: '',
  121. answer_index: 0,
  122. hasPlay: false,
  123. hz_content: '',
  124. hz_strokes: '',
  125. py_audio_file_id: '',
  126. strokeColorList: [],
  127. contentRealHeight: 0, //答题内容区域高度
  128. };
  129. },
  130. watch: {
  131. 'questionData.question_id': {
  132. handler(val, oldVal) {
  133. var that = this;
  134. that.commonComputedAnswerControl(val);
  135. that.isShow = false;
  136. that.isShowC = false;
  137. that.currentTab = 0;
  138. that.prevTab = 0;
  139. that.currentPager = 0;
  140. that.tabCurrent = 'tabNum0';
  141. that.userAnswerList = [];
  142. // that.questionData.option_list.forEach(p => {
  143. // var strokes_content_list = [];
  144. // p.pinyin_item_list.forEach(m => {
  145. // strokes_content_list.push();
  146. // })
  147. // that.userAnswerList.push({
  148. // mark: p.mark,
  149. // strokes_content_list: strokes_content_list
  150. // });
  151. // })
  152. // console.log(that.userAnswerList);
  153. that.imgList = [];
  154. that.strokesList = {};
  155. if (val !== oldVal) {
  156. var cb = function() {
  157. that.handleData();
  158. };
  159. that.setUserAnswer(cb);
  160. }
  161. },
  162. immediate: true,
  163. deep: true,
  164. },
  165. },
  166. mounted() {
  167. uni.$on('_closePopup', this.closePopup);
  168. uni.$on('setOtherAudioPlaying', this.otherAudioPlaying);
  169. uni.getSystemInfo({
  170. success: (res) => {
  171. this.contentRealHeight = res.windowHeight - 340;
  172. }
  173. });
  174. },
  175. onUnload() {
  176. uni.$off('_closePopup', this.closePopup);
  177. uni.$off('setOtherAudioPlaying', this.otherAudioPlaying);
  178. },
  179. computed: {
  180. isViewAnalysis: function() {
  181. return isEnable(this.questionData.property.is_enable_analysis);
  182. }
  183. },
  184. methods: {
  185. // 初始化数据
  186. handleData() {
  187. var that = this;
  188. setTimeout(function() {
  189. that.isShow = true;
  190. }, 0)
  191. setTimeout(function() {
  192. that.isShowC = true;
  193. }, 10)
  194. var answer_list = [];
  195. this.questionData.option_list.forEach(p => {
  196. p.isPlaying = false;
  197. });
  198. },
  199. //播放当前音频的时候暂停其他音频
  200. otherAudioPlaying(audio_file_id, playing) {
  201. this.questionData.option_list.forEach(p => {
  202. p.isPlaying = false;
  203. if (p.audio_file_id == audio_file_id) {
  204. p.isPlaying = true;
  205. }
  206. });
  207. this.$forceUpdate();
  208. },
  209. //切换汉字
  210. swichMenu(id) {
  211. this.currentPager = 0;
  212. this.currentTab = id;
  213. this.tabCurrent = 'tabNum' + id;
  214. },
  215. //切换当前汉字田字格数
  216. prevIndex(i) {
  217. if (i === 0) return;
  218. this.currentPager--;
  219. },
  220. nextIndex(i, total) {
  221. if (i === total - 1) return;
  222. this.currentPager++;
  223. },
  224. saveStrock(mark, data, img, answerIndex) {
  225. if (!mark) return;
  226. var en = this.questionData.option_list.find(p => p.mark == mark);
  227. if (en == null) return;
  228. var learn_type = this.questionData.property.learn_type;
  229. var oldAnswer = this.userAnswerList.find(p => p.mark == mark);
  230. var hasAnswer = false;
  231. if (!oldAnswer) {
  232. oldAnswer = {
  233. mark: mark,
  234. strokes_content_list: []
  235. };
  236. var answerCount = this.questionData.property.tian_number;
  237. for (var i = 0; i < answerCount; i++) {
  238. oldAnswer.strokes_content_list[i] = '';
  239. }
  240. } else {
  241. hasAnswer = true;
  242. oldAnswer.strokes_content_list[answerIndex] = '';
  243. }
  244. if (data) {
  245. var curHZ = this.strokesList[mark] || {};
  246. var curList = curHZ[answerIndex] || [];
  247. curList.push(data);
  248. curHZ[answerIndex] = curList;
  249. this.strokesList[mark] = curHZ;
  250. var strokes_content = {
  251. hz: en.content.split('')[answerIndex % en.pinyin_item_list.length],
  252. strokes_content: JSON.stringify(curList[0]),
  253. strokes_image: img
  254. };
  255. oldAnswer.strokes_content_list[answerIndex] = JSON.stringify(strokes_content);
  256. if (!hasAnswer)
  257. this.userAnswerList.push(oldAnswer);
  258. }
  259. // console.log(this.userAnswerList);
  260. this.returnUserAnswerList = this.userAnswerList;
  261. var questionId = this.questionData.question_id;
  262. this.questionData.user_answer[questionId].isEdit = this.userAnswerList.length > 0;
  263. this.questionData.user_answer[questionId].answer_list = this.userAnswerList;
  264. const id = 'con_' + this.questionData.question_id + '_' + mark + answerIndex;
  265. const element = this.$refs[id];
  266. if (img) {
  267. this.$forceUpdate();
  268. this.$refs.parentPopup.close();
  269. this.imgList[mark + answerIndex] = img;
  270. element[0].setAttribute('src', img);
  271. element[0].style = "display:block";
  272. } else {
  273. element[0].setAttribute('src', '');
  274. element[0].style = "display:none";
  275. }
  276. // console.log('保存的', this.imgList);
  277. },
  278. setUserAnswer: function(cb) {
  279. // console.log('设置的', this.imgList);
  280. var that = this;
  281. var callback = function() {
  282. var userAnswer = [];
  283. var questionId = that.questionData.question_id;
  284. var _ua = that.questionData.user_answer[questionId];
  285. if (_ua && _ua.answer_list && _ua.answer_list.length > 0)
  286. userAnswer = _ua.answer_list;
  287. that.returnUserAnswerList = userAnswer;
  288. userAnswer.forEach(p => {
  289. if (p.strokes_content_list) {
  290. p.strokes_content_list.forEach((item, i) => {
  291. if (item == null || item.length <= 0) return;
  292. that.imgList[p.mark + i] = JSON.parse(item).strokes_image;
  293. })
  294. }
  295. });
  296. if (cb && typeof cb === 'function') {
  297. cb();
  298. }
  299. }
  300. this.$emit("getUserAnswer", this.questionData.question_id, callback);
  301. },
  302. //书写汉字弹窗
  303. showHanziWritePop(type, canvas_id, item_mark, pinyin_item, answer_index) {
  304. this.$refs.parentPopup.open('center');
  305. this.answer_index = answer_index;
  306. if ('write' == type) {
  307. canvas_id = canvas_id + this.answer_index;
  308. }
  309. this.canvas_id = canvas_id;
  310. this.item_mark = item_mark;
  311. this.pinyin_item = pinyin_item;
  312. },
  313. //关闭弹窗
  314. closePopup() {
  315. this.$refs.parentPopup.close();
  316. },
  317. },
  318. }
  319. </script>
  320. <style lang="scss" scoped>
  321. .word-dictation-area {
  322. .words-box {
  323. margin: 32rpx 0;
  324. /deep/ .uni-scroll-view-content {
  325. display: flex;
  326. column-gap: 32rpx;
  327. }
  328. .words-item {
  329. opacity: 0.2;
  330. .dictation-box {
  331. white-space: nowrap;
  332. color: #ffffff;
  333. background-color: $uni-color-main;
  334. display: flex;
  335. align-items: center;
  336. column-gap: 10rpx;
  337. padding: 16rpx 32rpx;
  338. border-radius: 40rpx;
  339. .serial {
  340. margin-top: -2rpx;
  341. }
  342. }
  343. }
  344. .menu-topic-active {
  345. opacity: 1;
  346. }
  347. }
  348. .title-split {
  349. height: 20rpx;
  350. position: relative;
  351. width: 109.5%;
  352. left: -5%;
  353. background: $uni-bg-color-grey;
  354. box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.1) inset;
  355. }
  356. .swiper-box {
  357. margin-top: 32rpx;
  358. width: 100%;
  359. padding: 4rpx;
  360. .swiper-topic-area {
  361. width: 100%;
  362. display: flex;
  363. column-gap: 16rpx;
  364. row-gap: 16rpx;
  365. flex-wrap: wrap;
  366. .paint-content-box {
  367. display: flex;
  368. align-items: center;
  369. column-gap: 16rpx;
  370. row-gap: 16rpx;
  371. .paint-content-area {
  372. width: 72px;
  373. height: 72px;
  374. display: flex;
  375. align-items: center;
  376. justify-content: center;
  377. border: 1px solid #E81B1B;
  378. }
  379. }
  380. .dictation-content-box {
  381. display: flex;
  382. flex-direction: column;
  383. flex-wrap: wrap;
  384. align-items: center;
  385. row-gap: 16rpx;
  386. column-gap: 16rpx;
  387. .hanzi-writer-area {
  388. position: relative;
  389. .character-target-bg {
  390. // color: #DEDEDE;
  391. border: 1px solid #E81B1B;
  392. }
  393. .hanzi-writer-img {
  394. width: 72px;
  395. height: 72px;
  396. position: absolute;
  397. top: 1px;
  398. left: 1px;
  399. border: 0;
  400. }
  401. .hanzi-writer-img {
  402. z-index: 1;
  403. }
  404. }
  405. .play-handwriting-btn {
  406. width: 72px;
  407. height: 26px;
  408. background-color: #F6F6F6;
  409. border-radius: 6rpx;
  410. font-size: 24rpx;
  411. display: flex;
  412. align-items: center;
  413. justify-content: center;
  414. column-gap: 16rpx;
  415. }
  416. }
  417. }
  418. .reference {
  419. margin: 32rpx 0;
  420. background-color: $uni-bg-color-grey;
  421. padding: 24rpx;
  422. display: flex;
  423. flex-direction: column;
  424. .reference-title {
  425. color: #4E5969;
  426. font-size: 28rpx;
  427. margin-bottom: 16rpx;
  428. }
  429. .pinyin-box {
  430. display: flex;
  431. column-gap: 16rpx;
  432. margin-bottom: 8rpx;
  433. .pinyin-text {
  434. width: 64px;
  435. text-align: center;
  436. }
  437. }
  438. .strock-chinese-box {
  439. display: flex;
  440. column-gap: 16rpx;
  441. .strock-chinese {
  442. border: 1px solid #e81b1b;
  443. }
  444. }
  445. }
  446. }
  447. .popup-box {
  448. padding: 24rpx;
  449. border-radius: 16rpx;
  450. background-color: #ffffff;
  451. .close-box {
  452. display: flex;
  453. justify-content: right;
  454. }
  455. }
  456. .reference {
  457. background-color: #f9f8f9;
  458. padding: 24rpx;
  459. .reference-title {
  460. display: block;
  461. line-height: 64rpx;
  462. color: #4E5969;
  463. font-size: 28rpx;
  464. }
  465. .reference-answer {
  466. color: #1D2129;
  467. line-height: 48rpx;
  468. font-size: 14pt;
  469. }
  470. }
  471. }
  472. .audio-wrapper {
  473. margin: 0;
  474. /deep/ .audio-play {
  475. width: 16px !important;
  476. height: 16px !important;
  477. }
  478. /deep/ .voice-play {
  479. width: 16px !important;
  480. height: 16px !important;
  481. }
  482. }
  483. </style>
  484. <style>
  485. /deep/ uni-swiper {
  486. /* height: calc(100vh - 570rpx) !important; */
  487. }
  488. </style>