login.uvue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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-2xl font-bold mt-2' }">{{ 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: 32 } }"
  22. active-icon="checkbox-circle-line"
  23. inactive-icon="checkbox-blank-circle-line"
  24. >
  25. </cl-checkbox>
  26. <cl-text :pt="{ className: '!text-sm' }" color="info">
  27. {{ t("已阅读并同意") }}
  28. </cl-text>
  29. <cl-text
  30. :pt="{ className: '!text-sm mx-1' }"
  31. @tap.stop="toDoc(t('用户协议'), 'userAgreement')"
  32. >
  33. {{ t("用户协议") }}
  34. </cl-text>
  35. <cl-text :pt="{ className: '!text-sm' }" color="info">
  36. {{ t("和") }}
  37. </cl-text>
  38. <cl-text
  39. :pt="{ className: '!text-sm mx-1' }"
  40. @tap.stop="toDoc(t('隐私政策'), 'privacyPolicy')"
  41. >
  42. {{ t("隐私政策") }}
  43. </cl-text>
  44. </view>
  45. <view class="flex flex-row justify-center mt-10 px-10">
  46. <view
  47. 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"
  48. @tap="refs.callMethod('loginWx', 'login')"
  49. >
  50. <cl-icon name="wechat-fill" :size="38" color="#00b223"></cl-icon>
  51. </view>
  52. <view
  53. 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"
  54. >
  55. <cl-icon name="apple-fill" :size="38"></cl-icon>
  56. </view>
  57. </view>
  58. </view>
  59. </cl-page>
  60. </template>
  61. <script setup lang="ts">
  62. import { config } from "@/config";
  63. import { parse, router, useRefs, useStore, type Token } from "@/cool";
  64. import { t } from "@/locale";
  65. import { provide, reactive, ref } from "vue";
  66. import type { LoginForm } from "./types";
  67. import { useUi } from "@/uni_modules/cool-ui";
  68. import LoginPhone from "./components/login/phone.uvue";
  69. import LoginWx from "./components/login/wx.uvue";
  70. const { user } = useStore();
  71. const ui = useUi();
  72. const refs = useRefs();
  73. // 表单
  74. const form = reactive<LoginForm>({
  75. phone: "18000000000",
  76. smsCode: "6666"
  77. });
  78. // 是否同意
  79. const agree = ref(false);
  80. // 登录成功
  81. function toLogin(res: any) {
  82. user.setToken(parse<Token>(res)!);
  83. router.home();
  84. }
  85. // 跳转文档
  86. function toDoc(name: string, path: string) {}
  87. // 是否同意
  88. function isAgree() {
  89. if (!agree.value) {
  90. ui.showToast({
  91. message: t("请先阅读并同意用户协议和隐私政策")
  92. });
  93. return false;
  94. }
  95. return true;
  96. }
  97. provide("isAgree", isAgree);
  98. </script>