123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446 |
- <template>
- <view class="wordcard-area" v-model="questionData">
- <view class="question_title">
- <text class="question_number">
- {{ questionNumberEndIsBracket(questionData.property.question_number) }}
- </text>
- <text class="question_stem" v-html="sanitizeHTML(questionData.stem)"
- :ref="'richText-1-1'+questionData.question_id"
- @longpress="previewByRichTextImg(-1,-1,questionData.question_id)"></text>
- </view>
- <view class="description"
- v-if="isEnable(questionData.property.is_enable_description)&&questionData.description.length > 0"
- v-html="sanitizeHTML(questionData.description)" :ref="'richText-2-2'+questionData.question_id"
- @longpress="previewByRichTextImg(-2,-2,questionData.question_id)">
- </view>
- <scroll-view v-if="isShow" class="words-box" scroll-x :scroll-into-view="tabCurrent">
- <view v-for="(item, index) in questionData.option_list" :key="index" @click="swichMenu(index)"
- :id="'tabNum'+index" :class="['words-item',currentTab===index ? 'menu-topic-active' : '']" v-if="item.content">
- {{item.content}}
- </view>
- </scroll-view>
- <swiper v-if="isShowC" class="swiper-box" :current="currentTab" disable-touch>
- <swiper-item class="swiper-topic-list" v-for="(item, index) in questionData.option_list" :key="index">
- <view class="swiper-topic-area">
- <image v-if="item.picture_url" :src="item.picture_url" mode="heightFix" @click="preview(item.picture_url)" />
- <!-- <uni-rate size="18" :value="item.rate" /> -->
- <view v-if="item.audio_file_id||item.pinyin">
- <AudioPlay v-if="item.audio_file_id.length>0" :file-id="item.audio_file_id" />
- <!-- <text v-if="item.pinyin.length>0">{{item.pinyin}}</text> -->
- </view>
- <view class="pinyin-box" v-if="item.pinyin.length>0&&item.pinyin.trim().split(' ').length>0">
- <text class="pinyin" v-for="(pinyin,indexP) in item.pinyin.trim().split(' ')" :key="indexP">
- {{pinyin}}
- </text>
- </view>
- <view class="strock-chinese-box">
- <Strockplayredline v-for="(word,indexW) in item.hz_strokes_list" :key="indexW" strokeColor="#000000"
- :class="['strock-chinese']" :play-storkes="true" :book-text="word.hz"
- :target-view="questionData.question_id+'_' + index +'_'+ indexW" :book-strokes="word.strokes" />
- </view>
- <view class="line"></view>
- <view class="text-box">
- <view class="example-box" v-if="item.definition.length>0">
- <view class="example-title">释义:</view>
- <view class="example-text">{{item.definition}}</view>
- </view>
- <view class="example-box" v-if="item.collocation.length>0">
- <view class="example-title">搭配:</view>
- <view class="example-text">{{item.collocation}}</view>
- </view>
- <view class="example-box" v-if="item.example_sentence.length>0">
- <view class="example-title">例句:</view>
- <view class="example-text" v-for="(example_sentence,indexE) in item.example_sentence" :key="indexE">
- <template v-if="example_sentence.length>0">
- {{computedQuestionNumber(indexE,questionData.option_number_show_mode)}} {{example_sentence}}
- </template>
- </view>
- </view>
- </view>
- <!-- 语音作答 -->
- <SoundRecord v-if="answer_list[currentTab]" ref="soundRecord" :notOnTheCurPage=true @setAudioId="setFileId"
- type="small" :wav-blob.sync="answer_list[currentTab].audio_file_id"
- :disabled="answer_control[questionData.question_id].isReadOnly">
- </SoundRecord>
- </view>
- </swiper-item>
- </swiper>
- <uni-popup ref="parentPopup" :mask-click="false">
- <view class="canvas-area">
- <text class="canvas-title">录音中...
- <text>{{ secondFormatConversion(recordTimes) }}</text>
- </text>
- <canvas canvas-id="recordCanvas" id="recordCanvas" type="2d" ref="record"></canvas>
- <view class="sound-item-svg" @click="parentHandleStop">
- <svg fill="#ffffff">
- <use xlink:href="#icon-audio-stop"></use>
- </svg>
- </view>
- </view>
- </uni-popup>
- </view>
- </template>
- <script>
- import {
- questionData,
- sanitizeHTML,
- isEnable,
- computedQuestionNumber,
- answer_control,
- } from '@/pages/answer_question/common/data/common.js';
- import {
- GetFileStoreInfo,
- GetStaticResources,
- GetFileURLMap
- } from '@/api/api.js';
- import {
- convertStringToCollection,
- secondFormatConversion
- } from '@/utils/transform.js';
- import Strockplayredline from '@/components/Strockplayredline/Strockplayredline.vue';
- import SoundRecord from '@/components/sound-record/sound-record.vue';
- import AnswerControlMixin from '@/pages/answer_question/common/data/AnswerControlMixin.js';
- export default {
- name: "word-card-question",
- mixins: [AnswerControlMixin],
- components: {
- Strockplayredline,
- SoundRecord
- },
- props: {
- questionData: questionData,
- },
- data() {
- return {
- isEnable,
- sanitizeHTML,
- computedQuestionNumber,
- convertStringToCollection,
- secondFormatConversion,
- answer_control,
- currentTab: 0, //当前标签
- tabCurrent: 'tabNum0', //当前标签对应页
- isShow: true, //初始化scrooview内容
- isShowC: true, //初始化内容
- answer_list: [],
- timer: null, // 计时器
- recordTimes: 0,
- };
- },
- watch: {
- answer_list: {
- handler(val) {
- if (this.isAnswerReady)
- this.saveUserAnswer();
- },
- deep: true,
- immediate: true,
- },
- 'questionData.question_id': {
- handler(val) {
- this.commonComputedAnswerControl(val);
- this.answer_list = [];
- this.questionData.option_list.forEach((item) => {
- let obj = {
- mark: item.mark,
- audio_file_id: '',
- };
- this.answer_list.push(obj);
- });
- this.$nextTick(() => {
- var that = this;
- this.currentTab = 0;
- this.tabCurrent = 'tabNum0';
- this.isShow = false;
- this.isShowC = false;
- setTimeout(function() {
- that.isShow = true;
- }, 0)
- setTimeout(function() {
- that.isShowC = true;
- }, 10)
- this.getFileUrl();
- this.isAnswerReady = true;
- this.setUserAnswer();
- });
- this.$forceUpdate();
- },
- deep: true,
- immediate: true,
- },
- },
- mounted() {
- uni.$on('openOrClosePopup', this.openPopup);
- },
- onUnload() {
- uni.$off('openOrClosePopup', this.openPopup);
- },
- methods: {
- //打开遮罩
- openPopup(isOpen) {
- if (isOpen) {
- this.$refs.parentPopup.open('center');
- this.recordTimes = 0;
- this.timer = setInterval(() => {
- this.recordTimes += 1;
- }, 1000);
- }
- },
- parentHandleStop() {
- this.$refs.soundRecord[this.currentTab].handleStop();
- this.$refs.parentPopup.close();
- clearInterval(this.timer); //清除计时器
- },
- getFileUrl() {
- var file_id = this.questionData.option_list[this.currentTab].picture_file_id;
- if (!file_id) return;
- if (!this.questionData.option_list[this.currentTab].picture_url) {
- GetFileStoreInfo({
- file_id: file_id
- }).then(({
- file_id,
- file_url
- }) => {
- this.$set(this.questionData.option_list[this.currentTab], 'picture_url', file_url);
- });
- }
- },
- playAudio(audio_file_id, index) {
- if (!audio_file_id) return;
- GetFileURLMap({
- file_id_list: [audio_file_id]
- }).then(({
- url_map
- }) => {
- var isNotCurAudio = this.currentTab != index;
- this.$emit("playAudio", url_map[audio_file_id], isNotCurAudio);
- this.currentTab = index;
- });
- },
- //切换词卡
- swichMenu(id) {
- this.currentTab = id;
- this.tabCurrent = 'tabNum' + id;
- this.getFileUrl();
- },
- //异步更新声音ID有问题,所以采用方法手动赋值
- setFileId(fileId) {
- this.questionData.user_answer[this.questionData.question_id].isEdit = true;
- this.$forceUpdate();
- },
- //填写答案后保存答案
- saveUserAnswer: function() {
- var that = this;
- var questionId = this.questionData.question_id;
- this.questionData.user_answer[questionId].isEdit = true;
- var ansed = that.answer_list;
- this.questionData.user_answer[questionId].is_fill_answer =
- ansed.filter(p => p.audio_file_id).length > 0;
- this.questionData.user_answer[questionId].content = JSON.stringify(ansed);
- this.questionData.user_answer[questionId].answer_list = ansed;
- },
- //获取用户答案
- setUserAnswer: function() {
- var that = this;
- var callback = function() {
- var questionId = that.questionData.question_id;
- if (that.questionData.user_answer[questionId].answer_list.length > 0) {
- that.answer_list = that.questionData.user_answer[questionId].answer_list;
- }
- }
- this.$emit("getUserAnswer", this.questionData.question_id, callback);
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- .wordcard-area {
- .question_title {
- display: flex;
- flex-direction: row;
- margin-bottom: 32rpx;
- .question_number,
- .question_stem {
- color: #34343A;
- }
- .question_number {
- margin-right: 10rpx;
- }
- }
- .description {
- padding: 24rpx 48rpx;
- border-radius: 40rpx;
- font-size: $font-size-serial;
- background-color: $uni-bg-color-grey;
- margin-top: 32rpx;
- }
- .words-box {
- margin: 32rpx 0;
- /deep/ .uni-scroll-view-content {
- display: flex;
- column-gap: 32rpx;
- }
- .words-item {
- opacity: 0.2;
- white-space: nowrap;
- color: #ffffff;
- background-color: #165DFF;
- display: flex;
- align-items: center;
- column-gap: 10rpx;
- padding: 16rpx 32rpx;
- border-radius: 40rpx;
- }
- .menu-topic-active {
- opacity: 1;
- }
- }
- /deep/ .swiper-box {
- margin-top: 32rpx;
- height: 800px;
- .swiper-topic-area {
- display: flex;
- flex-direction: column;
- align-items: center;
- row-gap: 32rpx;
- .strock-chinese-box {
- display: flex;
- .strock-chinese {
- border: 1px solid #e81b1b;
- border-right: none;
- }
- .strock-chinese:last-child {
- border-right: 1px solid #e81b1b;
- }
- }
- .pinyin-box {
- display: flex;
- margin-bottom: -28rpx;
- .pinyin {
- width: 64px;
- text-align: center;
- }
- }
- .line {
- width: 100%;
- height: 1px;
- background-color: #000000;
- opacity: 8%;
- }
- .text-box {
- text-align: left;
- width: 100%;
- .definition {
- font-size: 32rpx;
- font-weight: 400;
- line-height: 48rpx;
- }
- .example-box {
- margin-top: 32rpx;
- .example-title {
- font-size: 32rpx;
- font-weight: 400;
- line-height: 44rpx;
- opacity: 0.4;
- margin-bottom: 16rpx;
- }
- .example-text {
- font-size: 32rpx;
- font-weight: 400;
- line-height: 44rpx;
- }
- }
- }
- }
- }
- }
- /deep/ .sound-record-wrapper {
- background-color: $uni-bg-color-grey;
- padding: 8rpx;
- border-radius: 80rpx;
- align-items: center;
- column-gap: 16rpx;
- margin-top: 0;
- }
- .canvas-area {
- width: 308rpx;
- height: 312rpx;
- text-align: center;
- background-color: rgba(0, 0, 0, 0.8);
- border-radius: 32rpx;
- position: absolute;
- left: 50%;
- top: 50%;
- transform: translate(-50%, -50%);
- padding: 48rpx 32rpx;
- z-index: 111;
- .canvas-title {
- color: #ffffff;
- font-size: 28rpx;
- }
- canvas {
- width: 300rpx;
- height: 92rpx;
- margin: 46rpx 0;
- }
- .sound-item-svg {
- width: 96rpx;
- height: 96rpx;
- border-radius: 160rpx;
- background-color: #7346d3;
- display: flex;
- justify-content: center;
- align-items: center;
- margin: 0 auto;
- svg {
- width: 44rpx;
- height: 44rpx;
- }
- }
- }
- .audio-wrapper {
- margin: 0;
- /deep/ .audio-play {
- width: 16px !important;
- height: 16px !important;
- padding: 16rpx;
- }
- /deep/ .voice-play {
- width: 16px !important;
- height: 16px !important;
- padding: 16rpx;
- }
- }
- </style>
|