index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. this.$router.push({
  103. path: `/personal_workbench/edit_task/edit/${this.$refs.preview.select_node}`,
  104. query: { project_id: this.project_id },
  105. });
  106. },
  107. /**
  108. * 提交课件到审核流程
  109. */
  110. submitCoursewareToAuditFlow() {
  111. SubmitBookCoursewareToAuditFlow({ id: this.$refs.preview.select_node }).then(() => {
  112. this.$message.success('课件已提交审核');
  113. this.$refs.preview.getBookCoursewareInfo(this.$refs.preview.select_node);
  114. });
  115. },
  116. /**
  117. * 打开保存为个人模板的弹窗
  118. */
  119. openCreateTemplateDialog() {
  120. this.visibleTemplate = true;
  121. },
  122. /**
  123. * 保存为个人模板
  124. * @param {object} form 模板信息
  125. * @param {string} form.name 模板名称
  126. * @param {string[]} form.label_list 模板标签列表
  127. * @param {string} form.memo 模板备注
  128. * @param {number} form.scope 模板范围
  129. * @param {string} form.is_select_part_courseware_mode 是否选择部分课件模式
  130. * @param {number} form.content_type 模板内容类型 0: 内容模板,1: 样式模板
  131. */
  132. saveCoursewareAsTemplate(form) {
  133. this.$confirm('确定保存为个人模板吗?', '提示', {
  134. confirmButtonText: '确定',
  135. cancelButtonText: '取消',
  136. type: 'warning',
  137. })
  138. .then(() => {
  139. this.visibleTemplate = false;
  140. let courseware_info = {};
  141. if (form.is_select_part_courseware_mode === 'true') {
  142. courseware_info = this.$refs.preview.computedSelectedGroupCoursewareInfo();
  143. if (courseware_info?.component_id_list.length === 0) {
  144. this.$message.warning('请选择要保存的内容');
  145. return;
  146. }
  147. }
  148. SaveCoursewareAsTemplatePersonal({
  149. courseware_id: this.$refs.preview.select_node,
  150. courseware_info,
  151. ...form,
  152. })
  153. .then(({ courseware_id }) => {
  154. if (form.content_type === 0) {
  155. return this.$message.success('已保存为个人模板');
  156. }
  157. this.$refs.preview.saveCoursewareStyleTemplate({
  158. courseware_id,
  159. is_select_part_courseware_mode: form.is_select_part_courseware_mode,
  160. component_id_list: courseware_info?.component_id_list || [],
  161. });
  162. })
  163. .catch(() => {
  164. this.$message.error('保存个人模板失败');
  165. });
  166. })
  167. .catch(() => {});
  168. },
  169. /**
  170. * 显示背景设置弹窗
  171. */
  172. showSetBackground() {
  173. this.visibleBackground = true;
  174. },
  175. /**
  176. * 显示组件背景设置弹窗
  177. */
  178. async showSetComponentBackground() {
  179. if (this.curComponentData.component_id === '') {
  180. this.$message.warning('请先选择一个组件');
  181. return;
  182. }
  183. const loading = this.$loading('加载组件数据中...');
  184. await GetCoursewareComponentBackground(this.curComponentData).then(({ background }) => {
  185. if (background) {
  186. this.componentBackground = JSON.parse(background);
  187. } else {
  188. this.revertComponentBackground();
  189. }
  190. });
  191. loading.close();
  192. this.visibleComponentBackground = true;
  193. },
  194. /**
  195. * 设置组件背景
  196. * @param {string} url 背景图片地址
  197. * @param {string} position 背景图片位置
  198. * @param {string} background
  199. */
  200. saveCoursewareComponentBackground(url, position, background) {
  201. this.componentBackground = {
  202. background_image_url: url,
  203. background_position: position,
  204. background,
  205. };
  206. const backgroundStr = JSON.stringify(this.componentBackground);
  207. SaveCoursewareComponentBackground({
  208. ...this.curComponentData,
  209. background: backgroundStr,
  210. })
  211. .then(() => {
  212. this.$message.success('组件背景设置成功');
  213. this.$refs.preview.updateComponentBackground(this.curComponentData, backgroundStr);
  214. })
  215. .finally(() => {
  216. this.revertComponentBackground();
  217. });
  218. },
  219. /**
  220. * 还原组件背景数据
  221. */
  222. revertComponentBackground() {
  223. this.componentBackground = {
  224. background_image_url: '',
  225. background_position: {},
  226. background: {},
  227. };
  228. },
  229. /**
  230. * 设置背景
  231. * @param {string} url 背景图片地址
  232. * @param {string} position 背景图片位置
  233. * @param {string} background
  234. */
  235. setBackground(url, position, background) {
  236. this.background = {
  237. background_image_url: url,
  238. background_position: position,
  239. background,
  240. };
  241. SaveCoursewareBackground({ id: this.id, background: JSON.stringify(this.background) }).then(() => {
  242. this.$message.success('背景设置成功');
  243. this.$refs.preview.updateBackground(this.background);
  244. });
  245. },
  246. },
  247. };
  248. </script>
  249. <style lang="scss" scoped>
  250. @use '@/styles/mixin.scss' as *;
  251. .task-preview {
  252. @include page-content(true);
  253. }
  254. </style>
  255. <style lang="scss">
  256. .el-popover.el-popper {
  257. min-width: 100px;
  258. }
  259. </style>