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.

508 lines
9.9 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. <text class="headphone-btn">🎧</text>
  13. </view>
  14. </view>
  15. <!-- Logo -->
  16. <!-- <image class="logo" src="/static/logo.png" mode="aspectFit"></image> -->
  17. <!-- 欢迎语 -->
  18. <text class="welcome-text">登录DeepChart</text>
  19. <!-- 邮箱/手机号切换 -->
  20. <view class="switch-container">
  21. <text
  22. class="switch-item"
  23. :class="{ active: switchType === 'Email' }"
  24. @click="switchEmail"
  25. >邮箱/用户名</text
  26. >
  27. <text
  28. class="switch-item"
  29. :class="{ active: switchType === 'Phone' }"
  30. @click="switchPhone"
  31. >手机号</text
  32. >
  33. </view>
  34. <!-- 输入框 -->
  35. <view class="input-container">
  36. <input
  37. v-if="switchType === 'Email'"
  38. class="input-field"
  39. type="text"
  40. placeholder="输入邮箱/用户名"
  41. v-model="email"
  42. />
  43. <view v-else class="phone-input-container">
  44. <view class="country-code-selector" @click="showCountryPicker">
  45. <image
  46. class="country-flag-img"
  47. :src="selectedCountry.flag"
  48. mode="aspectFit"
  49. ></image>
  50. <text class="country-code">{{ selectedCountry.code }}</text>
  51. <text class="arrow-down"></text>
  52. </view>
  53. <input
  54. class="input-field phone-input"
  55. type="number"
  56. placeholder="输入手机号"
  57. v-model="phone"
  58. @input="onPhoneInput"
  59. />
  60. </view>
  61. </view>
  62. <!-- 注册按钮 -->
  63. <button class="register-btn" @click="register">下一步</button>
  64. <!-- 或者 -->
  65. <text class="or-text">或者</text>
  66. <!-- 第三方登录 -->
  67. <view class="third-party-login">
  68. <view class="third-party-btn" @click="loginWithApple">
  69. <image
  70. class="apple-icon"
  71. src="/static/apple-icon.png"
  72. mode="aspectFit"
  73. ></image>
  74. <text class="third-party-text">通过 Apple 继续</text>
  75. </view>
  76. <view class="third-party-btn" @click="loginWithGoogle">
  77. <image
  78. class="google-icon"
  79. src="/static/google-icon.png"
  80. mode="aspectFit"
  81. ></image>
  82. <text class="third-party-text">通过 Google 继续</text>
  83. </view>
  84. </view>
  85. <!-- 已有账号 -->
  86. <view class="existing-account">
  87. <text class="account-text">未注册账号</text>
  88. <text class="login-link" @click="goToRegistration">注册</text>
  89. </view>
  90. </view>
  91. </template>
  92. <script setup>
  93. import { ref } from "vue";
  94. // 导入完整的国家列表
  95. import countryList from "./list.js";
  96. const email = ref("");
  97. const phone = ref("");
  98. const agreed = ref(false);
  99. const switchType = ref("Email"); // 默认是邮箱注册
  100. const { safeAreaInsets } = uni.getSystemInfoSync();
  101. // 使用从list.js导入的完整国家列表数据
  102. const countries = ref(
  103. countryList.list.map((item) => ({
  104. name: item.name,
  105. code: `+${item.tel}`,
  106. flag: item.flag,
  107. short: item.short,
  108. en: item.en,
  109. }))
  110. );
  111. // 默认选中的国家(中国)
  112. const selectedCountry = ref(
  113. countries.value.find((country) => country.short === "CN") ||
  114. countries.value[0]
  115. );
  116. // 显示国家选择器
  117. function showCountryPicker() {
  118. uni.showActionSheet({
  119. itemList: countries.value.map(
  120. (country) => `${country.name} ${country.code}`
  121. ),
  122. success: function (res) {
  123. selectedCountry.value = countries.value[res.tapIndex];
  124. },
  125. });
  126. }
  127. function goToIndex() {
  128. // 返回上一页
  129. uni.navigateTo({ url: "/pages/start/index/index" });
  130. }
  131. function switchEmail() {
  132. // 切换到邮箱注册
  133. switchType.value = "Email";
  134. }
  135. function switchPhone() {
  136. // 切换到手机注册
  137. switchType.value = "Phone";
  138. }
  139. function register() {
  140. if (switchType.value === "Email") {
  141. // 登录逻辑
  142. if (!email.value) {
  143. uni.showToast({
  144. title: "请输入邮箱地址",
  145. icon: "none",
  146. });
  147. return;
  148. }
  149. // 发送登录请求
  150. console.log("登录:", email.value);
  151. }
  152. if (switchType.value === "Phone") {
  153. // 登录逻辑
  154. if (!phone.value) {
  155. uni.showToast({
  156. title: "请输入手机号码",
  157. icon: "none",
  158. });
  159. return;
  160. }
  161. // 发送登录请求
  162. console.log("登录:", phone.value);
  163. }
  164. }
  165. function loginWithApple() {
  166. // Apple登录逻辑
  167. console.log("通过Apple登录");
  168. uni.login({
  169. provider: "apple",
  170. success: function (loginRes) {
  171. // 登录成功
  172. uni.getUserInfo({
  173. provider: "apple",
  174. success: function (info) {
  175. // 获取用户信息成功, info.authResult中保存登录认证数据
  176. console.log(info);
  177. },
  178. });
  179. },
  180. fail: function (err) {
  181. // 登录授权失败
  182. // err.code错误码参考`授权失败错误码(code)说明`
  183. console.log(err);
  184. },
  185. });
  186. }
  187. function loginWithGoogle() {
  188. // Google登录逻辑
  189. console.log("通过Google登录");
  190. uni.login({
  191. provider: "google",
  192. success: function (loginRes) {
  193. // 登录成功
  194. uni.getUserInfo({
  195. provider: "google",
  196. success: function (info) {
  197. // 获取用户信息成功, info.authResult保存用户信息
  198. console.log(info);
  199. },
  200. });
  201. },
  202. fail: function (err) {
  203. // 登录授权失败
  204. // err.code是错误码
  205. console.log(err);
  206. },
  207. });
  208. }
  209. function goToRegistration() {
  210. // 跳转到登录页
  211. uni.navigateTo({
  212. url: "/pages/start/Registration/Registration",
  213. });
  214. }
  215. function onPhoneInput(e) {
  216. // 确保只允许输入数字
  217. const value = e.detail.value;
  218. // 使用 isNaN 检查是否为有效数字
  219. if (isNaN(value)) {
  220. phone.value = "";
  221. } else {
  222. phone.value = value;
  223. }
  224. }
  225. </script>
  226. <style scoped>
  227. .login-registration-container {
  228. display: flex;
  229. flex-direction: column;
  230. align-items: center;
  231. justify-content: center;
  232. padding: 0 40rpx;
  233. height: 100vh;
  234. background-color: #ffffff;
  235. }
  236. /* 自定义导航栏样式 */
  237. .custom-navbar {
  238. position: absolute;
  239. top: 0;
  240. left: 0;
  241. /* z-index: 999; */
  242. width: 90%;
  243. height: 80rpx;
  244. display: flex;
  245. justify-content: space-between;
  246. align-items: center;
  247. padding: 10rpx 40rpx;
  248. margin-bottom: 20rpx;
  249. }
  250. .nav-left,
  251. .nav-right {
  252. flex: 1;
  253. }
  254. .nav-right {
  255. display: flex;
  256. justify-content: flex-end;
  257. }
  258. .back-btn,
  259. .headphone-btn {
  260. font-size: 36rpx;
  261. font-weight: bold;
  262. color: #333333;
  263. padding: 10rpx;
  264. }
  265. .logo {
  266. width: 120rpx;
  267. height: 120rpx;
  268. margin-bottom: 60rpx;
  269. border-radius: 20%;
  270. }
  271. .welcome-text {
  272. font-size: 48rpx;
  273. font-weight: bold;
  274. color: #333333;
  275. margin-bottom: 60rpx;
  276. /* text-align: left; */
  277. /* align-self: flex-start; */
  278. }
  279. .switch-container {
  280. display: flex;
  281. margin-bottom: 40rpx;
  282. align-self: flex-start;
  283. }
  284. .switch-item {
  285. font-size: 28rpx;
  286. color: #999999;
  287. padding: 10rpx 20rpx;
  288. position: relative;
  289. }
  290. .switch-item::after {
  291. content: "";
  292. position: absolute;
  293. bottom: 0;
  294. left: 50%;
  295. transform: translateX(-50%);
  296. width: 60%; /* 控制边框宽度 */
  297. height: 2rpx;
  298. background-color: transparent;
  299. }
  300. .switch-item.active {
  301. color: #333333;
  302. font-weight: 700;
  303. }
  304. .switch-item.active::after {
  305. content: "";
  306. position: absolute;
  307. top: 60rpx;
  308. bottom: 0;
  309. left: 50%;
  310. transform: translateX(-50%);
  311. width: 30%; /* 控制边框宽度 */
  312. height: 7rpx;
  313. background-color: #333333;
  314. }
  315. .input-container {
  316. width: 100%;
  317. margin-bottom: 40rpx;
  318. }
  319. .input-field {
  320. width: 90%;
  321. height: 80rpx;
  322. border-radius: 20rpx;
  323. border: 2rpx solid #e5e5e5;
  324. padding: 0 30rpx;
  325. font-size: 28rpx;
  326. color: #333333;
  327. background-color: #f5f5f5;
  328. }
  329. .phone-input-container {
  330. display: flex;
  331. align-items: center;
  332. width: 95.8%;
  333. height: 80rpx;
  334. border-radius: 20rpx;
  335. border: 2rpx solid #e5e5e5;
  336. background-color: #f5f5f5;
  337. padding: 0 10rpx;
  338. }
  339. .country-code-selector {
  340. display: flex;
  341. align-items: center;
  342. padding: 0 20rpx;
  343. height: 100%;
  344. border-right: 2rpx solid #e5e5e5;
  345. background-color: #f5f5f5;
  346. border-radius: 20rpx 0 0 20rpx;
  347. }
  348. .country-code {
  349. font-size: 28rpx;
  350. color: #333333;
  351. margin-right: 10rpx;
  352. }
  353. .country-flag-img {
  354. width: 40rpx;
  355. height: 40rpx;
  356. margin-right: 10rpx;
  357. }
  358. .arrow-down {
  359. font-size: 20rpx;
  360. color: #999999;
  361. }
  362. .phone-input {
  363. flex: 1;
  364. width: auto;
  365. height: 100%;
  366. border: none;
  367. background-color: transparent;
  368. padding: 0 20rpx;
  369. }
  370. .agreement-container {
  371. /* display: flex; */
  372. align-items: center;
  373. margin-bottom: 40rpx;
  374. align-self: flex-start;
  375. }
  376. .checkbox {
  377. width: 10rpx;
  378. height: 10rpx;
  379. margin-right: 30rpx;
  380. /* flex: content; */
  381. }
  382. .agreement-text {
  383. margin-left: 20rpx;
  384. font-size: 24rpx;
  385. color: #666666;
  386. }
  387. .link {
  388. color: #333333;
  389. font-weight: bold;
  390. text-decoration: underline;
  391. }
  392. .register-btn {
  393. width: 100%;
  394. height: 80rpx;
  395. background-color: #333333;
  396. color: white;
  397. font-size: 32rpx;
  398. font-weight: bold;
  399. border-radius: 40rpx;
  400. margin-bottom: 40rpx;
  401. }
  402. .or-text {
  403. font-size: 24rpx;
  404. color: #999999;
  405. margin-bottom: 40rpx;
  406. }
  407. .third-party-login {
  408. width: 100%;
  409. margin-bottom: 60rpx;
  410. }
  411. .third-party-text {
  412. font-weight: bold;
  413. }
  414. .third-party-btn {
  415. width: 100%;
  416. height: 80rpx;
  417. background-color: white;
  418. border: 2rpx solid #e5e5e5;
  419. border-radius: 40rpx;
  420. display: flex;
  421. align-items: center;
  422. justify-content: center;
  423. margin-bottom: 20rpx;
  424. font-size: 28rpx;
  425. color: #333333;
  426. }
  427. .apple-icon {
  428. width: 30rpx;
  429. height: 30rpx;
  430. margin-right: 20rpx;
  431. }
  432. .google-icon {
  433. width: 30rpx;
  434. height: 30rpx;
  435. margin-right: 20rpx;
  436. }
  437. .existing-account {
  438. display: flex;
  439. align-items: center;
  440. }
  441. .account-text {
  442. font-size: 24rpx;
  443. color: #666666;
  444. }
  445. .login-link {
  446. font-size: 24rpx;
  447. font-weight: bold;
  448. color: #333333;
  449. margin-left: 10rpx;
  450. text-decoration: underline;
  451. }
  452. </style>