| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- import SerialNumberPosition from './SerialNumberPosition.vue';
- import PinyinText from '@/components/PinyinText.vue';
- import AnswerAnalysis from '@/views/book/courseware/preview/common/AnswerAnalysis.vue';
- import PreviewOperation from '@/views/book/courseware/preview/common/PreviewOperation.vue';
- import AnswerCorrect from '@/views/book/courseware/preview/common/AnswerCorrect.vue';
- import { isEnable } from '@/views/book/courseware/data/common';
- import { ContentGetCoursewareComponentContent, ContentSaveCoursewareComponentContent } 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,
- visibleAnswerAnalysis: false, // 是否显示答案解析弹窗
- answerAnalysisState: null, // 答案解析弹窗前的状态快照
- visibleAnswerCorrect: false, // 是否显示批改弹窗
- isCheckCorrect: false, // 是否查看批改信息
- };
- },
- provide() {
- return {
- openAnswerCorrect: (isCheckCorrect) => this.openAnswerCorrect(isCheckCorrect),
- };
- },
- inject: ['getLang', 'getChinese', 'convertText', 'getTitleList', 'getPermissionControl'],
- props: {
- id: {
- type: String,
- default: '',
- },
- content: {
- type: String,
- default: '',
- },
- background: {
- type: Object,
- default: () => ({}),
- },
- coursewareId: {
- type: String,
- default: '',
- },
- type: {
- type: String,
- default: '',
- },
- isMobile: {
- type: Boolean,
- default: false,
- },
- },
- computed: {
- showLang() {
- return this.getLang() !== 'ZH';
- },
- permissionControl() {
- return this.getPermissionControl();
- },
- },
- watch: {
- content: {
- handler(newVal) {
- if (this.type === 'edit') return;
- if (!newVal) return;
- this.data = JSON.parse(newVal);
- },
- immediate: true,
- },
- 'permissionControl.can_answer': {
- handler(newVal) {
- this.disabled = !newVal;
- },
- immediate: true,
- },
- },
- components: {
- SerialNumberPosition,
- PinyinText,
- AnswerAnalysis,
- PreviewOperation,
- AnswerCorrect,
- },
- 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;
- },
- judgeCorrect() {
- this.isJudgingRightWrong = true;
- this.isShowRightAnswer = false;
- },
- /**
- * 获取批改信息
- * @returns {string} 批改信息
- */
- getAnswerCorrect() {
- return this.data.answer_correct || '';
- },
- /**
- * 设置批改信息
- * @param {string} correct 批改信息
- */
- setAnswerCorrect(correct) {
- this.$set(this.data, 'answer_correct', correct);
- },
- /**
- * 得到序号外部样式
- */
- 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,
- };
- },
- /**
- * 计算组件背景样式
- * @returns {Object} 组件背景样式对象
- */
- getComponentStyle() {
- const {
- background_image_url: bcImgUrl = '',
- background_position: pos = {},
- background: back,
- } = this.background || {};
- let canvasStyle = {
- backgroundSize: bcImgUrl ? `${pos.width}% ${pos.height}%` : '',
- backgroundPosition: bcImgUrl ? `${pos.left}% ${pos.top}%` : '',
- backgroundImage: bcImgUrl ? `url(${bcImgUrl})` : '',
- backgroundColor: bcImgUrl ? `rgba(255, 255, 255, ${1 - back?.image_opacity / 100})` : '',
- };
- if (back) {
- if (back.mode === 'image') {
- canvasStyle['backgroundBlendMode'] = 'lighten';
- } else {
- canvasStyle['backgroundBlendMode'] = '';
- }
- if (back.imageMode === 'fill') {
- canvasStyle['backgroundRepeat'] = 'repeat';
- canvasStyle['backgroundSize'] = '';
- canvasStyle['backgroundPosition'] = '';
- } else {
- canvasStyle['backgroundRepeat'] = 'no-repeat';
- }
- if (back.imageMode === 'stretch') {
- canvasStyle['backgroundSize'] = '100% 100%';
- }
- if (back.imageMode === 'adapt') {
- canvasStyle['backgroundSize'] = 'contain';
- }
- if (back.imageMode === 'auto') {
- canvasStyle['backgroundPosition'] = `${pos.imgX}% ${pos.imgY}%`;
- }
- if (back.mode === 'color') {
- canvasStyle['backgroundColor'] = back.color;
- canvasStyle['backgroundImage'] = '';
- canvasStyle['backgroundRepeat'] = '';
- canvasStyle['backgroundPosition'] = '';
- canvasStyle['backgroundSize'] = '';
- }
- if (back.enable_border) {
- canvasStyle['border'] = `${back.border_width}px ${back.border_style} ${back.border_color}`;
- } else {
- canvasStyle['border'] = 'none';
- }
- if (back.enable_radius) {
- canvasStyle['border-top-left-radius'] = `${back.top_left_radius}px`;
- canvasStyle['border-top-right-radius'] = `${back.top_right_radius}px`;
- canvasStyle['border-bottom-left-radius'] = `${back.bottom_left_radius}px`;
- canvasStyle['border-bottom-right-radius'] = `${back.bottom_right_radius}px`;
- } else {
- canvasStyle['border-radius'] = '0';
- }
- }
- return canvasStyle;
- },
- // 显示答案与解析页面
- showAnswerAnalysis() {
- if (!this.answerAnalysisState) {
- this.answerAnalysisState = {
- disabled: this.disabled,
- isJudgingRightWrong: this.isJudgingRightWrong,
- };
- }
- this.visibleAnswerAnalysis = true;
- this.disabled = true;
- this.isJudgingRightWrong = this.permissionControl.can_judge_correct;
- this.isShowRightAnswer = this.permissionControl.can_show_answer;
- },
- // 关闭答案与解析页面
- closeAnswerAnalysis() {
- if (this.answerAnalysisState) {
- this.disabled = this.answerAnalysisState.disabled;
- this.isJudgingRightWrong = this.answerAnalysisState.isJudgingRightWrong;
- this.isShowRightAnswer = false;
- this.answerAnalysisState = null;
- } else {
- this.disabled = false;
- this.isJudgingRightWrong = false;
- this.isShowRightAnswer = false;
- }
- },
- /**
- * 显示批改页面
- * @param {boolean} isCheckCorrect 是否查看批改
- */
- openAnswerCorrect(isCheckCorrect) {
- this.visibleAnswerCorrect = true;
- this.isCheckCorrect = isCheckCorrect;
- },
- /**
- * @description 关闭批改页面,并传递批改信息
- * @param {string} correct 批改信息
- */
- closeAnswerCorrect(correct) {
- this.visibleAnswerCorrect = false;
- this.$set(this.data, 'answer_correct', correct);
- },
- getNoTextContentData() {
- let noTextContentData = JSON.parse(JSON.stringify(this.data));
- if (noTextContentData.content) {
- noTextContentData.content = '';
- }
- return noTextContentData;
- },
- /**
- * @description 保存样式模板
- * @param {string} courseware_id 课件id
- */
- saveStyleTemplate(courseware_id) {
- const content = this.getNoTextContentData();
- return ContentSaveCoursewareComponentContent({
- courseware_id,
- component_id: this.id,
- component_type: this.data.type,
- content: JSON.stringify(content),
- });
- },
- },
- };
- export default mixin;
|