wk.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>群活码</title>
  8. <script src="https://cdn.jsdelivr.net/npm/vue@2.7.14"></script>
  9. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@nutui/nutui@2.3.10/dist/nutui.min.css">
  10. <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  11. <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.min.js"></script>
  12. <script src="https://cdn.jsdelivr.net/npm/@nutui/nutui@2.3.10/dist/nutui.min.js"></script>
  13. </head>
  14. <style>
  15. body {
  16. background-color: #f7f7f7;
  17. margin: 0;
  18. }
  19. .qr-code-body {
  20. margin-top: 30px;
  21. border-radius: 5px;
  22. background-color: #fff;
  23. padding: 40px 20px;
  24. }
  25. .qr-code-header {
  26. display: flex;
  27. }
  28. .qr-code-content {
  29. padding: 20px;
  30. }
  31. .qr-code-img {
  32. border-radius: 5px;
  33. }
  34. .qr-code-notice {
  35. text-align: center;
  36. font-size: 12px;
  37. color: #ccc;
  38. }
  39. </style>
  40. <body>
  41. <div id="app">
  42. <nut-navbar :left-show="false" :right-show="false">加入群聊</nut-navbar>
  43. <nut-row type="flex" justify="center">
  44. <nut-col :span="23">
  45. <div class="qr-code-body">
  46. <div class="qr-code-header">
  47. <div class="qr-code-avatar">
  48. <nut-avatar size="large" shape="square" bg-icon :bg-image="data.avatar"></nut-avatar>
  49. </div>
  50. <div class="qr-code-title">
  51. {{ data.name }}
  52. </div>
  53. </div>
  54. <div class="qr-code-content">
  55. <img class="qr-code-img" :src="data.code" width="100%">
  56. </div>
  57. <div class="qr-code-footer">
  58. <div class="qr-code-notice">
  59. 长按二维码识别获取群信息加入群聊
  60. </div>
  61. </div>
  62. </div>
  63. </nut-col>
  64. </nut-row>
  65. </div>
  66. </body>
  67. <script>
  68. /**
  69. * 获取get请求参数的值
  70. * @param {String} name
  71. * @returns {String||null}
  72. */
  73. const getQuery = (name) => {
  74. const reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  75. const r = window.location.search.substr(1).match(reg);
  76. if (r != null) {
  77. return decodeURIComponent(r[2]);
  78. }
  79. return null;
  80. }
  81. const UrlDecode = (zipStr) => {
  82. var uzipStr = '';
  83. for (var i = 0; i < zipStr.length; i += 1) {
  84. var chr = zipStr.charAt(i);
  85. if (chr === '+') {
  86. uzipStr += ' ';
  87. } else if (chr === '%') {
  88. var asc = zipStr.substring(i + 1, i + 3);
  89. if (parseInt('0x' + asc) > 0x7f) {
  90. uzipStr += decodeURI('%' + asc.toString() + zipStr.substring(i + 3, i + 9).toString());
  91. i += 8;
  92. } else {
  93. uzipStr += AsciiToString(parseInt('0x' + asc));
  94. i += 2;
  95. }
  96. } else {
  97. uzipStr += chr;
  98. }
  99. }
  100. return uzipStr;
  101. }
  102. function StringToAscii(str) {
  103. return str.charCodeAt(0).toString(16);
  104. }
  105. function AsciiToString(asccode) {
  106. return String.fromCharCode(asccode);
  107. }
  108. // vue
  109. var app = new Vue({
  110. el: '#app',
  111. data() {
  112. return {
  113. baseUrl: '',
  114. mallId: '',
  115. enc: '',
  116. api: '/workwx/v1/group-infinite/code',
  117. data: {},
  118. }
  119. },
  120. methods: {
  121. /**
  122. * 获取
  123. */
  124. getCode() {
  125. let url = this.baseUrl + this.api
  126. // 为给定 ID 的 user 创建请求
  127. axios({
  128. method: 'get',
  129. url: url,
  130. params: {
  131. mall_id: this.mallId,
  132. enc: this.enc
  133. }
  134. }).then((res) => {
  135. this.data = res.data.data
  136. })
  137. },
  138. },
  139. mounted() {
  140. this.baseUrl = getQuery('api_host') ? getQuery('api_host') : null
  141. this.enc = getQuery('enc') ? getQuery('enc') : null
  142. if (!(this.baseUrl && this.enc)) {
  143. this.$notify.danger('内容不合法')
  144. } else {
  145. this.baseUrl = UrlDecode(this.baseUrl)
  146. }
  147. this.getCode()
  148. },
  149. })
  150. </script>
  151. </html>