ImageTextPreview.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <!-- eslint-disable vue/no-v-html -->
  2. <template>
  3. <div class="imageText-preview" :style="[getAreaStyle(), getComponentStyle()]">
  4. <SerialNumberPosition v-if="isEnable(data.property.sn_display_mode)" :property="data.property" />
  5. <template v-if="data.mp3_list && data.mp3_list.length > 0 && mp3_url">
  6. <AudioLine
  7. ref="audioLine"
  8. audio-id="Audio"
  9. :mp3="mp3_url"
  10. :get-cur-time="getCurTime"
  11. :duration="data.mp3_list[0].media_duration"
  12. :mp3-source="data.mp3_list[0].source"
  13. :width="audio_width"
  14. :ed="ed"
  15. type="audioLine"
  16. :attrib="data.unified_attrib"
  17. @emptyEd="emptyEd"
  18. />
  19. </template>
  20. <div
  21. v-if="image_url"
  22. class="img-box"
  23. :style="{
  24. background: 'url(' + image_url + ') center / contain no-repeat',
  25. width: isMobile ? '100%' : data.image_width + 'px',
  26. height: data.image_height + 'px',
  27. }"
  28. >
  29. <div
  30. v-for="(itemP, indexP) in data.text_list"
  31. :key="'text' + indexP"
  32. :class="['position-item', sentIndex === indexP ? 'active' : '']"
  33. :style="{
  34. width: itemP.width,
  35. height: itemP.height,
  36. left: itemP.x,
  37. top: itemP.y,
  38. }"
  39. @click="handleChangePosition(indexP)"
  40. ></div>
  41. <div
  42. v-for="(itemP, indexP) in data.input_list"
  43. :key="'input' + indexP"
  44. :class="['position-item position-item-input', 'active', ...computedAnswerClass(indexP)]"
  45. :style="{
  46. width: itemP.width,
  47. height: itemP.height,
  48. left: itemP.x,
  49. top: itemP.y,
  50. }"
  51. >
  52. <el-input
  53. v-model="answer.answer_list[indexP].text"
  54. :disabled="disabled"
  55. type="textarea"
  56. style="height: 100%"
  57. placeholder="请输入"
  58. />
  59. </div>
  60. </div>
  61. <div v-if="isShowRightAnswer" class="right-answer">
  62. <div class="title">正确答案</div>
  63. <div
  64. v-if="image_url"
  65. class="img-box"
  66. :style="{
  67. background: 'url(' + image_url + ') center / contain no-repeat',
  68. width: data.image_width + 'px',
  69. height: data.image_height + 'px',
  70. }"
  71. >
  72. <div
  73. v-for="(itemP, indexP) in data.input_list"
  74. :key="'input' + indexP"
  75. :class="['position-item position-item-input', 'active']"
  76. :style="{
  77. width: itemP.width,
  78. height: itemP.height,
  79. left: itemP.x,
  80. top: itemP.y,
  81. }"
  82. >
  83. <el-input
  84. v-model="itemP.text"
  85. :disabled="disabled"
  86. type="textarea"
  87. style="height: 100%"
  88. placeholder="请输入"
  89. />
  90. </div>
  91. </div>
  92. </div>
  93. <el-dialog
  94. v-if="mageazineDetailShow"
  95. :visible.sync="mageazineDetailShow"
  96. :show-close="false"
  97. :close-on-click-modal="false"
  98. :width="isMobile ? '100%' : '80%'"
  99. class="login-dialog magazine-detail-dialog"
  100. :class="[isMobile ? 'magazine-detail-dialog-phone' : '']"
  101. :modal="false"
  102. >
  103. <magazine-sentence
  104. :font-size="fontSize"
  105. :sentence-theme="sentenceTheme"
  106. :data="data.word_time"
  107. :active-index="sentIndex"
  108. :mp3-url="mp3_url"
  109. :multilingual-text-list="showLang && multilingualTextList[getLang()] ? multilingualTextList[getLang()] : []"
  110. :property="data.property"
  111. :attrib="data.unified_attrib"
  112. @closeWord="closeMagazineSentence"
  113. @changeTheme="changeTheme"
  114. />
  115. </el-dialog>
  116. </div>
  117. </template>
  118. <script>
  119. import PreviewMixin from '../common/PreviewMixin';
  120. import AudioLine from '../voice_matrix/components/AudioLine.vue';
  121. import { getImageTextData } from '@/views/book/courseware/data/imageText';
  122. import MagazineSentence from './components/MagazineSentence.vue';
  123. export default {
  124. name: 'ImageTextPreview',
  125. components: { AudioLine, MagazineSentence },
  126. mixins: [PreviewMixin],
  127. props: {
  128. isMobile: {
  129. type: Boolean,
  130. default: false,
  131. },
  132. },
  133. data() {
  134. return {
  135. data: getImageTextData(),
  136. curTime: 0,
  137. paraIndex: -1, // 段落索引
  138. sentIndex: -1, // 句子索引
  139. ed: undefined,
  140. mp3_url: '',
  141. image_url: '',
  142. audio_width: 0,
  143. mageazineDetailIndex: null, // 当前高亮第几个
  144. mageazineDetailShow: false,
  145. inputIndex: null,
  146. fontSize: 20,
  147. sentenceTheme: 0,
  148. multilingualTextList: {},
  149. };
  150. },
  151. watch: {
  152. 'data.image_list': {
  153. handler() {
  154. this.initData();
  155. },
  156. },
  157. },
  158. created() {
  159. this.initData();
  160. },
  161. mounted() {
  162. this.audio_width = document.getElementsByClassName('imageText-preview')[0].clientWidth - 150;
  163. },
  164. methods: {
  165. initData() {
  166. if (!this.isJudgingRightWrong) {
  167. this.answer.answer_list = [];
  168. this.data.input_list.forEach((item) => {
  169. let obj = {
  170. text: '',
  171. answer: item.text,
  172. id: item.id,
  173. };
  174. this.answer.answer_list.push(obj);
  175. });
  176. }
  177. if (this.showLang) {
  178. this.data.multilingual.forEach((item) => {
  179. let trans_arr = item.translation.split('\n');
  180. this.$set(this.multilingualTextList, item.type, trans_arr);
  181. });
  182. }
  183. this.data.image_list.forEach((item) => {
  184. this.image_url = item.file_url;
  185. // GetFileURLMap({ file_id_list: [item.file_id] }).then(({ url_map }) => {
  186. // this.image_url = url_map[item.file_id];
  187. // });
  188. });
  189. this.data.mp3_list.forEach((item) => {
  190. this.mp3_url = item.temporary_url;
  191. // GetFileURLMap({ file_id_list: [item.file_id] }).then(({ url_map }) => {
  192. // this.mp3_url = url_map[item.file_id];
  193. // });
  194. });
  195. if (this.isMobile) {
  196. setTimeout(() => {
  197. let totalWidth = document.querySelector('.imageText-preview').offsetWidth;
  198. let rate = totalWidth / this.data.image_width;
  199. this.data.image_height *= rate;
  200. this.data.input_list.forEach((item) => {
  201. item.width = `${item.width.replace('px', '') * rate}px`;
  202. item.height = `${item.height.replace('px', '') * rate}px`;
  203. item.x = `${item.x.replace('px', '') * rate}px`;
  204. item.y = `${item.y.replace('px', '') * rate}px`;
  205. });
  206. this.data.text_list.forEach((item) => {
  207. item.width = `${item.width.replace('px', '') * rate}px`;
  208. item.height = `${item.height.replace('px', '') * rate}px`;
  209. item.x = `${item.x.replace('px', '') * rate}px`;
  210. item.y = `${item.y.replace('px', '') * rate}px`;
  211. });
  212. }, 50);
  213. }
  214. },
  215. /**
  216. * 计算答题对错选项字体颜色
  217. * @param {string} mark 选项标识
  218. */
  219. computedAnswerClass(i) {
  220. if (!this.isJudgingRightWrong && !this.isShowRightAnswer) {
  221. return '';
  222. }
  223. let answerOption = this.data.input_list[i] ? this.data.input_list[i].text : '';
  224. let selectValue = this.answer.answer_list[i].text ? this.answer.answer_list[i].text.trim() : '';
  225. let classList = [];
  226. let isRight = answerOption && answerOption === selectValue;
  227. if (this.isJudgingRightWrong && answerOption) {
  228. isRight ? classList.push('right') : classList.push('wrong');
  229. }
  230. if (this.isShowRightAnswer && !isRight) {
  231. classList.push('show-right-answer');
  232. }
  233. return classList;
  234. },
  235. getCurTime(curTime) {
  236. this.curTime = curTime * 1000;
  237. this.getSentIndex(this.curTime);
  238. },
  239. getSentIndex(curTime) {
  240. for (let i = 0; i < this.data.word_time.length; i++) {
  241. let bg = this.data.word_time[i].bg;
  242. let ed = this.data.word_time[i].ed;
  243. if (curTime >= bg && curTime <= ed) {
  244. this.sentIndex = i;
  245. break;
  246. }
  247. }
  248. },
  249. emptyEd() {
  250. this.ed = undefined;
  251. },
  252. // 切换画刊里面的卡片
  253. handleChangePosition(index) {
  254. if (this.$refs.audioLine.audio.playing) {
  255. this.$refs.audioLine.PlayAudio();
  256. }
  257. this.sentIndex = index;
  258. this.mageazineDetailShow = true;
  259. },
  260. // 关闭画刊卡片
  261. closeMagazineSentence() {
  262. this.mageazineDetailShow = false;
  263. },
  264. // 切换主题色和文字大小
  265. changeTheme(theme, size) {
  266. if (theme !== '') this.sentenceTheme = theme;
  267. if (size) this.fontSize = size;
  268. },
  269. },
  270. };
  271. </script>
  272. <style lang="scss" scoped>
  273. @use '@/styles/mixin.scss' as *;
  274. .imageText-preview {
  275. max-width: 100%;
  276. overflow: auto;
  277. }
  278. .position-item {
  279. position: absolute;
  280. z-index: 1;
  281. cursor: pointer;
  282. border: 3px solid transparent;
  283. &.active {
  284. border-color: #ff1616;
  285. }
  286. &:hover {
  287. border-color: #ff1616;
  288. }
  289. &.position-item-input {
  290. border-color: #f90;
  291. &.right {
  292. border-color: $right-color;
  293. :deep .el-textarea__inner {
  294. color: $right-color;
  295. }
  296. }
  297. &.wrong {
  298. border-color: $error-color;
  299. :deep .el-textarea__inner {
  300. color: $error-color;
  301. }
  302. }
  303. }
  304. :deep .el-textarea__inner {
  305. height: 100%;
  306. padding: 5px;
  307. font-family: 'League', '楷体';
  308. text-align: center;
  309. resize: none;
  310. background: transparent;
  311. border: none;
  312. }
  313. }
  314. .img-box {
  315. position: relative;
  316. margin: 20px auto;
  317. }
  318. .right-answer {
  319. .title {
  320. margin: 24px 0;
  321. }
  322. }
  323. :deep .el-slider {
  324. flex: 1;
  325. width: auto !important;
  326. }
  327. </style>
  328. <style lang="scss">
  329. .magazine-detail-dialog {
  330. .el-dialog__header,
  331. .el-dialog__body {
  332. padding: 0;
  333. }
  334. .el-dialog {
  335. position: absolute;
  336. bottom: 50px;
  337. left: 50%;
  338. margin-left: -40%;
  339. border: none;
  340. border-radius: 16px;
  341. box-shadow:
  342. 0 6px 30px 5px rgba(0, 0, 0, 5%),
  343. 0 16px 24px 2px rgba(0, 0, 0, 4%),
  344. 0 8px 10px -5px rgba(0, 0, 0, 8%);
  345. }
  346. &-phone {
  347. .el-dialog {
  348. margin-left: -50%;
  349. }
  350. }
  351. }
  352. </style>