ModuleMixin.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // 组件混入
  2. import ModuleBase from './ModuleBase.vue';
  3. import { snGenerationMethodList, viewMethodList, audioViewMethodList } from '@/views/book/courseware/data/common';
  4. import { SaveCoursewareComponentContent, GetCoursewareComponentContent } from '@/api/book';
  5. const mixin = {
  6. data() {
  7. return {
  8. snGenerationMethodList,
  9. viewMethodList,
  10. audioViewMethodList,
  11. };
  12. },
  13. props: {
  14. id: {
  15. type: String,
  16. required: true,
  17. },
  18. },
  19. components: {
  20. ModuleBase,
  21. },
  22. provide() {
  23. return {
  24. showSetting: this.showSetting,
  25. id: this.id,
  26. };
  27. },
  28. inject: ['courseware_id'],
  29. created() {
  30. GetCoursewareComponentContent({ courseware_id: this.courseware_id, component_id: this.id }).then(({ content }) => {
  31. if (content) this.data = JSON.parse(content);
  32. });
  33. },
  34. methods: {
  35. /**
  36. * @description 显示设置
  37. */
  38. showSetting() {
  39. this.$emit('showSetting', this.data.property, this.data.type, this.id);
  40. },
  41. /**
  42. * @description 更新属性
  43. * @param {object} setting 属性
  44. * @param {string} type 属性类型
  45. */
  46. updateSetting(property) {
  47. this.data.property = property;
  48. },
  49. saveCoursewareComponentContent() {
  50. SaveCoursewareComponentContent({
  51. courseware_id: this.courseware_id,
  52. component_id: this.id,
  53. component_type: this.data.type,
  54. content: JSON.stringify(this.data),
  55. });
  56. },
  57. },
  58. };
  59. export default mixin;