resourceManageApi.js 1.09 KB
var globalApi = {}

class Api {
  constructor(url) {
    this.baseUrl = url;
  }

  _get(url, data, debug = false) {

    if (debug) {
      data = Object.assign({}, data, {debug: 'XYZ'})
    }

    return $.ajax({
      url: this.baseUrl + url,
      method: 'GET',
      contentType: 'appliction/json',
      dataType: "json",
      data: JSON.stringify(data)
    });
  }

  _post(url, data, debug = false) {
    if (debug) {
      data = Object.assign({}, data, {debug: 'XYZ'})
    }

    return $.ajax({
      url: this.baseUrl + url,
      method: 'POST',
      contentType: 'appliction/json',
      dataType: "json",
      data: JSON.stringify(data)
    });
  }
}

function initApi() {
  class ResourceApi extends Api {
    constructor() {
      super(contextPath)
    }

    info(id) {
      return this._post('/resource/getResourceInfo', {id})
    }

    edit(data) {
      return this._post('/resource/editResourceContentData', data)
    }

    editGoodsPool(data) {
      return this._post('/resource/batchEditResourceGoodsPool', data)
    }
  }

  globalApi.resource = new ResourceApi();

}

initApi();