|
@@ -6331,5 +6331,155 @@ notrelated:是否取消关联用一个父元素的input标签(点击input标签
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+ }).directive('imgComponent', function ($state, $http, $bsRouterState, $uuid, $bsfiles) {
|
|
|
+ return {
|
|
|
+ restrict: 'EA',
|
|
|
+ require: '?ngModel',
|
|
|
+ //作用域
|
|
|
+ scope: {
|
|
|
+ filerefid: '=',
|
|
|
+ filetypeid: '=',
|
|
|
+ readonly: '=',
|
|
|
+ ismulti: "=?",
|
|
|
+ height: '=?',
|
|
|
+ imgList: '=?',
|
|
|
+ width: '=?'
|
|
|
+ },
|
|
|
+ //html
|
|
|
+ templateUrl: '../js/template/modal-showimg.html',
|
|
|
+ //link函数
|
|
|
+ link: function (scope) {
|
|
|
+ scope.modalId = $uuid.getUUID();
|
|
|
+ scope.img = { rotate: 0, scale: 1, isload: false, url: '' };
|
|
|
+ scope.imgList = [];
|
|
|
+ scope.showIndex = -1;
|
|
|
+ scope.height = scope.height || 100;
|
|
|
+ scope.width = scope.width || 130;
|
|
|
+ //图片附件
|
|
|
+ scope.reqFileModel = {
|
|
|
+ selectdata: { FileRefID: '', pageindex: 1, pagesize: 10, ptotal: 0 },
|
|
|
+ filetype: 1,
|
|
|
+ items: [],
|
|
|
+ readonly: false,
|
|
|
+ typeparams: {
|
|
|
+ types: ['jpg', 'bmp', 'png', 'gif', 'jpe', 'jpeg'],
|
|
|
+ errormsg: '图片格式必须为*.jpg,*.gif,*.png,*.bmp,*.jpe,*.jpeg等格式'
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ scope.$watch('filerefid', function (newVal, oldVal) {
|
|
|
+ if (newVal != null) {
|
|
|
+ scope.img = { rotate: 0, scale: 1, isload: false, url: '' };
|
|
|
+ scope.getImgList();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ scope.getImgList = function () {
|
|
|
+ $http
|
|
|
+ ({
|
|
|
+ method: 'get',
|
|
|
+ url: '../../api/common/File/GetFileList',
|
|
|
+ params: {
|
|
|
+ fileRefId: scope.filerefid,
|
|
|
+ fileType: scope.filetypeid,
|
|
|
+ pageindex: 1,
|
|
|
+ pagesize: 1000
|
|
|
+ }
|
|
|
+ }).then(function (result) {
|
|
|
+ scope.imgList = result.data.Data.Result.rows;
|
|
|
+ scope.imgList.forEach(img => {
|
|
|
+ if (!img.base64) {
|
|
|
+ $http
|
|
|
+ ({
|
|
|
+ method: 'get',
|
|
|
+ url: '../../api/common/File/GetImageBase64',
|
|
|
+ params: {
|
|
|
+ fileId: img.AttachmentId,
|
|
|
+ }
|
|
|
+ }).then(function (imgRes) {
|
|
|
+ if (imgRes.data.IsSuccess) {
|
|
|
+ img.success = true;
|
|
|
+ img.base64 = "data:image/png;base64," + imgRes.data.Data.Base64Data;
|
|
|
+ img.height = imgRes.data.Data.Height;
|
|
|
+ img.width = imgRes.data.Data.Width;
|
|
|
+ img.blobUrl = URL.createObjectURL(scope.base64ToBlob(img.base64));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ img.success = false;
|
|
|
+ }
|
|
|
+ }, (error) => {
|
|
|
+ img.success = false;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ };
|
|
|
+ scope.showImg = function (index) {
|
|
|
+ scope.img.rotate = 0;
|
|
|
+ scope.showIndex = index;
|
|
|
+ scope.setBigImgUrl();
|
|
|
+ };
|
|
|
+ scope.uploadImg = function () {
|
|
|
+ scope.reqFileModel.selectdata.FileRefID = scope.filerefid;
|
|
|
+ scope.reqFileModel.filetype = scope.filetypeid;
|
|
|
+ $bsfiles.addFile(scope.reqFileModel).then(function (fid) {
|
|
|
+ scope.getImgList();
|
|
|
+ });
|
|
|
+ };
|
|
|
+ scope.deleteImg = function (fid) {
|
|
|
+ if (confirm("是否删除?")) {
|
|
|
+ $http({
|
|
|
+ url: '../../api/common/File/DeleteFile',
|
|
|
+ method: 'GET',
|
|
|
+ params: { fileId: fid }
|
|
|
+ }).then(function (rq) {
|
|
|
+ if (rq.data.IsSuccess) {
|
|
|
+ scope.getImgList();
|
|
|
+ }
|
|
|
+ $alert({
|
|
|
+ title: '消息',
|
|
|
+ content: rq.data.Message,
|
|
|
+ placement: 'top',
|
|
|
+ type: 'info',
|
|
|
+ show: true,
|
|
|
+ duration: 3
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+ scope.up = function () {
|
|
|
+ scope.showIndex -= 1;
|
|
|
+ scope.img = { rotate: 0, scale: 1, isload: false, url: '' };
|
|
|
+ scope.setBigImgUrl();
|
|
|
+ };
|
|
|
+ scope.next = function () {
|
|
|
+ scope.showIndex += 1;
|
|
|
+ scope.img = { rotate: 0, scale: 1, isload: false, url: '' };
|
|
|
+ scope.setBigImgUrl();
|
|
|
+ };
|
|
|
+ scope.zoomIn = function () {
|
|
|
+ scope.img.scale += 0.1;
|
|
|
+ };
|
|
|
+ scope.zoomOut = function () {
|
|
|
+ scope.img.scale -= 0.1;
|
|
|
+ };
|
|
|
+ scope.setBigImgUrl = function () {
|
|
|
+ scope.img.isload = scope.imgList[scope.showIndex].success;
|
|
|
+ scope.img.url = scope.imgList[scope.showIndex].blobUrl;
|
|
|
+ };
|
|
|
+
|
|
|
+ scope.base64ToBlob = function (data) {
|
|
|
+ var arr = data.split(','),
|
|
|
+ mime = arr[0].match(/:(.*?);/)[1],
|
|
|
+ bstr = atob(arr[1]),
|
|
|
+ n = bstr.length,
|
|
|
+ u8arr = new Uint8Array(n);
|
|
|
+
|
|
|
+ while (n--) {
|
|
|
+ u8arr[n] = bstr.charCodeAt(n);
|
|
|
+ }
|
|
|
+ return new Blob([u8arr], { type: mime });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
});
|
|
|
})(angular);
|