login.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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="#d0d0d0" 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="#d0d0d0" 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="#d0d0d0" 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="#d0d0d0" 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. },
  100. // 账号登录
  101. usenameLoginHandle(){
  102. if(!this.usernameForm.zhanghao){
  103. msg("请输入账号")
  104. return;
  105. }
  106. if(!this.usernameForm.mima){
  107. msg("请输入密码")
  108. return;
  109. }
  110. // usernameLogin(this.usernameForm).then(res=>{
  111. // console.log(res,45699)
  112. // })
  113. console.log(this.usernameForm)
  114. },
  115. toPage(url){
  116. console.log(url)
  117. uni.navigateTo({
  118. url:url
  119. })
  120. },
  121. // 点击获取验证码
  122. requestVerificationCode() {
  123. if (!this.isCounting) {
  124. // console.log(2)
  125. // 发起请求验证码的操作
  126. console.log("请求验证码...");
  127. // 开始倒计时
  128. this.isCounting = true;
  129. this.startCountdown();
  130. }
  131. },
  132. // 开始倒计时
  133. startCountdown() {
  134. // 每秒减少倒计时
  135. this.timer = setInterval(() => {
  136. this.countdown--;
  137. if (this.countdown <= 0) {
  138. clearInterval(this.timer);
  139. this.countdown = 60; // 重置倒计时
  140. this.isCounting = false; // 停止倒计时
  141. }
  142. }, 1000);
  143. },
  144. },
  145. // 在组件销毁时清理定时器
  146. beforeDestroy() {
  147. // 在组件销毁时清理定时器
  148. if (this.timer) {
  149. clearInterval(this.timer);
  150. }
  151. },
  152. }
  153. </script>
  154. <style lang="scss">
  155. .form-item .u-input--border{
  156. border-radius: 16rpx !important;
  157. }
  158. </style>
  159. <style lang="scss" scoped>
  160. .app-login-page {
  161. background-color: #f7f7f7;
  162. width: 100vw;
  163. height: 100vh;
  164. display: flex;
  165. justify-content: center;
  166. align-items: center;
  167. }
  168. .app-login {
  169. width: 90%;
  170. }
  171. .app-icon {
  172. text-align: center;
  173. }
  174. .app-title {
  175. text-align: center;
  176. font-size: 44rpx;
  177. letter-spacing: 2px;
  178. font-weight: 700;
  179. }
  180. .mb-30 {
  181. margin-bottom: 30rpx;
  182. }
  183. .text-red {
  184. color: #df0505;
  185. }
  186. .login-form {
  187. background-color: #ffffff;
  188. width: 100%;
  189. padding: 50rpx 40rpx;
  190. border-radius: 15rpx;
  191. box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2);
  192. border: 1px solid #036df6;
  193. }
  194. .loginType {
  195. color: #000000;
  196. margin-bottom: 15rpx;
  197. .loginType-text {
  198. font-size: 30rpx;
  199. margin-right: 30rpx;
  200. }
  201. .loginType-text-active {
  202. font-size: 40rpx;
  203. margin-right: 30rpx;
  204. }
  205. }
  206. .form-item {
  207. display: flex;
  208. align-items: center;
  209. margin-bottom: 60rpx;
  210. .form-item-input {
  211. width: 100%;
  212. background-color: #f7f7f7 !important;
  213. }
  214. .form-item-text {
  215. width: 240rpx;
  216. flex: 0 0 auto;
  217. text-align: center;
  218. color: #000000;
  219. // margin: 0 20px;
  220. }
  221. }
  222. .form-button {
  223. background: linear-gradient(90deg, #006af5, #21b0fc);
  224. border-radius: 20rpx;
  225. line-height: 80rpx;
  226. text-align: center;
  227. color: #fff;
  228. margin-bottom: 50rpx;
  229. }
  230. .risgiter-forget {
  231. font-size: 30rpx;
  232. display: flex;
  233. justify-content: space-between;
  234. }
  235. </style>