You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

773 lines
16 KiB

1 month ago
  1. <template>
  2. <view class="login-registration-container">
  3. <!-- 自定义导航栏 -->
  4. <view
  5. class="custom-navbar"
  6. :style="{ paddingTop: safeAreaInsets?.top + 'px' }"
  7. >
  8. <!-- <view class="nav-left">
  9. <text class="back-btn" @click="goToIndex"></text>
  10. </view> -->
  11. <view class="nav-right">
  12. <image
  13. class="icons"
  14. src="../../../static/icons/Headset.png"
  15. alt="联系客服"
  16. />
  17. <image
  18. class="icons"
  19. @click="goToIndex"
  20. src="../../../static/icons/Frame.png"
  21. alt="返回首页"
  22. />
  23. </view>
  24. </view>
  25. <!-- Logo -->
  26. <!-- <image class="logo" src="/static/logo.png" mode="aspectFit"></image> -->
  27. <!-- 欢迎语 -->
  28. <text class="welcome-text">登录DeepChart</text>
  29. <!-- 邮箱/手机号切换 -->
  30. <view class="switch-container">
  31. <text
  32. class="switch-item"
  33. :class="{ active: switchType === 'User' }"
  34. @click="switchUser"
  35. >用户名</text
  36. >
  37. <text
  38. class="switch-item"
  39. :class="{ active: switchType === 'Phone' }"
  40. @click="switchPhone"
  41. >手机号</text
  42. ><text
  43. class="switch-item"
  44. :class="{ active: switchType === 'Email' }"
  45. @click="switchEmail"
  46. >邮箱</text
  47. >
  48. </view>
  49. <!-- 输入框 -->
  50. <view class="input-container">
  51. <view v-if="switchType === 'User'">
  52. <!-- 修改邮箱输入框容器将图标包含在内 -->
  53. <view class="input-with-icon">
  54. <image
  55. class="input-icon"
  56. src="../../../static/icons/People-safe.png"
  57. alt=""
  58. />
  59. <input
  60. class="input-field"
  61. type="text"
  62. placeholder="请输入DeepChart ID"
  63. v-model="email"
  64. />
  65. </view>
  66. <view class="input-with-icon">
  67. <image
  68. class="input-icon"
  69. src="../../../static/icons/Unlock.png"
  70. alt=""
  71. />
  72. <input
  73. class="input-field"
  74. type="text"
  75. placeholder="请输入密码"
  76. v-model="password"
  77. />
  78. </view>
  79. </view>
  80. <view v-if="switchType === 'Email'">
  81. <!-- 修改邮箱输入框容器将图标包含在内 -->
  82. <view class="input-with-icon">
  83. <image
  84. class="input-icon"
  85. src="../../../static/icons/Mail.png"
  86. alt=""
  87. />
  88. <input
  89. class="input-field"
  90. type="text"
  91. placeholder="请输入邮箱"
  92. v-model="email"
  93. />
  94. <view>
  95. <button
  96. class="send-code-btn-email"
  97. :disabled="isCodeBtnDisabled"
  98. :class="{ 'send-code-btn-disabled': isCodeBtnDisabled }"
  99. @click="sendCode"
  100. >
  101. <text
  102. class="send-code-text"
  103. :class="{ 'send-code-btn-disabled-text': isCodeBtnDisabled }"
  104. >{{ codeBtnText }}</text
  105. >
  106. </button>
  107. </view>
  108. </view>
  109. <view class="input-with-icon">
  110. <image
  111. class="input-icon"
  112. src="../../../static/icons/Text-recognition.png"
  113. alt=""
  114. />
  115. <input
  116. class="input-field"
  117. type="text"
  118. placeholder="请输入验证码"
  119. v-model="password"
  120. />
  121. </view>
  122. </view>
  123. <view v-if="switchType === 'Phone'" class="phone-input-container">
  124. <view class="country-code-selector" @click="showCountryPicker">
  125. <image
  126. class="country-flag-img"
  127. src="../../../static/icons/Iphone.png"
  128. mode="aspectFit"
  129. ></image>
  130. <text class="country-code">{{ selectedCountry.code }}</text>
  131. <!-- <text class="arrow-down"></text> -->
  132. </view>
  133. <input
  134. class="input-field phone-input"
  135. type="number"
  136. placeholder="输入手机号"
  137. v-model="phone"
  138. @input="onPhoneInput"
  139. />
  140. <view>
  141. <button
  142. class="send-code-btn"
  143. :disabled="isCodeBtnDisabled"
  144. :class="{ 'send-code-btn-disabled': isCodeBtnDisabled }"
  145. @click="sendCode"
  146. >
  147. <text
  148. class="send-code-text"
  149. :class="{ 'send-code-btn-disabled-text': isCodeBtnDisabled }"
  150. >{{ codeBtnText }}</text
  151. >
  152. </button>
  153. </view>
  154. </view>
  155. <view v-if="switchType === 'Phone'" class="input-with-icon">
  156. <image
  157. class="input-icon"
  158. src="../../../static/icons/Text-recognition.png"
  159. alt=""
  160. />
  161. <input
  162. class="input-field"
  163. type="text"
  164. placeholder="请输入验证码"
  165. v-model="password"
  166. />
  167. </view>
  168. </view>
  169. <!-- 用户协议 -->
  170. <view @click="changeCheckbox" class="agreement-container-one">
  171. <image
  172. class="checkbox"
  173. :src="checkboxUrl"
  174. ></image>
  175. <text class="agreement-text-one"
  176. >接受 <text class="link" @click="openAgreement">用户协议</text>
  177. <text class="link" @click="openPrivacy">隐私政策</text></text
  178. >
  179. </view>
  180. <view v-if="switchType === 'User'" class="agreement-container">
  181. <text class="agreement-text"
  182. ><text @click="recoverPassword">忘记ID/密码</text>
  183. </text>
  184. </view>
  185. <view v-else class="agreement-container">
  186. <text class="agreement-text">
  187. <!-- 添加占位元素防止页面变形 -->
  188. <text style="visibility: hidden;">占位符</text>
  189. </text>
  190. </view>
  191. <!-- 注册按钮 -->
  192. <button class="register-btn" @click="register">登录</button>
  193. <!-- 或者 -->
  194. <text class="or-text" @click="goToRegistration"
  195. >如果您还没有账号点击注册 >
  196. </text>
  197. <!-- 第三方登录 -->
  198. <view class="third-party-login">
  199. <view class="third-party-btn" @click="loginWithApple">
  200. <image
  201. class="apple-icon"
  202. src="../../../static/icons/appleIcons.png"
  203. mode="aspectFit"
  204. ></image>
  205. <text class="third-party-text">通过 Apple 登录 </text>
  206. </view>
  207. <view class="third-party-btn" @click="loginWithGoogle">
  208. <image
  209. class="google-icon"
  210. src="../../../static/icons/GoogleIcons.png"
  211. mode="aspectFit"
  212. ></image>
  213. <text class="third-party-text">通过 Google 登录</text>
  214. </view>
  215. </view>
  216. </view>
  217. </template>
  218. <script setup>
  219. import { ref } from "vue";
  220. // 导入完整的国家列表
  221. import countryList from "./list.js";
  222. const email = ref("");
  223. const password = ref("");
  224. const phone = ref("");
  225. const agreed = ref(false);
  226. const switchType = ref("Email"); // 默认是邮箱注册
  227. const { safeAreaInsets } = uni.getSystemInfoSync();
  228. const codeBtnText = ref("获取验证码");
  229. const isCodeBtnDisabled = ref(false); // 添加验证码按钮禁用状态
  230. const checkboxUrl = ref("../../../static/icons/Check-one-false.png");
  231. // 使用从list.js导入的完整国家列表数据
  232. const countries = ref(
  233. countryList.list.map((item) => ({
  234. name: item.name,
  235. code: `+${item.tel}`,
  236. flag: item.flag,
  237. short: item.short,
  238. en: item.en,
  239. }))
  240. );
  241. // 默认选中的国家(中国)
  242. const selectedCountry = ref(
  243. countries.value.find((country) => country.short === "CN") ||
  244. countries.value[0]
  245. );
  246. // 显示国家选择器
  247. function showCountryPicker() {
  248. uni.showActionSheet({
  249. itemList: countries.value.map(
  250. (country) => `${country.name} ${country.code}`
  251. ),
  252. success: function (res) {
  253. selectedCountry.value = countries.value[res.tapIndex];
  254. },
  255. });
  256. }
  257. function goToIndex() {
  258. // 返回上一页
  259. uni.navigateTo({
  260. url: "/pages/start/index/index",
  261. });
  262. }
  263. function switchUser() {
  264. // 切换到手机注册
  265. switchType.value = "User";
  266. }
  267. function switchEmail() {
  268. // 切换到邮箱注册
  269. switchType.value = "Email";
  270. }
  271. function switchPhone() {
  272. // 切换到手机注册
  273. switchType.value = "Phone";
  274. }
  275. function register() {
  276. if (switchType.value === "Email") {
  277. // 登录逻辑
  278. if (!email.value) {
  279. uni.showToast({
  280. title: "请输入邮箱地址",
  281. icon: "none",
  282. });
  283. return;
  284. }
  285. // 发送登录请求
  286. console.log("登录:", email.value);
  287. }
  288. if (switchType.value === "Phone") {
  289. // 登录逻辑
  290. if (!phone.value) {
  291. uni.showToast({
  292. title: "请输入手机号码",
  293. icon: "none",
  294. });
  295. return;
  296. }
  297. // 发送登录请求
  298. console.log("登录:", phone.value);
  299. }
  300. }
  301. function loginWithApple() {
  302. // Apple登录逻辑
  303. console.log("通过Apple登录");
  304. uni.login({
  305. provider: "apple",
  306. success: function (loginRes) {
  307. // 登录成功
  308. uni.getUserInfo({
  309. provider: "apple",
  310. success: function (info) {
  311. console.log(info);
  312. },
  313. });
  314. },
  315. fail: function (err) {
  316. // 登录授权失败
  317. // err.code错误码参考`授权失败错误码(code)说明`
  318. console.log(err);
  319. },
  320. });
  321. }
  322. function loginWithGoogle() {
  323. // Google登录逻辑
  324. console.log("通过Google登录");
  325. uni.login({
  326. provider: "google",
  327. success: function (loginRes) {
  328. // 登录成功
  329. uni.getUserInfo({
  330. provider: "google",
  331. success: function (info) {
  332. console.log(info);
  333. },
  334. });
  335. },
  336. fail: function (err) {
  337. // 登录授权失败
  338. // err.code是错误码
  339. console.log(err);
  340. },
  341. });
  342. }
  343. function goToRegistration() {
  344. // 跳转到登录页
  345. uni.navigateTo({
  346. url: "/pages/start/Registration/Registration",
  347. });
  348. }
  349. function onPhoneInput(e) {
  350. // 确保只允许输入数字
  351. const value = e.detail.value;
  352. // 使用 isNaN 检查是否为有效数字
  353. if (isNaN(value)) {
  354. phone.value = "";
  355. } else {
  356. phone.value = value;
  357. }
  358. }
  359. function sendCode() {
  360. // 如果按钮已禁用,则不执行后续逻辑
  361. if (isCodeBtnDisabled.value) return;
  362. // 设置按钮为禁用状态
  363. isCodeBtnDisabled.value = true;
  364. codeBtnText.value = "重新发送";
  365. let time = 6;
  366. const timer = setInterval(() => {
  367. time--;
  368. codeBtnText.value = "重新发送 " + time + "s";
  369. if (time <= 0) {
  370. clearInterval(timer);
  371. codeBtnText.value = "重新发送";
  372. // 倒计时结束后启用按钮
  373. isCodeBtnDisabled.value = false;
  374. }
  375. }, 1000);
  376. return;
  377. }
  378. function openAgreement() {
  379. // 打开用户协议
  380. console.log("打开用户协议");
  381. uni.navigateTo({
  382. url: "/pages/start/agreement/agreement",
  383. });
  384. }
  385. function openPrivacy() {
  386. // 打开隐私政策
  387. console.log("打开隐私政策");
  388. uni.navigateTo({
  389. url: "/pages/start/privacy/privacy",
  390. });
  391. }
  392. function recoverPassword() {
  393. // 忘记密码
  394. console.log("忘记密码");
  395. }
  396. function changeCheckbox(){
  397. agreed.value = !agreed.value;
  398. checkboxUrl.value = agreed.value ? "../../../static/icons/Check-one-true.png" : "../../../static/icons/Check-one-false.png";
  399. }
  400. </script>
  401. <style scoped>
  402. .login-registration-container {
  403. display: flex;
  404. flex-direction: column;
  405. align-items: center;
  406. justify-content: center;
  407. padding: 0 70rpx;
  408. height: 100vh;
  409. background-color: #ffffff;
  410. }
  411. /* 自定义导航栏样式 */
  412. .custom-navbar {
  413. position: absolute;
  414. top: 0;
  415. left: 0;
  416. /* z-index: 999; */
  417. width: 90%;
  418. height: 80rpx;
  419. display: flex;
  420. justify-content: space-between;
  421. align-items: center;
  422. padding: 10rpx 40rpx;
  423. margin-bottom: 20rpx;
  424. }
  425. .nav-left,
  426. .nav-right {
  427. flex: 1;
  428. }
  429. .nav-right {
  430. display: flex;
  431. justify-content: flex-end;
  432. }
  433. .icons {
  434. margin: 20rpx;
  435. width: 40rpx;
  436. height: 40rpx;
  437. /* margin-right: 10rpx; */
  438. }
  439. .back-btn,
  440. .headphone-btn {
  441. font-size: 36rpx;
  442. font-weight: bold;
  443. color: #333333;
  444. padding: 10rpx;
  445. }
  446. .logo {
  447. width: 120rpx;
  448. height: 120rpx;
  449. margin-bottom: 60rpx;
  450. border-radius: 20%;
  451. }
  452. .welcome-text {
  453. font-size: 48rpx;
  454. font-weight: bold;
  455. color: #333333;
  456. margin-bottom: 60rpx;
  457. /* text-align: left; */
  458. /* align-self: flex-start; */
  459. }
  460. .switch-container {
  461. display: flex;
  462. margin-bottom: 40rpx;
  463. align-self: flex-start;
  464. }
  465. .switch-item {
  466. font-size: 28rpx;
  467. color: #999999;
  468. padding: 10rpx 20rpx;
  469. position: relative;
  470. }
  471. .switch-item::after {
  472. content: "";
  473. position: absolute;
  474. bottom: 0;
  475. left: 50%;
  476. transform: translateX(-50%);
  477. width: 60%;
  478. /* 控制边框宽度 */
  479. height: 2rpx;
  480. background-color: transparent;
  481. }
  482. .switch-item.active {
  483. color: #333333;
  484. font-weight: 700;
  485. }
  486. .switch-item.active::after {
  487. content: "";
  488. position: absolute;
  489. top: 60rpx;
  490. bottom: 0;
  491. left: 50%;
  492. transform: translateX(-50%);
  493. width: 30%;
  494. /* 控制边框宽度 */
  495. height: 7rpx;
  496. background-color: #333333;
  497. }
  498. .input-container {
  499. width: 100%;
  500. }
  501. /* 添加图标输入框样式 */
  502. .input-with-icon {
  503. display: flex;
  504. align-items: center;
  505. width: 100%;
  506. height: 80rpx;
  507. border-bottom: 2rpx solid #e5e5e5;
  508. margin-bottom: 20rpx;
  509. }
  510. .input-icon {
  511. width: 40rpx;
  512. height: 40rpx;
  513. margin: 0 20rpx;
  514. }
  515. .input-field {
  516. flex: 1;
  517. height: 80rpx;
  518. padding: 15rpx 0;
  519. font-size: 28rpx;
  520. color: #333333;
  521. border: none;
  522. background-color: transparent;
  523. }
  524. .phone-input-container {
  525. display: flex;
  526. align-items: center;
  527. width: 95.8%;
  528. height: 80rpx;
  529. /* border-radius: 20rpx; */
  530. /* border: 2rpx solid #e5e5e5; */
  531. /* background-color: #f5f5f5; */
  532. padding: 0 10rpx;
  533. border-bottom: 2rpx solid #e5e5e5;
  534. margin-bottom: 20rpx;
  535. }
  536. .country-code-selector {
  537. display: flex;
  538. align-items: center;
  539. padding: 0 10rpx;
  540. padding-bottom: 1rpx;
  541. height: 100%;
  542. /* border-right: 2rpx solid #e5e5e5; */
  543. /* background-color: #f5f5f5; */
  544. border-radius: 20rpx 0 0 20rpx;
  545. }
  546. .country-code {
  547. font-size: 28rpx;
  548. color: #333333;
  549. margin-right: 10rpx;
  550. }
  551. .country-flag-img {
  552. width: 40rpx;
  553. height: 40rpx;
  554. margin-right: 10rpx;
  555. }
  556. .arrow-down {
  557. font-size: 20rpx;
  558. color: #999999;
  559. }
  560. .phone-input {
  561. flex: 1;
  562. width: auto;
  563. height: 100%;
  564. border: none;
  565. background-color: transparent;
  566. padding: 0 0rpx;
  567. }
  568. .send-code-btn {
  569. width: 200rpx;
  570. height: 60rpx;
  571. display: inline-flex;
  572. padding: 0rpx 10rpx;
  573. justify-content: center;
  574. align-items: center;
  575. gap: 10px;
  576. border-radius: 4px;
  577. background: #000;
  578. }
  579. .send-code-btn-email {
  580. width: 200rpx;
  581. height: 60rpx;
  582. display: inline-flex;
  583. padding: 0rpx 10rpx;
  584. justify-content: center;
  585. align-items: center;
  586. gap: 10px;
  587. border-radius: 4px;
  588. background: #000;
  589. margin-right: 15rpx;
  590. }
  591. .send-code-btn-disabled {
  592. background: #e6e6e6;
  593. /* 禁用状态下的灰色背景 */
  594. }
  595. .send-code-btn-disabled-text {
  596. color: #999999 !important;
  597. }
  598. .send-code-text {
  599. color: #fff;
  600. font-size: 28rpx;
  601. }
  602. .agreement-container-one {
  603. display: flex;
  604. align-items: center;
  605. align-self: flex-start;
  606. margin-bottom: 80rpx;
  607. }
  608. .agreement-container {
  609. display: flex;
  610. align-items: center;
  611. margin-bottom: 30rpx;
  612. margin-top: -60rpx;
  613. align-self: flex-start;
  614. }
  615. .checkbox {
  616. width: 30rpx;
  617. height: 30rpx;
  618. margin-left: 20rpx;
  619. /* flex: content; */
  620. }
  621. .agreement-text-one {
  622. font-size: 22rpx;
  623. color: #666666;
  624. text-align: center;
  625. margin-left: 10rpx;
  626. }
  627. .agreement-text {
  628. margin-left: 20rpx;
  629. font-size: 24rpx;
  630. color: #666666;
  631. white-space: nowrap;
  632. }
  633. .link {
  634. color: #333333;
  635. font-weight: bold;
  636. text-decoration: underline;
  637. }
  638. .register-btn {
  639. width: 100%;
  640. height: 80rpx;
  641. background-color: #000000;
  642. color: white;
  643. font-size: 32rpx;
  644. font-weight: bold;
  645. border-radius: 40rpx;
  646. margin-bottom: 40rpx;
  647. }
  648. .or-text {
  649. font-size: 24rpx;
  650. color: #999999;
  651. margin-bottom: 40rpx;
  652. }
  653. .third-party-login {
  654. width: 100%;
  655. margin-bottom: 60rpx;
  656. }
  657. .third-party-text {
  658. color: #ffffff;
  659. font-weight: bold;
  660. white-space: pre;
  661. }
  662. .third-party-btn {
  663. width: 100%;
  664. height: 80rpx;
  665. background-color: rgb(0, 0, 0);
  666. border: 2rpx solid #e5e5e5;
  667. border-radius: 40rpx;
  668. display: flex;
  669. align-items: center;
  670. justify-content: center;
  671. margin-bottom: 20rpx;
  672. font-size: 28rpx;
  673. color: #333333;
  674. }
  675. .google-icon,
  676. .apple-icon {
  677. width: 60rpx;
  678. height: 60rpx;
  679. margin-right: 20rpx;
  680. }
  681. .existing-account {
  682. display: flex;
  683. align-items: center;
  684. }
  685. .account-text {
  686. font-size: 24rpx;
  687. color: #666666;
  688. }
  689. .login-link {
  690. font-size: 24rpx;
  691. font-weight: bold;
  692. color: #333333;
  693. margin-left: 10rpx;
  694. text-decoration: underline;
  695. }
  696. </style>