starter.directive('httpSrc', function ($http, global) { return { restrict: "A", link: function (scope, element, attrs) { var requestConfig = { method: 'GET', responseType: 'arraybuffer', cache: 'true' }; function base64Img(data) { var arr = new Uint8Array(data); var raw = ''; var i, j, subArray, chunk = 5000; for (i = 0, j = arr.length; i < j; i += chunk) { subArray = arr.subarray(i, i + chunk); raw += String.fromCharCode.apply(null, subArray); } return btoa(raw); } attrs.$observe('httpSrc', function (newValue) { requestConfig.url = newValue; if (newValue.indexOf('data:image') >= 0) { attrs.$set('src', newValue); } else { global.fetch_user().then(function () { $http(requestConfig).then(function (data) { attrs.$set('src', "data:image/jpeg;base64," + base64Img(data.data)); }); }); } }); } } }) .directive('erpBxPhotoBar', [function () { return { restrict: "E", scope: { files: '=', deleteImage:'=', headerBorder:'@', isDisabled:'=' }, replace: true, template: '
', controller: function ($scope, $rootScope, $q, showPopup, ImageManage) { $scope.popup = { isPopup: false }; $scope.headerBorder === 'true' ? $scope.headerBorder = true : $scope.headerBorder = false; $scope.shouBigImage = function (url) { $scope.imageUrl = url; $scope.$emit('showImage', {url: url}); } $scope.addphoto = function (disabled) { if (disabled) { return } $scope.popup.optionsPopup = showPopup.showSelectImgPopup(Camera, ImagePicker, $scope); $scope.popup.isPopup = true; } function ImagePicker() { //打开相册 $scope.popup.optionsPopup.close(); ImageManage.ImagePicker_getPictures($rootScope.commons.upload_maxcount - $scope.files.length).then(function (data) { $q.all(data).then(function (res) { $scope.files = $scope.files.concat(_.map(res, function (value) { return {"file_thumbnail_path": value, "file_full_path": value}; })); }, function (error) { alert(error); }); }); } function Camera() { $scope.popup.optionsPopup.close(); ImageManage.Camera_getPicture().then(function (result) { $scope.files.push({ "file_thumbnail_path": result, "file_full_path": result }); }); } $rootScope.$on('deleteImage', function (event, data) { var img = _.find($scope.files, function (image) { return image.file_full_path == $scope.imageUrl; }); if (img) { $scope.files.splice(_.indexOf($scope.files, img), 1); if (img.id) $scope.deleteImage.push({id:img.id, filename: img.fileName}); } $rootScope.commons.bigImage = false; }) } } }]) .directive('erpBxLargerImage', [function () { return { restrict: "E", template: '
', controller: function ($scope, $rootScope) { $scope.showImage = false; $scope.hideBigImage = function () { $rootScope.commons.bigImage = false; } $scope.deleteimage = function () { $scope.$emit('deleteImage'); } $rootScope.$on('showImage', function (event, data) { $scope.imageUrl = data.url; $rootScope.commons.bigImage = true; }) } } }])