gaokao-year-field.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <template>
  2. <mx-form-item v-if="disabled" v-model="model.gaokaoYear" label="毕业年份" disabled/>
  3. <mx-form-item v-else prop="gaokaoYear" label="毕业年份">
  4. <uv-radio-group v-model="model.gaokaoYear" class="justify-end gap-20">
  5. <uv-radio v-for="y in gaokaoYearOptions" :label="y" :name="y"/>
  6. </uv-radio-group>
  7. </mx-form-item>
  8. </template>
  9. <script setup>
  10. import {ref, watchEffect} from 'vue'
  11. import {useInjectFormData} from "@/pages/login/components/hooks/useFormDataInjection";
  12. import {createPropDefine} from "@/utils";
  13. import {getRegisterGaokaoYears} from "@/api/login";
  14. const props = defineProps({
  15. disabled: createPropDefine(false, Boolean)
  16. })
  17. const [model] = useInjectFormData()
  18. const gaokaoYearOptions = ref([])
  19. watchEffect(async () => {
  20. if (props.disabled) return
  21. const res = await getRegisterGaokaoYears()
  22. gaokaoYearOptions.value = res.data
  23. // validate, and make gaokaoYear select the first ele as default.
  24. if (!res.data.includes(model.value.gaokaoYear)) {
  25. model.value.gaokaoYear = res.data[0]
  26. }
  27. })
  28. </script>
  29. <style scoped>
  30. </style>