phone.uvue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 v-model="loginModel.username" prefix-icon="device-fill" :placeholder="t('请输入手机号')" :border="false" :pt="{
  11. className: parseClass([
  12. '!h-[45px] flex-1 !rounded-xl !px-4',
  13. [isDark, '!bg-surface-70', '!bg-white']
  14. ]),
  15. prefixIcon: {
  16. className: 'mr-1'
  17. }
  18. }"></cl-input>
  19. </view>
  20. <view class="relative flex flex-row items-center mb-5">
  21. <cl-input v-model="loginModel.password" prefix-icon="device-fill" :placeholder="t('请输入手机号')" :border="false" :pt="{
  22. className: parseClass([
  23. '!h-[45px] flex-1 !rounded-xl !px-4',
  24. [isDark, '!bg-surface-70', '!bg-white']
  25. ]),
  26. prefixIcon: {
  27. className: 'mr-1'
  28. }
  29. }"></cl-input>
  30. </view>
  31. <cl-button :pt="{
  32. className: '!h-[45px] !rounded-xl'
  33. }" :loading="loading" :disabled="disabled" @tap="toLogin">
  34. {{ t("登录") }}
  35. </cl-button>
  36. </view>
  37. </template>
  38. <script setup lang="ts">
  39. import { computed, inject, ref, type PropType, reactive } from "vue";
  40. import type { LoginForm } from "../../types";
  41. import SmsBtn from "../sms-btn.uvue";
  42. import { isDark, parseClass, request, useRefs, type Response, t, stringify } from "@/.cool";
  43. import { useUi } from "@/uni_modules/cool-ui";
  44. // import { loginApi } from "@/api/user";
  45. const props = defineProps({
  46. form: {
  47. type: Object as PropType<LoginForm>,
  48. default: () => ({})
  49. }
  50. });
  51. const loginModel = reactive({
  52. username: 'superadmin',
  53. password: '123456',
  54. randomStr: 0,
  55. grant_type: 'password',
  56. scope: 'server',
  57. loginType: 88
  58. })
  59. const emit = defineEmits(["success"]);
  60. const ui = useUi();
  61. const refs = useRefs();
  62. // 是否同意
  63. const isAgree = inject("isAgree") as () => boolean;
  64. // 是否显示验证码
  65. const showCode = ref(false);
  66. // 是否加载中
  67. const loading = ref(false);
  68. // 是否禁用
  69. const disabled = computed(() => {
  70. return props.form.phone == "" || props.form.smsCode == "";
  71. });
  72. // 登录
  73. async function toLogin() {
  74. if (!isAgree()) {
  75. return;
  76. }
  77. const { phone, smsCode } = props.form;
  78. // loading.value = true;
  79. await request<any>({
  80. url: `/oauth/token?${stringify(loginModel)}`,
  81. method: 'POST',
  82. data: loginModel
  83. })
  84. .then((res) => {
  85. emit("success", res);
  86. })
  87. .catch((err) => {
  88. ui.showToast({
  89. message: (err as Response).message!
  90. });
  91. });
  92. loading.value = false;
  93. }
  94. </script>