ModuleMixin.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. deleteComponent: {
  19. type: Function,
  20. required: true,
  21. },
  22. componentMove: {
  23. type: Function,
  24. required: true,
  25. },
  26. },
  27. components: {
  28. ModuleBase,
  29. },
  30. provide() {
  31. return {
  32. showSetting: this.showSetting,
  33. id: this.id,
  34. deleteComponent: this.deleteComponent,
  35. handleComponentMove: this.handleComponentMove,
  36. };
  37. },
  38. inject: ['courseware_id'],
  39. created() {
  40. GetCoursewareComponentContent({ courseware_id: this.courseware_id, component_id: this.id }).then(({ content }) => {
  41. if (content) {
  42. this.$nextTick(() => {
  43. // 数据加载完成后的操作
  44. this.data = JSON.parse(content);
  45. });
  46. }
  47. });
  48. },
  49. methods: {
  50. /**
  51. * @description 显示设置
  52. */
  53. showSetting() {
  54. this.$emit('showSetting', this.data.property, this.data.type, this.id);
  55. },
  56. /**
  57. * @description 更新属性
  58. * @param {object} setting 属性
  59. * @param {string} type 属性类型
  60. */
  61. updateSetting(property) {
  62. this.data.property = property;
  63. },
  64. handleComponentMove(data) {
  65. this.componentMove({ ...data, id: this.id });
  66. },
  67. saveCoursewareComponentContent() {
  68. SaveCoursewareComponentContent({
  69. courseware_id: this.courseware_id,
  70. component_id: this.id,
  71. component_type: this.data.type,
  72. content: JSON.stringify(this.data),
  73. });
  74. },
  75. },
  76. };
  77. export default mixin;