PreviewMixin.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import SerialNumberPosition from './SerialNumberPosition.vue';
  2. import DOMPurify from 'dompurify';
  3. import { GetCoursewareComponentContent_View } from '@/api/book';
  4. const mixin = {
  5. data() {
  6. return {
  7. answer: { answer_list: [] }, // 答案
  8. disabled: false, // 是否禁用
  9. };
  10. },
  11. props: {
  12. id: {
  13. type: String,
  14. required: true,
  15. },
  16. coursewareId: {
  17. type: String,
  18. required: true,
  19. },
  20. },
  21. components: {
  22. SerialNumberPosition,
  23. },
  24. created() {
  25. this.getCoursewareComponentContent_View();
  26. },
  27. methods: {
  28. getCoursewareComponentContent_View() {
  29. GetCoursewareComponentContent_View({ courseware_id: this.coursewareId, component_id: this.id }).then(
  30. ({ content }) => {
  31. if (content) this.data = JSON.parse(content);
  32. },
  33. );
  34. },
  35. /**
  36. * 得到序号外部样式
  37. */
  38. getAreaStyle() {
  39. const position = this.data.property.sn_position;
  40. let grid = '';
  41. if (position.includes('right')) {
  42. grid = `"main position" / 1fr auto`;
  43. } else if (position.includes('left')) {
  44. grid = `"position main" / auto 1fr`;
  45. } else if (position.includes('top')) {
  46. grid = `"position" auto "main" 1fr`;
  47. } else if (position.includes('bottom')) {
  48. grid = `"main" 1fr "position" auto`;
  49. }
  50. return {
  51. grid,
  52. };
  53. },
  54. /**
  55. * 过滤 html,防止 xss 攻击
  56. * @param {string} html 需要过滤的html
  57. * @returns {string} 过滤后的html
  58. */
  59. sanitizeHTML(html) {
  60. return DOMPurify.sanitize(html);
  61. },
  62. },
  63. };
  64. export default mixin;