login.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. <template>
  2. <view class="login-container">
  3. <!-- 顶部导航栏 -->
  4. <view class="nav-bar">
  5. <text class="nav-title">登录</text>
  6. </view>
  7. <!-- Logo 区域 -->
  8. <view class="logo-section">
  9. <image class="logo-icon" src="/static/image/public/logo.png" mode="aspectFill"></image>
  10. <text class="app-name">布尔销销乐</text>
  11. </view>
  12. <!-- 表单区域 -->
  13. <view class="form-section">
  14. <!-- 手机号输入 -->
  15. <view class="input-item">
  16. <uni-easyinput v-model="phoneNumber" placeholder="请输入手机号" type="number" maxlength="11"
  17. :clearable="false" class="phone-input" />
  18. </view>
  19. <!-- 验证码输入 -->
  20. <view class="input-item verify-code-row">
  21. <uni-easyinput v-model="verifyCode" placeholder="验证码" type="number" maxlength="6" :clearable="false"
  22. class="code-input" />
  23. <text class="get-code-btn" :class="{ disabled: countdown > 0 }" @click="getVerifyCode">
  24. {{ countdown > 0 ? `${countdown}s` : '获取验证码' }}
  25. </text>
  26. </view>
  27. <!-- 登录按钮 -->
  28. <view class="login-btn-wrapper">
  29. <button class="login-btn" @click="handleLogin" :loading="isLoading">登录</button>
  30. </view>
  31. <!-- 协议说明 -->
  32. <view class="agreement-text">
  33. <text class="gray-text">登录即代表您已同意</text>
  34. <text class="link-text" @click="showUserAgreement">《用户协议》</text>
  35. <text class="gray-text">与</text>
  36. <text class="link-text" @click="showPrivacyPolicy">《隐私政策》</text>
  37. </view>
  38. </view>
  39. <!-- 其他登录方式 -->
  40. <view class="other-method-section">
  41. <view class="divider">
  42. <view class="divider-line"></view>
  43. <text class="divider-text">其他方式</text>
  44. <view class="divider-line"></view>
  45. </view>
  46. <!-- 微信一键登录 -->
  47. <view class="wechat-login-wrapper">
  48. <button class="wechat-login-btn" @click="wechatLogin">
  49. <text class="wechat-icon"></text>
  50. <text class="wechat-text">微信一键登录</text>
  51. </button>
  52. </view>
  53. </view>
  54. <!-- 用户协议弹窗 -->
  55. <view class="agreement-popup" v-if="showUserAgreementPopup" @click="closeUserAgreement">
  56. <view class="popup-mask"></view>
  57. <view class="popup-content" @click.stop>
  58. <view class="popup-header">
  59. <text class="popup-title">用户协议</text>
  60. <text class="popup-close" @click="closeUserAgreement">✕</text>
  61. </view>
  62. <scroll-view scroll-y class="popup-body">
  63. <view class="agreement-content">
  64. <text class="agreement-title">用户协议</text>
  65. <text class="update-time">最后更新时间:2026 年 4 月 24 日</text>
  66. <view class="section">
  67. <text class="section-title">一、协议的接受与修改</text>
  68. <text class="section-content">
  69. 1.1 欢迎您使用布尔销销乐服务。请您仔细阅读本用户协议,以确保您了解我们的产品或服务,以及本协议规定的双方的权利和义务。\n
  70. 1.2 当您使用本服务时,即表示您已阅读、理解并同意接受本协议的所有条款。如果您不同意本协议的任何条款,请立即停止使用本服务。\n
  71. 1.3 我们有权根据需要不时修改本协议条款,修改后的协议一旦公布即有效代替原来的协议。您可随时查阅最新协议。
  72. </text>
  73. </view>
  74. <view class="section">
  75. <text class="section-title">二、服务内容</text>
  76. <text class="section-content">
  77. 2.1 布尔销销乐是一款面向企业的客户关系管理工具,提供客户管理、销售跟进、数据分析等功能。\n
  78. 2.2 我们有权对服务内容进行变更、中断或终止,变更、中断或终止服务前将尽可能提前通知用户。
  79. </text>
  80. </view>
  81. <view class="section">
  82. <text class="section-title">三、用户账号</text>
  83. <text class="section-content">
  84. 3.1 您需要通过手机号验证码登录或微信授权登录方式使用本服务。\n
  85. 3.2 您应保证提供的信息真实、准确、完整。\n
  86. 3.3 您应妥善保管您的账号信息,因您保管不善导致账号被盗、密码失密或遭受其他损失的,您应自行承担相应责任。
  87. </text>
  88. </view>
  89. <view class="section">
  90. <text class="section-title">四、用户行为规范</text>
  91. <text class="section-content">
  92. 4.1 您在使用本服务时,应遵守国家法律法规,不得利用本服务从事任何违法违规活动。\n
  93. 4.2 您不得利用本服务制作、复制、发布、传播含有下列内容的信息:\n
  94. (1) 反对宪法所确定的基本原则的;\n
  95. (2) 危害国家安全、泄露国家秘密的;\n
  96. (3) 损害国家荣誉和利益的;\n
  97. (4) 煽动民族仇恨、民族歧视的;\n
  98. (5) 破坏国家宗教政策,宣扬邪教和封建迷信的;\n
  99. (6) 散布谣言、淫秽色情、赌博、暴力、凶杀、恐怖或者教唆犯罪的。
  100. </text>
  101. </view>
  102. <view class="section">
  103. <text class="section-title">五、知识产权</text>
  104. <text class="section-content">
  105. 5.1 本服务包含的所有内容(包括但不限于文字、图片、音频、视频、软件、程序、代码、界面设计等)的知识产权均归我们所有。\n
  106. 5.2 未经我们书面许可,您不得以任何形式复制、传播、展示、修改本服务的内容。
  107. </text>
  108. </view>
  109. <view class="section">
  110. <text class="section-title">六、免责声明</text>
  111. <text class="section-content">
  112. 6.1 因不可抗力(如自然灾害、政府行为、社会异常事件等)导致服务中断或数据丢失,我们不承担责任。\n
  113. 6.2 因网络状况、通讯线路、黑客攻击、计算机病毒、政府管制等任何非我们原因导致的服务中断或数据丢失,我们不承担责任。
  114. </text>
  115. </view>
  116. <view class="section">
  117. <text class="section-title">七、协议终止</text>
  118. <text class="section-content">
  119. 7.1 您有权随时停止使用本服务并注销账号。\n
  120. 7.2 如您违反本协议,我们有权终止向您提供服务,并保留追究法律责任的权利。
  121. </text>
  122. </view>
  123. <view class="section">
  124. <text class="section-title">八、法律适用与争议解决</text>
  125. <text class="section-content">
  126. 8.1 本协议的成立、生效、履行、解释及争议解决均适用中华人民共和国法律。\n
  127. 8.2 如双方就本协议内容或其执行发生任何争议,应友好协商解决;协商不成的,任何一方均可向我们所在地有管辖权的人民法院提起诉讼。
  128. </text>
  129. </view>
  130. <view class="section">
  131. <text class="section-title">九、联系我们</text>
  132. <text class="section-content">
  133. 如您对本协议有任何疑问,请通过以下方式联系我们:\n
  134. 客服电话:400-XXX-XXXX\n
  135. 客服邮箱:support@example.com
  136. </text>
  137. </view>
  138. </view>
  139. </scroll-view>
  140. <view class="popup-footer">
  141. <button class="agree-btn" @click="closeUserAgreement">我已知晓</button>
  142. </view>
  143. </view>
  144. </view>
  145. <!-- 隐私政策弹窗 -->
  146. <view class="agreement-popup" v-if="showPrivacyPolicyPopup" @click="closePrivacyPolicy">
  147. <view class="popup-mask"></view>
  148. <view class="popup-content" @click.stop>
  149. <view class="popup-header">
  150. <text class="popup-title">隐私政策</text>
  151. <text class="popup-close" @click="closePrivacyPolicy">✕</text>
  152. </view>
  153. <scroll-view scroll-y class="popup-body">
  154. <view class="agreement-content">
  155. <text class="agreement-title">隐私政策</text>
  156. <text class="update-time">最后更新时间:2026 年 4 月 24 日</text>
  157. <view class="section">
  158. <text class="section-title">一、我们如何收集和使用您的个人信息</text>
  159. <text class="section-content">
  160. 1.1 为了向您提供服务,我们可能会收集以下信息:\n
  161. (1) 手机号码:用于账号注册和登录验证;\n
  162. (2) 微信昵称、头像:用于完善您的个人资料(仅在微信授权登录时收集);\n
  163. (3) 设备信息:用于保障服务安全和优化用户体验。\n
  164. 1.2 我们收集的信息仅用于提供服务、改进产品质量和保障账号安全,不会用于其他用途。
  165. </text>
  166. </view>
  167. <view class="section">
  168. <text class="section-title">二、我们如何共享、转让、公开披露您的个人信息</text>
  169. <text class="section-content">
  170. 2.1 我们不会与任何公司、组织和个人共享您的个人信息,但以下情况除外:\n
  171. (1) 事先获得您的明确同意;\n
  172. (2) 根据法律法规或政府主管部门的强制性要求。\n
  173. 2.2 我们不会转让您的个人信息给任何第三方。\n
  174. 2.3 我们不会公开披露您的个人信息,除非获得您的明确同意或基于法律规定。
  175. </text>
  176. </view>
  177. <view class="section">
  178. <text class="section-title">三、我们如何保护您的个人信息</text>
  179. <text class="section-content">
  180. 3.1 我们已使用符合业界标准的安全防护措施保护您的个人信息。\n
  181. 3.2 我们采取数据加密、访问控制等技术措施防止数据遭到未经授权的访问、使用、修改或泄露。\n
  182. 3.3 我们仅允许有必要知晓这些信息的员工访问您的个人信息,并为此设置了严格的访问权限控制。
  183. </text>
  184. </view>
  185. <view class="section">
  186. <text class="section-title">四、您的权利</text>
  187. <text class="section-content">
  188. 4.1 您有权访问、更正、删除您的个人信息。\n
  189. 4.2 您有权改变您授权同意的范围或撤回您的授权。\n
  190. 4.3 您有权注销您的账号。
  191. </text>
  192. </view>
  193. <view class="section">
  194. <text class="section-title">五、我们如何处理未成年人的个人信息</text>
  195. <text class="section-content">
  196. 5.1 我们非常重视对未成年人个人信息的保护。\n
  197. 5.2 若您是 18 周岁以下的未成年人,在使用本服务前,应事先取得您家长或法定监护人的书面同意。
  198. </text>
  199. </view>
  200. <view class="section">
  201. <text class="section-title">六、隐私政策的更新</text>
  202. <text class="section-content">
  203. 6.1 我们可能会适时对本隐私政策进行修订。\n
  204. 6.2 当本政策的条款发生变更时,我们会在版本更新时以适当的方式向您提示变更后的内容。
  205. </text>
  206. </view>
  207. <view class="section">
  208. <text class="section-title">七、联系我们</text>
  209. <text class="section-content">
  210. 如您对本隐私政策有任何疑问,请通过以下方式联系我们:\n
  211. 客服电话:400-XXX-XXXX\n
  212. 客服邮箱:support@example.com
  213. </text>
  214. </view>
  215. </view>
  216. </scroll-view>
  217. <view class="popup-footer">
  218. <button class="agree-btn" @click="closePrivacyPolicy">我已知晓</button>
  219. </view>
  220. </view>
  221. </view>
  222. </view>
  223. </template>
  224. <script setup>
  225. import {
  226. ref
  227. } from 'vue'
  228. import {
  229. sendVerifyCode,
  230. loginByPhone
  231. } from '@/api/user.js'
  232. import {
  233. saveUserInfo
  234. } from '@/utils/userCache.js'
  235. // 表单数据
  236. const phoneNumber = ref('')
  237. const verifyCode = ref('')
  238. const countdown = ref(0)
  239. const isLoading = ref(false)
  240. let timer = null
  241. // 弹窗控制
  242. const showUserAgreementPopup = ref(false)
  243. const showPrivacyPolicyPopup = ref(false)
  244. // 获取验证码
  245. const getVerifyCode = async () => {
  246. if (countdown.value > 0) return
  247. if (!phoneNumber.value || phoneNumber.value.length !== 11) {
  248. uni.showToast({
  249. title: '请输入正确的手机号',
  250. icon: 'none'
  251. })
  252. return
  253. }
  254. try {
  255. const res = await sendVerifyCode(phoneNumber.value)
  256. console.log('验证码发送成功:', res)
  257. // 开始倒计时
  258. countdown.value = 60
  259. timer = setInterval(() => {
  260. countdown.value--
  261. if (countdown.value <= 0) {
  262. clearInterval(timer)
  263. }
  264. }, 1000)
  265. uni.showToast({
  266. title: '验证码已发送',
  267. icon: 'success'
  268. })
  269. } catch (error) {
  270. console.error('发送验证码失败:', error)
  271. }
  272. }
  273. // 处理登录
  274. const handleLogin = async () => {
  275. if (isLoading.value) return
  276. if (!phoneNumber.value || phoneNumber.value.length !== 11) {
  277. uni.showToast({
  278. title: '请输入正确的手机号',
  279. icon: 'none'
  280. })
  281. return
  282. }
  283. if (!verifyCode.value || verifyCode.value.length !== 6) {
  284. uni.showToast({
  285. title: '请输入验证码',
  286. icon: 'none'
  287. })
  288. return
  289. }
  290. isLoading.value = true
  291. try {
  292. const res = await loginByPhone(phoneNumber.value, verifyCode.value)
  293. console.log('登录成功:', res)
  294. // 保存用户信息和 token
  295. const {
  296. userInfo,
  297. token
  298. } = res.data || res
  299. const saveSuccess = saveUserInfo(userInfo, token)
  300. if (saveSuccess) {
  301. uni.showToast({
  302. title: '登录成功',
  303. icon: 'success'
  304. })
  305. // 延迟跳转
  306. setTimeout(() => {
  307. uni.reLaunch({
  308. url: '/pages/index/index'
  309. })
  310. }, 1500)
  311. } else {
  312. uni.showToast({
  313. title: '保存登录信息失败',
  314. icon: 'none'
  315. })
  316. }
  317. } catch (error) {
  318. console.error('登录失败:', error)
  319. } finally {
  320. isLoading.value = false
  321. }
  322. }
  323. // 微信登录
  324. const wechatLogin = () => {
  325. // #ifdef MP-WEIXIN
  326. uni.getUserProfile({
  327. desc: '用于完善用户资料',
  328. success: (res) => {
  329. console.log('微信授权成功:', res.userInfo)
  330. // TODO: 调用微信登录接口
  331. uni.showToast({
  332. title: '微信授权成功',
  333. icon: 'success'
  334. })
  335. },
  336. fail: (err) => {
  337. console.log('微信授权失败:', err)
  338. }
  339. })
  340. // #endif
  341. // #ifndef MP-WEIXIN
  342. uni.showToast({
  343. title: '请在微信小程序中使用',
  344. icon: 'none'
  345. })
  346. // #endif
  347. }
  348. // 显示用户协议
  349. const showUserAgreement = () => {
  350. showUserAgreementPopup.value = true
  351. }
  352. // 关闭用户协议
  353. const closeUserAgreement = () => {
  354. showUserAgreementPopup.value = false
  355. }
  356. // 显示隐私政策
  357. const showPrivacyPolicy = () => {
  358. showPrivacyPolicyPopup.value = true
  359. }
  360. // 关闭隐私政策
  361. const closePrivacyPolicy = () => {
  362. showPrivacyPolicyPopup.value = false
  363. }
  364. // 页面卸载时清除定时器
  365. import {
  366. onUnmounted
  367. } from 'vue'
  368. onUnmounted(() => {
  369. if (timer) {
  370. clearInterval(timer)
  371. }
  372. })
  373. </script>
  374. <style lang="scss" scoped>
  375. .login-container {
  376. min-height: 100vh;
  377. background-color: #ffffff;
  378. padding: 0 40rpx;
  379. position: relative;
  380. }
  381. // 导航栏
  382. .nav-bar {
  383. height: 88rpx;
  384. display: flex;
  385. align-items: center;
  386. justify-content: center;
  387. .nav-title {
  388. font-size: 34rpx;
  389. font-weight: 600;
  390. color: #000000;
  391. }
  392. }
  393. // Logo 区域
  394. .logo-section {
  395. display: flex;
  396. flex-direction: column;
  397. align-items: center;
  398. margin-top: 60rpx;
  399. margin-bottom: 80rpx;
  400. .logo-icon {
  401. width: 160rpx;
  402. height: 160rpx;
  403. background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%);
  404. border-radius: 32rpx;
  405. box-shadow: 0 8rpx 24rpx rgba(24, 144, 255, 0.3);
  406. }
  407. .app-name {
  408. font-size: 40rpx;
  409. font-weight: 600;
  410. color: #000000;
  411. margin-top: 32rpx;
  412. }
  413. }
  414. // 表单区域
  415. .form-section {
  416. .input-item {
  417. margin-bottom: 24rpx;
  418. .phone-input,
  419. .code-input {
  420. background-color: #f5f7fa;
  421. border-radius: 16rpx;
  422. font-size: 28rpx;
  423. }
  424. }
  425. .verify-code-row {
  426. display: flex;
  427. align-items: center;
  428. .code-input {
  429. flex: 1;
  430. margin-right: 20rpx;
  431. }
  432. .get-code-btn {
  433. font-size: 26rpx;
  434. color: #1890ff;
  435. white-space: nowrap;
  436. &.disabled {
  437. color: #999999;
  438. }
  439. }
  440. }
  441. .login-btn-wrapper {
  442. margin-top: 48rpx;
  443. margin-bottom: 24rpx;
  444. .login-btn {
  445. width: 100%;
  446. height: 88rpx;
  447. background: linear-gradient(90deg, #1890ff 0%, #096dd9 100%);
  448. border-radius: 16rpx;
  449. border: none;
  450. font-size: 32rpx;
  451. font-weight: 500;
  452. color: #ffffff;
  453. display: flex;
  454. align-items: center;
  455. justify-content: center;
  456. &::after {
  457. border: none;
  458. }
  459. }
  460. }
  461. .agreement-text {
  462. display: flex;
  463. flex-wrap: wrap;
  464. justify-content: center;
  465. font-size: 22rpx;
  466. .gray-text {
  467. color: #999999;
  468. margin: 0 4rpx;
  469. }
  470. .link-text {
  471. color: #1890ff;
  472. margin: 0 4rpx;
  473. }
  474. }
  475. }
  476. // 其他登录方式
  477. .other-method-section {
  478. margin-top: 120rpx;
  479. .divider {
  480. display: flex;
  481. align-items: center;
  482. justify-content: center;
  483. margin-bottom: 40rpx;
  484. .divider-line {
  485. width: 120rpx;
  486. height: 1rpx;
  487. background-color: #e5e5e5;
  488. }
  489. .divider-text {
  490. font-size: 24rpx;
  491. color: #999999;
  492. margin: 0 24rpx;
  493. }
  494. }
  495. .wechat-login-wrapper {
  496. .wechat-login-btn {
  497. width: 100%;
  498. height: 88rpx;
  499. background: linear-gradient(90deg, #07c160 0%, #06ad56 100%);
  500. border-radius: 16rpx;
  501. border: none;
  502. font-size: 32rpx;
  503. font-weight: 500;
  504. color: #ffffff;
  505. display: flex;
  506. align-items: center;
  507. justify-content: center;
  508. &::after {
  509. border: none;
  510. }
  511. .wechat-icon {
  512. margin-right: 12rpx;
  513. font-size: 36rpx;
  514. }
  515. .wechat-text {
  516. color: #ffffff;
  517. }
  518. }
  519. }
  520. }
  521. // 协议弹窗
  522. .agreement-popup {
  523. position: fixed;
  524. top: 0;
  525. left: 0;
  526. right: 0;
  527. bottom: 0;
  528. z-index: 1000;
  529. .popup-mask {
  530. position: absolute;
  531. top: 0;
  532. left: 0;
  533. right: 0;
  534. bottom: 0;
  535. background-color: rgba(0, 0, 0, 0.5);
  536. }
  537. .popup-content {
  538. position: absolute;
  539. bottom: 0;
  540. left: 0;
  541. right: 0;
  542. background-color: #ffffff;
  543. border-radius: 32rpx 32rpx 0 0;
  544. max-height: 80vh;
  545. display: flex;
  546. flex-direction: column;
  547. animation: slideUp 0.3s ease-out;
  548. .popup-header {
  549. display: flex;
  550. align-items: center;
  551. justify-content: space-between;
  552. padding: 32rpx;
  553. border-bottom: 1rpx solid #f0f0f0;
  554. .popup-title {
  555. font-size: 32rpx;
  556. font-weight: 600;
  557. color: #000000;
  558. }
  559. .popup-close {
  560. font-size: 40rpx;
  561. color: #999999;
  562. width: 60rpx;
  563. height: 60rpx;
  564. display: flex;
  565. align-items: center;
  566. justify-content: center;
  567. }
  568. }
  569. .popup-body {
  570. flex: 1;
  571. overflow-y: auto;
  572. padding: 32rpx;
  573. .agreement-content {
  574. display: flex;
  575. flex-direction: column;
  576. .agreement-title {
  577. font-size: 36rpx;
  578. font-weight: 600;
  579. color: #000000;
  580. display: block;
  581. text-align: center;
  582. margin-bottom: 20rpx;
  583. }
  584. .update-time {
  585. font-size: 24rpx;
  586. color: #999999;
  587. display: block;
  588. text-align: center;
  589. margin-bottom: 40rpx;
  590. }
  591. .section {
  592. margin-bottom: 32rpx;
  593. .section-title {
  594. font-size: 28rpx;
  595. font-weight: 600;
  596. color: #000000;
  597. display: block;
  598. margin-bottom: 16rpx;
  599. }
  600. .section-content {
  601. font-size: 24rpx;
  602. color: #333333;
  603. line-height: 1.8;
  604. display: block;
  605. white-space: pre-wrap;
  606. }
  607. }
  608. }
  609. }
  610. .popup-footer {
  611. padding: 24rpx 32rpx 40rpx;
  612. border-top: 1rpx solid #f0f0f0;
  613. .agree-btn {
  614. width: 100%;
  615. height: 80rpx;
  616. background: linear-gradient(90deg, #1890ff 0%, #096dd9 100%);
  617. border-radius: 16rpx;
  618. border: none;
  619. font-size: 30rpx;
  620. font-weight: 500;
  621. color: #ffffff;
  622. display: flex;
  623. align-items: center;
  624. justify-content: center;
  625. &::after {
  626. border: none;
  627. }
  628. }
  629. }
  630. }
  631. }
  632. @keyframes slideUp {
  633. from {
  634. transform: translateY(100%);
  635. }
  636. to {
  637. transform: translateY(0);
  638. }
  639. }
  640. </style>