ChinesePreview.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. <!-- eslint-disable vue/no-v-html -->
  2. <template>
  3. <div class="chinese-preview">
  4. <div class="stem">
  5. <span class="question-number">{{ data.property.question_number }}.</span>
  6. <span v-html="sanitizeHTML(data.stem)"></span>
  7. </div>
  8. <div v-if="isEnable(data.property.is_enable_description)" class="description">{{ data.description }}</div>
  9. <!-- 笔画学习 -->
  10. <div :class="['words-box', 'words-box-' + data.property.learn_type]">
  11. <div v-for="(item, index) in data.option_list" :key="index" :class="['words-item']">
  12. <template v-if="item.content && item.content.trim() && item.strokes">
  13. <div
  14. v-if="data.property.learn_type !== 'dictation'"
  15. class="words-top"
  16. :style="{
  17. width: 64 * (writer_number + 1 > writer_number_yuan ? writer_number_yuan : writer_number + 1) + 'px',
  18. }"
  19. >
  20. <div class="words-left">
  21. <AudioPlay :file-id="item.audio_file_id" theme-color="gray" />
  22. <span class="pinyin">{{ item.pinyin }}</span>
  23. </div>
  24. <p class="words-right">{{ item.definition }}</p>
  25. <p class="words-right">{{ item.collocation }}</p>
  26. </div>
  27. <div v-if="data.property.learn_type === 'paint'" class="card-box">
  28. <!-- 描红 -->
  29. <Strockplayredline
  30. :play-storkes="true"
  31. :book-text="item.content"
  32. :target-div="'pre' + item.content + index"
  33. :book-strokes="item.strokes"
  34. :class="['strock-chinese', 'border-right-none']"
  35. />
  36. <Strockred
  37. v-for="itemI in writer_number"
  38. :key="itemI + data.property.learn_type"
  39. :book-text="item.content"
  40. :hanzi-color="hanzi_color"
  41. :reset="true"
  42. :target-div="'write-praT' + item.content + itemI + Math.random().toString(36).substring(2, 10)"
  43. :book-strokes="item.strokes"
  44. :class="[
  45. 'strock-chinese',
  46. (itemI + 1) % writer_number_yuan !== 0 && itemI !== writer_number ? 'border-right-none' : '',
  47. ]"
  48. />
  49. <!-- <div
  50. v-for="(items, indexs) in item.imgArr"
  51. :key="indexs"
  52. :class="['strockplay-newWord border-left-none']"
  53. @click="freeWrite(items, index, indexs)"
  54. >
  55. <SvgIcon icon-class="hanzi-writer-bg" class="character-target-bg" />
  56. <img
  57. v-if="!play_status && items && items.strokes_image_url"
  58. class="hanzi-writer-img"
  59. :src="items.strokes_image_url"
  60. alt=""
  61. />
  62. </div> -->
  63. </div>
  64. <div v-else-if="data.property.learn_type === 'write'" class="card-box">
  65. <!-- 书写 -->
  66. <Strockplayredline
  67. :play-storkes="true"
  68. :book-text="item.content"
  69. :target-div="'pre' + item.content + index"
  70. :book-strokes="item.strokes"
  71. :class="['strock-chinese']"
  72. />
  73. <div v-for="(items, indexs) in item.imgArr" :key="indexs" class="con-box">
  74. <div
  75. :class="['strockplay-newWord', (indexs + 1) % writer_number_yuan !== 0 ? 'border-left-none' : '']"
  76. @click="freeWrite(items, index, indexs)"
  77. >
  78. <SvgIcon icon-class="hanzi-writer-bg" class="character-target-bg" />
  79. <img
  80. v-if="!play_status && items && items.strokes_image_url"
  81. class="hanzi-writer-img"
  82. :src="items.strokes_image_url"
  83. alt=""
  84. />
  85. </div>
  86. </div>
  87. </div>
  88. </template>
  89. <div v-if="data.property.learn_type === 'dictation'" class="card-box">
  90. <div class="words-info">
  91. <span>{{ computeOptionMethods[data.option_number_show_mode](index) }} </span>
  92. <span class="pinyin">{{ item.pinyin }}</span>
  93. <AudioPlay :file-id="item.audio_file_id" theme-color="white" />
  94. </div>
  95. <div class="words-dic-box">
  96. <div v-for="(itemc, indexc) in item.imgArr" :key="indexc" class="words-dic-item">
  97. <span class="pinyin">{{ item.pinyin_arr[indexc].pinyin_item }}</span>
  98. <div :class="['strockplay-newWord']" @click="freeWrite(itemc, index, indexc)">
  99. <SvgIcon icon-class="hanzi-writer-bg" class="character-target-bg" />
  100. <img
  101. v-if="!play_status && itemc && itemc.strokes_image_url"
  102. class="hanzi-writer-img"
  103. :src="itemc.strokes_image_url"
  104. alt=""
  105. />
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. </div>
  111. </div>
  112. <div v-if="if_free_show" class="practiceBox practice-box-strock">
  113. <FreewriteLettle
  114. ref="freePaint"
  115. :current-tree-i-d="'1234456'"
  116. :current-hz="current_hz"
  117. :curren-hz-data="current_hz_data"
  118. :row-index="active_index"
  119. :col-index="active_col_index"
  120. @closeIfFreeShow="closeIfFreeShow"
  121. @changePraShow="changePraShow"
  122. @changeCurQue="changeCurQue"
  123. @deleteWriteRecord="deleteWriteRecord"
  124. />
  125. </div>
  126. </div>
  127. </template>
  128. <script>
  129. import { computeOptionMethods } from '@/views/exercise_questions/data/common';
  130. import PreviewMixin from './components/PreviewMixin';
  131. import Strockplayredline from './components/common/Strockplayredline.vue';
  132. import Strockred from './components/common/Strockred.vue';
  133. import FreewriteLettle from './components/common/FreewriteLettle.vue';
  134. import { GetStaticResources } from '@/api/app';
  135. export default {
  136. name: 'ChinesePreview',
  137. components: {
  138. Strockplayredline,
  139. Strockred,
  140. FreewriteLettle,
  141. },
  142. mixins: [PreviewMixin],
  143. data() {
  144. return {
  145. computeOptionMethods,
  146. hanzi_color: '#404040', // 描红汉字底色
  147. writer_number_yuan: 19,
  148. writer_number: null, // 书写个数
  149. answer_list: {
  150. write_model: {},
  151. }, // 用户答题数据
  152. if_free_show: false,
  153. free_img: [],
  154. active_index: null,
  155. active_col_index: null,
  156. current_hz: '', // 当前汉字
  157. current_hz_data: null, // 当前汉字数据
  158. play_status: false, // 播放状态
  159. hz_data: [
  160. '你',
  161. '最',
  162. '近',
  163. '怎',
  164. '么',
  165. '样',
  166. '我',
  167. '很',
  168. '好',
  169. '再',
  170. '见',
  171. '吃',
  172. '饭',
  173. '天',
  174. '启',
  175. '扫',
  176. '描',
  177. '以',
  178. '平',
  179. '太',
  180. '效',
  181. '国',
  182. '是',
  183. '称',
  184. '需',
  185. '值',
  186. '复',
  187. '包',
  188. '头',
  189. '条',
  190. '够',
  191. '关',
  192. '放',
  193. '发',
  194. '补',
  195. '快',
  196. '素',
  197. ],
  198. };
  199. },
  200. watch: {
  201. 'data.property.learn_type': {
  202. handler(val, oldVal) {
  203. if (val !== oldVal) {
  204. this.handleData();
  205. }
  206. },
  207. deep: true,
  208. },
  209. },
  210. created() {
  211. this.handleData();
  212. },
  213. mounted() {},
  214. methods: {
  215. // 初始化数据
  216. handleData() {
  217. // if (
  218. // document.getElementsByClassName('preview-content') &&
  219. // document.getElementsByClassName('preview-content')[0] &&
  220. // !this.writer_number
  221. // ) {
  222. // this.writer_number_yuan =
  223. // Math.floor((document.getElementsByClassName('preview-content')[0].clientWidth - 128) / 64) - 1;
  224. // }
  225. // if (this.data.property.learn_type === 'paint') {
  226. // this.writer_number = this.writer_number_yuan - 5;
  227. // } else {
  228. // this.writer_number = this.writer_number_yuan;
  229. // }
  230. this.writer_number_yuan = Math.floor(
  231. (document.getElementsByClassName('preview-content')[0].clientWidth - 128) / 64,
  232. );
  233. this.writer_number = this.data.property.tian_number ? Number(this.data.property.tian_number) : 8;
  234. this.data.option_list.forEach((item, index) => {
  235. let arr = [];
  236. if (this.data.property.learn_type === 'dictation') {
  237. item.pinyin_arr = [];
  238. let pinyin_arr = item.pinyin.trim().split(' ');
  239. pinyin_arr.forEach((itemp) => {
  240. let obj = {
  241. pinyin_item: itemp,
  242. };
  243. arr.push(null);
  244. item.pinyin_arr.push(obj);
  245. });
  246. item.imgArr = arr;
  247. this.answer_list.write_model[this.hz_data[index]] = arr;
  248. } else if (item.content.trim()) {
  249. let MethodName = 'hz_resource_manager-GetHZStrokesContent';
  250. let data = {
  251. hz: item.content.trim(),
  252. };
  253. GetStaticResources(MethodName, data).then((res) => {
  254. this.$set(item, 'strokes', res);
  255. });
  256. for (let i = 0; i < this.writer_number; i++) {
  257. arr.push(null);
  258. }
  259. item.imgArr = arr;
  260. this.answer_list.write_model[item.content] = arr;
  261. }
  262. });
  263. },
  264. changePraShow() {
  265. this.if_free_show = false;
  266. },
  267. closeIfFreeShow(data, rowIndex, colIndex) {
  268. this.data.option_list[rowIndex].imgArr[colIndex] = data;
  269. this.if_free_show = false;
  270. this.freeWrite(data, rowIndex, colIndex);
  271. this.$forceUpdate();
  272. },
  273. freeWrite(imgUrl, index, indexs) {
  274. this.if_free_show = true;
  275. this.active_index = index;
  276. this.active_col_index = indexs;
  277. if (this.data.property.learn_type === 'dictation') {
  278. this.current_hz = this.hz_data[index];
  279. } else {
  280. this.current_hz = this.data.option_list[index].content;
  281. }
  282. this.current_hz_data = imgUrl;
  283. },
  284. // 删除记录
  285. deleteWriteRecord(rowIndex, colIndex, current_hz) {
  286. this.$set(this.data.option_list[rowIndex].imgArr, colIndex, {});
  287. let answer = {
  288. hz: current_hz,
  289. strokes_content: '',
  290. strokes_image_url: '',
  291. };
  292. this.changeCurQue(answer, colIndex);
  293. this.current_hz_data = null;
  294. this.$forceUpdate();
  295. },
  296. changeCurQue(answer, colIndex) {
  297. if (answer) {
  298. let write_model = this.answer_list.write_model;
  299. let hz = answer.hz;
  300. write_model[hz][colIndex] = answer;
  301. }
  302. },
  303. },
  304. };
  305. </script>
  306. <style lang="scss" scoped>
  307. @use '@/styles/mixin.scss' as *;
  308. .chinese-preview {
  309. @include preview;
  310. .words-box {
  311. .words-item {
  312. // display: flex;
  313. // flex-wrap: wrap;
  314. min-width: 64px;
  315. margin-bottom: 24px;
  316. }
  317. .words-top {
  318. display: flex;
  319. width: 100%;
  320. min-height: 30px;
  321. border: 1px solid #e81b1b;
  322. .words-left {
  323. box-sizing: border-box;
  324. display: flex;
  325. column-gap: 4px;
  326. align-items: center;
  327. justify-content: center;
  328. width: 64px;
  329. margin-right: 12px;
  330. border-right: 1px solid #e81b1b;
  331. }
  332. .words-right {
  333. padding: 8px 4px;
  334. margin: 0;
  335. font-size: 14px;
  336. line-height: 14px;
  337. color: #000;
  338. }
  339. }
  340. .audio-wrapper {
  341. height: 16px;
  342. :deep .audio-play {
  343. width: 16px;
  344. height: 16px;
  345. color: #000;
  346. background-color: initial;
  347. }
  348. :deep .audio-play.not-url {
  349. color: #a1a1a1;
  350. }
  351. :deep .voice-play {
  352. width: 16px;
  353. height: 16px;
  354. }
  355. }
  356. .words-info {
  357. display: flex;
  358. column-gap: 4px;
  359. align-items: center;
  360. justify-content: center;
  361. width: max-content;
  362. padding: 5px 16px;
  363. margin: 0 auto 8px;
  364. font-size: 14px;
  365. line-height: 22px;
  366. color: #fff;
  367. background: #165dff;
  368. border-radius: 20px;
  369. .pinyin {
  370. font-size: 14px;
  371. color: #fff;
  372. }
  373. .audio-wrapper {
  374. :deep .audio-play {
  375. color: #fff;
  376. }
  377. :deep .audio-play.not-url {
  378. color: #a1a1a1;
  379. }
  380. }
  381. }
  382. .card-box {
  383. display: flex;
  384. flex-wrap: wrap;
  385. }
  386. .pinyin {
  387. font-family: 'League';
  388. font-size: 12px;
  389. font-weight: 500;
  390. color: #000;
  391. }
  392. .strock-chinese {
  393. border: 1px solid #e81b1b;
  394. border-top: none;
  395. }
  396. .strockplay-newWord {
  397. position: relative;
  398. box-sizing: border-box;
  399. flex-shrink: 0;
  400. width: 64px;
  401. height: 64px;
  402. border: 1px solid #e81b1b;
  403. border-top: none;
  404. .character-target-bg,
  405. .hanzi-writer-img {
  406. position: absolute;
  407. top: 0;
  408. left: 0;
  409. width: 100%;
  410. height: 100%;
  411. color: #dedede;
  412. }
  413. .hanzi-writer-img {
  414. z-index: 1;
  415. }
  416. }
  417. .border-left-none {
  418. border-left: none;
  419. }
  420. .border-right-none {
  421. border-right: none;
  422. }
  423. &-learn {
  424. display: flex;
  425. column-gap: 24px;
  426. .words-item {
  427. display: block;
  428. }
  429. }
  430. }
  431. .words-box-dictation {
  432. display: flex;
  433. flex-wrap: wrap;
  434. column-gap: 24px;
  435. .card-box {
  436. display: block;
  437. }
  438. .words-dic-box {
  439. display: flex;
  440. column-gap: 6px;
  441. width: max-content;
  442. margin: 0 auto;
  443. }
  444. .words-dic-item {
  445. text-align: center;
  446. .pinyin {
  447. line-height: 30px;
  448. }
  449. }
  450. }
  451. .words-dic-item {
  452. .strockplay-newWord {
  453. border-top: 1px solid #e81b1b;
  454. }
  455. }
  456. .practiceBox {
  457. position: fixed;
  458. top: 0;
  459. left: 0;
  460. z-index: 101;
  461. box-sizing: border-box;
  462. width: 100%;
  463. height: 100vh;
  464. overflow: hidden;
  465. overflow-y: auto;
  466. background: rgba(0, 0, 0, 19%);
  467. &.practice-box-strock {
  468. display: flex;
  469. align-items: center;
  470. justify-content: center;
  471. padding-top: 0;
  472. }
  473. }
  474. }
  475. </style>