liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
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
var locat = (window.location+'').split('/'); 
$(function(){if('tool'== locat[3]){locat =  locat[0]+'//'+locat[2];}else{locat =  locat[0]+'//'+locat[2]+'/'+locat[3];};});
 
 
//清除空格
String.prototype.trim=function(){
     return this.replace(/(^\s*)|(\s*$)/g,'');
};
 
//====================上传二维码=================
$(document).ready(function(){
    var str='';
    $("#uploadify1").uploadify({
        'buttonImg'    :     locat+"/static/img/twoDimensonCode.png",
        'uploader'    :    locat+"/static/uploadify/uploadify.swf",
        'script'    :    locat+"/static/uploadify/uploadFile.jsp;jsessionid="+jsessionid,
        'cancelImg' :    locat+"/static/uploadify/cancel.png",
        'folder'    :    locat+"/uploadFiles/twoDimensionCode",//上传文件存放的路径,请保持与uploadFile.jsp中PATH的值相同
        'queueId'    :    "fileQueue",
        'queueSizeLimit'    :    1,//限制上传文件的数量
        //'fileExt'    :    "*.rar,*.zip",
        //'fileDesc'    :    "RAR *.rar",//限制文件类型
        'fileExt'     : '*.jpg;*.gif;*.png',
        'fileDesc'    : 'Please choose(.JPG, .GIF, .PNG)',
        'auto'        :    false,
        'multi'        :    true,//是否允许多文件上传
        'simUploadLimit':    2,//同时运行上传的进程数量
        'buttonText':    "files",
        'scriptData':    {'uploadPath':'/uploadFiles/twoDimensionCode/'},//这个参数用于传递用户自己的参数,此时'method' 必须设置为GET, 后台可以用request.getParameter('name')获取名字的值
        'method'    :    "GET",
        'onComplete':function(event,queueId,fileObj,response,data){
            str = response.trim();//单个上传完毕执行
        },
        'onAllComplete' : function(event,data) {
            //alert(str);    //全部上传完毕执行
            readContent(str);
        },
        'onSelect' : function(event, queueId, fileObj){
            $("#hasTp1").val("ok");
        }
    });
            
});
//====================上传二维码=================
 
function uploadTwo(){
    if($("#uploadify1").val()){
        top.layer.alert('请选择二维码!', {icon: 0});
    return false;
    }
    $('#uploadify1').uploadifyUpload();
}    
 
//去后台解析二维码返回解析内容
function readContent(str){
    $.ajax({
        type: "POST",
        url: locat+'/a/tools/TwoDimensionCodeController/readTwoDimensionCode',
        data: {imgId:str,tm:new Date().getTime()},
        dataType:'json',
        cache: false,
        success: function(data){
             if("success" == data.result){
                 if('null' == data.readContent || null == data.readContent){
                     top.layer.alert('读取失败,二维码无效!', {icon: 0});
                 }else{
                     $("#readContent").text(data.readContent);
                 }
             }else{
                 top.layer.alert('后台读取出错!', {icon: 0});
                 return;
             }
        }
    });
}
 
//生成二维码
function createTwoD(){
    
    if($("#encoderContent").val()==""){
        top.layer.alert('输入框不能为空!', {icon: 0});
        $("#encoderContent").focus();
        return false;
    }
    $.ajax({
        type: "POST",
        url: locat+'/a/tools/TwoDimensionCodeController/createTwoDimensionCode.do',
        data: {encoderContent:$("#encoderContent").val(),tm:new Date().getTime()},
        dataType:'json',
        cache: false,
        success: function(data){
             
             if(data.success){
                 $("#encoderImgId").attr("src",data.body.filePath);       
             }else{
                 top.layer.alert('生成二维码失败!', {icon: 0});
                 return false;
             }
             
             
        }
    });
    return true;
}