| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- import SerialNumberPosition from './SerialNumberPosition.vue';
- import PinyinText from '@/components/PinyinText.vue';
- import { isEnable } from '@/views/book/courseware/data/common';
- import { ContentGetCoursewareComponentContent } from '@/api/book';
- import { sanitizeHTML } from '@/utils/common';
- const mixin = {
- data() {
- return {
- sanitizeHTML,
- typeList: ['interaction'],
- answer: { answer_list: [], is_right: false }, // 用户答案
- isJudgingRightWrong: false, // 是否判断对错
- isShowRightAnswer: false, // 是否显示正确答案
- disabled: false, // 是否禁用
- isShowParse: false, // 是否显示解析
- isEnable,
- loader: false,
- };
- },
- inject: ['getLang', 'getChinese', 'convertText', 'getTitleList'],
- props: {
- id: {
- type: String,
- default: '',
- },
- content: {
- type: String,
- default: '',
- },
- coursewareId: {
- type: String,
- default: '',
- },
- type: {
- type: String,
- default: '',
- },
- isMobile: {
- type: Boolean,
- default: false,
- },
- },
- computed: {
- showLang() {
- return this.getLang() !== 'ZH';
- },
- },
- watch: {
- content: {
- handler(newVal) {
- if (this.type === 'edit') return;
- if (!newVal) return;
- this.data = JSON.parse(newVal);
- },
- immediate: true,
- },
- },
- components: {
- SerialNumberPosition,
- PinyinText,
- },
- created() {
- // 这里分为 预览 和 编辑调整位置、视频互动组件 三种情况
- // 预览时,content 直接传入
- // 编辑调整位置时,content 需要通过接口获取
- if (this.type === 'edit') {
- this.getCoursewareComponentContent();
- }
- },
- methods: {
- getCoursewareComponentContent() {
- ContentGetCoursewareComponentContent({ courseware_id: this.coursewareId, component_id: this.id }).then(
- ({ content }) => {
- if (content) {
- let oldData = JSON.parse(content);
- if (oldData.type === 'audio') {
- let p = oldData.property || {};
- if (!p.file_name_display_mode) p.file_name_display_mode = 'true';
- if (p.view_method === 'independent' && !p.style_mode) {
- p.style_mode = 'middle';
- }
- if (!p.style_mode) p.style_mode = 'big';
- if (p.view_method === 'icon') {
- p.file_name_display_mode = 'false';
- p.view_method = 'independent';
- p.style_mode = 'small';
- }
- }
- this.data = oldData;
- }
- this.loader = true;
- },
- );
- },
- /**
- * 获取用户答案
- * @returns {array} 用户答案
- */
- getAnswer() {
- return this.answer;
- },
- /**
- * 显示答案
- * @param {boolean} isJudgingRightWrong 是否判断对错
- * @param {boolean} isShowRightAnswer 是否显示正确答案
- * @param {object} userAnswer 用户答案
- * @param {boolean} disabled 是否禁用
- */
- showAnswer(isJudgingRightWrong, isShowRightAnswer, userAnswer, disabled) {
- // if (this.loader === false) {
- // return setTimeout(() => this.showAnswer(isJudgingRightWrong, isShowRightAnswer, userAnswer, disabled), 100);
- // }
- this.isJudgingRightWrong = isJudgingRightWrong;
- this.isShowRightAnswer = isShowRightAnswer;
- this.disabled = disabled;
- if (userAnswer) this.answer = userAnswer;
- },
- /**
- * 得到序号外部样式
- */
- getAreaStyle() {
- if (!isEnable(this.data.property.sn_display_mode)) {
- return {
- grid: `"main" / 1fr`,
- };
- }
- const position = this.data.property.sn_position;
- let grid = '';
- if (position.includes('right')) {
- grid = `"main position" / 1fr auto`;
- } else if (position.includes('left')) {
- grid = `"position main" / auto 1fr`;
- } else if (position.includes('top')) {
- grid = `"position" auto "main" 1fr`;
- } else if (position.includes('bottom')) {
- grid = `"main" 1fr "position" auto`;
- }
- return {
- grid,
- };
- },
- /**
- * 得到背景图、背景色及边框样式
- */
- getComponentStyle() {
- let backgroundData = {};
- if (Object.hasOwn(this.data.property, 'background_image_url')) {
- // 保护性读取位置/大小值,避免 undefined 导致字符串 "undefined%"
- const { background_position: pos } = this.data.property;
- const widthPct = typeof pos.width === 'undefined' ? '' : pos.width;
- const heightPct = typeof pos.height === 'undefined' ? '' : pos.height;
- const leftPct = typeof pos.left === 'undefined' ? '' : pos.left;
- const topPct = typeof pos.top === 'undefined' ? '' : pos.top;
- backgroundData.backgroundImage = `url(${this.data.property.background_image_url})`;
- let bcSize = '';
- if (pos.image_mode === 'fill') {
- bcSize = '100% 100%';
- } else if (pos.image_mode === 'repeat') {
- bcSize = 'auto';
- } else {
- bcSize = `${widthPct}% ${heightPct}%`;
- }
- backgroundData.backgroundSize = bcSize;
- backgroundData.backgroundPosition = pos.image_mode === 'fill' ? '0% 0%' : `${leftPct}% ${topPct}%`;
- backgroundData.backgroundRepeat = pos.image_mode === 'repeat' ? 'repeat' : 'no-repeat';
- }
- let borderData = {};
- if (Object.hasOwn(this.data.property, 'is_border')) {
- const isBorder = isEnable(this.data.property.is_border);
- borderData.borderWidth = isBorder ? (this.data.property.border_style === 'double' ? '3px' : '1px') : '0px';
- borderData.borderStyle = isBorder ? this.data.property.border_style : 'none';
- borderData.borderColor = isBorder ? this.data.property.border_color : 'transparent';
- }
- return {
- backgroundColor: this.data.property?.background_color,
- ...backgroundData,
- ...borderData,
- };
- },
- },
- };
- export default mixin;
|