index.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <div>
  3. <a-modal
  4. v-model:visible="visible"
  5. :title="$t('navbar.check.info')"
  6. @cancel="() => handleCancel()"
  7. @before-ok="handleBeforeOk"
  8. >
  9. <a-form :model="form">
  10. <a-form-item field="name" label="ID">
  11. <a-input v-model="form.id" placeholder="ID" />
  12. </a-form-item>
  13. </a-form>
  14. </a-modal>
  15. </div>
  16. </template>
  17. <script setup lang="ts" name="CheckInPage">
  18. import { reactive, ref, shallowRef, watch, getCurrentInstance } from 'vue';
  19. import { fetchCheckIn } from '@/api/record';
  20. import dayjs from 'dayjs';
  21. const this_ = getCurrentInstance()?.appContext.config.globalProperties;
  22. interface CheckIn {
  23. id: string;
  24. time: string;
  25. }
  26. interface CheckInPageProps {
  27. modelValue: boolean;
  28. }
  29. interface CheckInPageEmits {
  30. (e: 'update:modelValue', value: boolean): void;
  31. }
  32. const props = withDefaults(defineProps<CheckInPageProps>(), {
  33. modelValue: false,
  34. });
  35. const emit = defineEmits<CheckInPageEmits>();
  36. const visible = shallowRef<boolean>(false);
  37. watch(
  38. () => props.modelValue,
  39. value => {
  40. visible.value = value;
  41. }
  42. );
  43. const form = ref<CheckIn>({
  44. id: '',
  45. time: '',
  46. });
  47. const handleBeforeOk = (done: (closed: boolean) => void) => {
  48. form.value.time = dayjs().format('YYYY-MM-DD HH:mm:ss');
  49. fetchCheckIn(form.value)
  50. .then(res => {
  51. this_?.$message.success('签到成功');
  52. done(true); // 关闭模态框
  53. handleCancel();
  54. })
  55. .catch(() => {
  56. done(false); // 不关闭模态框(例如提交失败时)
  57. });
  58. };
  59. const handleCancel = () => {
  60. form.value = {
  61. id: '',
  62. time: '',
  63. };
  64. visible.value = false;
  65. emit('update:modelValue', false);
  66. };
  67. </script>