login.uvue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <cl-page>
  3. <cl-topbar safe-area-top background-color="transparent"></cl-topbar>
  4. <view class="px-10">
  5. <!-- Logo -->
  6. <view class="flex flex-col items-center justify-center py-20">
  7. <view class="p-3 bg-primary-500 rounded-2xl">
  8. <cl-image
  9. src="/static/logo.png"
  10. mode="widthFix"
  11. :width="80"
  12. :height="80"
  13. ></cl-image>
  14. </view>
  15. <cl-text :pt="{ className: 'text-xl font-bold mt-3' }">{{ config.name }}</cl-text>
  16. </view>
  17. <!-- 手机号登录 -->
  18. <login-phone :form="form" @success="toLogin"></login-phone>
  19. <!-- 微信登录 -->
  20. <login-wx :ref="refs.set('loginWx')"></login-wx>
  21. <!-- 协议 -->
  22. <view class="mt-6 flex flex-row flex-wrap items-center justify-center">
  23. <cl-checkbox
  24. v-model="agree"
  25. :pt="{ icon: { size: 28 } }"
  26. active-icon="checkbox-circle-fill"
  27. inactive-icon="checkbox-blank-circle-line"
  28. >
  29. </cl-checkbox>
  30. <cl-text color="info" :pt="{ className: 'text-xs' }">{{
  31. t("已阅读并同意")
  32. }}</cl-text>
  33. <cl-text
  34. :pt="{ className: 'text-xs' }"
  35. @tap.stop="toDoc(t('用户协议'), 'userAgreement')"
  36. >
  37. 《{{ t("用户协议") }}》
  38. </cl-text>
  39. <cl-text color="info" :pt="{ className: 'text-xs' }">、</cl-text>
  40. <cl-text
  41. :pt="{ className: 'text-xs' }"
  42. @tap.stop="toDoc(t('隐私政策'), 'privacyPolicy')"
  43. >
  44. 《{{ t("隐私政策") }}》
  45. </cl-text>
  46. </view>
  47. <!-- 第三方登录 -->
  48. <view class="flex flex-row justify-center mt-10 px-10">
  49. <view
  50. class="login-item"
  51. :class="{
  52. 'is-dark': isDark
  53. }"
  54. @tap="refs.callMethod('loginWx', 'login')"
  55. >
  56. <cl-icon name="wechat-fill" :size="38" color="#00b223"></cl-icon>
  57. </view>
  58. <view class="login-item" :class="{ 'is-dark': isDark }">
  59. <cl-icon name="apple-fill" :size="38"></cl-icon>
  60. </view>
  61. </view>
  62. </view>
  63. </cl-page>
  64. </template>
  65. <script setup lang="ts">
  66. import { config } from "@/config";
  67. import { isDark, parse, router, useRefs, useStore, type Token } from "@/cool";
  68. import { t } from "@/locale";
  69. import { provide, reactive, ref } from "vue";
  70. import type { LoginForm } from "./types";
  71. import { useUi } from "@/uni_modules/cool-ui";
  72. import LoginPhone from "./components/login/phone.uvue";
  73. import LoginWx from "./components/login/wx.uvue";
  74. const { user } = useStore();
  75. const ui = useUi();
  76. const refs = useRefs();
  77. // 表单
  78. const form = reactive<LoginForm>({
  79. phone: "18000000000",
  80. smsCode: "6666"
  81. });
  82. // 是否同意
  83. const agree = ref(false);
  84. // 登录成功
  85. async function toLogin(res: any) {
  86. user.setToken(parse<Token>(res)!);
  87. user.get();
  88. router.nextLogin();
  89. }
  90. // 跳转文档
  91. function toDoc(name: string, path: string) {}
  92. // 是否同意
  93. function isAgree() {
  94. if (!agree.value) {
  95. ui.showToast({
  96. message: t("请先阅读并同意《用户协议》和《隐私政策》")
  97. });
  98. return false;
  99. }
  100. return true;
  101. }
  102. provide("isAgree", isAgree);
  103. </script>
  104. <style lang="scss" scoped>
  105. .login-item {
  106. @apply mx-2 p-2 flex items-center justify-center rounded-full bg-white border border-solid border-surface-100;
  107. &.is-dark {
  108. @apply border-surface-600 bg-surface-700;
  109. }
  110. }
  111. </style>