index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. <template>
  2. <view class="login-page">
  3. <view class="brand-area">
  4. <image class="logo" src="/static/logo.png" mode="aspectFit" />
  5. <text class="brand-title">小鹅通</text>
  6. <view class="slogan-area">
  7. <text class="slogan">让知识创造价值</text>
  8. <view class="slogan-underline"></view>
  9. </view>
  10. </view>
  11. <view class="phone-area">
  12. <text class="phone">199****4261</text>
  13. <text class="carrier">号码认证由中国电信提供</text>
  14. </view>
  15. <button class="main-btn login-btn" :disabled="!agreed" @tap="handleLogin">一键登录</button>
  16. <button class="main-btn wechat-btn" :disabled="!agreed" @tap="socialLogin('wechat')">
  17. <image class="wechat-icon" src="/static/wechat.png" /> 微信登录
  18. </button>
  19. <view class="protocol-area">
  20. <checkbox :checked="agreed" @tap="agreed = !agreed" color="#2979ff" />
  21. <text class="protocol-text">
  22. 我已阅读并同意
  23. <text class="link" @tap="openProtocol('service')">《服务协议》</text>、
  24. <text class="link" @tap="openProtocol('privacy')">《隐私政策》</text>
  25. </text>
  26. </view>
  27. <view class="other-login">
  28. <text class="other-title">其他方式登录</text>
  29. <view class="other-icons">
  30. <view @tap="showLoginPopup = true">
  31. <image class="icon" src="/static/phone.png" />
  32. </view>
  33. <view >
  34. <image class="icon" src="/static/qq.png" />
  35. </view>
  36. </view>
  37. </view>
  38. <!-- 登录弹窗 -->
  39. <view v-if="showLoginPopup" class="popup-mask">
  40. <view class="popup-box">
  41. <text class="close-btn" @tap="showLoginPopup = false">×</text>
  42. <view class="popup-title">登录</view>
  43. <view class="popup-tabs">
  44. <text :class="{active: loginTab==='phone'}" @tap="loginTab='phone'">手机号登录</text>
  45. <text :class="{active: loginTab==='account'}" @tap="loginTab='account'">账号密码登录</text>
  46. </view>
  47. <view v-if="loginTab==='phone'">
  48. <view class="input-row">
  49. <input v-model="loginPhone" placeholder="请输入手机号" />
  50. </view>
  51. <view class="input-row code-row">
  52. <input v-model="loginCode" placeholder="请输入验证码" />
  53. <button class="code-btn" :disabled="loginCodeCountdown > 0" @tap="getLoginCode">
  54. {{ loginCodeCountdown > 0 ? loginCodeCountdown + 's' : '获取验证码' }}
  55. </button>
  56. </view>
  57. </view>
  58. <view v-else>
  59. <view class="input-row">
  60. <input v-model="loginAccount" placeholder="请输入账号" />
  61. </view>
  62. <view class="input-row">
  63. <input v-model="loginPassword" type="password" placeholder="请输入密码" />
  64. </view>
  65. </view>
  66. <button class="main-btn popup-login-btn" @tap="handlePopupLogin">登录</button>
  67. <view class="popup-footer">
  68. <text @tap="openRegister">去注册</text>
  69. </view>
  70. </view>
  71. </view>
  72. <!-- 注册弹窗 -->
  73. <view v-if="showRegisterPopup" class="popup-mask">
  74. <view class="popup-box">
  75. <text class="close-btn" @tap="showRegisterPopup = false">×</text>
  76. <view class="popup-title">注册</view>
  77. <view class="input-row">
  78. <input v-model="regPhone" placeholder="请输入手机号" />
  79. </view>
  80. <view class="input-row code-row">
  81. <input v-model="regCode" placeholder="请输入验证码" />
  82. <button class="code-btn" @tap="getRegCode">
  83. {{ regCodeCountdown > 0 ? regCodeCountdown + 's' : '获取验证码' }}
  84. </button>
  85. </view>
  86. <view class="input-row">
  87. <input v-model="regAccount" placeholder="请输入账号" />
  88. </view>
  89. <view class="input-row">
  90. <input v-model="regPassword" type="password" placeholder="请输入密码" />
  91. </view>
  92. <button class="main-btn popup-login-btn" @tap="handleRegister">注册</button>
  93. </view>
  94. </view>
  95. </view>
  96. </template>
  97. <script setup>
  98. import { ref, onUnmounted } from 'vue'
  99. const agreed = ref(false)
  100. const showLoginPopup = ref(false)
  101. const showRegisterPopup = ref(false)
  102. const loginTab = ref('phone')
  103. const loginPhone = ref('')
  104. const loginCode = ref('')
  105. const loginAccount = ref('')
  106. const loginPassword = ref('')
  107. const regPhone = ref('')
  108. const regCode = ref('')
  109. const regAccount = ref('')
  110. const regPassword = ref('')
  111. const loginCodeCountdown = ref(0)
  112. const regCodeCountdown = ref(0)
  113. let loginCodeTimer = null
  114. let regCodeTimer = null
  115. function handleLogin() {
  116. if (!agreed.value) {
  117. uni.showToast({ title: '请先同意协议', icon: 'none' })
  118. return
  119. }
  120. // 登录逻辑
  121. }
  122. function openProtocol(type) {
  123. const urls = {
  124. service: '/pages/protocol/service',
  125. privacy: '/pages/protocol/privacy'
  126. }
  127. uni.navigateTo({ url: urls[type] })
  128. }
  129. function socialLogin(type) {
  130. // 微信、QQ等登录逻辑
  131. }
  132. function openRegister() {
  133. showLoginPopup.value = false
  134. showRegisterPopup.value = true
  135. }
  136. function getLoginCode() {
  137. if (loginCodeCountdown.value > 0) return;
  138. if (!/^1[3-9]\d{9}$/.test(loginPhone.value)) {
  139. uni.showToast({ title: '请输入正确手机号', icon: 'none' });
  140. return;
  141. }
  142. // 先启动倒计时
  143. loginCodeCountdown.value = 60;
  144. loginCodeTimer = setInterval(() => {
  145. if (loginCodeCountdown.value > 0) {
  146. loginCodeCountdown.value--;
  147. } else {
  148. clearInterval(loginCodeTimer);
  149. loginCodeTimer = null;
  150. }
  151. }, 1000);
  152. uni.request({
  153. url: 'http://localhost:9500/user/code',
  154. method: 'POST',
  155. data: { phone: loginPhone.value },
  156. success(res) {
  157. console.log('验证码接口返回', res);
  158. if (res.data && (res.data.code === 0 || res.data.success)) {
  159. uni.showToast({ title: '验证码已发送', icon: 'none' });
  160. } else {
  161. uni.showToast({ title: res.data.msg || '发送失败', icon: 'none' });
  162. }
  163. },
  164. fail(err) {
  165. console.log('验证码接口失败', err);
  166. uni.showToast({ title: '网络错误', icon: 'none' });
  167. }
  168. });
  169. }
  170. function getRegCode() {
  171. if (regCodeCountdown.value > 0) return
  172. regCodeCountdown.value = 60
  173. uni.showToast({ title: '验证码已发送', icon: 'none' })
  174. regCodeTimer = setInterval(() => {
  175. if (regCodeCountdown.value > 0) {
  176. regCodeCountdown.value--
  177. } else {
  178. clearInterval(regCodeTimer)
  179. regCodeTimer = null
  180. }
  181. }, 1000)
  182. }
  183. function handlePopupLogin() {
  184. if (loginTab.value === 'phone') {
  185. if (!/^1[3-9]\d{9}$/.test(loginPhone.value)) {
  186. uni.showToast({ title: '请输入正确手机号', icon: 'none' });
  187. return;
  188. }
  189. if (!loginCode.value) {
  190. uni.showToast({ title: '请输入验证码', icon: 'none' });
  191. return;
  192. }
  193. uni.request({
  194. url: 'http://localhost:9500/user/login',
  195. method: 'POST',
  196. data: { phone: loginPhone.value, code: loginCode.value },
  197. success(res) {
  198. console.log('登录接口返回', res);
  199. if (res.data && (res.data.code === 0 || res.data.success)) {
  200. uni.showToast({ title: '登录成功', icon: 'success' });
  201. uni.setStorageSync('userPhone', loginPhone.value);
  202. // 跳转首页
  203. uni.switchTab({ url: '/pages/index/index' });
  204. } else {
  205. uni.showToast({ title: res.data.msg || '登录失败', icon: 'none' });
  206. }
  207. },
  208. fail(err) {
  209. console.log('登录接口失败', err);
  210. uni.showToast({ title: '网络错误', icon: 'none' });
  211. }
  212. });
  213. } else {
  214. if (loginAccount.value === '零零' && loginPassword.value === '666') {
  215. uni.setStorageSync('userPhone', loginAccount.value)
  216. uni.switchTab({ url: '/pages/index/index' })
  217. } else {
  218. uni.showToast({ title: '账号或密码错误', icon: 'none' })
  219. }
  220. }
  221. }
  222. function handleRegister() { /* 注册逻辑 */ }
  223. onUnmounted(() => {
  224. if (loginCodeTimer) clearInterval(loginCodeTimer)
  225. if (regCodeTimer) clearInterval(regCodeTimer)
  226. })
  227. </script>
  228. <style lang="scss" scoped>
  229. .login-page {
  230. min-height: 100vh;
  231. background: #fff;
  232. display: flex;
  233. flex-direction: column;
  234. align-items: center;
  235. justify-content: flex-start;
  236. padding: 0 40rpx;
  237. }
  238. .brand-area {
  239. margin-top: 100rpx;
  240. display: flex;
  241. flex-direction: column;
  242. align-items: center;
  243. .logo {
  244. width: 120rpx;
  245. height: 120rpx;
  246. margin-bottom: 20rpx;
  247. }
  248. .brand-title {
  249. font-size: 44rpx;
  250. font-weight: bold;
  251. color: #222;
  252. margin-bottom: 20rpx;
  253. }
  254. .slogan-area {
  255. display: flex;
  256. flex-direction: column;
  257. align-items: center;
  258. .slogan {
  259. font-size: 28rpx;
  260. color: #2979ff;
  261. margin-bottom: 8rpx;
  262. }
  263. .slogan-underline {
  264. width: 220rpx;
  265. height: 8rpx;
  266. background: #e3f0ff;
  267. border-radius: 4rpx;
  268. }
  269. }
  270. }
  271. .phone-area {
  272. margin: 500rpx 0 40rpx 0;
  273. display: flex;
  274. flex-direction: column;
  275. align-items: center;
  276. .phone {
  277. font-size: 36rpx;
  278. color: #222;
  279. font-weight: 500;
  280. margin-bottom: 10rpx;
  281. }
  282. .carrier {
  283. font-size: 24rpx;
  284. color: #aaa;
  285. }
  286. }
  287. .main-btn {
  288. width: 100%;
  289. height: 88rpx;
  290. border-radius: 44rpx;
  291. font-size: 32rpx;
  292. font-weight: 500;
  293. margin-bottom: 32rpx;
  294. }
  295. .login-btn {
  296. background: #1976ff;
  297. color: #fff;
  298. border: none;
  299. }
  300. .wechat-btn {
  301. background: #1aad19;
  302. color: #fff;
  303. border: none;
  304. display: flex;
  305. align-items: center;
  306. justify-content: center;
  307. .wechat-icon {
  308. width: 40rpx;
  309. height: 40rpx;
  310. margin-right: 16rpx;
  311. vertical-align: middle;
  312. }
  313. }
  314. .protocol-area {
  315. display: flex;
  316. align-items: center;
  317. margin: 30rpx 0 0 0;
  318. .protocol-text {
  319. font-size: 22rpx;
  320. color: #999;
  321. margin-left: 10rpx;
  322. .link {
  323. color: #1976ff;
  324. }
  325. }
  326. }
  327. .other-login {
  328. margin-top: 80rpx;
  329. display: flex;
  330. flex-direction: column;
  331. align-items: center;
  332. .other-title {
  333. font-size: 24rpx;
  334. color: #bbb;
  335. margin-bottom: 20rpx;
  336. }
  337. .other-icons {
  338. display: flex;
  339. gap: 60rpx;
  340. .icon {
  341. width: 60rpx;
  342. height: 60rpx;
  343. }
  344. }
  345. }
  346. .icon-circle {
  347. width: 80rpx;
  348. height: 80rpx;
  349. border: 1px solid #ccc;
  350. border-radius: 50%;
  351. display: flex;
  352. align-items: center;
  353. justify-content: center;
  354. margin: 0 20rpx;
  355. background: #fff;
  356. }
  357. .popup-mask {
  358. position: fixed;
  359. left: 0; top: 0; right: 0; bottom: 0;
  360. background: rgba(0,0,0,0.25);
  361. z-index: 999;
  362. display: flex;
  363. align-items: center;
  364. justify-content: center;
  365. }
  366. .popup-box {
  367. width: 90vw;
  368. max-width: 600rpx;
  369. background: #fff;
  370. border-radius: 24rpx;
  371. box-shadow: 0 8rpx 32rpx rgba(0,0,0,0.10);
  372. padding: 60rpx 40rpx 40rpx 40rpx;
  373. position: relative;
  374. display: flex;
  375. flex-direction: column;
  376. align-items: stretch;
  377. }
  378. .close-btn {
  379. position: absolute;
  380. right: 32rpx;
  381. top: 24rpx;
  382. font-size: 48rpx;
  383. color: #bbb;
  384. z-index: 2;
  385. font-weight: bold;
  386. }
  387. .popup-title {
  388. text-align: center;
  389. font-size: 36rpx;
  390. font-weight: bold;
  391. color: #222;
  392. margin-bottom: 32rpx;
  393. letter-spacing: 2rpx;
  394. }
  395. .popup-tabs {
  396. display: flex;
  397. justify-content: center;
  398. margin-bottom: 32rpx;
  399. text {
  400. font-size: 28rpx;
  401. margin: 0 36rpx;
  402. color: #888;
  403. padding-bottom: 8rpx;
  404. position: relative;
  405. &.active {
  406. color: #1976ff;
  407. font-weight: bold;
  408. }
  409. &.active::after {
  410. content: '';
  411. display: block;
  412. position: absolute;
  413. left: 0; right: 0; bottom: 0;
  414. height: 4rpx;
  415. background: #1976ff;
  416. border-radius: 2rpx;
  417. }
  418. }
  419. }
  420. .input-row {
  421. margin-bottom: 28rpx;
  422. display: flex;
  423. align-items: center;
  424. input {
  425. flex: 1;
  426. height: 80rpx;
  427. border-radius: 40rpx;
  428. background: #f7f8fa;
  429. border: 1px solid #eee;
  430. padding: 0 32rpx;
  431. font-size: 28rpx;
  432. color: #333;
  433. }
  434. }
  435. .code-row {
  436. input {
  437. flex: 1;
  438. margin-right: 16rpx;
  439. }
  440. .code-btn {
  441. width: 160rpx;
  442. height: 64rpx;
  443. border-radius: 32rpx;
  444. background: #1976ff;
  445. color: #fff;
  446. font-size: 24rpx;
  447. border: none;
  448. padding: 0;
  449. }
  450. }
  451. .popup-login-btn {
  452. margin-top: 12rpx;
  453. margin-bottom: 16rpx;
  454. width: 100%;
  455. height: 88rpx;
  456. border-radius: 44rpx;
  457. font-size: 32rpx;
  458. font-weight: 500;
  459. background: #1976ff;
  460. color: #fff;
  461. border: none;
  462. }
  463. .popup-footer {
  464. text-align: center;
  465. margin-top: 10rpx;
  466. color: #1976ff;
  467. font-size: 26rpx;
  468. font-weight: 500;
  469. letter-spacing: 1rpx;
  470. }
  471. </style>