ImageTextPreview.vue 10 KB

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