Commit 4ee84e75799fda4e384329d1cb5d70b06be221bb

Authored by ly525
1 parent 56b22e8b

update works total

front-end/h5/src/store/modules/editor.js
... ... @@ -9,7 +9,11 @@ const state = {
9 9 uuidMap2Name: {},
10 10 formRecords: []
11 11 },
12   - workTemplates: []
  12 + workTemplates: [],
  13 + total: {
  14 + works: 0,
  15 + templates: 0
  16 + }
13 17 }
14 18  
15 19 // getters
... ...
front-end/h5/src/store/modules/work.js
... ... @@ -104,6 +104,17 @@ export const actions = {
104 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 118 fetchWorks ({ commit, dispatch, state }, payload = { is_template: false, _limit: 10 }) {
108 119 return new AxiosWrapper({
109 120 dispatch,
... ... @@ -266,6 +277,10 @@ export const mutations = {
266 277 const [cover] = value
267 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 285 * payload: {
271 286 * type: @params {String} "editor/setWorks",
... ...
front-end/h5/src/utils/http.js
... ... @@ -7,7 +7,7 @@ message.config({
7 7  
8 8 export class AxiosWrapper {
9 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 11 this.name = name
12 12 // eslint-disable-next-line camelcase
13 13 this.loading_name = loading_name
... ... @@ -21,6 +21,7 @@ export class AxiosWrapper {
21 21 this.customRequest = customRequest
22 22 this.successCallback = successCallback
23 23 this.failCallback = failCallback
  24 + this.actionPayloadExtra = actionPayloadExtra
24 25 this.source = axios.CancelToken.source()
25 26 this.instance = axios.create({
26 27 // baseURL: '/v1',
... ... @@ -148,7 +149,7 @@ export class AxiosWrapper {
148 149 if (this.successCallback) {
149 150 this.successCallback(response)
150 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 154 } else if (this.responseType === 'json') {
154 155 message.error(response.data.msg)
... ...
front-end/h5/src/views/work-manager/list-mixin.js
... ... @@ -23,7 +23,7 @@ export default {
23 23 }
24 24 }),
25 25 computed: {
26   - ...mapState('editor', ['works', 'workTemplates']),
  26 + ...mapState('editor', ['works', 'workTemplates', 'total']),
27 27 ...mapState('loading', ['fetchWorks_loading', 'fetchWorkTemplates_loading']),
28 28 workList () {
29 29 const workList = this.isTemplate ? this.workTemplates : this.works
... ... @@ -35,6 +35,7 @@ export default {
35 35 },
36 36 methods: {
37 37 ...mapActions('editor', [
  38 + 'fetchCount',
38 39 'fetchWorks',
39 40 'createWork',
40 41 'deleteWork',
... ... @@ -54,7 +55,6 @@ export default {
54 55 _limit: pageSize,
55 56 _start: (pageNum - 1) * pageSize
56 57 }
57   - debugger
58 58 this.isTemplate ? this.fetchWorkTemplates(payload) : this.fetchWorks(payload)
59 59 }
60 60 },
... ... @@ -99,7 +99,7 @@ export default {
99 99 <a-pagination
100 100 show-size-changer
101 101 default-current={1}
102   - total={500}
  102 + total={this.isTemplate ? this.total.templates : this.total.works }
103 103 current={this.pagination.pageNum}
104 104 onShowSizeChange={(pageNum, pageSize) => {
105 105 this.pagination.pageNum = 1
... ... @@ -164,6 +164,6 @@ export default {
164 164 },
165 165 created () {
166 166 this.handleSearch()
167   - // this.isTemplate ? this.fetchWorkTemplates() : this.fetchWorks()
  167 + this.fetchCount({ is_template: this.isTemplate })
168 168 }
169 169 }
... ...