Commit 4aac184ed5d04575a27f67a7b8179e5d274b48f3
1 parent
d0830352
add loading for fetch work list
Showing
3 changed files
with
33 additions
and
16 deletions
front-end/h5/src/store/modules/loading.js
front-end/h5/src/store/modules/work.js
| ... | ... | @@ -49,11 +49,15 @@ export const actions = { |
| 49 | 49 | commit('setEditingPage') |
| 50 | 50 | }) |
| 51 | 51 | }, |
| 52 | - fetchWorks ({ commit, state }, workId) { | |
| 53 | - strapi.getEntries('works', {}).then(entries => { | |
| 54 | - entries.sort((a, b) => b.id - a.id) | |
| 55 | - commit('setWorks', entries) | |
| 56 | - }) | |
| 52 | + fetchWorks ({ commit, dispatch, state }, workId) { | |
| 53 | + new AxiosWrapper({ | |
| 54 | + dispatch, | |
| 55 | + commit, | |
| 56 | + name: 'editor/setWorks', | |
| 57 | + loading_name: 'fetchWorks_loading', | |
| 58 | + successMsg: '获取作品列表成功', | |
| 59 | + customRequest: strapi.getEntries.bind(strapi) | |
| 60 | + }).get('works', {}) | |
| 57 | 61 | }, |
| 58 | 62 | /** |
| 59 | 63 | * |
| ... | ... | @@ -129,8 +133,15 @@ export const actions = { |
| 129 | 133 | |
| 130 | 134 | // mutations |
| 131 | 135 | export const mutations = { |
| 132 | - setWorks (state, works) { | |
| 133 | - state.works = works | |
| 136 | + /** | |
| 137 | + * payload: { | |
| 138 | + * type: @params {String} "editor/setWorks", | |
| 139 | + * value: @params {Array} work list | |
| 140 | + * } | |
| 141 | + */ | |
| 142 | + setWorks (state, { type, value }) { | |
| 143 | + value.sort((a, b) => b.id - a.id) | |
| 144 | + state.works = value | |
| 134 | 145 | }, |
| 135 | 146 | setWork (state, work) { |
| 136 | 147 | window.__work = work | ... | ... |
front-end/h5/src/views/work-manager/list.vue
| ... | ... | @@ -104,7 +104,8 @@ export default { |
| 104 | 104 | previewVisible: false |
| 105 | 105 | }), |
| 106 | 106 | computed: { |
| 107 | - ...mapState('editor', ['works']) | |
| 107 | + ...mapState('editor', ['works']), | |
| 108 | + ...mapState('loading', ['fetchWorks_loading']) | |
| 108 | 109 | }, |
| 109 | 110 | methods: { |
| 110 | 111 | ...mapActions('editor', [ |
| ... | ... | @@ -125,14 +126,18 @@ export default { |
| 125 | 126 | <AddNewCard handleCreate={this.createWork} /> |
| 126 | 127 | </a-col> |
| 127 | 128 | { |
| 128 | - this.works.map(work => ( | |
| 129 | - <a-col span={6} key={work.id} style="margin-bottom: 20px;"> | |
| 130 | - <ListItemCard work={work} handleClickPreview={e => { | |
| 131 | - this.previewVisible = true | |
| 132 | - this.activeWork = work | |
| 133 | - }} /> | |
| 129 | + this.fetchWorks_loading | |
| 130 | + ? <a-col span={18} style="margin-bottom: 10px;text-align: center;height: 355px;line-height: 355px;border-bottom: 1px solid #ebedf0;background: rgba(255, 255, 255, 0.5);"> | |
| 131 | + <a-spin tip="作品列表获取中..."/> | |
| 134 | 132 | </a-col> |
| 135 | - )) | |
| 133 | + : this.works.map(work => ( | |
| 134 | + <a-col span={6} key={work.id} style="margin-bottom: 20px;"> | |
| 135 | + <ListItemCard work={work} handleClickPreview={e => { | |
| 136 | + this.previewVisible = true | |
| 137 | + this.activeWork = work | |
| 138 | + }} /> | |
| 139 | + </a-col> | |
| 140 | + )) | |
| 136 | 141 | } |
| 137 | 142 | </a-row> |
| 138 | 143 | { | ... | ... |