welcome.tpl 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>欢迎页面-X-admin2.0</title>
  6. <meta name="renderer" content="webkit">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  8. <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
  9. <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
  10. <link rel="stylesheet" href="./static/css/font.css">
  11. <link rel="stylesheet" href="./static/css/xadmin.css">
  12. <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  13. <script src="./static/lib/layui/layui.js" charset="utf-8"></script>
  14. <script type="text/javascript" src="./static/js/xadmin.js"></script>
  15. </head>
  16. <body onload="InitParams({{.sharecode}})">
  17. <input type="text" id="token" value={{.token}} hidden=true>
  18. <div class="x-body layui-anim layui-anim-up">
  19. <blockquote class="layui-elem-quote">欢迎{{.rolename}}:
  20. <span class="x-red">{{.username}}</span>!当前时间:{{.sysTime}}
  21. </blockquote>
  22. </div>
  23. <div class="x-body layui-anim layui-anim-up">
  24. <blockquote class="layui-elem-quote">
  25. 推广码: <input id="sharecode" type="text" />
  26. {{" "}}
  27. <input value="复制" class="layui-btn" type="button" onclick="copyToClip()" />
  28. <br>
  29. <br>
  30. <input value="刷新推广码" class="layui-btn" style="width:128px;" type="button" onclick="randCode()" />
  31. {{" "}}
  32. <input value="更新" class="layui-btn" style="width:128px;" type="button" onclick="UpdateShareCode()">
  33. </blockquote>
  34. </div>
  35. <script language="JavaScript">
  36. var currShareCode = ""
  37. function InitParams(sharecode) {
  38. if (sharecode.length > 0) {
  39. document.getElementById("sharecode").value = sharecode;
  40. currShareCode = sharecode
  41. }
  42. }
  43. function copyToClip() {
  44. var aux = document.createElement("input");
  45. aux.setAttribute("value", currShareCode);
  46. document.body.appendChild(aux);
  47. aux.select();
  48. document.execCommand("copy");
  49. document.body.removeChild(aux);
  50. layer.msg('复制成功!',{icon:1,time:1000});
  51. }
  52. var randChats = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
  53. function generateMixed(n) {
  54. var res = "";
  55. for(var i = 0; i < n ; i ++) {
  56. var id = Math.ceil(Math.random()*(randChats.length-1));
  57. res += randChats[id];
  58. }
  59. return res;
  60. }
  61. // 随机兑换码
  62. function randCode() {
  63. currShareCode = generateMixed(6)
  64. document.getElementById("sharecode").value = currShareCode;
  65. }
  66. function UpdateShareCode () {
  67. var token = document.getElementById("token").value;
  68. var sharecode = document.getElementById("sharecode").value;
  69. if (sharecode.length != 6){
  70. alert("兑换码长度错误!6位大写字母");
  71. return;
  72. }
  73. // 兑换码字符检查
  74. for (var i = 0; i < sharecode.length; i ++){
  75. var isMatch = false
  76. for (var j = 0; j < randChats.length; j ++) {
  77. if (sharecode[i] == randChats[j]){
  78. isMatch = true;
  79. break;
  80. }
  81. }
  82. if (isMatch == false){
  83. alert("兑换码错误!请使用大写字母");
  84. return;
  85. }
  86. }
  87. var text = "token=" + encodeURI(token);
  88. text += "&sharecode=" + encodeURI(sharecode);
  89. $.ajax({
  90. type:"post",
  91. url:"/welcome?" + text,
  92. success:function (data) {
  93. // alert(data.status);
  94. if (data.status){
  95. window.location.href="/welcome";
  96. if (data.info){
  97. layer.msg(data.info,{icon:1,time:1000});
  98. }
  99. }else{
  100. if (data.info){
  101. alert(data.info);
  102. }else{
  103. window.location.href="/accountlogin";
  104. }
  105. }
  106. }
  107. });
  108. }
  109. </script>
  110. </body>
  111. </html>