login.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <view class="app-login-page">
  3. <view class="app-login">
  4. <view class="app-icon mb-30">
  5. <image src="/static/images/login-icon.png" mode="aspectFit" style="height: 40px;"></image>
  6. </view>
  7. <view class="app-title mb-30">
  8. 欢迎使用会员中心系统小程序
  9. </view>
  10. <view class="mb-30 login-form">
  11. <view class="loginType">
  12. <text :class="[loginType=='phone'? 'loginType-text-active': 'loginType-text']"
  13. @click="loginType = 'phone'">手机登录</text>
  14. <text :class="[loginType=='username'? 'loginType-text-active': 'loginType-text']"
  15. @click="loginType = 'username'">账号登录</text>
  16. </view>
  17. <view class="phone-form" v-if="loginType=='phone'">、
  18. <view class="form-item">
  19. <u-input height="80" placeholder="请输入手机号" border-color="#b1b1b1" v-model="phoneForm.shoujihao"
  20. :border="true" class="form-item-input" type="number"/>
  21. </view>
  22. <view class="form-item">
  23. <u-input height="80" placeholder="请输入验证码" border-color="#b1b1b1" v-model="phoneForm.yanzhengma"
  24. :border="true" class="form-item-input" />
  25. <text class="form-item-text" v-if="!isCounting" @click="requestVerificationCode">
  26. 发送验证码</text>
  27. <text class="form-item-text" v-else>
  28. {{ `发送验证码(${countdown})` }}</text>
  29. </view>
  30. <view class="form-button" @click="phoneLoginHandle">
  31. 立即登录
  32. </view>
  33. </view>
  34. <view class="phone-form" v-if="loginType=='username'">、
  35. <view class="form-item">
  36. <u-input height="80" placeholder="请输入账号" border-color="#b1b1b1" v-model="usernameForm.zhanghao"
  37. :border="true" class="form-item-input" />
  38. </view>
  39. <view class="form-item">
  40. <u-input height="80" placeholder="请输入密码" border-color="#b1b1b1" v-model="usernameForm.mima"
  41. :border="true" class="form-item-input" />
  42. </view>
  43. <view class="form-button" @click="usenameLoginHandle">
  44. 立即登录
  45. </view>
  46. </view>
  47. <view class="risgiter-forget">
  48. <view @click="toPage('/pages/forget/forget')">忘记密码?</view>
  49. <view @click="toPage('/pages/register/register')">无账号?<text class="text-red">立即注册</text></view>
  50. </view>
  51. </view>
  52. <view class="app-user-book mb-30">
  53. <u-checkbox-group style="display: flex;justify-content: center;">
  54. <u-checkbox v-model="userBook" name="yes" shape="circle">我已阅读&#x300A;用户手册&#x300B;及隐私政策</u-checkbox>
  55. </u-checkbox-group>
  56. </view>
  57. <u-divider bg-color="transparent" margin-bottom="30" color="#010101" border-color="#010101"
  58. half-width="200">使用第三方账号登录</u-divider>
  59. <view class="app-icon mb-30">
  60. <image src="/static/images/weixin.png" mode="aspectFit" style="height: 40px;"></image>
  61. </view>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import { usernameLogin } from "@/api/user.js"
  67. import { msg } from "@/utils/common.js"
  68. export default {
  69. data() {
  70. return {
  71. countdown: 60, // 倒计时初始值
  72. isCounting: false, // 是否正在倒计时
  73. timer: null, // 定义定时器
  74. loginType: "phone",
  75. phoneForm: {
  76. shoujihao: "",
  77. yanzhengma: ""
  78. },
  79. usernameForm: {
  80. zhanghao: 'zhangsan',
  81. mima: "12345678"
  82. },
  83. userBook: false,
  84. }
  85. },
  86. methods: {
  87. // 手机登录
  88. phoneLoginHandle() {
  89. const regex = /^1[3-9]\d{9}$/;
  90. if (!regex.test(this.phoneForm.shoujihao)) {
  91. msg("请输入正确的手机号")
  92. return;
  93. }
  94. if (!this.phoneForm.yanzhengma) {
  95. msg("请输入验证码")
  96. return;
  97. }
  98. console.log(this.phoneForm)
  99. // this.showToast("密码错误")
  100. },
  101. // 账号登录
  102. usenameLoginHandle(){
  103. if(!this.usernameForm.zhanghao){
  104. msg("请输入账号")
  105. return;
  106. }
  107. if(!this.usernameForm.mima){
  108. msg("请输入密码")
  109. return;
  110. }
  111. // usernameLogin(this.usernameForm).then(res=>{
  112. // console.log(res,45699)
  113. // })
  114. console.log(this.usernameForm)
  115. },
  116. toPage(url){
  117. console.log(url)
  118. uni.navigateTo({
  119. url:url
  120. })
  121. },
  122. // 点击获取验证码
  123. requestVerificationCode() {
  124. if (!this.isCounting) {
  125. console.log(2)
  126. // 发起请求验证码的操作
  127. console.log("请求验证码...");
  128. // 开始倒计时
  129. this.isCounting = true;
  130. this.startCountdown();
  131. }
  132. },
  133. // 开始倒计时
  134. startCountdown() {
  135. // 每秒减少倒计时
  136. this.timer = setInterval(() => {
  137. this.countdown--;
  138. if (this.countdown <= 0) {
  139. clearInterval(this.timer);
  140. this.countdown = 60; // 重置倒计时
  141. this.isCounting = false; // 停止倒计时
  142. }
  143. }, 1000);
  144. },
  145. },
  146. // 在组件销毁时清理定时器
  147. beforeDestroy() {
  148. // 在组件销毁时清理定时器
  149. if (this.timer) {
  150. clearInterval(this.timer);
  151. }
  152. },
  153. }
  154. </script>
  155. <style lang="scss" scoped>
  156. .app-login-page {
  157. background-color: #f7f7f7;
  158. width: 100vw;
  159. height: 100vh;
  160. display: flex;
  161. justify-content: center;
  162. align-items: center;
  163. }
  164. .app-login {
  165. width: 90%;
  166. }
  167. .app-icon {
  168. text-align: center;
  169. }
  170. .app-title {
  171. text-align: center;
  172. font-size: 44rpx;
  173. letter-spacing: 2px;
  174. font-weight: 700;
  175. }
  176. .mb-30 {
  177. margin-bottom: 30rpx;
  178. }
  179. .text-red {
  180. color: #df0505;
  181. }
  182. .login-form {
  183. background-color: #ffffff;
  184. width: 100%;
  185. padding: 50rpx 40rpx;
  186. border-radius: 15rpx;
  187. box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2);
  188. border: 1px solid #036df6;
  189. }
  190. .loginType {
  191. color: #000000;
  192. margin-bottom: 15rpx;
  193. .loginType-text {
  194. font-size: 30rpx;
  195. margin-right: 30rpx;
  196. }
  197. .loginType-text-active {
  198. font-size: 40rpx;
  199. margin-right: 30rpx;
  200. }
  201. }
  202. .form-item {
  203. display: flex;
  204. align-items: center;
  205. margin-bottom: 60rpx;
  206. .form-item-input {
  207. width: 100%;
  208. background-color: #f7f7f7 !important;
  209. }
  210. .form-item-text {
  211. width: 240rpx;
  212. flex: 0 0 auto;
  213. text-align: center;
  214. color: #000000;
  215. // margin: 0 20px;
  216. }
  217. }
  218. .form-button {
  219. background: linear-gradient(90deg, #006af5, #21b0fc);
  220. border-radius: 20rpx;
  221. line-height: 80rpx;
  222. text-align: center;
  223. color: #fff;
  224. margin-bottom: 50rpx;
  225. }
  226. .risgiter-forget {
  227. font-size: 30rpx;
  228. display: flex;
  229. justify-content: space-between;
  230. }
  231. </style>