Kaynağa Gözat

推广码复制

neo 1 yıl önce
ebeveyn
işleme
9466ce03ab
1 değiştirilmiş dosya ile 20 ekleme ve 5 silme
  1. 20 5
      views/welcome.tpl

+ 20 - 5
views/welcome.tpl

@@ -18,25 +18,39 @@
18 18
     <input type="text" id="token" value={{.token}} hidden=true>
19 19
     <div class="x-body layui-anim layui-anim-up">
20 20
         <blockquote class="layui-elem-quote">欢迎{{.rolename}}:
21
-            <span class="x-red">{{.username}}</span>!当前时间:{{.sysTime}}</blockquote>
21
+            <span class="x-red">{{.username}}</span>!当前时间:{{.sysTime}}
22
+        </blockquote>
22 23
     </div>
23 24
     <div class="x-body layui-anim layui-anim-up">
24 25
         <blockquote class="layui-elem-quote">
25
-            推广码<input id="sharecode" style="width:128px;" type="text" class="layui-input">
26
-            <br>
27
-            <input value="刷新" class="layui-btn" style="width:128px;" type="button" onclick="randCode()">
26
+            推广码: <input id="sharecode" type="text" />
27
+            {{"         "}}
28
+            <input value="复制" class="layui-btn" type="button" onclick="copyToClip()" />
28 29
             <br>
29 30
             <br>
31
+            <input value="刷新" class="layui-btn" style="width:128px;" type="button" onclick="randCode()" />
32
+            {{"         "}}
30 33
             <input value="更新" class="layui-btn" style="width:128px;" type="button" onclick="UpdateShareCode()">
31 34
         </blockquote>
32 35
     </div>
33 36
 
34 37
     <script language="JavaScript">
38
+      var currShareCode = ""
35 39
       function InitParams(sharecode) {
36 40
         if (sharecode.length > 0) {
37 41
             document.getElementById("sharecode").value = sharecode;
42
+            currShareCode = sharecode
38 43
         }
39 44
       }
45
+      function copyToClip() {
46
+        var aux = document.createElement("input");
47
+        aux.setAttribute("value", currShareCode);
48
+        document.body.appendChild(aux);
49
+        aux.select();
50
+        document.execCommand("copy");
51
+        document.body.removeChild(aux);
52
+        layer.msg('复制成功!',{icon:1,time:1000});
53
+      }
40 54
 
41 55
       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'];
42 56
       function generateMixed(n) {
@@ -49,7 +63,8 @@
49 63
       }
50 64
       // 随机兑换码
51 65
       function randCode() {
52
-        document.getElementById("sharecode").value = generateMixed(6);
66
+        currShareCode = generateMixed(6)
67
+        document.getElementById("sharecode").value = currShareCode;
53 68
       }
54 69
       
55 70
       function UpdateShareCode () {