login.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <FlexCol gap="gap.xl" padding="space.lg">
  3. <FlexCol center>
  4. <Text fontConfig="h2">传承人登录</Text>
  5. <Text fontConfig="subText">欢迎使用非遗数字化资源信息校对系统</Text>
  6. </FlexCol>
  7. <FlexCol radius="radius.md" backgroundColor="white" overflow="hidden">
  8. <DynamicForm
  9. ref="formRef"
  10. :model="formModel"
  11. :options="formDefine"
  12. />
  13. </FlexCol>
  14. <FlexCol gap="gap.md">
  15. <Button type="primary" block :loading="loading" @click="handleSubmit">
  16. 登录
  17. </Button>
  18. <Button block @click="back()">
  19. 返回
  20. </Button>
  21. </FlexCol>
  22. <XBarSpace />
  23. </FlexCol>
  24. </template>
  25. <script setup lang="ts">
  26. import { onMounted, ref } from 'vue';
  27. import { useAuthStore } from '@/store/auth';
  28. import { showError } from '@/common/composeabe/ErrorDisplay';
  29. import { toast } from '@/components/utils/DialogAction';
  30. import Button from '@/components/basic/Button.vue';
  31. import XBarSpace from '@/components/layout/space/XBarSpace.vue';
  32. import DynamicForm from '@/components/dynamic/DynamicForm.vue';
  33. import type { IDynamicFormOptions, IDynamicFormRef } from '@/components/dynamic';
  34. import type { FormProps } from '@/components/form/Form.vue';
  35. import type { RadioValueProps } from '@/components/dynamic/wrappers/RadioValue';
  36. import { back, redirectTo } from '@/components/utils/PageAction';
  37. import FlexCol from '@/components/layout/FlexCol.vue';
  38. import FlexRow from '@/components/layout/FlexRow.vue';
  39. import Text from '@/components/basic/Text.vue';
  40. const authStore = useAuthStore();
  41. const formRef = ref<IDynamicFormRef>();
  42. const loading = ref(false);
  43. const formModel = ref({
  44. mobile: '',
  45. account: '',
  46. password: '',
  47. type: 0,
  48. });
  49. const formDefine: IDynamicFormOptions = {
  50. formAdditionaProps: {
  51. labelFlex: 4,
  52. inputFlex: 8,
  53. } as FormProps,
  54. formRules: {
  55. mobile: [{ required: true, message: '请输入账号' }],
  56. account: [{ required: true, message: '请输入账号' }],
  57. password: [{ required: true, message: '请输入密码' }],
  58. },
  59. formItems: [
  60. {
  61. label: '账号',
  62. name: 'mobile',
  63. type: 'text',
  64. defaultValue: '',
  65. show: { callback: (_, m) => (m as { type: number }).type === 0 },
  66. additionalProps: {
  67. placeholder: '请输入账号',
  68. },
  69. },
  70. {
  71. label: '账号',
  72. name: 'account',
  73. type: 'text',
  74. defaultValue: '',
  75. show: { callback: (_, m) => (m as { type: number }).type === 1 },
  76. additionalProps: {
  77. placeholder: '请输入账号',
  78. },
  79. },
  80. {
  81. label: '密码',
  82. name: 'password',
  83. type: 'text',
  84. defaultValue: '',
  85. formProps: {
  86. type: 'password',
  87. },
  88. additionalProps: {
  89. placeholder: '请输入密码',
  90. },
  91. },
  92. /* {
  93. label: '登录类型',
  94. name: 'type',
  95. type: 'radio-value',
  96. defaultValue: 0,
  97. additionalProps: {
  98. options: [
  99. { text: '传承人', value: 0 },
  100. { text: '管理员', value: 1 },
  101. ],
  102. } as RadioValueProps,
  103. }, */
  104. ],
  105. };
  106. async function handleSubmit() {
  107. if (!formRef.value)
  108. return;
  109. try {
  110. await formRef.value.validate();
  111. } catch {
  112. uni.showToast({
  113. title: '有必填项未填写,请检查',
  114. icon: 'none',
  115. });
  116. return;
  117. }
  118. const loginType = Number(formModel.value.type);
  119. const account =
  120. loginType === 1
  121. ? formModel.value.account.trim()
  122. : formModel.value.mobile.trim();
  123. if (!account) {
  124. uni.showToast({
  125. title: '请输入账号',
  126. icon: 'none',
  127. });
  128. return;
  129. }
  130. loading.value = true;
  131. try {
  132. await authStore.loginCollect(account, formModel.value.password, loginType);
  133. toast('您已成功登录');
  134. await new Promise((r) => setTimeout(r, 200));
  135. if (authStore.loginType === 0) {
  136. uni.redirectTo({ url: '/pages/collect/inheritor' });
  137. } else {
  138. uni.switchTab({ url: '/pages/user/index' });
  139. }
  140. } catch (e) {
  141. showError(e);
  142. } finally {
  143. loading.value = false;
  144. }
  145. }
  146. onMounted(() => {
  147. if (authStore.isLogged && authStore.isCollect) {
  148. redirectTo('/pages/collect/inheritor');
  149. }
  150. });
  151. </script>
  152. <style lang="scss">
  153. </style>