verify-code.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. <template>
  2. <view class="login-bg">
  3. <view class="login-center">
  4. <view class="login-card">
  5. <!-- 顶部Tab切换 -->
  6. <view class="login-tabs">
  7. <view :class="['tab', loginType==='code' ? 'active' : '']" @click="loginType='code'">验证码登录</view>
  8. <view :class="['tab', loginType==='password' ? 'active' : '']" @click="loginType='password'">密码登录</view>
  9. </view>
  10. <!-- 验证码登录表单 -->
  11. <view v-if="loginType==='code'" class="form-area">
  12. <input class="input" type="number" v-model="phone" maxlength="11" placeholder="请输入手机号" />
  13. <view class="input-group">
  14. <input class="input" type="number" v-model="verifyCode" maxlength="6" placeholder="请输入验证码" />
  15. <text class="send-code" :class="{disabled: counting}" @click="sendVerifyCode">
  16. {{ counting ? `${countdown}s后重发` : '获取验证码' }}
  17. </text>
  18. </view>
  19. </view>
  20. <!-- 密码登录表单 -->
  21. <view v-else class="form-area">
  22. <input class="input" type="text" v-model="account" maxlength="32" placeholder="请输入账号/手机号" />
  23. <view class="input-group">
  24. <input class="input" :type="showPassword ? 'text' : 'password'" v-model="password" maxlength="20" placeholder="请输入密码" />
  25. <text class="iconfont" :class="showPassword ? 'icon-eye-open' : 'icon-eye-close'" @click="showPassword=!showPassword"></text>
  26. </view>
  27. </view>
  28. <!-- 返回微信登录链接 -->
  29. <view class="back-to-wechat" @click="goToWechatLogin">
  30. <text class="back-link">返回微信登录</text>
  31. </view>
  32. <!-- 登录按钮 -->
  33. <button class="login-btn" :disabled="!isFormValid" @click="handleLogin">
  34. 登录/注册
  35. </button>
  36. <!-- 协议勾选 -->
  37. <view class="agreement">
  38. <checkbox-group @change="handleAgreementChange">
  39. <label class="agreement-label">
  40. <checkbox :checked="isAgreed" color="#07C160" />
  41. <text class="agreement-text">
  42. 我已阅读并同意
  43. <text class="link" @click.stop="showServiceAgreement = true">《用户协议》</text>
  44. <text class="link" @click.stop="showPrivacyPolicy = true">《隐私政策》</text>
  45. </text>
  46. </label>
  47. </checkbox-group>
  48. </view>
  49. </view>
  50. <!-- 协议弹窗 -->
  51. <!-- <uni-popup ref="popup" :show="showServiceAgreement || showPrivacyPolicy" type="center" @close="closePopup">
  52. <view class="popup-content">
  53. <view class="popup-title">{{ showServiceAgreement ? '服务协议' : '隐私政策' }}</view>
  54. <scroll-view scroll-y class="popup-scroll">
  55. <text v-if="showServiceAgreement">这里是服务协议内容...</text>
  56. <text v-else>这里是隐私政策内容...</text>
  57. </scroll-view>
  58. <button class="popup-btn" @click="closePopup">我已知晓</button>
  59. </view>
  60. </uni-popup> -->
  61. </view>
  62. </view>
  63. </template>
  64. <script>
  65. export default {
  66. data() {
  67. return {
  68. loginType: 'code',
  69. phone: '',
  70. verifyCode: '',
  71. account: '',
  72. password: '',
  73. showPassword: false,
  74. counting: false,
  75. countdown: 60,
  76. isAgreed: false,
  77. showServiceAgreement: false,
  78. showPrivacyPolicy: false
  79. }
  80. },
  81. computed: {
  82. isFormValid() {
  83. if (!this.isAgreed) return false
  84. if (this.loginType === 'code') {
  85. return this.phone.length === 11 && this.verifyCode.length === 6
  86. } else {
  87. return this.account.length > 0 && this.password.length >= 6
  88. }
  89. }
  90. },
  91. methods: {
  92. handleAgreementChange(e) {
  93. this.isAgreed = e.detail.value.length > 0
  94. },
  95. async sendVerifyCode() {
  96. if (this.counting) return
  97. if (this.phone.length !== 11) {
  98. uni.showToast({ title: '请输入正确的手机号', icon: 'none' })
  99. return
  100. }
  101. try {
  102. // 调用获取验证码接口
  103. const res = await uni.request({
  104. url: 'http://localhost:9527/api/getCode',
  105. method: 'POST',
  106. data: {
  107. phone: this.phone
  108. },
  109. header: {
  110. 'content-type': 'application/json'
  111. },
  112. });
  113. console.log(res.statusCode);
  114. if (res.statusCode === 200 ) {
  115. console.log('验证码接口返回:', res);
  116. uni.showToast({
  117. title: '验证码已发送',
  118. icon: 'success'
  119. });
  120. // 开始倒计时
  121. this.counting = true
  122. this.countdown = 60
  123. this.startCountdown()
  124. } else {
  125. throw new Error(res.data.msg || '获取验证码失败')
  126. }
  127. } catch (error) {
  128. console.error('获取验证码失败:', error);
  129. uni.showToast({
  130. title: error.message || '获取验证码失败,请重试',
  131. icon: 'none'
  132. });
  133. }
  134. },
  135. startCountdown() {
  136. const timer = setInterval(() => {
  137. if (this.countdown > 0) {
  138. this.countdown--
  139. } else {
  140. this.counting = false
  141. clearInterval(timer)
  142. }
  143. }, 1000)
  144. },
  145. async handleLogin() {
  146. if (!this.isFormValid) return
  147. if (!this.isAgreed) {
  148. uni.showToast({ title: '请先同意服务协议和隐私政策', icon: 'none' })
  149. return
  150. }
  151. // TODO: 调用后端登录接口
  152. uni.switchTab({
  153. url: '/pages/discover/index' // 替换为实际页面路径
  154. });
  155. },
  156. closePopup() {
  157. this.showServiceAgreement = false
  158. this.showPrivacyPolicy = false
  159. },
  160. goToWechatLogin() {
  161. uni.switchTab({
  162. url: '/pages/login/index'
  163. })
  164. }
  165. }
  166. }
  167. </script>
  168. <style lang="scss">
  169. .login-bg {
  170. min-height: 100vh;
  171. width: 100vw;
  172. background: linear-gradient(135deg, #f5f7fa 0%, #e4e8f0 100%);
  173. display: flex;
  174. align-items: center;
  175. justify-content: center;
  176. }
  177. .login-center {
  178. width: 100vw;
  179. min-height: 100vh;
  180. display: flex;
  181. align-items: center;
  182. justify-content: center;
  183. padding: 40rpx;
  184. }
  185. .login-card {
  186. width: 100%;
  187. max-width: 750rpx;
  188. background: rgba(255, 255, 255, 0.98);
  189. border-radius: 40rpx;
  190. box-shadow: 0 20rpx 60rpx rgba(0, 0, 0, 0.08);
  191. padding: 80rpx 60rpx;
  192. display: flex;
  193. flex-direction: column;
  194. align-items: center;
  195. backdrop-filter: blur(10px);
  196. transform: translateY(0);
  197. transition: transform 0.3s ease;
  198. margin: 0 auto;
  199. &:hover {
  200. transform: translateY(-5rpx);
  201. }
  202. }
  203. .login-tabs {
  204. width: 100%;
  205. display: flex;
  206. justify-content: center;
  207. margin-bottom: 60rpx;
  208. position: relative;
  209. &::after {
  210. content: '';
  211. position: absolute;
  212. bottom: 0;
  213. left: 50%;
  214. transform: translateX(-50%);
  215. width: 60%;
  216. height: 1px;
  217. background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.1), transparent);
  218. }
  219. .tab {
  220. flex: 1;
  221. text-align: center;
  222. font-size: 34rpx;
  223. color: #666;
  224. padding-bottom: 20rpx;
  225. border-bottom: 4rpx solid transparent;
  226. font-weight: 500;
  227. transition: all 0.3s ease;
  228. position: relative;
  229. &.active {
  230. color: #2c3e50;
  231. font-weight: 700;
  232. &::after {
  233. content: '';
  234. position: absolute;
  235. bottom: -4rpx;
  236. left: 50%;
  237. transform: translateX(-50%);
  238. width: 40%;
  239. height: 4rpx;
  240. background: linear-gradient(90deg, #2c3e50, #3498db);
  241. border-radius: 2rpx;
  242. }
  243. }
  244. }
  245. }
  246. .form-area {
  247. width: 100%;
  248. margin-bottom: 50rpx;
  249. .input {
  250. width: 100%;
  251. height: 100rpx;
  252. border: none;
  253. border-bottom: 2rpx solid rgba(0, 0, 0, 0.1);
  254. font-size: 34rpx;
  255. margin-bottom: 40rpx;
  256. background: transparent;
  257. outline: none;
  258. padding: 0 16rpx;
  259. transition: all 0.3s ease;
  260. &:focus {
  261. border-bottom-color: #07C160;
  262. }
  263. }
  264. .input-group {
  265. display: flex;
  266. align-items: center;
  267. position: relative;
  268. .input {
  269. flex: 1;
  270. margin-bottom: 0;
  271. }
  272. .send-code {
  273. font-size: 30rpx;
  274. color: #ffffff;
  275. margin-left: 24rpx;
  276. padding: 16rpx 32rpx;
  277. background: linear-gradient(45deg, #07C160, #0a9d4e);
  278. border-radius: 36rpx;
  279. transition: all 0.3s ease;
  280. box-shadow: 0 4rpx 12rpx rgba(7, 193, 96, 0.2);
  281. &.disabled {
  282. color: #ffffff;
  283. background: #e0e0e0;
  284. box-shadow: none;
  285. }
  286. &:active:not(.disabled) {
  287. transform: scale(0.95);
  288. box-shadow: 0 2rpx 6rpx rgba(7, 193, 96, 0.15);
  289. }
  290. }
  291. .iconfont {
  292. font-size: 44rpx;
  293. color: #666;
  294. margin-left: 20rpx;
  295. transition: all 0.3s ease;
  296. &:active {
  297. transform: scale(0.9);
  298. }
  299. }
  300. }
  301. }
  302. .login-btn {
  303. width: 100%;
  304. height: 100rpx;
  305. background: linear-gradient(45deg, #07C160, #0a9d4e);
  306. color: #fff;
  307. border-radius: 50rpx;
  308. font-size: 36rpx;
  309. font-weight: 600;
  310. border: none;
  311. margin: 30rpx 0 50rpx;
  312. box-shadow: 0 8rpx 20rpx rgba(7, 193, 96, 0.2);
  313. transition: all 0.3s ease;
  314. &:active {
  315. transform: scale(0.98);
  316. box-shadow: 0 4rpx 10rpx rgba(7, 193, 96, 0.15);
  317. }
  318. &:disabled {
  319. background: #e0e0e0;
  320. color: #aaa;
  321. box-shadow: none;
  322. }
  323. }
  324. .agreement {
  325. margin-top: 30rpx;
  326. text-align: center;
  327. .agreement-label {
  328. display: inline-flex;
  329. align-items: center;
  330. font-size: 26rpx;
  331. color: #666;
  332. }
  333. .agreement-text {
  334. margin-left: 10rpx;
  335. }
  336. .link {
  337. color: #07C160;
  338. text-decoration: none;
  339. font-weight: 500;
  340. position: relative;
  341. &::after {
  342. content: '';
  343. position: absolute;
  344. bottom: -2rpx;
  345. left: 0;
  346. width: 100%;
  347. height: 1px;
  348. background: #07C160;
  349. transform: scaleX(0);
  350. transition: transform 0.3s ease;
  351. }
  352. &:active::after {
  353. transform: scaleX(1);
  354. }
  355. }
  356. }
  357. .back-to-wechat {
  358. margin-top: 50rpx;
  359. text-align: center;
  360. .back-link {
  361. color: #3498db;
  362. font-size: 30rpx;
  363. font-weight: 500;
  364. text-decoration: none;
  365. position: relative;
  366. padding: 10rpx 0;
  367. &::after {
  368. content: '';
  369. position: absolute;
  370. bottom: 0;
  371. left: 0;
  372. width: 100%;
  373. height: 1px;
  374. background: #3498db;
  375. transform: scaleX(0);
  376. transition: transform 0.3s ease;
  377. }
  378. &:active::after {
  379. transform: scaleX(1);
  380. }
  381. }
  382. }
  383. // 协议弹窗样式
  384. .popup-content {
  385. width: 650rpx;
  386. background: #fff;
  387. border-radius: 40rpx;
  388. padding: 60rpx 50rpx 40rpx;
  389. display: flex;
  390. flex-direction: column;
  391. align-items: center;
  392. box-shadow: 0 20rpx 60rpx rgba(0, 0, 0, 0.1);
  393. }
  394. .popup-title {
  395. font-size: 40rpx;
  396. font-weight: bold;
  397. background: linear-gradient(45deg, #07C160, #0a9d4e);
  398. -webkit-background-clip: text;
  399. color: transparent;
  400. margin-bottom: 40rpx;
  401. }
  402. .popup-scroll {
  403. max-height: 400rpx;
  404. width: 100%;
  405. margin-bottom: 40rpx;
  406. font-size: 30rpx;
  407. color: #444;
  408. line-height: 1.6;
  409. }
  410. .popup-btn {
  411. width: 100%;
  412. height: 88rpx;
  413. background: linear-gradient(45deg, #07C160, #0a9d4e);
  414. color: #fff;
  415. border-radius: 44rpx;
  416. font-size: 32rpx;
  417. font-weight: 600;
  418. border: none;
  419. box-shadow: 0 8rpx 20rpx rgba(7, 193, 96, 0.2);
  420. transition: all 0.3s ease;
  421. &:active {
  422. transform: scale(0.98);
  423. box-shadow: 0 4rpx 10rpx rgba(7, 193, 96, 0.15);
  424. }
  425. }
  426. </style>