var reader = new FileReader(); //本地预览
reader.readAsDataURL(file[0]);
reader.onloadend = function () { //图片转换为base64
var base64Data = reader.result.replace(/^data:image\/\w+;base64,/, "");
ajaxReq.ajax('upload_image','POST',{
data: {
image_data: base64Data,
file_name: file[0].name
},
beforeSend:function(){
},
success:function(res){
//console.log(res);
var imgdata = res.files[0];
$scope.products.forEach((item,index)=>{
if(index == $scope.product_img_list_idx){
item.file_id = imgdata.file_id;
item.file_url = imgdata.url;
}
})
$scope.$apply();
}
});
}
}