phone.uvue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <view class="flex flex-col mb-5">
  3. <cl-text :size="18" :pt="{ className: 'font-bold' }">{{ t("您好,欢迎登录!") }}</cl-text>
  4. <cl-text :pt="{ className: 'mt-2' }" color="info">{{
  5. t("首次登录将自动为您完成注册")
  6. }}</cl-text>
  7. </view>
  8. <view class="flex flex-col">
  9. <view class="mb-3 flex flex-row">
  10. <cl-input
  11. v-model="loginModel.username"
  12. prefix-icon="device-fill"
  13. :placeholder="t('请输入手机号')"
  14. :border="false"
  15. :pt="{
  16. className: parseClass([
  17. '!h-[45px] flex-1 !rounded-xl !px-4',
  18. [isDark, '!bg-surface-70', '!bg-white']
  19. ]),
  20. prefixIcon: {
  21. className: 'mr-1'
  22. }
  23. }"
  24. ></cl-input>
  25. </view>
  26. <view class="relative flex flex-row items-center mb-5">
  27. <cl-input
  28. v-model="loginModel.password"
  29. :clearable="false"
  30. type="number"
  31. prefix-icon="shield-check-fill"
  32. :border="false"
  33. :pt="{
  34. className: parseClass([
  35. '!h-[45px] flex-1 !rounded-xl !px-4',
  36. [isDark, '!bg-surface-70', '!bg-white']
  37. ]),
  38. prefixIcon: {
  39. className: 'mr-1'
  40. }
  41. }"
  42. >
  43. </cl-input>
  44. </view>
  45. <cl-button
  46. :loading="loading"
  47. :disabled="disabled"
  48. @tap="toLogin"
  49. >
  50. {{ t("登录") }}
  51. </cl-button>
  52. </view>
  53. </template>
  54. <script setup lang="ts">
  55. import { computed, inject,reactive, ref, type PropType } from "vue";
  56. import type { LoginForm } from "../../types";
  57. import SmsBtn from "../sms-btn.uvue";
  58. import { isDark, parseClass, request, useRefs, type Response, t, stringify } from "@/.cool";
  59. import { useUi } from "@/uni_modules/cool-ui";
  60. type LoginModal = {
  61. username: string;
  62. password: string;
  63. randomStr: number;
  64. grant_type: string;
  65. scope: string;
  66. loginType: number;
  67. };
  68. const props = defineProps({
  69. form: {
  70. type: Object as PropType<LoginForm>,
  71. default: () => ({})
  72. }
  73. });
  74. const loginModel = reactive<LoginModal>({
  75. username: 'gg',
  76. password: '123456',
  77. randomStr: 0,
  78. grant_type: 'password',
  79. scope: 'server',
  80. loginType: 88
  81. })
  82. const emit = defineEmits(["success"]);
  83. const ui = useUi();
  84. const refs = useRefs();
  85. // 是否同意
  86. const isAgree = inject("isAgree") as () => boolean;
  87. // 是否显示验证码
  88. const showCode = ref(false);
  89. // 是否加载中
  90. const loading = ref(false);
  91. // 是否禁用
  92. const disabled = computed(() => {
  93. return props.form.phone == "" || props.form.smsCode == "";
  94. });
  95. // 登录
  96. async function toLogin() {
  97. if (!isAgree()) {
  98. return;
  99. }
  100. const { phone, smsCode } = props.form;
  101. const loginData = JSON.parse(JSON.stringify(loginModel)) as UTSJSONObject;
  102. await request({
  103. url: `/oauth/token?${stringify(loginData)}`,
  104. method: 'POST',
  105. data: loginData
  106. })
  107. .then((res) => {
  108. emit("success", res);
  109. })
  110. .catch((err) => {
  111. ui.showToast({
  112. message: (err as Response).message!
  113. });
  114. });
  115. loading.value = false;
  116. }
  117. </script>