store.js 636 Bytes
Newer Older
wangdanlei's avatar
wangdanlei committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/**
 * Created by CXG on 19/7/3.
 */

/**
 * @param {Object} sapproval
 * @param {Object} selfAction
 * @returns {Object}
 */
export function actionInit(sapproval, selfAction) {
  const resOBj = {}
  if (sapproval) {
    Object.keys(sapproval).forEach(function(key) {
      resOBj[key] = ({ commit }, params) => {
        return new Promise((resolve, reject) => {
          sapproval[key](params).then(res => {
            resolve(res)
          }).catch(error => {
            reject(error)
          })
        })
      }
    })
  }
  if (selfAction) {
    return Object.assign(resOBj, selfAction)
  } else {
    return resOBj
  }
}