login.uvue 3.1 KB

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