1
13693261870
2022-09-16 762f2fb45db004618ba099aa3c0bd89dba1eb843
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
148
149
150
151
152
153
154
155
156
157
158
159
160
$(function () {
    $("#jqGrid").jqGrid({
        url: restServerBaseURL + 'sys/attachment/list',
        datatype: "json",
        colModel: [            
            { label: 'id', name: 'id', index: 'id', key: true, hidden: true },
            { label: '标题', name: 'title', index: 'title', width: 100,align:'center' },
            { label: '缩略图', name: 'path', index: 'path', width: 100,align:'center', formatter: function(value, options, row){
                var mime=row.mimeType;
                if(mime.indexOf('image') >= 0){
                    return '<img class="img-thumbnail" style="width: 60px;height: 60px;" src="'+uploadFileResource+value+'" >';
                }else if(mime.indexOf('audio') >= 0){
                    return '<img class="img-thumbnail" style="width: 60px;height: 60px;" src="'+restServerBaseURL+'image/audio.jpg" >';
                }else if(mime.indexOf('video') >= 0){
                    return '<img class="img-thumbnail" style="width: 60px;height: 60px;" src="'+restServerBaseURL+'image/video.jpg" >';
                }else if(mime.indexOf('application') >= 0){
                    return '<img class="img-thumbnail" style="width: 60px;height: 60px;" src="'+restServerBaseURL+'image/file.jpg" >';
                }
            } },
            { label: '后缀', name: 'suffix', index: 'suffix', width: 50,align:'center' },
            { label: '类型', name: 'mimeType', index: 'mime_type', width: 60,align:'center' },
            { label: '创建时间', name: 'createTime', index: 'create_time', width: 90,align:'center' }
        ],
        viewrecords: true,
        height: "auto",
        rowNum: 10,
        //rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
    var callBackUrl = "http://" + window.location.host + baseURL + "admin/modules/ajaxuploadproxy.html";
    new AjaxUpload('#upload', {
        action: restServerBaseURL + 'sys/attachment/upload?token=' + token,
        name: 'file',
        data:{callBackUrl:callBackUrl,category:'sysatachment'},
        autoSubmit:true,
        responseType:"json",
        onSubmit:function(file, extension){
            layer.load(2);
            /*if (!(extension && /^(jpg|jpeg|png|gif)$/.test(extension.toLowerCase()))){
                alert('只支持jpg、png、gif格式的图片!');
                return false;
            }*/
        },
        onComplete : function(file, r){
           /* layer.closeAll('loading');
            if(r.code == 0){
                vm.reload();
            }else{
                alert(r.msg);
            }*/
        }
    });
 
});
 
function ajaxUploadComplete(code,path){
    layer.closeAll('loading');
    if(code == 0){
        vm.reload();
    }else{
        alert("上传失败");
    }
}
 
var vm = new Vue({
    el:'#rapp',
    data:{
        q:{
            title: null,
            mime_type: ''
        },
        showList: true,
        title: null,
        attachment: {},
        mimeType: 'image/jpeg',
        uploadFileResource: uploadFileResource,
        restServerBaseURL: restServerBaseURL
    },
    methods: {
        query: function () {
            vm.reload();
        },
        download: function (){
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            var url=restServerBaseURL + "sys/attachment/download/"+id+"?token="+token;
            window.location.href=url;
        },
        getAttachment: function (attachmentId){
            $.get(restServerBaseURL + "sys/attachment/info/"+attachmentId, function(r){
                vm.attachment = r.attachment;
                vm.mimeType = r.attachment.mimeType;
            });
        },
        info: function (){
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            vm.getAttachment(id);
            openLayer('700px', '600px', '查看附件', 'attachmentInfoLayer');
        },
        del: function () {
            var ids = getSelectedRows();
            if(ids == null){
                return ;
            }
            confirm('确定要删除选中的记录?', function(){
                $.ajax({
                    type: "POST",
                    url: restServerBaseURL + "sys/attachment/delete",
                    contentType: "application/json",
                    data: JSON.stringify(ids),
                    success: function(r){
                        if(r.code == 0){
                            alert('操作成功', function(){
                                vm.reload();
                            });
                        }else{
                            alert(r.msg);
                        }
                    }
                });
            });
        },
        reload: function () {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{ 
                postData:{'title': vm.q.title, 'mime_type': vm.q.mime_type},
                page:page
            }).trigger("reloadGrid");
        },
        refresh: function () {
            vm.showList = true;
            window.location.reload();
        }
    }
});