123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- 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: '<div class="item camera-item" ng-class={"border-top-none":headerBorder}><div ng-repeat="image in files" ng-click="shouBigImage(image.file_full_path)"><img http-src="{{image.file_thumbnail_path}}"/></div><div class="center" ng-click="addphoto(isDisabled)"><i class="icon ion-camera"></i></div></div>',
- 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: '<div id="rightDisplay" ng-show="$root.commons.bigImage" class="popover-backdrop1" ng-click="hideBigImage()" ><img class="fullscreen-image" http-src="{{imageUrl}}" ng-pinch-zoom/><i class="ion-ios-trash-outline" ng-click="deleteimage();"></i></div>',
- 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;
- })
- }
- }
- }])
|