login.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <view class="login">
  3. <view class="HLogo">
  4. <img src="@/static/img/ycjs.png" alt="" />
  5. <p>欢迎登录一茶酒社</p>
  6. </view>
  7. <view class="phoneL" v-if="LoginType == 1">
  8. <view class="clearfix"><input v-model="formD2.mobile" placeholder="请输入手机号" type="number" maxlength="11" /></view>
  9. <view class="clearfix">
  10. <input v-model="formD2.captcha" placeholder="请输入验证码" confirm-type="go" type="number" maxlength="5" class="w70" />
  11. <view @click="getVerifyCode" :class="{w30:true,corb:msgNum!=='获取验证码'}">{{msgNum}}</view>
  12. </view>
  13. <view v-if="signIn" class="clearfix">
  14. <input placeholder="请输入邀请码" v-model="formD2.invite" />
  15. </view>
  16. </view>
  17. <view class="numberL" v-else>
  18. <view class="clearfix">
  19. <input placeholder="请输入账号" v-model="formD.username" />
  20. </view>
  21. <view class="clearfix">
  22. <input placeholder="请输入密码" v-model="formD.password" password />
  23. </view>
  24. <view class="clearfix">
  25. <input placeholder="请输入验证码" confirm-type="go" maxlength="4" class="w70" v-model="formD.verifyCode" />
  26. <img :src="verifyimage" @click="changVerifyimage" class="w30 verifyImg" alt="" />
  27. </view>
  28. </view>
  29. <view @click="login" :class="{bagBtn:true,corg:ISFill}">登录</view>
  30. <view class="btnTxt" @click="signIn = !signIn">立即注册</view>
  31. <!-- <view class="btnTxt" @click="LoginType = LoginType == 1 ? 0 : 1">
  32. {{ LoginType == 1 ? "密码登录" : "验证码登录" }}
  33. </view> -->
  34. </view>
  35. </template>
  36. <script>
  37. let app = getApp();
  38. var appEv = app.$vm.$options;
  39. import { get, post } from "@/request/api.js";
  40. export default {
  41. name: "login",
  42. data() {
  43. return {
  44. LoginType: 1,
  45. timestamp: parseInt((new Date()) / 1),
  46. formD: {
  47. username: "",
  48. password: "",
  49. verifyCode: "",
  50. },
  51. formD2: {
  52. mobile: '',
  53. captcha: "",
  54. invite: ""
  55. },
  56. verifyimage: "",
  57. msgNum: "获取验证码",
  58. signKey: '',
  59. messageId: "",
  60. ISFill: false,
  61. signIn: false, //是否为注册
  62. };
  63. },
  64. onLoad(option) {
  65. // this.changVerifyimage(); //获取图形验证码
  66. // this.getKey();
  67. },
  68. onLaunch() {},
  69. onShow() {},
  70. onHide() {},
  71. methods: {
  72. login() {
  73. if (!this.ISFill) {
  74. uni.showToast({
  75. title: "登录信息填写有误哦",
  76. duration: 2000,
  77. icon: "none",
  78. });
  79. return
  80. }
  81. post("login",this.formD2).then((res) => {
  82. if (res.code === 0) {
  83. uni.setStorageSync('token', res.data.token);
  84. this.getuserInfo();
  85. }
  86. });
  87. },
  88. getuserInfo() {
  89. post("/user/userinfo").then((res) => {
  90. if (res.code === 0) {
  91. uni.setStorageSync('userinfo', res.data.data);
  92. uni.navigateBack();
  93. }
  94. });
  95. },
  96. changVerifyimage() {
  97. let MathRandom = Math.random();
  98. this.verifyimage = this.$hosts.Hhost + "login/login/verifyimage.do?random=" + MathRandom;
  99. },
  100. getKey() {
  101. get("login/login/getKey.do").then(res => {
  102. if (res.resultCode == 1) {
  103. this.signKey = res.data.key
  104. }
  105. })
  106. },
  107. getVerifyCode() {
  108. console.log(appEv);
  109. if (!this.isPhone(this.formD2.mobile)) {
  110. appEv.errTips("手机号填写有误!");
  111. return
  112. }
  113. post("getSms", {
  114. mobile: this.formD2.mobile
  115. }).then((res) => {
  116. if (res.code === 0) {
  117. let number = 59;
  118. let as = setInterval(() => {
  119. this.msgNum = number + "s后重发"
  120. number--;
  121. if (number == 0) {
  122. this.msgNum = "重发验证码"
  123. clearTimeout(as);
  124. }
  125. }, 1000);
  126. }
  127. });
  128. },
  129. isPhone(s) {
  130. return /^1[0-9]{10}$/.test(s)
  131. },
  132. FillIn() {
  133. if (this.LoginType == 1) {
  134. let m = this.formD2.mobile
  135. let v = this.formD2.captcha
  136. if (m && v && v.length == 5 && this.isPhone(m)) this.ISFill = true
  137. else this.ISFill = false
  138. } else {
  139. let u = this.formD.username
  140. let p = this.formD.password
  141. let v = this.formD.verifyCode
  142. if (u && p && v && v.length == 4) this.ISFill = true
  143. else this.ISFill = false
  144. }
  145. }
  146. },
  147. computed: {},
  148. watch: {
  149. formD: {
  150. deep: true,
  151. handler(val) {
  152. this.FillIn()
  153. }
  154. },
  155. formD2: {
  156. deep: true,
  157. handler(val) {
  158. this.FillIn()
  159. }
  160. },
  161. },
  162. };
  163. </script>
  164. <style scoped lang='scss'>
  165. .login {
  166. text-align: center;
  167. .HLogo {
  168. padding-top: 80rpx;
  169. margin-bottom: 60rpx;
  170. img {
  171. width: 120rpx;
  172. height: 120rpx;
  173. border-radius: 50%;
  174. background: #ffffff;
  175. border: 1px solid #e6e6e6;
  176. }
  177. P {
  178. // font-weight: 500;
  179. font-size: 40rpx;
  180. margin-top: 16rpx;
  181. font-family: "webfont" !important;
  182. }
  183. }
  184. input {
  185. width: 100%;
  186. padding: 20rpx 0;
  187. font-size: 32rpx;
  188. text-align: left;
  189. }
  190. .phoneL,
  191. .numberL {
  192. padding: 0 40rpx;
  193. margin-bottom: 80rpx;
  194. .clearfix {
  195. border-bottom: 1px solid #d9d9d9;
  196. margin-bottom: 40rpx;
  197. .w70 {
  198. width: 70%;
  199. float: left;
  200. }
  201. .w30 {
  202. width: 30%;
  203. float: right;
  204. text-align: right;
  205. padding: 22rpx 0;
  206. color: #2e997f;
  207. }
  208. .verifyImg {
  209. width: 162rpx;
  210. height: 56rpx;
  211. padding: 0;
  212. margin: 14rpx 0;
  213. }
  214. &:last-child {
  215. margin-bottom: 0;
  216. }
  217. .corb {
  218. color: #999;
  219. }
  220. }
  221. }
  222. .bagBtn {
  223. width: 620rpx;
  224. height: 100rpx;
  225. line-height: 100rpx;
  226. text-align: center;
  227. color: #fff;
  228. font-size: 36rpx;
  229. background: #cde9e3;
  230. border-radius: 50rpx;
  231. margin: 0 auto;
  232. &.corg {
  233. background: #58B8A1;
  234. }
  235. }
  236. .btnTxt {
  237. color: #2e997f;
  238. font-size: 32rpx;
  239. margin-top: 30rpx;
  240. }
  241. }
  242. </style>