index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <template>
  2. <div class="task-preview">
  3. <MenuPage only-key="/personal_workbench/edit_task" />
  4. <CommonPreview
  5. :id="id"
  6. ref="preview"
  7. :project-id="project_id"
  8. type="edit_preview"
  9. @updateBackground="background = $event"
  10. @selectedComponent="curComponentData = $event"
  11. >
  12. <template #operator="{ courseware }">
  13. <span class="link" @click="openCreateTemplateDialog">保存为个人模板</span>
  14. <template v-if="isTrue(courseware.is_can_start_edit)">
  15. <span class="link" @click="showSetBackground">背景设置</span>
  16. <span class="link" @click="showSetComponentBackground">组件背景设置</span>
  17. <span class="link" @click="editTask()">开始编辑</span>
  18. </template>
  19. <span v-if="isTrue(courseware.is_can_submit_audit)" class="link" @click="submitCoursewareToAuditFlow()">
  20. 提交审核
  21. </span>
  22. <span class="link" @click="goBackBookList()">返回教材列表</span>
  23. </template>
  24. </CommonPreview>
  25. <CreateCoursewareAsTemplateVue :visible.sync="visibleTemplate" @confirm="saveCoursewareAsTemplate" />
  26. <SetBackground
  27. :visible.sync="visibleBackground"
  28. :url="background.background_image_url"
  29. :position="background.background_position"
  30. :background-data="background.background"
  31. @setBackground="setBackground"
  32. />
  33. <SetComponentBackground
  34. :visible.sync="visibleComponentBackground"
  35. :url="componentBackground.background_image_url"
  36. :position="componentBackground.background_position"
  37. :background-data="componentBackground.background"
  38. :component-data="curComponentData"
  39. @setComponentBackground="saveCoursewareComponentBackground"
  40. />
  41. </div>
  42. </template>
  43. <script>
  44. import MenuPage from '@/views/personal_workbench/common/menu.vue';
  45. import CommonPreview from '@/components/CommonPreview.vue';
  46. import CreateCoursewareAsTemplateVue from '@/views/personal_workbench/edit_task/preview/CreateCoursewareAsTemplate.vue';
  47. import SetBackground from '@/views/book/courseware/create/components/SetBackground.vue';
  48. import SetComponentBackground from '@/views/book/courseware/create/components/SetComponentBackground.vue';
  49. import { SubmitBookCoursewareToAuditFlow } from '@/api/project';
  50. import { isTrue } from '@/utils/validate';
  51. import { SaveCoursewareAsTemplatePersonal } from '@/api/template';
  52. import {
  53. SaveCoursewareBackground,
  54. GetCoursewareBackground,
  55. GetCoursewareComponentBackground,
  56. SaveCoursewareComponentBackground,
  57. } from '@/api/book';
  58. export default {
  59. name: 'TaskPreviewPage',
  60. components: {
  61. MenuPage,
  62. CommonPreview,
  63. CreateCoursewareAsTemplateVue,
  64. SetBackground,
  65. SetComponentBackground,
  66. },
  67. data() {
  68. return {
  69. id: this.$route.params.id,
  70. project_id: this.$route.query.project_id,
  71. isTrue,
  72. visibleTemplate: false,
  73. background: {
  74. background_image_url: '',
  75. background_position: {},
  76. background: {},
  77. },
  78. visibleBackground: false,
  79. visibleComponentBackground: false,
  80. // 当前选中组件数据
  81. curComponentData: {
  82. courseware_id: '',
  83. component_id: '',
  84. },
  85. componentBackground: {
  86. background_image_url: '',
  87. background_position: {},
  88. background: {},
  89. },
  90. };
  91. },
  92. created() {
  93. GetCoursewareBackground({ id: this.id }).then(({ background }) => {
  94. if (background) this.background = JSON.parse(background);
  95. });
  96. },
  97. methods: {
  98. goBackBookList() {
  99. this.$router.push({ path: '/personal_workbench/edit_task' });
  100. },
  101. editTask() {
  102. const visibleId = this.$refs.preview.getFirstVisibleComponentId();
  103. this.$router.push({
  104. path: `/personal_workbench/edit_task/edit/${this.$refs.preview.select_node}`,
  105. query: { project_id: this.project_id, visible_id: visibleId },
  106. });
  107. },
  108. /**
  109. * 提交课件到审核流程
  110. */
  111. submitCoursewareToAuditFlow() {
  112. SubmitBookCoursewareToAuditFlow({ id: this.$refs.preview.select_node }).then(() => {
  113. this.$message.success('课件已提交审核');
  114. this.$refs.preview.getBookCoursewareInfo(this.$refs.preview.select_node);
  115. });
  116. },
  117. /**
  118. * 打开保存为个人模板的弹窗
  119. */
  120. openCreateTemplateDialog() {
  121. this.visibleTemplate = true;
  122. },
  123. /**
  124. * 保存为个人模板
  125. * @param {object} form 模板信息
  126. * @param {string} form.name 模板名称
  127. * @param {string[]} form.label_list 模板标签列表
  128. * @param {string} form.memo 模板备注
  129. * @param {number} form.scope 模板范围
  130. * @param {string} form.is_select_part_courseware_mode 是否选择部分课件模式
  131. * @param {number} form.content_type 模板内容类型 0: 内容模板,1: 样式模板
  132. */
  133. saveCoursewareAsTemplate(form) {
  134. this.$confirm('确定保存为个人模板吗?', '提示', {
  135. confirmButtonText: '确定',
  136. cancelButtonText: '取消',
  137. type: 'warning',
  138. })
  139. .then(() => {
  140. this.visibleTemplate = false;
  141. let courseware_info = {};
  142. if (form.is_select_part_courseware_mode === 'true') {
  143. courseware_info = this.$refs.preview.computedSelectedGroupCoursewareInfo();
  144. if (courseware_info?.component_id_list.length === 0) {
  145. this.$message.warning('请选择要保存的内容');
  146. return;
  147. }
  148. }
  149. SaveCoursewareAsTemplatePersonal({
  150. courseware_id: this.$refs.preview.select_node,
  151. courseware_info,
  152. ...form,
  153. })
  154. .then(({ courseware_id }) => {
  155. if (form.content_type === 0) {
  156. return this.$message.success('已保存为个人模板');
  157. }
  158. this.$refs.preview.saveCoursewareStyleTemplate({
  159. courseware_id,
  160. is_select_part_courseware_mode: form.is_select_part_courseware_mode,
  161. component_id_list: courseware_info?.component_id_list || [],
  162. });
  163. })
  164. .catch(() => {
  165. this.$message.error('保存个人模板失败');
  166. });
  167. })
  168. .catch(() => {});
  169. },
  170. /**
  171. * 显示背景设置弹窗
  172. */
  173. showSetBackground() {
  174. this.visibleBackground = true;
  175. },
  176. /**
  177. * 显示组件背景设置弹窗
  178. */
  179. async showSetComponentBackground() {
  180. if (this.curComponentData.component_id === '') {
  181. this.$message.warning('请先选择一个组件');
  182. return;
  183. }
  184. const loading = this.$loading('加载组件数据中...');
  185. await GetCoursewareComponentBackground(this.curComponentData).then(({ background }) => {
  186. if (background) {
  187. this.componentBackground = JSON.parse(background);
  188. } else {
  189. this.revertComponentBackground();
  190. }
  191. });
  192. loading.close();
  193. this.visibleComponentBackground = true;
  194. },
  195. /**
  196. * 设置组件背景
  197. * @param {string} url 背景图片地址
  198. * @param {string} position 背景图片位置
  199. * @param {string} background
  200. */
  201. saveCoursewareComponentBackground(url, position, background) {
  202. this.componentBackground = {
  203. background_image_url: url,
  204. background_position: position,
  205. background,
  206. };
  207. const backgroundStr = JSON.stringify(this.componentBackground);
  208. SaveCoursewareComponentBackground({
  209. ...this.curComponentData,
  210. background: backgroundStr,
  211. })
  212. .then(() => {
  213. this.$message.success('组件背景设置成功');
  214. this.$refs.preview.updateComponentBackground(this.curComponentData, backgroundStr);
  215. })
  216. .finally(() => {
  217. this.revertComponentBackground();
  218. });
  219. },
  220. /**
  221. * 还原组件背景数据
  222. */
  223. revertComponentBackground() {
  224. this.componentBackground = {
  225. background_image_url: '',
  226. background_position: {},
  227. background: {},
  228. };
  229. },
  230. /**
  231. * 设置背景
  232. * @param {string} url 背景图片地址
  233. * @param {string} position 背景图片位置
  234. * @param {string} background
  235. */
  236. setBackground(url, position, background) {
  237. this.background = {
  238. background_image_url: url,
  239. background_position: position,
  240. background,
  241. };
  242. SaveCoursewareBackground({ id: this.id, background: JSON.stringify(this.background) }).then(() => {
  243. this.$message.success('背景设置成功');
  244. this.$refs.preview.updateBackground(this.background);
  245. });
  246. },
  247. },
  248. };
  249. </script>
  250. <style lang="scss" scoped>
  251. @use '@/styles/mixin.scss' as *;
  252. .task-preview {
  253. @include page-content(true);
  254. }
  255. </style>
  256. <style lang="scss">
  257. .el-popover.el-popper {
  258. min-width: 100px;
  259. }
  260. </style>