login.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  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">{{appName}}</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. getCurrentConfig
  227. } from '@/config/index.js'
  228. import {
  229. ref,
  230. onMounted
  231. } from 'vue'
  232. import {
  233. login,
  234. sendCode
  235. } from '@/api/user.js'
  236. import {
  237. saveUserInfo
  238. } from '@/utils/userCache.js'
  239. let appName = ref('')
  240. onMounted(async () => {
  241. const config = await getCurrentConfig()
  242. appName.value = config.appName
  243. version.value = config.appVersion
  244. })
  245. // 表单数据
  246. const phoneNumber = ref('')
  247. const verifyCode = ref('')
  248. const countdown = ref(0)
  249. const isLoading = ref(false)
  250. let timer = null
  251. // 弹窗控制
  252. const showUserAgreementPopup = ref(false)
  253. const showPrivacyPolicyPopup = ref(false)
  254. // 获取验证码
  255. const getVerifyCode = async () => {
  256. if (countdown.value > 0) return
  257. if (!phoneNumber.value || phoneNumber.value.length !== 11) {
  258. uni.showToast({
  259. title: '请输入正确的手机号',
  260. icon: 'none'
  261. })
  262. return
  263. }
  264. try {
  265. const res = await login(phoneNumber.value)
  266. console.log('验证码发送成功:', res)
  267. // 开始倒计时
  268. countdown.value = 60
  269. timer = setInterval(() => {
  270. countdown.value--
  271. if (countdown.value <= 0) {
  272. clearInterval(timer)
  273. }
  274. }, 1000)
  275. uni.showToast({
  276. title: '验证码已发送',
  277. icon: 'success'
  278. })
  279. } catch (error) {
  280. console.error('发送验证码失败:', error)
  281. }
  282. }
  283. // 处理登录
  284. const handleLogin = async () => {
  285. if (isLoading.value) return
  286. if (!phoneNumber.value || phoneNumber.value.length !== 11) {
  287. uni.showToast({
  288. title: '请输入正确的手机号',
  289. icon: 'none'
  290. })
  291. return
  292. }
  293. if (!verifyCode.value || verifyCode.value.length !== 6) {
  294. uni.showToast({
  295. title: '请输入验证码',
  296. icon: 'none'
  297. })
  298. return
  299. }
  300. isLoading.value = true
  301. try {
  302. const res = await sendCode(phoneNumber.value, verifyCode.value)
  303. console.log('登录成功:', res)
  304. // 保存用户信息和 token
  305. const {
  306. userInfo,
  307. token
  308. } = res.data || res
  309. const saveSuccess = saveUserInfo(userInfo, token)
  310. if (saveSuccess) {
  311. uni.showToast({
  312. title: '登录成功',
  313. icon: 'success'
  314. })
  315. // 延迟跳转
  316. setTimeout(() => {
  317. uni.reLaunch({
  318. url: '/pages/index/index'
  319. })
  320. }, 1500)
  321. } else {
  322. uni.showToast({
  323. title: '保存登录信息失败',
  324. icon: 'none'
  325. })
  326. }
  327. } catch (error) {
  328. console.error('登录失败:', error)
  329. } finally {
  330. isLoading.value = false
  331. }
  332. }
  333. // 微信登录
  334. const wechatLogin = () => {
  335. // #ifdef MP-WEIXIN
  336. uni.getUserProfile({
  337. desc: '用于完善用户资料',
  338. success: (res) => {
  339. console.log('微信授权成功:', res.userInfo)
  340. // TODO: 调用微信登录接口
  341. uni.showToast({
  342. title: '微信授权成功',
  343. icon: 'success'
  344. })
  345. },
  346. fail: (err) => {
  347. console.log('微信授权失败:', err)
  348. }
  349. })
  350. // #endif
  351. // #ifndef MP-WEIXIN
  352. uni.showToast({
  353. title: '请在微信小程序中使用',
  354. icon: 'none'
  355. })
  356. // #endif
  357. }
  358. // 显示用户协议
  359. const showUserAgreement = () => {
  360. showUserAgreementPopup.value = true
  361. }
  362. // 关闭用户协议
  363. const closeUserAgreement = () => {
  364. showUserAgreementPopup.value = false
  365. }
  366. // 显示隐私政策
  367. const showPrivacyPolicy = () => {
  368. showPrivacyPolicyPopup.value = true
  369. }
  370. // 关闭隐私政策
  371. const closePrivacyPolicy = () => {
  372. showPrivacyPolicyPopup.value = false
  373. }
  374. // 页面卸载时清除定时器
  375. import {
  376. onUnmounted
  377. } from 'vue'
  378. onUnmounted(() => {
  379. if (timer) {
  380. clearInterval(timer)
  381. }
  382. })
  383. </script>
  384. <style lang="scss" scoped>
  385. .login-container {
  386. min-height: 100vh;
  387. background-color: #ffffff;
  388. padding: 0 40rpx;
  389. position: relative;
  390. }
  391. // 导航栏
  392. .nav-bar {
  393. height: 88rpx;
  394. display: flex;
  395. align-items: center;
  396. justify-content: center;
  397. .nav-title {
  398. font-size: 34rpx;
  399. font-weight: 600;
  400. color: #000000;
  401. }
  402. }
  403. // Logo 区域
  404. .logo-section {
  405. display: flex;
  406. flex-direction: column;
  407. align-items: center;
  408. margin-top: 60rpx;
  409. margin-bottom: 80rpx;
  410. .logo-icon {
  411. width: 160rpx;
  412. height: 160rpx;
  413. background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%);
  414. border-radius: 32rpx;
  415. box-shadow: 0 8rpx 24rpx rgba(24, 144, 255, 0.3);
  416. }
  417. .app-name {
  418. font-size: 40rpx;
  419. font-weight: 600;
  420. color: #000000;
  421. margin-top: 32rpx;
  422. }
  423. }
  424. // 表单区域
  425. .form-section {
  426. .input-item {
  427. margin-bottom: 24rpx;
  428. .phone-input,
  429. .code-input {
  430. background-color: #f5f7fa;
  431. border-radius: 16rpx;
  432. font-size: 28rpx;
  433. }
  434. }
  435. .verify-code-row {
  436. display: flex;
  437. align-items: center;
  438. .code-input {
  439. flex: 1;
  440. margin-right: 20rpx;
  441. }
  442. .get-code-btn {
  443. font-size: 26rpx;
  444. color: #1890ff;
  445. white-space: nowrap;
  446. &.disabled {
  447. color: #999999;
  448. }
  449. }
  450. }
  451. .login-btn-wrapper {
  452. margin-top: 48rpx;
  453. margin-bottom: 24rpx;
  454. .login-btn {
  455. width: 100%;
  456. height: 88rpx;
  457. background: linear-gradient(90deg, #1890ff 0%, #096dd9 100%);
  458. border-radius: 16rpx;
  459. border: none;
  460. font-size: 32rpx;
  461. font-weight: 500;
  462. color: #ffffff;
  463. display: flex;
  464. align-items: center;
  465. justify-content: center;
  466. &::after {
  467. border: none;
  468. }
  469. }
  470. }
  471. .agreement-text {
  472. display: flex;
  473. flex-wrap: wrap;
  474. justify-content: center;
  475. font-size: 22rpx;
  476. .gray-text {
  477. color: #999999;
  478. margin: 0 4rpx;
  479. }
  480. .link-text {
  481. color: #1890ff;
  482. margin: 0 4rpx;
  483. }
  484. }
  485. }
  486. // 其他登录方式
  487. .other-method-section {
  488. margin-top: 120rpx;
  489. .divider {
  490. display: flex;
  491. align-items: center;
  492. justify-content: center;
  493. margin-bottom: 40rpx;
  494. .divider-line {
  495. width: 120rpx;
  496. height: 1rpx;
  497. background-color: #e5e5e5;
  498. }
  499. .divider-text {
  500. font-size: 24rpx;
  501. color: #999999;
  502. margin: 0 24rpx;
  503. }
  504. }
  505. .wechat-login-wrapper {
  506. .wechat-login-btn {
  507. width: 100%;
  508. height: 88rpx;
  509. background: linear-gradient(90deg, #07c160 0%, #06ad56 100%);
  510. border-radius: 16rpx;
  511. border: none;
  512. font-size: 32rpx;
  513. font-weight: 500;
  514. color: #ffffff;
  515. display: flex;
  516. align-items: center;
  517. justify-content: center;
  518. &::after {
  519. border: none;
  520. }
  521. .wechat-icon {
  522. margin-right: 12rpx;
  523. font-size: 36rpx;
  524. }
  525. .wechat-text {
  526. color: #ffffff;
  527. }
  528. }
  529. }
  530. }
  531. // 协议弹窗
  532. .agreement-popup {
  533. position: fixed;
  534. top: 0;
  535. left: 0;
  536. right: 0;
  537. bottom: 0;
  538. z-index: 1000;
  539. .popup-mask {
  540. position: absolute;
  541. top: 0;
  542. left: 0;
  543. right: 0;
  544. bottom: 0;
  545. background-color: rgba(0, 0, 0, 0.5);
  546. }
  547. .popup-content {
  548. position: absolute;
  549. bottom: 0;
  550. left: 0;
  551. right: 0;
  552. background-color: #ffffff;
  553. border-radius: 32rpx 32rpx 0 0;
  554. max-height: 80vh;
  555. display: flex;
  556. flex-direction: column;
  557. animation: slideUp 0.3s ease-out;
  558. .popup-header {
  559. display: flex;
  560. align-items: center;
  561. justify-content: space-between;
  562. padding: 32rpx;
  563. border-bottom: 1rpx solid #f0f0f0;
  564. .popup-title {
  565. font-size: 32rpx;
  566. font-weight: 600;
  567. color: #000000;
  568. }
  569. .popup-close {
  570. font-size: 40rpx;
  571. color: #999999;
  572. width: 60rpx;
  573. height: 60rpx;
  574. display: flex;
  575. align-items: center;
  576. justify-content: center;
  577. }
  578. }
  579. .popup-body {
  580. flex: 1;
  581. overflow-y: auto;
  582. padding: 32rpx;
  583. .agreement-content {
  584. display: flex;
  585. flex-direction: column;
  586. .agreement-title {
  587. font-size: 36rpx;
  588. font-weight: 600;
  589. color: #000000;
  590. display: block;
  591. text-align: center;
  592. margin-bottom: 20rpx;
  593. }
  594. .update-time {
  595. font-size: 24rpx;
  596. color: #999999;
  597. display: block;
  598. text-align: center;
  599. margin-bottom: 40rpx;
  600. }
  601. .section {
  602. margin-bottom: 32rpx;
  603. .section-title {
  604. font-size: 28rpx;
  605. font-weight: 600;
  606. color: #000000;
  607. display: block;
  608. margin-bottom: 16rpx;
  609. }
  610. .section-content {
  611. font-size: 24rpx;
  612. color: #333333;
  613. line-height: 1.8;
  614. display: block;
  615. white-space: pre-wrap;
  616. }
  617. }
  618. }
  619. }
  620. .popup-footer {
  621. padding: 24rpx 32rpx 40rpx;
  622. border-top: 1rpx solid #f0f0f0;
  623. .agree-btn {
  624. width: 100%;
  625. height: 80rpx;
  626. background: linear-gradient(90deg, #1890ff 0%, #096dd9 100%);
  627. border-radius: 16rpx;
  628. border: none;
  629. font-size: 30rpx;
  630. font-weight: 500;
  631. color: #ffffff;
  632. display: flex;
  633. align-items: center;
  634. justify-content: center;
  635. &::after {
  636. border: none;
  637. }
  638. }
  639. }
  640. }
  641. }
  642. @keyframes slideUp {
  643. from {
  644. transform: translateY(100%);
  645. }
  646. to {
  647. transform: translateY(0);
  648. }
  649. }
  650. </style>