2018-05-29上传图片

上传图片,以订购单为例:
step01: uploadImage
src/app/modules/purchase_orders/purchaseOrderFactory.js

  var createPurchaseOrder = function(order, items, store_id) {
    order.store_id = store_id;
    return $http.post($rootScope.gateway + '/v2/stores/' + store_id + '/purchase_orders',
      purchaseOrderMapper(order, items));
  };   

  var uploadPurchaseOrderImage = function(id, file) {
    var fd = new FormData();
    fd.append('image', file);
    return $http.post($rootScope.gateway + '/v2/stores/' + DashboardFactory.getStoreId() + '/purchase_orders/' + id + '/purchase_order_images', fd, {
      transformRequest: angular.identity,
      headers: { 'Content-Type': undefined }
    });
  }; 

step02: 处理逻辑
src/app/modules/purchase_orders/purchaseOrdersController.js

PurchaseOrderFactory.createPurchaseOrder($scope.order, items, $scope.current_store_id)
  .success(function (data) {
    if ($scope.orderImages.length) {
      _.each($scope.orderImages, function (file, i) {
        PurchaseOrderFactory.uploadPurchaseOrderImage(data.purchase_order.id, file)
          .success(function (data) {
            if (i === $scope.orderImages.length - 1) {
              $state.go('app.dashboard.purchase-orders.index', { store_id: DashboardFactory.getStoreId() });
            }
          })
          .error(function (err) {
            alert('Image uploading failed.');
            $state.go('app.dashboard.purchase-orders.index', { store_id: $stateParams.store_id });
          });
      });
    } else {
      $state.go('app.dashboard.purchase-orders.index', { store_id: $stateParams.store_id });
    }
  });

折扣部分的改动:
src/app/modules/discounts/discountFactory.js

  var uploadAdvancedDiscountImage = function(id, file) {
    var fd = new FormData();
    fd.append('image', file);
    return $http.post($rootScope.gateway + '/api/v4/stores/' + DashboardFactory.getStoreId() + '/discounts/' + id + '/discount_images', fd, {
      transformRequest: angular.identity,
      headers: { 'Content-Type': undefined }
    });
  };  

src/app/modules/discounts/advancedDiscountsController.js

// 497  
    $scope.orderImages = [];
    $scope.addImage = function (file, allFiles) {
      $scope.orderImages = allFiles;
    };

538-540

            if ($scope.orderImages.length) {
              _.each($scope.orderImages, function (file, i) {
                DiscountFactory.uploadAdvancedDiscountImage(data.discount.id, file)
                  .success(function (data) {
                    if (i === $scope.orderImages.length - 1) {
                      $scope.isSubmitting = false;
                      $state.go('app.dashboard.discounts.index', { store_id: DashboardFactory.getStoreId() });
                    }
                  })
                  .error(function (err) {
                    alert('Image uploading failed.');
                    $state.go('app.dashboard.discounts.index', { store_id: DashboardFactory.getStoreId() });
                  })
              })
            } else {
              $scope.isSubmitting = false;
              $state.go('app.dashboard.discounts.index', { store_id: DashboardFactory.getStoreId() });
            }

src/app/modules/discounts/advanced_discount_form.html

        <div class='panel-section'>
            <h3>{{'Images' |translate}}</h3>
            <div class="xgrid -gallery">
                <div ng-repeat='image in discount_images' class="xgrid-cell -default-25">
                    <img ng-src="{{image.image_url}}" alt="{{image.note}}" class="_rs-image">
                </div>
            </div>
            <input-image title='Add Image' on-select='addImage' ng-show="editMode"></input-image>
        </div>  
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1 Webpack 1.1 概念简介 1.1.1 WebPack是什么 1、一个打包工具 2、一个模块加载工具 3...
    Kevin_Junbaozi阅读 11,786评论 0 16
  • 放大自己,资源无尽----李欣频 如果你只把自己当作一片树叶,你自己会与其它树叶抢夺资源,但如果你把自己视为许多树...
    吴宇强阅读 1,778评论 0 0
  • 文|@发愤的草莓 写文章“第一怕”是什么? 第一怕没东西写。 不知要写什么好,如巧妇无米下炊一般发愁。 还记得上学...
    发愤的草莓阅读 5,124评论 12 31
  • 大托,一个隐居在湖南隆回虎形山脉密林深处的瑶寨。 闻说它的名字,只因了那神秘的石瀑。在小沙江镇,与五连瀑的亲密接触...
    梦里李大侠阅读 5,474评论 0 2

友情链接更多精彩内容