index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <template>
  2. <div ref="create" class="create">
  3. <div class="create-left">
  4. <div class="back-container">
  5. <el-button class="back" @click="judgeIsHasChange"><i class="el-icon-arrow-left"></i> 返回</el-button>
  6. <span class="title">Frame {{ Number(index) + 1 }}</span>
  7. </div>
  8. <div v-for="{ value, label, children } in bookTypeOption" :key="value" class="components">
  9. <div class="components-title">{{ label }}</div>
  10. <div
  11. v-for="{ value: childValue, icon, label: childLabel } in children"
  12. :key="childValue"
  13. ref="componentsItem"
  14. class="components-item"
  15. @mousedown="dragStart($event, childValue)"
  16. >
  17. <SvgIcon v-if="icon" :icon-class="icon" />
  18. <span>{{ childLabel }}</span>
  19. </div>
  20. </div>
  21. </div>
  22. <div class="create-middle">
  23. <div class="create-operation">
  24. <el-button @click="showSetBackground"><SvgIcon icon-class="background-img" />背景图</el-button>
  25. <el-button><SvgIcon icon-class="template" />模板</el-button>
  26. <el-button class="exit-edit">
  27. <span @click="saveCoursewareContent('edit')">
  28. <template v-if="isEdit"> <i class="el-icon-close"></i><span> 退出编辑</span> </template>
  29. <template v-else> <i class="el-icon-edit"></i><span> 编辑</span> </template>
  30. </span>
  31. <el-button class="save" type="primary">
  32. <span @click="saveCoursewareContent"><SvgIcon icon-class="save" /> <span>保存</span></span>
  33. <el-popover placement="bottom" popper-class="save-popover" trigger="click">
  34. <div class="save-template">保存为模板</div>
  35. <i slot="reference" class="el-icon-arrow-down"></i>
  36. </el-popover>
  37. </el-button>
  38. </el-button>
  39. </div>
  40. <CreateCanvas
  41. ref="createCanvas"
  42. :is-edit="isEdit"
  43. @showSetting="showSetting"
  44. @changeData="changeData"
  45. @back="back"
  46. @changeEditStatus="changeEditStatus"
  47. />
  48. </div>
  49. <div class="create-right">
  50. <div class="setting-tittle">设置</div>
  51. <component :is="componentSettingList[curSettingType]" ref="setting" />
  52. </div>
  53. <SelectBackground :visible.sync="visible" @setBackgroundImage="setBackgroundImage" />
  54. <WarnSave :visible.sync="visibleWarn" @directQuit="back" @saveAndClose="saveCoursewareContent" />
  55. </div>
  56. </template>
  57. <script>
  58. import { bookTypeOption, componentSettingList } from '../data/bookType';
  59. import CreateCanvas from './components/createCanvas.vue';
  60. import SelectBackground from './components/SelectBackground.vue';
  61. import WarnSave from './components/WarnSave.vue';
  62. export default {
  63. name: 'CreatePage',
  64. components: {
  65. CreateCanvas,
  66. SelectBackground,
  67. WarnSave,
  68. },
  69. provide() {
  70. return {
  71. getCurSettingId: () => this.curSettingId,
  72. courseware_id: this.courseware_id,
  73. };
  74. },
  75. data() {
  76. const { book_id, chapter_id, index } = this.$route.query;
  77. return {
  78. courseware_id: this.$route.params.courseware_id,
  79. book_id,
  80. index,
  81. chapter_id,
  82. curSettingType: '',
  83. curSettingId: '',
  84. componentSettingList,
  85. bookTypeOption,
  86. visible: false,
  87. visibleWarn: false,
  88. isEdit: true, // 是否编辑状态
  89. isChange: false, // 是否有改动
  90. };
  91. },
  92. methods: {
  93. judgeIsHasChange() {
  94. if (this.isChange) {
  95. this.visibleWarn = true;
  96. return;
  97. }
  98. this.back();
  99. },
  100. back() {
  101. this.$router.push({ path: '/chapter', query: { chapter_id: this.chapter_id, book_id: this.book_id } });
  102. },
  103. /**
  104. * 切换编辑状态
  105. */
  106. changeEditStatus() {
  107. this.isEdit = !this.isEdit;
  108. },
  109. dragStart(event, type) {
  110. this.$refs.createCanvas.dragStart(event, type);
  111. },
  112. changeData() {
  113. this.isChange = true;
  114. },
  115. /**
  116. * 保存课件内容
  117. * @param {string} type 是否退出
  118. */
  119. saveCoursewareContent(type = '') {
  120. if (type === 'edit' && !this.isChange) {
  121. this.changeEditStatus();
  122. return;
  123. }
  124. this.$refs.createCanvas.saveCoursewareContent(type);
  125. this.isChange = false;
  126. },
  127. showSetBackground() {
  128. this.visible = true;
  129. },
  130. /**
  131. * 显示设置
  132. * @param {object} setting
  133. * @param {string} type
  134. */
  135. showSetting(setting, type, id) {
  136. this.curSettingType = type;
  137. this.curSettingId = id;
  138. this.$nextTick(() => {
  139. this.$refs.setting.setSetting(setting);
  140. });
  141. },
  142. setBackgroundImage(...data) {
  143. this.$refs.createCanvas.setBackgroundImage(...data);
  144. },
  145. },
  146. };
  147. </script>
  148. <style lang="scss" scoped>
  149. .create {
  150. display: flex;
  151. height: 100%;
  152. &-left {
  153. display: flex;
  154. flex-direction: column;
  155. width: 180px;
  156. overflow: auto;
  157. background-color: #fff;
  158. .back-container {
  159. display: flex;
  160. flex-direction: column;
  161. row-gap: 8px;
  162. padding: 4px;
  163. .back {
  164. color: #000;
  165. text-align: left;
  166. background-color: #f4f4f4;
  167. }
  168. .title {
  169. padding: 0 16px;
  170. font-size: 14px;
  171. font-weight: bold;
  172. }
  173. }
  174. .components {
  175. display: flex;
  176. flex-direction: column;
  177. padding: 24px 8px 4px;
  178. margin-top: 12px;
  179. border-top: 1px solid #e5e6eb;
  180. .components-title {
  181. padding-left: 8px;
  182. font-size: 14px;
  183. font-weight: bold;
  184. color: #999;
  185. }
  186. .components-item {
  187. display: flex;
  188. align-items: center;
  189. padding: 5px 16px;
  190. cursor: pointer;
  191. svg {
  192. width: 16px;
  193. height: 16px;
  194. margin-right: 8px;
  195. }
  196. }
  197. }
  198. }
  199. &-middle {
  200. flex: 1;
  201. padding: 24px 20px;
  202. overflow: auto;
  203. background-color: #ececec;
  204. .create-operation {
  205. display: flex;
  206. column-gap: 6px;
  207. align-items: center;
  208. justify-content: center;
  209. margin-bottom: 16px;
  210. .exit-edit {
  211. padding: 4px 4px 4px 16px;
  212. }
  213. > .el-button {
  214. height: 40px;
  215. font-size: 16px;
  216. font-weight: bold;
  217. :deep > span {
  218. display: flex;
  219. column-gap: 8px;
  220. align-items: center;
  221. }
  222. .save.el-button {
  223. height: 32px;
  224. margin-left: 8px;
  225. font-size: 16px;
  226. :deep > span {
  227. display: flex;
  228. column-gap: 4px;
  229. align-items: center;
  230. margin-top: -1px;
  231. }
  232. }
  233. }
  234. }
  235. }
  236. &-right {
  237. width: 280px;
  238. padding: 16px 8px;
  239. background-color: #fff;
  240. .setting-tittle {
  241. margin-bottom: 16px;
  242. font-weight: bold;
  243. color: #000;
  244. }
  245. }
  246. }
  247. </style>
  248. <style lang="scss">
  249. .save-popover {
  250. width: 100px;
  251. min-width: 100px;
  252. padding: 4px;
  253. .save-template {
  254. padding: 4px 8px;
  255. text-align: center;
  256. cursor: pointer;
  257. &:hover {
  258. background-color: #f1f1f1;
  259. }
  260. }
  261. }
  262. </style>