Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | <template> <v-container class="py-6" fluid> <h2>{{ t('ui.page.profile.address.title') }}</h2> <p>履歴書・職務経歴書に記載する現住所・連絡先、メアドや電話番号、ポートフォリオ(url)、最寄り駅の網羅を目的とする</p> <v-form @submit.prevent="onSubmit"> <v-row> <v-col cols="12"> <v-alert v-if="serverGeneralError" type="error" variant="tonal" class="mb-4"> {{ serverGeneralError }} </v-alert> </v-col> <v-col cols="12" md="6"> <!-- 目的 --> <RequiredSelect v-bind="fPurposeId" :items="purposeOptions" component="v-select" :label="L.purposeId" :label-key="L.purposeId" variant="underlined" required /> </v-col> <v-col cols="12" md="6"> <!-- 国コード --> <RequiredSelect v-bind="fCountryCode" :items="countryOptions" component="v-select" :label="L.countryCode" :label-ket="L.countryCode" variant="underlined" required /> </v-col> <v-col cols="12" md="6"> <!-- 都道府県 --> <RequiredInput v-bind="fAdministrativeArea" :label="L.administrativeArea" :label-key="L.administrativeArea" :placeholder="PH.administrativeArea" variant="underlined" required /> </v-col> <v-col cols="12" md="6"> <!-- 市区町村 --> <RequiredInput v-bind="fLocality" :label="L.locality" :label-key="L.locality" :placeholder="PH.locality" variant="underlined" /> </v-col> <v-col cols="12" md="6"> <!-- 丁目・番地 --> <RequiredInput v-bind="fDependentLocality" :label="L.dependentLocality" :label-key="L.dependentLocality" :placeholder="PH.dependentLocality" variant="underlined" /> </v-col> <v-col cols="12" md="6"> <!-- 郵便番号 --> <RequiredInput v-bind="fPostalCode" :label="L.postalCode" :label-key="L.postalCode" :placeholder="PH.postalCode" variant="underlined" required /> </v-col> <v-col cols="12" md="6"> <!-- 住所1/2/3 --> <RequiredInput v-bind="fAddressLine1" :label="L.addressLine1" :label-key="L.addressLine1" :placeholder="PH.addressLine1" variant="underlined" required /> <RequiredInput v-bind="fAddressLine2" :label="L.addressLine2" :label-key="L.addressLine2" :placeholder="PH.addressLine2" variant="underlined" /> <RequiredInput v-bind="fAddressLine3" :label="L.addressLine3" :label-key="L.addressLine3" :placeholder="PH.addressLine3" variant="underlined" /> </v-col> <v-col cols="12" md="6" class=" grid-cols-2 gap-4"> <!-- 緯度/経度 --> <RequiredNumber v-bind="fLatitude" :label="L.latitude" :label-key="L.latitude" :placeholder="PH.latitude" variant="underlined" /> <RequiredNumber v-bind="fLongitude" :label="L.longitude" :label-key="L.longitude" :placeholder="PH.longitude" variant="underlined" /> </v-col> <v-col cols="12" md="6" class="flex items-center gap-3 mt-2"> <v-btn type="submit" :loading="isSubmitting" :disabled="isSubmitting" variant="flat"> {{ t('ui.component.atom.button.add.simple') }} </v-btn> <v-btn type="button" :disabled="isSubmitting" variant="outlined" @click="resetForm()"> {{ t('ui.component.atom.button.reset.simple') }} </v-btn> </v-col> </v-row> </v-form> </v-container> </template> <script setup lang="ts"> // region Dependency Injection import {computed, onMounted, ref} from 'vue' import {useI18n} from 'vue-i18n' import {useForm} from 'vee-validate' // import {z} from 'zod' // import {toTypedSchema} from '@vee-validate/zod' import {useApi} from '@/composables/useApi' import {useVuetifyField} from '@/libs/vee/bindV' import logger from "@/libs/logger/logger"; import {withLoading} from "@/libs/loading"; // import {emptyToNull} from '@/utils' import { setErrorsFrom422 } from '@/libs/vee/backendErrors' import { makeFieldCatalog, type TFunc } from '@/libs/vee/fieldCatalog' import { makeAddressSchema, type AddressForm } from '@/validation/addressSchema'; // endregion Dependency Injection // region Component Injection import RequiredSelect from "@/components/atoms/RequiredSelect.vue"; import RequiredInput from "@/components/atoms/RequiredInput.vue"; import RequiredNumber from "@/components/atoms/RequiredNumber.vue"; // endregion Component Injection // region interface type PurposeAPIOption = { code: string; id: number; label: string; value: number } type CountryAPICountry = { label: string; value: string } type PurposeOption = { label: string; value: number } type CountryOption = { label: string; value: string } // endregion interface // region constants const api = useApi() const { t } = useI18n() const purposeOptions = ref<PurposeOption[]>([]) const countryOptions = ref<CountryOption[]>([]) // Address の名前配列を定義(単一ソース) // as const を付けると型がキレイに絞れます const ADDRESS_NAMES = [ 'purposeId', 'countryCode', 'administrativeArea', 'locality', 'dependentLocality', 'postalCode', 'addressLine1', 'addressLine2', 'addressLine3', 'latitude', 'longitude', ] as const type AddressFieldName = typeof ADDRESS_NAMES[number] const tf: TFunc = (key, params) => t(key, params) // ← “t を上書きしない”ための薄いラッパ // 取得に labelKeyOf を含める const { L, PH, labelKeyOf, phKeyOf, resolveField, msgFromCode } = makeFieldCatalog<AddressFieldName>({ baseKey: 'domain.address', names: ADDRESS_NAMES, t: tf, rulesDefaultBranch: 'string', // 任意(既定 'string') }) // endregion constants // region props // endregion props // region variable // endregion variable // region properties // endregion properties // region emits // endregion emits // region validator // endregion validator // region methods const schema = makeAddressSchema(tf, L); const { handleSubmit, resetForm, setErrors, setFieldTouched, submitCount, // ← これを Vuetify ヘルパに渡す isSubmitting, } = useForm<AddressForm>({ validationSchema: schema, initialValues: { purposeId: undefined, // countryCode: 'JP', countryCode: undefined, administrativeArea: '', locality: '', dependentLocality: '', postalCode: '', addressLine1: '', addressLine2: '', addressLine3: '', latitude: undefined as number | undefined, longitude: undefined as number | undefined, }, }) // const submitCount = formSubmitCnt ?? computed(() => (meta.value as any)?.submitCount ?? 0) /* ========= 8) 送信 ========= */ const serverGeneralError = computed<string | null>({ get: () => null, set: () => {}, }) // 今は使わないが枠だけ残す // const touch = (name: string, isTouched: boolean) => { // setFieldTouched(name as keyof AddressForm, isTouched) // } /* ========= 10) フィールドバインド ========= */ const fPurposeId = useVuetifyField<number>('purposeId', submitCount, { emptyToNull: true, toNumber: true }) const fCountryCode = useVuetifyField<string>('countryCode', submitCount, { emptyToNull: true }) const fAdministrativeArea = useVuetifyField<string>('administrativeArea', submitCount) const fLocality = useVuetifyField<string>('locality', submitCount) const fDependentLocality = useVuetifyField<string>('dependentLocality', submitCount) const fPostalCode = useVuetifyField<string>('postalCode', submitCount) const fAddressLine1 = useVuetifyField<string>('addressLine1', submitCount) const fAddressLine2 = useVuetifyField<string>('addressLine2', submitCount) const fAddressLine3 = useVuetifyField<string>('addressLine3', submitCount) const fLatitude = useVuetifyField<number>('latitude', submitCount, { emptyToNull: true, toNumber: true }) const fLongitude = useVuetifyField<number>('longitude', submitCount, { emptyToNull: true, toNumber: true }) const onSubmit = handleSubmit(async (values) => { try { const payload = { ...values } Object.keys(payload).forEach(k => (payload as any)[k] === undefined && delete (payload as any)[k]) await withLoading( () => api.post('/fl/address', payload), 'address:onSubmit' ) resetForm() serverGeneralError.value = null } catch (e: any) { const ok = setErrorsFrom422<AddressFieldName>(e, { setErrors, setTouched: (n, v) => setFieldTouched(n as any, v), resolveField, msgFromCode, fieldLabelKeyOf: labelKeyOf, // そのまま渡せる }) if (!ok) { // 422 以外 or 想定外エラー時 serverGeneralError.value = e?.response?.data?.error?.message ?? e.message ?? t('validation.unknown') console.error(e) } } }) async function getPurpose() { try { const response = await api.get('/option/address/purpose', { params: { // lang: String(locale.value), } }) const p = (response?.data?.options ?? []) as PurposeAPIOption[] purposeOptions.value = p.map(o => ({ label: o.label, value: o.value })) // return response } catch (e) { logger.error(`error : ${JSON.stringify(e)}`) } } async function getCountry() { try { const response = await api.get('/option/address/countries', { params: { // lang: String(locale.value), // onlySupported: false, } }) const c = (response?.data?.countries ?? []) as CountryAPICountry[] countryOptions.value = c.map(x => ({ label: x.label, value: x.value })) // return response } catch (e) { logger.error(`error : ${JSON.stringify(e)}`) } } onMounted(async () => { const [] = await withLoading(() => { return Promise.all([ getPurpose(), getCountry(), ]) }, 'address:onMounted') }) // endregion methods // region export // endregion export </script> <style scoped> </style> |