login.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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" :focus="Focus == 1" /></view>
  9. <view class="clearfix">
  10. <input v-model="formD2.captcha" placeholder="请输入验证码" confirm-type="go" type="number" maxlength="5" :focus="Focus == 2" 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">{{ 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 { 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. Focus: 1, //输入框焦点 1手机号 2验证码
  63. };
  64. },
  65. onLoad(option) {
  66. // this.changVerifyimage(); //获取图形验证码
  67. // this.getKey();
  68. },
  69. onLaunch() {},
  70. onShow() {},
  71. onHide() {},
  72. methods: {
  73. login() {
  74. if (!this.ISFill) {
  75. uni.showToast({
  76. title: "登录信息填写有误哦",
  77. duration: 2000,
  78. icon: "none",
  79. });
  80. return
  81. }
  82. post("login",this.formD2).then((res) => {
  83. if (res.code === 0) {
  84. uni.setStorageSync('token', res.data.token);
  85. this.getuserInfo();
  86. }
  87. });
  88. },
  89. getuserInfo() {
  90. post("user/userinfo").then((res) => {
  91. if (res.code === 0) {
  92. uni.setStorageSync('userinfo', res.data.data);
  93. let pages = getCurrentPages() // 获取栈实例
  94. let page = pages[pages.length - 1].route // 获取当前页面的数据,包含页面路由
  95. let is = 1;
  96. for (const i of pages) {
  97. is++;
  98. if(i.route != page) break;
  99. }
  100. uni.navigateBack({
  101. delta: is
  102. });
  103. }
  104. });
  105. },
  106. getVerifyCode() {
  107. if (!this.isPhone(this.formD2.mobile)) {
  108. appEv.errTips("手机号填写有误!");
  109. return
  110. }
  111. post("getSms", {
  112. mobile: this.formD2.mobile
  113. }).then((res) => {
  114. if (res.code === 0) {
  115. this.Focus = 2; //给验证码框焦点
  116. let number = 59;
  117. let as = setInterval(() => {
  118. this.msgNum = number + "s后重发"
  119. number--;
  120. if (number == 0) {
  121. this.msgNum = "重发验证码"
  122. clearTimeout(as);
  123. }
  124. }, 1000);
  125. }
  126. });
  127. },
  128. isPhone(s) {
  129. return /^1[0-9]{10}$/.test(s)
  130. },
  131. FillIn() {
  132. if (this.LoginType == 1) {
  133. let m = this.formD2.mobile
  134. let v = this.formD2.captcha
  135. if (m && v && v.length == 5 && this.isPhone(m)) this.ISFill = true
  136. else this.ISFill = false
  137. } else {
  138. let u = this.formD.username
  139. let p = this.formD.password
  140. let v = this.formD.verifyCode
  141. if (u && p && v && v.length == 4) this.ISFill = true
  142. else this.ISFill = false
  143. }
  144. },
  145. },
  146. computed: {},
  147. watch: {
  148. formD: {
  149. deep: true,
  150. handler(val) {
  151. this.FillIn()
  152. }
  153. },
  154. formD2: {
  155. deep: true,
  156. handler(val) {
  157. this.FillIn()
  158. }
  159. },
  160. },
  161. };
  162. </script>
  163. <style scoped lang='scss'>
  164. .login {
  165. text-align: center;
  166. .HLogo {
  167. padding-top: 80rpx;
  168. margin-bottom: 60rpx;
  169. img {
  170. width: 120rpx;
  171. height: 120rpx;
  172. border-radius: 50%;
  173. background: #ffffff;
  174. border: 1px solid #e6e6e6;
  175. }
  176. P {
  177. // font-weight: 500;
  178. font-size: 40rpx;
  179. margin-top: 16rpx;
  180. font-family: "webfont" !important;
  181. }
  182. }
  183. input {
  184. width: 100%;
  185. padding: 20rpx 0;
  186. font-size: 32rpx;
  187. text-align: left;
  188. }
  189. .phoneL,
  190. .numberL {
  191. padding: 0 40rpx;
  192. margin-bottom: 80rpx;
  193. .clearfix {
  194. border-bottom: 1px solid #d9d9d9;
  195. margin-bottom: 40rpx;
  196. .w70 {
  197. width: 70%;
  198. float: left;
  199. }
  200. .w30 {
  201. width: 30%;
  202. float: right;
  203. text-align: right;
  204. padding: 22rpx 0;
  205. color: #2e997f;
  206. }
  207. .verifyImg {
  208. width: 162rpx;
  209. height: 56rpx;
  210. padding: 0;
  211. margin: 14rpx 0;
  212. }
  213. &:last-child {
  214. margin-bottom: 0;
  215. }
  216. .corb {
  217. color: #999;
  218. }
  219. }
  220. }
  221. .bagBtn {
  222. width: 620rpx;
  223. height: 100rpx;
  224. line-height: 100rpx;
  225. text-align: center;
  226. color: #fff;
  227. font-size: 36rpx;
  228. background: #cde9e3;
  229. border-radius: 50rpx;
  230. margin: 0 auto;
  231. &.corg {
  232. background: #58B8A1;
  233. }
  234. }
  235. .btnTxt {
  236. color: #2e997f;
  237. font-size: 32rpx;
  238. margin-top: 30rpx;
  239. }
  240. }
  241. </style>