word-card-question.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <view class="wordcard-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' : '']" v-if="item.content">
  19. {{item.content}}
  20. </view>
  21. </scroll-view>
  22. <swiper v-if="isShowC" class="swiper-box" :current="currentTab" disable-touch>
  23. <swiper-item class="swiper-topic-list" v-for="(item, index) in questionData.option_list" :key="index">
  24. <view class="swiper-topic-area">
  25. <image v-if="item.picture_url" :src="item.picture_url" mode="heightFix" @click="preview(item.picture_url)" />
  26. <!-- <uni-rate size="18" :value="item.rate" /> -->
  27. <view v-if="item.audio_file_id||item.pinyin">
  28. <AudioPlay v-if="item.audio_file_id.length>0" :file-id="item.audio_file_id" />
  29. <!-- <text v-if="item.pinyin.length>0">{{item.pinyin}}</text> -->
  30. </view>
  31. <view class="pinyin-box" v-if="item.pinyin.length>0&&item.pinyin.trim().split(' ').length>0">
  32. <text class="pinyin" v-for="(pinyin,indexP) in item.pinyin.trim().split(' ')" :key="indexP">
  33. {{pinyin}}
  34. </text>
  35. </view>
  36. <view class="strock-chinese-box">
  37. <Strockplayredline v-for="(word,indexW) in item.hz_strokes_list" :key="indexW" strokeColor="#000000"
  38. :class="['strock-chinese']" :play-storkes="true" :book-text="word.hz"
  39. :target-view="questionData.question_id+'_' + index +'_'+ indexW" :book-strokes="word.strokes" />
  40. </view>
  41. <view class="line"></view>
  42. <view class="text-box">
  43. <view class="example-box" v-if="item.definition.length>0">
  44. <view class="example-title">释义:</view>
  45. <view class="example-text">{{item.definition}}</view>
  46. </view>
  47. <view class="example-box" v-if="item.collocation.length>0">
  48. <view class="example-title">搭配:</view>
  49. <view class="example-text">{{item.collocation}}</view>
  50. </view>
  51. <view class="example-box" v-if="item.example_sentence.length>0">
  52. <view class="example-title">例句:</view>
  53. <view class="example-text" v-for="(example_sentence,indexE) in item.example_sentence" :key="indexE">
  54. <template v-if="example_sentence.length>0">
  55. {{computedQuestionNumber(indexE,questionData.option_number_show_mode)}} {{example_sentence}}
  56. </template>
  57. </view>
  58. </view>
  59. </view>
  60. <!-- 语音作答 -->
  61. <SoundRecord v-if="answer_list[currentTab]" ref="soundRecord" :notOnTheCurPage=true @setAudioId="setFileId"
  62. type="small" :wav-blob.sync="answer_list[currentTab].audio_file_id"
  63. :disabled="answer_control[questionData.question_id].isReadOnly">
  64. </SoundRecord>
  65. </view>
  66. </swiper-item>
  67. </swiper>
  68. <uni-popup ref="parentPopup" :mask-click="false">
  69. <view class="canvas-area">
  70. <text class="canvas-title">录音中...
  71. <text>{{ secondFormatConversion(recordTimes) }}</text>
  72. </text>
  73. <canvas canvas-id="recordCanvas" id="recordCanvas" type="2d" ref="record"></canvas>
  74. <view class="sound-item-svg" @click="parentHandleStop">
  75. <svg fill="#ffffff">
  76. <use xlink:href="#icon-audio-stop"></use>
  77. </svg>
  78. </view>
  79. </view>
  80. </uni-popup>
  81. </view>
  82. </template>
  83. <script>
  84. import {
  85. questionData,
  86. sanitizeHTML,
  87. isEnable,
  88. computedQuestionNumber,
  89. answer_control,
  90. } from '@/pages/answer_question/common/data/common.js';
  91. import {
  92. GetFileStoreInfo,
  93. GetStaticResources,
  94. GetFileURLMap
  95. } from '@/api/api.js';
  96. import {
  97. convertStringToCollection,
  98. secondFormatConversion
  99. } from '@/utils/transform.js';
  100. import Strockplayredline from '@/components/Strockplayredline/Strockplayredline.vue';
  101. import SoundRecord from '@/components/sound-record/sound-record.vue';
  102. import AnswerControlMixin from '@/pages/answer_question/common/data/AnswerControlMixin.js';
  103. export default {
  104. name: "word-card-question",
  105. mixins: [AnswerControlMixin],
  106. components: {
  107. Strockplayredline,
  108. SoundRecord
  109. },
  110. props: {
  111. questionData: questionData,
  112. },
  113. data() {
  114. return {
  115. isEnable,
  116. sanitizeHTML,
  117. computedQuestionNumber,
  118. convertStringToCollection,
  119. secondFormatConversion,
  120. answer_control,
  121. currentTab: 0, //当前标签
  122. tabCurrent: 'tabNum0', //当前标签对应页
  123. isShow: true, //初始化scrooview内容
  124. isShowC: true, //初始化内容
  125. answer_list: [],
  126. timer: null, // 计时器
  127. recordTimes: 0,
  128. };
  129. },
  130. watch: {
  131. answer_list: {
  132. handler(val) {
  133. if (this.isAnswerReady)
  134. this.saveUserAnswer();
  135. },
  136. deep: true,
  137. immediate: true,
  138. },
  139. 'questionData.question_id': {
  140. handler(val) {
  141. this.commonComputedAnswerControl(val);
  142. this.answer_list = [];
  143. this.questionData.option_list.forEach((item) => {
  144. let obj = {
  145. mark: item.mark,
  146. audio_file_id: '',
  147. };
  148. this.answer_list.push(obj);
  149. });
  150. this.$nextTick(() => {
  151. var that = this;
  152. this.currentTab = 0;
  153. this.tabCurrent = 'tabNum0';
  154. this.isShow = false;
  155. this.isShowC = false;
  156. setTimeout(function() {
  157. that.isShow = true;
  158. }, 0)
  159. setTimeout(function() {
  160. that.isShowC = true;
  161. }, 10)
  162. this.getFileUrl();
  163. this.isAnswerReady = true;
  164. this.setUserAnswer();
  165. });
  166. this.$forceUpdate();
  167. },
  168. deep: true,
  169. immediate: true,
  170. },
  171. },
  172. mounted() {
  173. uni.$on('openOrClosePopup', this.openPopup);
  174. },
  175. onUnload() {
  176. uni.$off('openOrClosePopup', this.openPopup);
  177. },
  178. methods: {
  179. //打开遮罩
  180. openPopup(isOpen) {
  181. if (isOpen) {
  182. this.$refs.parentPopup.open('center');
  183. this.recordTimes = 0;
  184. this.timer = setInterval(() => {
  185. this.recordTimes += 1;
  186. }, 1000);
  187. }
  188. },
  189. parentHandleStop() {
  190. this.$refs.soundRecord[this.currentTab].handleStop();
  191. this.$refs.parentPopup.close();
  192. clearInterval(this.timer); //清除计时器
  193. },
  194. getFileUrl() {
  195. var file_id = this.questionData.option_list[this.currentTab].picture_file_id;
  196. if (!file_id) return;
  197. if (!this.questionData.option_list[this.currentTab].picture_url) {
  198. GetFileStoreInfo({
  199. file_id: file_id
  200. }).then(({
  201. file_id,
  202. file_url
  203. }) => {
  204. this.$set(this.questionData.option_list[this.currentTab], 'picture_url', file_url);
  205. });
  206. }
  207. },
  208. playAudio(audio_file_id, index) {
  209. if (!audio_file_id) return;
  210. GetFileURLMap({
  211. file_id_list: [audio_file_id]
  212. }).then(({
  213. url_map
  214. }) => {
  215. var isNotCurAudio = this.currentTab != index;
  216. this.$emit("playAudio", url_map[audio_file_id], isNotCurAudio);
  217. this.currentTab = index;
  218. });
  219. },
  220. //切换词卡
  221. swichMenu(id) {
  222. this.currentTab = id;
  223. this.tabCurrent = 'tabNum' + id;
  224. this.getFileUrl();
  225. },
  226. //异步更新声音ID有问题,所以采用方法手动赋值
  227. setFileId(fileId) {
  228. this.questionData.user_answer[this.questionData.question_id].isEdit = true;
  229. this.$forceUpdate();
  230. },
  231. //填写答案后保存答案
  232. saveUserAnswer: function() {
  233. var that = this;
  234. var questionId = this.questionData.question_id;
  235. this.questionData.user_answer[questionId].isEdit = true;
  236. var ansed = that.answer_list;
  237. this.questionData.user_answer[questionId].is_fill_answer =
  238. ansed.filter(p => p.audio_file_id).length > 0;
  239. this.questionData.user_answer[questionId].content = JSON.stringify(ansed);
  240. this.questionData.user_answer[questionId].answer_list = ansed;
  241. },
  242. //获取用户答案
  243. setUserAnswer: function() {
  244. var that = this;
  245. var callback = function() {
  246. var questionId = that.questionData.question_id;
  247. if (that.questionData.user_answer[questionId].answer_list.length > 0) {
  248. that.answer_list = that.questionData.user_answer[questionId].answer_list;
  249. }
  250. }
  251. this.$emit("getUserAnswer", this.questionData.question_id, callback);
  252. },
  253. }
  254. }
  255. </script>
  256. <style lang="scss" scoped>
  257. .wordcard-area {
  258. .question_title {
  259. display: flex;
  260. flex-direction: row;
  261. margin-bottom: 32rpx;
  262. .question_number,
  263. .question_stem {
  264. color: #34343A;
  265. }
  266. .question_number {
  267. margin-right: 10rpx;
  268. }
  269. }
  270. .description {
  271. padding: 24rpx 48rpx;
  272. border-radius: 40rpx;
  273. font-size: $font-size-serial;
  274. background-color: $uni-bg-color-grey;
  275. margin-top: 32rpx;
  276. }
  277. .words-box {
  278. margin: 32rpx 0;
  279. /deep/ .uni-scroll-view-content {
  280. display: flex;
  281. column-gap: 32rpx;
  282. }
  283. .words-item {
  284. opacity: 0.2;
  285. white-space: nowrap;
  286. color: #ffffff;
  287. background-color: #165DFF;
  288. display: flex;
  289. align-items: center;
  290. column-gap: 10rpx;
  291. padding: 16rpx 32rpx;
  292. border-radius: 40rpx;
  293. }
  294. .menu-topic-active {
  295. opacity: 1;
  296. }
  297. }
  298. /deep/ .swiper-box {
  299. margin-top: 32rpx;
  300. height: 800px;
  301. .swiper-topic-area {
  302. display: flex;
  303. flex-direction: column;
  304. align-items: center;
  305. row-gap: 32rpx;
  306. .strock-chinese-box {
  307. display: flex;
  308. .strock-chinese {
  309. border: 1px solid #e81b1b;
  310. border-right: none;
  311. }
  312. .strock-chinese:last-child {
  313. border-right: 1px solid #e81b1b;
  314. }
  315. }
  316. .pinyin-box {
  317. display: flex;
  318. margin-bottom: -28rpx;
  319. .pinyin {
  320. width: 64px;
  321. text-align: center;
  322. }
  323. }
  324. .line {
  325. width: 100%;
  326. height: 1px;
  327. background-color: #000000;
  328. opacity: 8%;
  329. }
  330. .text-box {
  331. text-align: left;
  332. width: 100%;
  333. .definition {
  334. font-size: 32rpx;
  335. font-weight: 400;
  336. line-height: 48rpx;
  337. }
  338. .example-box {
  339. margin-top: 32rpx;
  340. .example-title {
  341. font-size: 32rpx;
  342. font-weight: 400;
  343. line-height: 44rpx;
  344. opacity: 0.4;
  345. margin-bottom: 16rpx;
  346. }
  347. .example-text {
  348. font-size: 32rpx;
  349. font-weight: 400;
  350. line-height: 44rpx;
  351. }
  352. }
  353. }
  354. }
  355. }
  356. }
  357. /deep/ .sound-record-wrapper {
  358. background-color: $uni-bg-color-grey;
  359. padding: 8rpx;
  360. border-radius: 80rpx;
  361. align-items: center;
  362. column-gap: 16rpx;
  363. margin-top: 0;
  364. }
  365. .canvas-area {
  366. width: 308rpx;
  367. height: 312rpx;
  368. text-align: center;
  369. background-color: rgba(0, 0, 0, 0.8);
  370. border-radius: 32rpx;
  371. position: absolute;
  372. left: 50%;
  373. top: 50%;
  374. transform: translate(-50%, -50%);
  375. padding: 48rpx 32rpx;
  376. z-index: 111;
  377. .canvas-title {
  378. color: #ffffff;
  379. font-size: 28rpx;
  380. }
  381. canvas {
  382. width: 300rpx;
  383. height: 92rpx;
  384. margin: 46rpx 0;
  385. }
  386. .sound-item-svg {
  387. width: 96rpx;
  388. height: 96rpx;
  389. border-radius: 160rpx;
  390. background-color: #7346d3;
  391. display: flex;
  392. justify-content: center;
  393. align-items: center;
  394. margin: 0 auto;
  395. svg {
  396. width: 44rpx;
  397. height: 44rpx;
  398. }
  399. }
  400. }
  401. .audio-wrapper {
  402. margin: 0;
  403. /deep/ .audio-play {
  404. width: 16px !important;
  405. height: 16px !important;
  406. padding: 16rpx;
  407. }
  408. /deep/ .voice-play {
  409. width: 16px !important;
  410. height: 16px !important;
  411. padding: 16rpx;
  412. }
  413. }
  414. </style>