login.uvue 3.0 KB

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