readTwoD.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. $(top.hangge());
  4. //清除空格
  5. String.prototype.trim=function(){
  6. return this.replace(/(^\s*)|(\s*$)/g,'');
  7. };
  8. //====================上传二维码=================
  9. $(document).ready(function(){
  10. var str='';
  11. $("#uploadify1").uploadify({
  12. 'buttonImg' : locat+"/static/images/twoDimensonCode.png",
  13. 'uploader' : locat+"/plugins/uploadify/uploadify.swf",
  14. 'script' : locat+"/plugins/uploadify/uploadFile.jsp;jsessionid="+jsessionid,
  15. 'cancelImg' : locat+"/plugins/uploadify/cancel.png",
  16. 'folder' : locat+"/uploadFiles/twoDimensionCode",//上传文件存放的路径,请保持与uploadFile.jsp中PATH的值相同
  17. 'queueId' : "fileQueue",
  18. 'queueSizeLimit' : 1,//限制上传文件的数量
  19. //'fileExt' : "*.rar,*.zip",
  20. //'fileDesc' : "RAR *.rar",//限制文件类型
  21. 'fileExt' : '*.jpg;*.gif;*.png',
  22. 'fileDesc' : 'Please choose(.JPG, .GIF, .PNG)',
  23. 'auto' : false,
  24. 'multi' : true,//是否允许多文件上传
  25. 'simUploadLimit': 2,//同时运行上传的进程数量
  26. 'buttonText': "files",
  27. 'scriptData': {'uploadPath':'/uploadFiles/twoDimensionCode/'},//这个参数用于传递用户自己的参数,此时'method' 必须设置为GET, 后台可以用request.getParameter('name')获取名字的值
  28. 'method' : "GET",
  29. 'onComplete':function(event,queueId,fileObj,response,data){
  30. str = response.trim();//单个上传完毕执行
  31. },
  32. 'onAllComplete' : function(event,data) {
  33. //alert(str); //全部上传完毕执行
  34. readContent(str);
  35. },
  36. 'onSelect' : function(event, queueId, fileObj){
  37. $("#hasTp1").val("ok");
  38. }
  39. });
  40. });
  41. //====================上传二维码=================
  42. function uploadTwo(){
  43. if($("#hasTp1").val()=="no"){
  44. $("#tipsTwo").tips({
  45. side:3,
  46. msg:'请选择二维码',
  47. bg:'#AE81FF',
  48. time:2
  49. });
  50. return false;
  51. }
  52. $('#uploadify1').uploadifyUpload();
  53. }
  54. //去后台解析二维码返回解析内容
  55. function readContent(str){
  56. $.ajax({
  57. type: "POST",
  58. url: locat+'/tool/readTwoDimensionCode.do',
  59. data: {imgId:str,tm:new Date().getTime()},
  60. dataType:'json',
  61. cache: false,
  62. success: function(data){
  63. if("success" == data.result){
  64. if('null' == data.readContent || null == data.readContent){
  65. $("#readContent").text("读不出内容, 检查是否有效二维码");
  66. }else{
  67. $("#readContent").tips({
  68. side:3,
  69. msg:'读取成功',
  70. bg:'#75C117',
  71. time:3
  72. });
  73. $("#readContent").val(data.readContent);
  74. }
  75. }else{
  76. $("#readContent").tips({
  77. side:3,
  78. msg:'读取失败,后台有误',
  79. bg:'#FF5080',
  80. time:10
  81. });
  82. return;
  83. }
  84. }
  85. });
  86. }
  87. //生成二维码
  88. function createTwoD(){
  89. if($("#encoderContent").val()==""){
  90. $("#encoderContent").tips({
  91. side:3,
  92. msg:'输入内容',
  93. bg:'#AE81FF',
  94. time:2
  95. });
  96. $("#encoderContent").focus();
  97. return false;
  98. }
  99. $("#encoderImgId").attr("src",locat+"/static/images/jzx.gif");
  100. $.ajax({
  101. type: "POST",
  102. url: locat+'/tool/createTwoDimensionCode.do',
  103. data: {encoderContent:$("#encoderContent").val(),tm:new Date().getTime()},
  104. dataType:'json',
  105. cache: false,
  106. success: function(data){
  107. if("success" == data.result){
  108. $("#encoderContent").tips({
  109. side:3,
  110. msg:'生成成功',
  111. bg:'#75C117',
  112. time:3
  113. });
  114. $("#encoderImgId").attr("src",locat+'/uploadFiles/twoDimensionCode/' + data.encoderImgId);
  115. }else{
  116. $("#encoderContent").tips({
  117. side:3,
  118. msg:'生成失败,后台有误',
  119. bg:'#FF5080',
  120. time:10
  121. });
  122. $("#encoderImgId").attr("src",locat+"/uploadFiles/twoDimensionCode/default.png");
  123. return;
  124. }
  125. }
  126. });
  127. }