TwoDimensionCode.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. var locat = (window.location+'').split('/');
  2. $(function(){if('tool'== locat[3]){locat = locat[0]+'//'+locat[2];}else{locat = locat[0]+'//'+locat[2]+'/'+locat[3];};});
  3. //清除空格
  4. String.prototype.trim=function(){
  5. return this.replace(/(^\s*)|(\s*$)/g,'');
  6. };
  7. //====================上传二维码=================
  8. $(document).ready(function(){
  9. var str='';
  10. $("#uploadify1").uploadify({
  11. 'buttonImg' : locat+"/static/img/twoDimensonCode.png",
  12. 'uploader' : locat+"/static/uploadify/uploadify.swf",
  13. 'script' : locat+"/static/uploadify/uploadFile.jsp;jsessionid="+jsessionid,
  14. 'cancelImg' : locat+"/static/uploadify/cancel.png",
  15. 'folder' : locat+"/uploadFiles/twoDimensionCode",//上传文件存放的路径,请保持与uploadFile.jsp中PATH的值相同
  16. 'queueId' : "fileQueue",
  17. 'queueSizeLimit' : 1,//限制上传文件的数量
  18. //'fileExt' : "*.rar,*.zip",
  19. //'fileDesc' : "RAR *.rar",//限制文件类型
  20. 'fileExt' : '*.jpg;*.gif;*.png',
  21. 'fileDesc' : 'Please choose(.JPG, .GIF, .PNG)',
  22. 'auto' : false,
  23. 'multi' : true,//是否允许多文件上传
  24. 'simUploadLimit': 2,//同时运行上传的进程数量
  25. 'buttonText': "files",
  26. 'scriptData': {'uploadPath':'/uploadFiles/twoDimensionCode/'},//这个参数用于传递用户自己的参数,此时'method' 必须设置为GET, 后台可以用request.getParameter('name')获取名字的值
  27. 'method' : "GET",
  28. 'onComplete':function(event,queueId,fileObj,response,data){
  29. str = response.trim();//单个上传完毕执行
  30. },
  31. 'onAllComplete' : function(event,data) {
  32. //alert(str); //全部上传完毕执行
  33. readContent(str);
  34. },
  35. 'onSelect' : function(event, queueId, fileObj){
  36. $("#hasTp1").val("ok");
  37. }
  38. });
  39. });
  40. //====================上传二维码=================
  41. function uploadTwo(){
  42. if($("#uploadify1").val()){
  43. top.layer.alert('请选择二维码!', {icon: 0});
  44. return false;
  45. }
  46. $('#uploadify1').uploadifyUpload();
  47. }
  48. //去后台解析二维码返回解析内容
  49. function readContent(str){
  50. $.ajax({
  51. type: "POST",
  52. url: locat+'/a/tools/TwoDimensionCodeController/readTwoDimensionCode',
  53. data: {imgId:str,tm:new Date().getTime()},
  54. dataType:'json',
  55. cache: false,
  56. success: function(data){
  57. if("success" == data.result){
  58. if('null' == data.readContent || null == data.readContent){
  59. top.layer.alert('读取失败,二维码无效!', {icon: 0});
  60. }else{
  61. $("#readContent").text(data.readContent);
  62. }
  63. }else{
  64. top.layer.alert('后台读取出错!', {icon: 0});
  65. return;
  66. }
  67. }
  68. });
  69. }
  70. //生成二维码
  71. function createTwoD(){
  72. if($("#encoderContent").val()==""){
  73. top.layer.alert('输入框不能为空!', {icon: 0});
  74. $("#encoderContent").focus();
  75. return false;
  76. }
  77. $.ajax({
  78. type: "POST",
  79. url: locat+'/a/tools/TwoDimensionCodeController/createTwoDimensionCode.do',
  80. data: {encoderContent:$("#encoderContent").val(),tm:new Date().getTime()},
  81. dataType:'json',
  82. cache: false,
  83. success: function(data){
  84. if(data.success){
  85. $("#encoderImgId").attr("src",data.body.filePath);
  86. }else{
  87. top.layer.alert('生成二维码失败!', {icon: 0});
  88. return false;
  89. }
  90. }
  91. });
  92. return true;
  93. }