Commit 4ee84e75799fda4e384329d1cb5d70b06be221bb
1 parent
56b22e8b
update works total
Showing
4 changed files
with
27 additions
and
7 deletions
front-end/h5/src/store/modules/editor.js
| @@ -9,7 +9,11 @@ const state = { | @@ -9,7 +9,11 @@ const state = { | ||
| 9 | uuidMap2Name: {}, | 9 | uuidMap2Name: {}, |
| 10 | formRecords: [] | 10 | formRecords: [] |
| 11 | }, | 11 | }, |
| 12 | - workTemplates: [] | 12 | + workTemplates: [], |
| 13 | + total: { | ||
| 14 | + works: 0, | ||
| 15 | + templates: 0 | ||
| 16 | + } | ||
| 13 | } | 17 | } |
| 14 | 18 | ||
| 15 | // getters | 19 | // getters |
front-end/h5/src/store/modules/work.js
| @@ -104,6 +104,17 @@ export const actions = { | @@ -104,6 +104,17 @@ export const actions = { | ||
| 104 | commit('setEditingPage') | 104 | commit('setEditingPage') |
| 105 | }) | 105 | }) |
| 106 | }, | 106 | }, |
| 107 | + fetchCount ({ commit, dispatch, state }, payload = { is_template: false }) { | ||
| 108 | + return new AxiosWrapper({ | ||
| 109 | + dispatch, | ||
| 110 | + commit, | ||
| 111 | + name: 'editor/setWorksTotal', | ||
| 112 | + actionPayloadExtra: { | ||
| 113 | + isTemplate: payload.is_template | ||
| 114 | + }, | ||
| 115 | + customRequest: strapi.getEntries.bind(strapi) | ||
| 116 | + }).get('works/count', payload).catch(handleError) | ||
| 117 | + }, | ||
| 107 | fetchWorks ({ commit, dispatch, state }, payload = { is_template: false, _limit: 10 }) { | 118 | fetchWorks ({ commit, dispatch, state }, payload = { is_template: false, _limit: 10 }) { |
| 108 | return new AxiosWrapper({ | 119 | return new AxiosWrapper({ |
| 109 | dispatch, | 120 | dispatch, |
| @@ -266,6 +277,10 @@ export const mutations = { | @@ -266,6 +277,10 @@ export const mutations = { | ||
| 266 | const [cover] = value | 277 | const [cover] = value |
| 267 | state.work.cover_image_url = cover.url | 278 | state.work.cover_image_url = cover.url |
| 268 | }, | 279 | }, |
| 280 | + setWorksTotal (state, { type, value, ...other }) { | ||
| 281 | + const { isTemplate } = other | ||
| 282 | + state.total[isTemplate ? 'templates' : 'works'] = value | ||
| 283 | + }, | ||
| 269 | /** | 284 | /** |
| 270 | * payload: { | 285 | * payload: { |
| 271 | * type: @params {String} "editor/setWorks", | 286 | * type: @params {String} "editor/setWorks", |
front-end/h5/src/utils/http.js
| @@ -7,7 +7,7 @@ message.config({ | @@ -7,7 +7,7 @@ message.config({ | ||
| 7 | 7 | ||
| 8 | export class AxiosWrapper { | 8 | export class AxiosWrapper { |
| 9 | // eslint-disable-next-line camelcase | 9 | // eslint-disable-next-line camelcase |
| 10 | - constructor ({ name = 'default', loading_name, responseType = 'json', headers, dispatch, commit, router, successMsg, failMsg, successCallback, failCallback, customRequest }) { | 10 | + constructor ({ name = 'default', loading_name, responseType = 'json', headers, dispatch, commit, router, successMsg, failMsg, successCallback, failCallback, customRequest, actionPayloadExtra = {} }) { |
| 11 | this.name = name | 11 | this.name = name |
| 12 | // eslint-disable-next-line camelcase | 12 | // eslint-disable-next-line camelcase |
| 13 | this.loading_name = loading_name | 13 | this.loading_name = loading_name |
| @@ -21,6 +21,7 @@ export class AxiosWrapper { | @@ -21,6 +21,7 @@ export class AxiosWrapper { | ||
| 21 | this.customRequest = customRequest | 21 | this.customRequest = customRequest |
| 22 | this.successCallback = successCallback | 22 | this.successCallback = successCallback |
| 23 | this.failCallback = failCallback | 23 | this.failCallback = failCallback |
| 24 | + this.actionPayloadExtra = actionPayloadExtra | ||
| 24 | this.source = axios.CancelToken.source() | 25 | this.source = axios.CancelToken.source() |
| 25 | this.instance = axios.create({ | 26 | this.instance = axios.create({ |
| 26 | // baseURL: '/v1', | 27 | // baseURL: '/v1', |
| @@ -148,7 +149,7 @@ export class AxiosWrapper { | @@ -148,7 +149,7 @@ export class AxiosWrapper { | ||
| 148 | if (this.successCallback) { | 149 | if (this.successCallback) { |
| 149 | this.successCallback(response) | 150 | this.successCallback(response) |
| 150 | } else { | 151 | } else { |
| 151 | - this.commit({ type: this.name, value: response.data }, { root: true }) | 152 | + this.commit({ type: this.name, value: response.data, ...this.actionPayloadExtra }, { root: true }) |
| 152 | } | 153 | } |
| 153 | } else if (this.responseType === 'json') { | 154 | } else if (this.responseType === 'json') { |
| 154 | message.error(response.data.msg) | 155 | message.error(response.data.msg) |
front-end/h5/src/views/work-manager/list-mixin.js
| @@ -23,7 +23,7 @@ export default { | @@ -23,7 +23,7 @@ export default { | ||
| 23 | } | 23 | } |
| 24 | }), | 24 | }), |
| 25 | computed: { | 25 | computed: { |
| 26 | - ...mapState('editor', ['works', 'workTemplates']), | 26 | + ...mapState('editor', ['works', 'workTemplates', 'total']), |
| 27 | ...mapState('loading', ['fetchWorks_loading', 'fetchWorkTemplates_loading']), | 27 | ...mapState('loading', ['fetchWorks_loading', 'fetchWorkTemplates_loading']), |
| 28 | workList () { | 28 | workList () { |
| 29 | const workList = this.isTemplate ? this.workTemplates : this.works | 29 | const workList = this.isTemplate ? this.workTemplates : this.works |
| @@ -35,6 +35,7 @@ export default { | @@ -35,6 +35,7 @@ export default { | ||
| 35 | }, | 35 | }, |
| 36 | methods: { | 36 | methods: { |
| 37 | ...mapActions('editor', [ | 37 | ...mapActions('editor', [ |
| 38 | + 'fetchCount', | ||
| 38 | 'fetchWorks', | 39 | 'fetchWorks', |
| 39 | 'createWork', | 40 | 'createWork', |
| 40 | 'deleteWork', | 41 | 'deleteWork', |
| @@ -54,7 +55,6 @@ export default { | @@ -54,7 +55,6 @@ export default { | ||
| 54 | _limit: pageSize, | 55 | _limit: pageSize, |
| 55 | _start: (pageNum - 1) * pageSize | 56 | _start: (pageNum - 1) * pageSize |
| 56 | } | 57 | } |
| 57 | - debugger | ||
| 58 | this.isTemplate ? this.fetchWorkTemplates(payload) : this.fetchWorks(payload) | 58 | this.isTemplate ? this.fetchWorkTemplates(payload) : this.fetchWorks(payload) |
| 59 | } | 59 | } |
| 60 | }, | 60 | }, |
| @@ -99,7 +99,7 @@ export default { | @@ -99,7 +99,7 @@ export default { | ||
| 99 | <a-pagination | 99 | <a-pagination |
| 100 | show-size-changer | 100 | show-size-changer |
| 101 | default-current={1} | 101 | default-current={1} |
| 102 | - total={500} | 102 | + total={this.isTemplate ? this.total.templates : this.total.works } |
| 103 | current={this.pagination.pageNum} | 103 | current={this.pagination.pageNum} |
| 104 | onShowSizeChange={(pageNum, pageSize) => { | 104 | onShowSizeChange={(pageNum, pageSize) => { |
| 105 | this.pagination.pageNum = 1 | 105 | this.pagination.pageNum = 1 |
| @@ -164,6 +164,6 @@ export default { | @@ -164,6 +164,6 @@ export default { | ||
| 164 | }, | 164 | }, |
| 165 | created () { | 165 | created () { |
| 166 | this.handleSearch() | 166 | this.handleSearch() |
| 167 | - // this.isTemplate ? this.fetchWorkTemplates() : this.fetchWorks() | 167 | + this.fetchCount({ is_template: this.isTemplate }) |
| 168 | } | 168 | } |
| 169 | } | 169 | } |