login.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <view style="height:100vh;background: #fff;">
  3. <view class="img-a bg-gradual-cyan">
  4. <view class="t-b">
  5. 您好,
  6. <br />
  7. 欢迎使用,AirSmartChat
  8. </view>
  9. </view>
  10. <view class="login-view" style="">
  11. <view class="t-login">
  12. <form v-show="showType === 'login'" class="cl">
  13. <view class="t-a">
  14. <text class="txt">账号</text>
  15. <input type="text" name="username" placeholder="请输入您的账号" maxlength="20" v-model="username" />
  16. </view>
  17. <view class="t-a">
  18. <text class="txt">密码</text>
  19. <input type="password" name="password" maxlength="18" placeholder="请输入您的密码" v-model="password" />
  20. </view>
  21. <button v-show="showType === 'login'" class="bg-cyan shadow margin-top-lg" @tap="login()" :loading="loginLoading">登 录</button>
  22. </form>
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import { getUrlQuery } from '@/util/squ.js'
  29. import { doLogin as doLoginApi, LoginSuccess } from '@/util/login.js'
  30. import {
  31. post
  32. } from '@/util/request.js'
  33. export default {
  34. data() {
  35. return {
  36. showType: 'login',
  37. email: '',
  38. phone: '',
  39. password: '',
  40. username:'',
  41. passwordConfirm: '',
  42. verificationCode: '',
  43. identifyingCode: '',
  44. loginLoading: false,
  45. registerLoading: false,
  46. doRegisterLoading: false
  47. }
  48. },
  49. mounted() {
  50. this.createCode(4)
  51. },
  52. methods: {
  53. login() {
  54. if (!this.check()) {
  55. this.createCode(4)
  56. return
  57. }
  58. this.doLogin()
  59. },
  60. doLogin() {
  61. this.loginLoading = true
  62. doLoginApi('H5', {
  63. username: this.email || this.phone|| this.username,
  64. password: this.password
  65. }).then(res => {
  66. this.loginLoading = false
  67. if (res === LoginSuccess) {
  68. uni.showToast({ title: '登录成功' })
  69. // 跳转到主页发现已经登录,会自动重新获取用户信息,此处无需获取
  70. window.location.href = getUrlQuery('_originHref')
  71. } else {
  72. uni.showToast({ title: (res && res.data && res.data.message) || '登录失败', icon: 'none' })
  73. this.createCode(4)
  74. }
  75. })
  76. },
  77. check () {
  78. if (!this.username) {
  79. uni.showToast({ title: '请输入您的账号', icon: 'none' })
  80. return false
  81. }
  82. if (!this.password) {
  83. uni.showToast({ title: '请输入您的密码', icon: 'none' })
  84. return false
  85. }
  86. return true
  87. },
  88. createCode(length) {
  89. var code = "";
  90. var codeLength = parseInt(length); //验证码的长度
  91. var checkCode = document.getElementById("checkCode");
  92. // 所有候选组成验证码的字符,当然也可以用中文的
  93. var codeChars = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
  94. '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',
  95. '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');
  96. //循环组成验证码的字符串
  97. for (var i = 0; i < codeLength; i++) {
  98. //获取随机验证码下标
  99. var charNum = Math.floor(Math.random() * 62);
  100. //组合成指定字符验证码
  101. code += codeChars[charNum]
  102. }
  103. if (checkCode) {
  104. //为验证码区域添加样式名
  105. checkCode.className = "code"
  106. //将生成验证码赋值到显示区
  107. checkCode.innerHTML = code
  108. }
  109. },
  110. validateCode(inputCode) {
  111. // 获取显示区生成的验证码
  112. var checkCode = document.getElementById("checkCode").innerHTML
  113. //console.log(checkCode, inputCode);
  114. if (inputCode.length <= 0) {
  115. uni.showToast({ title: '请输入验证码', icon: 'none' })
  116. return false
  117. } else if (inputCode.toUpperCase() != checkCode.toUpperCase()) {
  118. uni.showToast({ title: '验证码输入有误', icon: 'none' })
  119. return false
  120. } else {
  121. return true
  122. }
  123. }
  124. }
  125. };
  126. </script>
  127. <style>
  128. .txt {
  129. font-size: 32rpx;
  130. font-weight: bold;
  131. color: #333333;
  132. }
  133. .img-a {
  134. width: 100%;
  135. height: 450rpx;
  136. background-size: 100%;
  137. }
  138. .reg {
  139. font-size: 28rpx;
  140. color: #fff;
  141. height: 90rpx;
  142. line-height: 90rpx;
  143. border-radius: 50rpx;
  144. font-weight: bold;
  145. background: #f5f6fa;
  146. color: #000000;
  147. text-align: center;
  148. margin-top: 30rpx;
  149. }
  150. .login-view {
  151. width: 100%;
  152. position: relative;
  153. margin-top: -120rpx;
  154. background-color: #ffffff;
  155. border-radius: 8% 8% 0% 0;
  156. }
  157. .t-login {
  158. width: 600rpx;
  159. margin: 0 auto;
  160. font-size: 28rpx;
  161. padding-top: 80rpx;
  162. }
  163. .t-login button {
  164. font-size: 28rpx;
  165. color: #fff;
  166. height: 90rpx;
  167. line-height: 90rpx;
  168. border-radius: 50rpx;
  169. font-weight: bold;
  170. }
  171. .t-login input {
  172. height: 90rpx;
  173. line-height: 90rpx;
  174. margin-bottom: 50rpx;
  175. border-bottom: 1px solid #e9e9e9;
  176. font-size: 28rpx;
  177. }
  178. .t-login .t-a {
  179. position: relative;
  180. }
  181. .t-b {
  182. text-align: left;
  183. font-size: 42rpx;
  184. color: #ffffff;
  185. padding: 130rpx 0 0 70rpx;
  186. font-weight: bold;
  187. line-height: 70rpx;
  188. }
  189. .t-login .t-c {
  190. position: absolute;
  191. right: 22rpx;
  192. top: 22rpx;
  193. background: #5677fc;
  194. color: #fff;
  195. font-size: 24rpx;
  196. border-radius: 50rpx;
  197. height: 50rpx;
  198. line-height: 50rpx;
  199. padding: 0 25rpx;
  200. }
  201. .t-login .t-d {
  202. text-align: center;
  203. color: #999;
  204. margin: 80rpx 0;
  205. }
  206. .t-login .t-g {
  207. float: left;
  208. width: 50%;
  209. }
  210. .t-login .t-e image {
  211. width: 50rpx;
  212. height: 50rpx;
  213. }
  214. .t-login .uni-input-placeholder {
  215. color: #aeaeae;
  216. }
  217. .cl {
  218. zoom: 1;
  219. }
  220. .cl:after {
  221. clear: both;
  222. display: block;
  223. visibility: hidden;
  224. height: 0;
  225. content: '\20';
  226. }
  227. .bg-gradual-cyan {
  228. background-image: linear-gradient(45deg, #1da480, #1cbbb4);
  229. color: #ffffff;
  230. }
  231. .code-box .code {
  232. font-family:Arial;
  233. font-style:italic;
  234. color:blue;
  235. font-size:24px;
  236. border:0;
  237. padding:2px 3px;
  238. letter-spacing:3px;
  239. font-weight:bolder;
  240. float:left;
  241. cursor:pointer;
  242. width:90px;
  243. height:30px;
  244. line-height:30px;
  245. text-align:center;
  246. vertical-align:middle;
  247. background-color:#D8B7E3;
  248. }
  249. .code-box span {
  250. text-decoration:none;
  251. font-size:14px;
  252. color:#288bc4;
  253. padding-left:10px;
  254. }
  255. .code-box span:hover {
  256. text-decoration:underline;
  257. cursor:pointer;
  258. }
  259. </style>