123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544 |
- <!-- eslint-disable vue/no-v-html -->
- <template>
- <div v-if="show_preview" class="chinese-preview">
- <div class="stem">
- <span class="question-number">{{ data.property.question_number }}.</span>
- <span v-html="sanitizeHTML(data.stem)"></span>
- </div>
- <div
- v-if="isEnable(data.property.is_enable_description)"
- class="description rich-text"
- v-html="sanitizeHTML(data.description)"
- ></div>
- <!-- 笔画学习 -->
- <div :class="['words-box', 'words-box-' + data.property.learn_type]">
- <div v-for="(item, index) in option_list" :key="index" :class="['words-item']">
- <template
- v-if="item.content && item.content.trim() && item.hz_strokes_list[0] && item.hz_strokes_list[0].strokes"
- >
- <div
- v-if="data.property.learn_type !== 'dictation'"
- class="words-top"
- :style="{
- width:
- 64 *
- ((writer_number + 1) * item.hz_strokes_list.length > writer_number_yuan
- ? writer_number_yuan
- : (writer_number + 1) * item.hz_strokes_list.length) +
- 'px',
- }"
- >
- <div class="words-left" :style="{ width: '64' * item.hz_strokes_list.length + 'px' }">
- <AudioPlay :file-id="item.audio_file_id" theme-color="gray" />
- <span class="pinyin">{{ item.pinyin }}</span>
- </div>
- <p class="words-right">{{ item.definition }}</p>
- <p class="words-right">{{ item.collocation }}</p>
- </div>
- <div v-if="data.property.learn_type === 'paint'" class="card-box">
- <!-- 描红 -->
- <template v-for="(items, indexs) in item.hz_strokes_list">
- <Strockplayredline
- :key="indexs"
- :play-storkes="true"
- :book-text="item.content"
- :target-div="'pre' + item.content + index + indexs"
- :book-strokes="items.strokes"
- :class="['strock-chinese', 'border-right-none']"
- />
- </template>
- <div v-for="itemI in writer_number" :key="itemI + data.property.learn_type + index" style="display: flex">
- <Strockred
- v-for="(items, indexs) in item.hz_strokes_list"
- :key="indexs"
- :book-text="item.content"
- :hanzi-color="hanzi_color"
- :reset="true"
- :target-div="'write-praT' + item.content + itemI + Math.random().toString(36).substring(2, 10)"
- :book-strokes="items.strokes"
- :class="[
- 'strock-chinese',
- ((item.hz_strokes_list.length * (itemI + 1) + indexs - 1) % writer_number_yuan !== 0 &&
- itemI !== writer_number) ||
- (itemI === writer_number && indexs !== item.hz_strokes_list.length - 1)
- ? 'border-right-none'
- : '',
- ]"
- />
- </div>
- </div>
- <div v-else-if="data.property.learn_type === 'write'" class="card-box">
- <!-- 书写 -->
- <template v-for="(items, indexs) in item.hz_strokes_list">
- <Strockplayredline
- :key="'write' + indexs"
- :play-storkes="true"
- :book-text="item.content"
- :target-div="'pre' + item.content + index + indexs"
- :book-strokes="items.strokes"
- :class="['strock-chinese', indexs !== item.hz_strokes_list.length - 1 ? 'border-right-none' : '']"
- />
- </template>
- <div v-for="(items, indexs) in item.imgArr" :key="indexs" class="con-box">
- <div
- :class="['strockplay-newWord', (indexs + 1) % writer_number_yuan !== 0 ? 'border-left-none' : '']"
- @click="freeWrite(items ? JSON.parse(items) : null, index, indexs, item.mark)"
- >
- <SvgIcon icon-class="hanzi-writer-bg" class="character-target-bg" />
- <img
- v-if="!play_status && items && JSON.parse(items).strokes_image"
- class="hanzi-writer-img"
- :src="JSON.parse(items).strokes_image"
- alt=""
- />
- </div>
- </div>
- </div>
- </template>
- <div v-if="data.property.learn_type === 'dictation'" class="card-box">
- <div class="words-info">
- <span>{{ computeOptionMethods[data.option_number_show_mode](index) }} </span>
- <span class="pinyin">{{ item.pinyin }}</span>
- <AudioPlay :file-id="item.audio_file_id" theme-color="white" />
- </div>
- <div class="words-dic-box">
- <div v-for="(itemc, indexc) in item.imgArr" :key="indexc" class="words-dic-item">
- <span class="pinyin">{{ item.pinyin_arr[indexc].pinyin_item }}</span>
- <div
- :class="['strockplay-newWord']"
- @click="freeWrite(itemc ? JSON.parse(itemc) : itemc, index, indexc, item.mark)"
- >
- <SvgIcon icon-class="hanzi-writer-bg" class="character-target-bg" />
- <img
- v-if="!play_status && itemc && JSON.parse(itemc).strokes_image"
- class="hanzi-writer-img"
- :src="JSON.parse(itemc).strokes_image"
- alt=""
- />
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div v-if="if_free_show" class="practiceBox practice-box-strock">
- <FreewriteLettle
- ref="freePaint"
- :current-tree-i-d="'1234456'"
- :current-hz="current_hz"
- :curren-hz-data="current_hz_data"
- :row-index="active_index"
- :col-index="active_col_index"
- :disabled="disabled"
- @closeIfFreeShow="closeIfFreeShow"
- @changePraShow="changePraShow"
- @changeCurQue="changeCurQue"
- @deleteWriteRecord="deleteWriteRecord"
- />
- </div>
- </div>
- </template>
- <script>
- import { computeOptionMethods } from '@/views/exercise_questions/data/common';
- import PreviewMixin from './components/PreviewMixin';
- import Strockplayredline from './components/common/Strockplayredline.vue';
- import Strockred from './components/common/Strockred.vue';
- import FreewriteLettle from './components/common/FreewriteLettle.vue';
- export default {
- name: 'ChinesePreview',
- components: {
- Strockplayredline,
- Strockred,
- FreewriteLettle,
- },
- mixins: [PreviewMixin],
- data() {
- return {
- computeOptionMethods,
- hanzi_color: '#404040', // 描红汉字底色
- writer_number_yuan: 19,
- writer_number: null, // 书写个数
- if_free_show: false,
- free_img: [],
- active_index: null,
- active_col_index: null,
- current_hz: '', // 当前汉字
- current_hz_data: null, // 当前汉字数据
- play_status: false, // 播放状态
- hz_data: [
- '你',
- '最',
- '近',
- '怎',
- '么',
- '样',
- '我',
- '很',
- '好',
- '再',
- '见',
- '吃',
- '饭',
- '天',
- '启',
- '扫',
- '描',
- '以',
- '平',
- '太',
- '效',
- '国',
- '是',
- '称',
- '需',
- '值',
- '复',
- '包',
- '头',
- '条',
- '够',
- '关',
- '放',
- '发',
- '补',
- '快',
- '素',
- ],
- active_mark: '',
- option_list: [],
- show_preview: false,
- };
- },
- watch: {
- 'data.property.learn_type': {
- handler(val, oldVal) {
- if (val !== oldVal) {
- this.handleData();
- }
- },
- deep: true,
- immediate: true,
- },
- data: {
- handler(val) {
- if (!val || this.data.type !== 'chinese') return;
- this.handleData();
- },
- deep: true,
- immediate: true,
- },
- isJudgingRightWrong: {
- handler(val) {
- if (!val) return;
- this.handleData();
- },
- immediate: true,
- },
- },
- created() {
- // this.handleData();
- },
- mounted() {},
- methods: {
- // 初始化数据
- handleData() {
- if (!this.isJudgingRightWrong) {
- this.answer.answer_list = [];
- }
- this.show_preview = false;
- this.writer_number = this.data.property.tian_number ? Number(this.data.property.tian_number) : 8;
- let option_list = JSON.parse(JSON.stringify(this.data)).option_list;
- option_list.forEach((item, index) => {
- let arr = [];
- if (this.data.property.learn_type === 'dictation') {
- item.pinyin_arr = [];
- let pinyin_arr = item.pinyin.trim().split(' ');
- pinyin_arr.forEach((itemp) => {
- let obj = {
- pinyin_item: itemp,
- };
- arr.push(null);
- item.pinyin_arr.push(obj);
- });
- if (this.isJudgingRightWrong) {
- item.imgArr = this.answer.answer_list[index].strokes_content_list;
- } else {
- item.imgArr = arr;
- }
- } else if (item.content.trim()) {
- for (let i = 0; i < this.writer_number; i++) {
- item.hz_strokes_list.forEach(() => {
- arr.push(null);
- });
- }
- if (this.isJudgingRightWrong) {
- item.imgArr = this.answer.answer_list[index].strokes_content_list;
- } else {
- item.imgArr = arr;
- }
- }
- let obj = {
- mark: item.mark,
- strokes_content_list: arr,
- };
- if (!this.isJudgingRightWrong) {
- this.answer.answer_list.push(obj);
- }
- });
- this.option_list = option_list;
- this.show_preview = true;
- if (document.getElementsByClassName('preview-content').length > 0) {
- this.writer_number_yuan = Math.floor(
- (document.getElementsByClassName('preview-content')[0].clientWidth - 128) / 64,
- );
- }
- },
- changePraShow() {
- this.if_free_show = false;
- },
- closeIfFreeShow(data, rowIndex, colIndex, mark) {
- this.option_list[rowIndex].imgArr[colIndex] = JSON.stringify(data);
- this.if_free_show = false;
- this.freeWrite(data, rowIndex, colIndex, mark);
- this.$forceUpdate();
- },
- freeWrite(imgUrl, index, indexs, mark) {
- this.if_free_show = true;
- this.active_index = index;
- this.active_col_index = indexs;
- this.active_mark = mark;
- if (this.data.property.learn_type === 'dictation') {
- this.current_hz = this.hz_data[index];
- } else {
- this.current_hz = this.option_list[index].content;
- }
- this.current_hz_data = imgUrl;
- },
- // 删除记录
- deleteWriteRecord(rowIndex, colIndex) {
- this.$set(this.option_list[rowIndex].imgArr, colIndex, JSON.stringify({}));
- this.changeCurQue(null, colIndex, this.active_mark);
- this.current_hz_data = null;
- this.active_mark = '';
- this.$forceUpdate();
- },
- changeCurQue(answer, colIndex, mark) {
- if (answer) {
- let write_model = [];
- this.answer.answer_list.forEach((itema) => {
- if (itema.mark === mark) {
- write_model = itema.strokes_content_list;
- }
- });
- write_model[colIndex] = JSON.stringify(answer);
- }
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- @use '@/styles/mixin.scss' as *;
- .chinese-preview {
- @include preview;
- .words-box {
- .words-item {
- // display: flex;
- // flex-wrap: wrap;
- min-width: 64px;
- margin-bottom: 24px;
- }
- .words-top {
- display: flex;
- width: 100%;
- min-height: 30px;
- border: 1px solid #e81b1b;
- .words-left {
- box-sizing: border-box;
- display: flex;
- column-gap: 4px;
- align-items: center;
- justify-content: center;
- width: 64px;
- margin-right: 12px;
- border-right: 1px solid #e81b1b;
- }
- .words-right {
- padding: 8px 4px;
- margin: 0;
- font-size: 14px;
- line-height: 14px;
- color: #000;
- }
- }
- .audio-wrapper {
- height: 16px;
- :deep .audio-play {
- width: 16px;
- height: 16px;
- color: #000;
- background-color: initial;
- }
- :deep .audio-play.not-url {
- color: #a1a1a1;
- }
- :deep .voice-play {
- width: 16px;
- height: 16px;
- }
- }
- .words-info {
- display: flex;
- column-gap: 4px;
- align-items: center;
- justify-content: center;
- width: max-content;
- padding: 5px 16px;
- margin: 0 auto 8px;
- font-size: 14px;
- line-height: 22px;
- color: #fff;
- background: #165dff;
- border-radius: 20px;
- .pinyin {
- font-size: 14px;
- color: #fff;
- }
- .audio-wrapper {
- :deep .audio-play {
- color: #fff;
- }
- :deep .audio-play.not-url {
- color: #a1a1a1;
- }
- }
- }
- .card-box {
- display: flex;
- flex-wrap: wrap;
- }
- .pinyin {
- font-family: 'League';
- font-size: 12px;
- font-weight: 500;
- color: #000;
- }
- .strock-chinese {
- border: 1px solid #e81b1b;
- border-top: none;
- }
- .strockplay-newWord {
- position: relative;
- box-sizing: border-box;
- flex-shrink: 0;
- width: 64px;
- height: 64px;
- border: 1px solid #e81b1b;
- border-top: none;
- .character-target-bg,
- .hanzi-writer-img {
- position: absolute;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- color: #dedede;
- }
- .hanzi-writer-img {
- z-index: 1;
- }
- }
- .border-left-none {
- border-left: none;
- }
- .border-right-none {
- border-right: none;
- }
- &-learn {
- display: flex;
- column-gap: 24px;
- .words-item {
- display: block;
- }
- }
- }
- .words-box-dictation {
- display: flex;
- flex-wrap: wrap;
- column-gap: 24px;
- .card-box {
- display: block;
- }
- .words-dic-box {
- display: flex;
- column-gap: 6px;
- width: max-content;
- margin: 0 auto;
- }
- .words-dic-item {
- text-align: center;
- .pinyin {
- line-height: 30px;
- }
- }
- }
- .words-dic-item {
- .strockplay-newWord {
- border-top: 1px solid #e81b1b;
- }
- }
- .practiceBox {
- position: fixed;
- top: 0;
- left: 0;
- z-index: 101;
- box-sizing: border-box;
- width: 100%;
- height: 100vh;
- overflow: hidden;
- overflow-y: auto;
- background: rgba(0, 0, 0, 19%);
- &.practice-box-strock {
- display: flex;
- align-items: center;
- justify-content: center;
- padding-top: 0;
- }
- }
- }
- </style>
|