phone copy.uvue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 @tap="toLogin">
  32. 登录
  33. </cl-button>
  34. </view>
  35. </template>
  36. <script setup lang="ts">
  37. import { computed, inject,reactive, ref, type PropType } from "vue";
  38. import type { LoginForm } from "../../types";
  39. import SmsBtn from "../sms-btn.uvue";
  40. import { isDark, parseClass, request, useRefs, type Response, t, stringify } from "@/.cool";
  41. import { useUi } from "@/uni_modules/cool-ui";
  42. // import { loginApi } from "@/api/user";
  43. const props = defineProps({
  44. form: {
  45. type: Object as PropType<LoginForm>,
  46. default: () => ({})
  47. }
  48. });
  49. const loginModel = reactive({
  50. username: 'superadmin',
  51. password: '123456',
  52. randomStr: 0,
  53. grant_type: 'password',
  54. scope: 'server',
  55. loginType: 88
  56. })
  57. const emit = defineEmits(["success"]);
  58. const ui = useUi();
  59. const refs = useRefs();
  60. // 是否同意
  61. const isAgree = inject("isAgree") as () => boolean;
  62. // 是否显示验证码
  63. const showCode = ref(false);
  64. // 是否加载中
  65. const loading = ref(false);
  66. // 是否禁用
  67. const disabled = computed(() => {
  68. return props.form.phone == "" || props.form.smsCode == "";
  69. });
  70. // 登录
  71. async function toLogin() {
  72. if (!isAgree()) {
  73. return;
  74. }
  75. // loading.value = true;
  76. await request({
  77. url: `/oauth/token?${stringify(loginModel)}`,
  78. method: 'POST',
  79. data: loginModel
  80. })
  81. .then((res) => {
  82. emit("success", res);
  83. })
  84. .catch((err) => {
  85. ui.showToast({
  86. message: (err as Response).message!
  87. });
  88. });
  89. loading.value = false;
  90. }
  91. </script>