Skip to content

Commit a2fb4ac

Browse files
committed
fix: #113
do save work before preview work zh: 预览作品之前先保存作品
1 parent cf9756c commit a2fb4ac

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

front-end/h5/src/components/core/editor/index.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,12 @@ export default {
123123
pages: state => state.work.pages,
124124
work: state => state.work
125125
}),
126-
...mapState('loading', ['saveWork_loading', 'setWorkAsTemplate_loading', 'uploadWorkCover_loading'])
126+
...mapState('loading', [
127+
'saveWork_loading',
128+
'previewWork_loading',
129+
'setWorkAsTemplate_loading',
130+
'uploadWorkCover_loading'
131+
])
127132
},
128133
methods: {
129134
...mapActions('editor', [
@@ -239,7 +244,7 @@ export default {
239244
style={{ lineHeight: '64px', float: 'right', background: 'transparent' }}
240245
>
241246
{/* 保存、预览、发布、设置为模板 */}
242-
<a-menu-item key="1" class="transparent-bg"><a-button type="primary" size="small" onClick={() => { this.previewVisible = true }}>{this.$t('editor.header.preview')}</a-button></a-menu-item>
247+
<a-menu-item key="1" class="transparent-bg"><a-button type="primary" size="small" onClick={() => { this.saveWork({ loadingName: 'previewWork_loading' }).then(() => { this.previewVisible = true }) }} loading={this.previewWork_loading}>{this.$t('editor.header.preview')}</a-button></a-menu-item>
243248
<a-menu-item key="2" class="transparent-bg"><a-button size="small" onClick={() => this.saveWork({ isSaveCover: true })} loading={this.saveWork_loading || this.uploadWorkCover_loading}>{this.$t('editor.header.save')}</a-button></a-menu-item>
244249
{/* <a-menu-item key="3" class="transparent-bg"><a-button size="small">发布</a-button></a-menu-item> */}
245250
<a-menu-item key="3" class="transparent-bg">

front-end/h5/src/store/modules/loading.js

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1+
/*
2+
* @Author: ly525
3+
* @Date: 2019-11-24 18:51:58
4+
* @LastEditors: ly525
5+
* @LastEditTime: 2019-12-08 17:21:48
6+
* @FilePath: /luban-h5/front-end/h5/src/store/modules/loading.js
7+
* @Github: https://github.com/ly525/luban-h5
8+
* @Description: loading module
9+
* @Copyright 2018 - 2019 luban-h5. All Rights Reserved
10+
*/
111
// initial state
212
const state = {
313
saveWork_loading: false,
14+
previewWork_loading: false,
415
fetchWorks_loading: false,
516
setWorkAsTemplate_loading: false,
617
fetchWorkTemplates_loading: false,

front-end/h5/src/store/modules/work.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export const actions = {
2121
strapi.createEntry('works', new Work()).then(entry => {
2222
const routeData = router.resolve({ name: 'editor', params: { workId: entry.id } })
2323
window.open(routeData.href, '_blank')
24+
// 如果希望不打开新 tab,可以注释上面面两行,启用下面一行的代码即可,不过不推荐。将编辑器单独起一个页面更有利于 vuex 的数据管理
25+
// router.replace({ name: 'editor', params: { workId: entry.id } })
2426
})
2527
},
2628
updateWork ({ commit, state }, payload = {}) {
@@ -33,13 +35,16 @@ export const actions = {
3335
},
3436
/**
3537
* isSaveCover {Boolean} 保存作品时,是否保存封面图
38+
* loadingName {String} saveWork_loading, previewWork_loading
39+
* 预览作品之前需要先保存,但希望 用户点击保存按钮 和 点击预览按钮 loading_name 能够不同(虽然都调用了 saveWork)
40+
* 因为 loading 效果要放在不同的按钮上
3641
*/
37-
saveWork ({ commit, dispatch, state }, { isSaveCover = false } = {}) {
42+
saveWork ({ commit, dispatch, state }, { isSaveCover = false, loadingName = 'saveWork_loading' } = {}) {
3843
const fn = (callback) => {
3944
new AxiosWrapper({
4045
dispatch,
4146
commit,
42-
loading_name: 'saveWork_loading',
47+
loading_name: loadingName,
4348
successMsg: '保存作品成功',
4449
customRequest: strapi.updateEntry.bind(strapi)
4550
}).put('works', state.work.id, state.work).then(callback)

0 commit comments

Comments
 (0)