directive.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. starter.directive('httpSrc', function ($http, global) {
  2. return {
  3. restrict: "A",
  4. link: function (scope, element, attrs) {
  5. var requestConfig = {
  6. method: 'GET',
  7. responseType: 'arraybuffer',
  8. cache: 'true'
  9. };
  10. function base64Img(data) {
  11. var arr = new Uint8Array(data);
  12. var raw = '';
  13. var i, j, subArray, chunk = 5000;
  14. for (i = 0, j = arr.length; i < j; i += chunk) {
  15. subArray = arr.subarray(i, i + chunk);
  16. raw += String.fromCharCode.apply(null, subArray);
  17. }
  18. return btoa(raw);
  19. }
  20. attrs.$observe('httpSrc', function (newValue) {
  21. requestConfig.url = newValue;
  22. if (newValue.indexOf('data:image') >= 0) {
  23. attrs.$set('src', newValue);
  24. } else {
  25. global.fetch_user().then(function () {
  26. $http(requestConfig).then(function (data) {
  27. attrs.$set('src', "data:image/jpeg;base64," + base64Img(data.data));
  28. });
  29. });
  30. }
  31. });
  32. }
  33. }
  34. })
  35. .directive('erpBxPhotoBar', [function () {
  36. return {
  37. restrict: "E",
  38. scope: {
  39. files: '=',
  40. deleteImage:'=',
  41. headerBorder:'@',
  42. isDisabled:'='
  43. },
  44. replace: true,
  45. 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>',
  46. controller: function ($scope, $rootScope, $q, showPopup, ImageManage) {
  47. $scope.popup = {
  48. isPopup: false
  49. };
  50. $scope.headerBorder === 'true' ? $scope.headerBorder = true : $scope.headerBorder = false;
  51. $scope.shouBigImage = function (url) {
  52. $scope.imageUrl = url;
  53. $scope.$emit('showImage', {url: url});
  54. }
  55. $scope.addphoto = function (disabled) {
  56. if (disabled) {
  57. return
  58. }
  59. $scope.popup.optionsPopup = showPopup.showSelectImgPopup(Camera, ImagePicker, $scope);
  60. $scope.popup.isPopup = true;
  61. }
  62. function ImagePicker() { //打开相册
  63. $scope.popup.optionsPopup.close();
  64. ImageManage.ImagePicker_getPictures($rootScope.commons.upload_maxcount - $scope.files.length).then(function (data) {
  65. $q.all(data).then(function (res) {
  66. $scope.files = $scope.files.concat(_.map(res, function (value) {
  67. return {"file_thumbnail_path": value, "file_full_path": value};
  68. }));
  69. }, function (error) {
  70. alert(error);
  71. });
  72. });
  73. }
  74. function Camera() {
  75. $scope.popup.optionsPopup.close();
  76. ImageManage.Camera_getPicture().then(function (result) {
  77. $scope.files.push({
  78. "file_thumbnail_path": result,
  79. "file_full_path": result
  80. });
  81. });
  82. }
  83. $rootScope.$on('deleteImage', function (event, data) {
  84. var img = _.find($scope.files, function (image) {
  85. return image.file_full_path == $scope.imageUrl;
  86. });
  87. if (img) {
  88. $scope.files.splice(_.indexOf($scope.files, img), 1);
  89. if (img.id)
  90. $scope.deleteImage.push({id:img.id, filename: img.fileName});
  91. }
  92. $rootScope.commons.bigImage = false;
  93. })
  94. }
  95. }
  96. }])
  97. .directive('erpBxLargerImage', [function () {
  98. return {
  99. restrict: "E",
  100. 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>',
  101. controller: function ($scope, $rootScope) {
  102. $scope.showImage = false;
  103. $scope.hideBigImage = function () {
  104. $rootScope.commons.bigImage = false;
  105. }
  106. $scope.deleteimage = function () {
  107. $scope.$emit('deleteImage');
  108. }
  109. $rootScope.$on('showImage', function (event, data) {
  110. $scope.imageUrl = data.url;
  111. $rootScope.commons.bigImage = true;
  112. })
  113. }
  114. }
  115. }])