田源
2024-04-07 2ac55ce0edf4870a29691b56bfad59f4830a11a2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
 * 自定义图片展示
 * @author wangting
 * @date 2021-3-11
 */
layui.define(['layer','element','flow'],function(exports){
    var webUtil = $webUtil;
    var Class = function() {
        this.MODELNAME = "ImageView";
        this.moduleKey = "ImageView";
        this.backPath = configData.compatibility?path:configData.objectServicePath;
        this.url = {
            imgview: 'imageViewerController/downloadImage'
        };
        this.sourceData  = {
            imgWidth:600,
            imgHeight:300
        };
        this.getContent = function (id,options) {
            var that = this;
            that.id=id;
            var html = [
                '<div class="lazyimgs" id="lazyimgs_',id,'" lay-filter="lazyimgs_',id,'" style="display:block; text-align: center"></div>'
            ].join("");
            return html;
        };
        this.init = function (id, options) {
            var that = this;
            webUtil.copyConfig(that, that.moduleKey);
            that.id=id;
 
            $.extend(that.sourceData,options);
        };
 
        this.loadForUI=function (sourceData){
            if(!sourceData){
                return;
            }
            var that =this;
            $("#lazyimgs_"+that.id).empty();
            //参数有调整
            //    /**
            //      * 业务类型
            //      */
            //     private String btmType;
            //
            //     /**
            //      * 图片显示的方式
            //      */
            //     private String imageType;
            //
            //     /**
            //      * 文件的主键
            //      */
            //     private String fileOid;
            //
            //     /**
            //      * 文件的路径
            //      */
            //     private String filePath;
 
            //fileOid 是在imageType等于“fileobject”时,利用propertyname在选择的这条数据中获取,也就是propertyname实际就是选择数据中的某个属性(注意属性不区分大小写)
            //filePath 是在imageType等于“filepath”时,利用propertyname在选择的这条数据中获取,
            var url = $webUtil.isNull(that.sourceData.url) ? that.url.imgview : that.sourceData.url;
            if(that.sourceData.urlParams.imageType=='fileobject'){
                that.sourceData.urlParams['fileOid']=sourceData[that.sourceData.urlParams.propertyname]
            }else if(that.sourceData.urlParams.imageType=='filepath'){
                that.sourceData.urlParams['filePath']=sourceData[that.sourceData.urlParams.propertyname]
            }
 
            if(that.sourceData.urlParams['fileOid']==''||that.sourceData.urlParams['filePath']==''){
                return;
            }
            var img = $('<img class="fullScreen" lay-src="' + that.backPath + url +
                '?fileOid=' + (that.sourceData.urlParams['fileOid']||'')
                + '&filePath=' + (that.sourceData.urlParams['filePath'].replace(/\\/g, '/')||'')
                + '&imageType=' + that.sourceData.urlParams.imageType
                + '&' + TOKEN_KEY + '=' + $webUtil.getToken() + '"> ');
            img.width(that.sourceData.imgWidth).height(that.sourceData.imgHeight).on('dblclick', function () {
                var div = $('<div style="position:absolute;width:100%;height: 100%;left:0;top:0;z-index: 99999"><i class="layui-icon layui-icon-close-fill" style="font-size:40px;position:absolute;right:0;top:0;z-index: 100000"></i></div>');
                $('.layui-body').append(div)
                var fullImg = new Image();
                fullImg.onerror = function () {
                };
                fullImg.src = this.src;
                fullImg.style.position = "absolute";
                fullImg.style.width = "98%";
                fullImg.style.height = "auto";
                fullImg.style.left = '1%';
                fullImg.style.top = '20px';
                div.append(fullImg);
                $('.layui-icon-close-fill', div).on('click', function () {
                    $(this).parent().remove()
                })
            })
            $("#lazyimgs_"+that.id).html(img);
            var flow = layui.flow;
            flow.lazyimg({
                elem: '.lazyimgs img'
            });
            // $webUtil.get(url , that.sourceData.urlParams, function (result) {
            //     if (result.success) {
            //         var img = $('<img class="fullScreen" lay-src="'+result+'"> ')
            //         img.width(that.sourceData.imgWidth).height(that.sourceData.imgHeight).on('dblclick', function () {
            //             var div = $('<div style="position:absolute;width:100%;height: 100%;left:0;top:0;z-index: 99999"><i class="layui-icon layui-icon-close-fill" style="font-size:40px;position:absolute;right:0;top:0;z-index: 100000"></i></div>');
            //             $('.layui-body').append(div)
            //             var fullImg = new Image();
            //             fullImg.onerror = function () {
            //             };
            //             fullImg.src = this.src;
            //             fullImg.style.position = "absolute";
            //             fullImg.style.width = "98%";
            //             fullImg.style.height = "auto";
            //             fullImg.style.left = '1%';
            //             fullImg.style.top = '20px';
            //             div.append(fullImg);
            //             $('.layui-icon-close-fill', div).on('click', function () {
            //                 $(this).parent().remove()
            //             })
            //         })
            //         $("#lazyimgs_"+that.id).html(img);
            //         var flow = layui.flow;
            //         flow.lazyimg({
            //             elem: '.lazyimgs img'
            //         });
            //     } else {
            //         $webUtil.showErrorMsg(result.msg);
            //     }
            // }, function (xhr, error) {
            //     $webUtil.showErrorMsg("获取图片出现了错误,可能是文件服务没有启动");
            // }, that.backPath);
        }
 
        this.refresh = function(){
            var that = this;
 
        };
 
        this.destory = function(){
            var that = this;
            var filter = "lazyimgs_" + that.id;
            $('#'+filter).remove()
        };
    };
    var cs = new Class();
    exports(cs.MODELNAME,cs);
});