//
This commit is contained in:
parent
a27eda7124
commit
819a82cd89
@ -38,7 +38,7 @@
|
||||
:value="form.color"
|
||||
@update:data="handleColorUpdate"
|
||||
/>
|
||||
<span v-if="colorDuplicated" class="text-red-500 invalid-feedback mt-1 d-block">
|
||||
<span v-if="colorDuplicated" class="text-danger invalid-feedback mt-1 d-block">
|
||||
이미 사용 중인 컬러입니다.
|
||||
</span>
|
||||
</div>
|
||||
@ -61,8 +61,46 @@
|
||||
이미 사용 중인 전화번호입니다.
|
||||
</span>
|
||||
|
||||
<!-- 기존 비밀번호 입력 -->
|
||||
<UserFormInput title="기존 비밀번호" name="currentPw" type="password"
|
||||
:value="password.current" @update:data="password.current = $event"
|
||||
@blur="checkCurrentPassword" />
|
||||
<span v-if="passwordError" class="text-danger invalid-feedback mt-1 d-block">
|
||||
비밀번호가 일치하지 않습니다.
|
||||
</span>
|
||||
|
||||
<!-- 비밀번호 재설정 -->
|
||||
<div v-if="showResetPw">
|
||||
<UserFormInput title="새 비밀번호" name="newPw" type="password"
|
||||
:value="password.new" @update:data="password.new = $event" />
|
||||
<span v-if="password.new && password.new.length < 4"
|
||||
class="text-danger invalid-feedback mt-1 d-block">
|
||||
새 비밀번호는 최소 4자리 이상이어야 합니다.
|
||||
</span>
|
||||
<span v-if="password.new === password.current"
|
||||
class="text-danger invalid-feedback mt-1 d-block">
|
||||
기존 비밀번호와 다르게 설정해주세요.
|
||||
</span>
|
||||
|
||||
<UserFormInput title="비밀번호 확인" name="confirmPw" type="password"
|
||||
:value="password.confirm" @update:data="password.confirm = $event" />
|
||||
<span v-if="password.confirm && password.confirm !== password.new"
|
||||
class="text-danger invalid-feedback mt-1 d-block">
|
||||
새 비밀번호와 일치하지 않습니다.
|
||||
</span>
|
||||
|
||||
<div class="d-flex justify-content-end mt-2">
|
||||
<button type="button" class="btn btn-sm btn-outline-primary"
|
||||
:disabled="!canResetPassword"
|
||||
@click="handlePasswordReset">
|
||||
비밀번호 변경
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex mt-5">
|
||||
<button type="submit" class="btn btn-primary w-100" :disabled="!isChanged || phoneDuplicated || colorDuplicated">
|
||||
<button type="submit" class="btn btn-primary w-100"
|
||||
:disabled="!isChanged || phoneDuplicated || colorDuplicated">
|
||||
정보 수정
|
||||
</button>
|
||||
</div>
|
||||
@ -73,7 +111,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, computed } from 'vue';
|
||||
import { ref, computed, onMounted } from 'vue';
|
||||
import $api from '@api';
|
||||
import UserFormInput from '@c/input/UserFormInput.vue';
|
||||
import FormSelect from '@c/input/FormSelect.vue';
|
||||
@ -83,12 +121,9 @@ import { useToastStore } from '@s/toastStore';
|
||||
const toastStore = useToastStore();
|
||||
|
||||
const form = ref({
|
||||
entryDate: '',
|
||||
birth: '',
|
||||
entryDate: '', birth: '', phone: '', color: '', mbti: '',
|
||||
address: { address: '', detailAddress: '', postcode: '' },
|
||||
phone: '',
|
||||
color: '',
|
||||
mbti: ''
|
||||
id: ''
|
||||
});
|
||||
const originalData = ref({});
|
||||
const profile = ref('');
|
||||
@ -101,30 +136,34 @@ const phoneDuplicated = ref(false);
|
||||
const mbtiList = ref([]);
|
||||
const colorList = ref([]);
|
||||
|
||||
const password = ref({ current: '', new: '', confirm: '' });
|
||||
const passwordError = ref(false);
|
||||
const showResetPw = ref(false);
|
||||
|
||||
const canResetPassword = computed(() => {
|
||||
return (
|
||||
password.value.new.length >= 4 &&
|
||||
password.value.new !== password.value.current &&
|
||||
password.value.new === password.value.confirm
|
||||
);
|
||||
});
|
||||
|
||||
const isChanged = computed(() => {
|
||||
const f = form.value;
|
||||
const o = originalData.value;
|
||||
return (
|
||||
f.entryDate !== o.entryDate ||
|
||||
f.birth !== o.birth ||
|
||||
f.phone !== o.phone ||
|
||||
f.color !== o.color ||
|
||||
f.mbti !== o.mbti ||
|
||||
f.entryDate !== o.entryDate || f.birth !== o.birth || f.phone !== o.phone ||
|
||||
f.color !== o.color || f.mbti !== o.mbti || profileChanged.value ||
|
||||
f.address.address !== o.address.address ||
|
||||
f.address.detailAddress !== o.address.detailAddress ||
|
||||
f.address.postcode !== o.address.postcode ||
|
||||
profileChanged.value
|
||||
f.address.postcode !== o.address.postcode
|
||||
);
|
||||
});
|
||||
|
||||
const baseUrl = $api.defaults.baseURL.replace(/api\/$/, '');
|
||||
const defaultProfile = "img/avatars/default-Profile.jpg";
|
||||
|
||||
const getProfileImageUrl = (fileName) => {
|
||||
return fileName?.trim()
|
||||
? `${baseUrl}upload/img/profile/${fileName}?t=${Date.now()}`
|
||||
: defaultProfile;
|
||||
};
|
||||
const getProfileImageUrl = (fileName) =>
|
||||
fileName?.trim() ? `${baseUrl}upload/img/profile/${fileName}?t=${Date.now()}` : defaultProfile;
|
||||
|
||||
const profilePreviewStyle = computed(() => ({
|
||||
width: '100px',
|
||||
@ -157,108 +196,101 @@ const onlyNumber = (e) => {
|
||||
|
||||
const checkPhoneDuplicate = async () => {
|
||||
const currentPhone = form.value.phone;
|
||||
if (currentPhone === originalData.value.phone) {
|
||||
phoneDuplicated.value = false;
|
||||
return;
|
||||
}
|
||||
const res = await $api.get('/user/checkPhone', { params: { memberTel: form.value.phone } });
|
||||
phoneDuplicated.value = !res.data.data;
|
||||
phoneDuplicated.value = currentPhone !== originalData.value.phone &&
|
||||
!(await $api.get('/user/checkPhone', { params: { memberTel: currentPhone } })).data.data;
|
||||
};
|
||||
|
||||
const handleColorUpdate = async (colorVal) => {
|
||||
form.value.color = colorVal;
|
||||
if (colorVal !== originalData.value.color) {
|
||||
const res = await $api.get('/user/checkColor', {
|
||||
params: { memberCol: colorVal }
|
||||
colorDuplicated.value = colorVal !== originalData.value.color &&
|
||||
(await $api.get('/user/checkColor', { params: { memberCol: colorVal } })).data.data;
|
||||
};
|
||||
|
||||
const checkCurrentPassword = async () => {
|
||||
if (!password.value.current) return;
|
||||
const res = await $api.post('/user/checkPassword', {
|
||||
id: form.value.id,
|
||||
password: password.value.current
|
||||
});
|
||||
colorDuplicated.value = res.data.data; // true면 중복
|
||||
passwordError.value = res.data.data;
|
||||
showResetPw.value = !res.data.data;
|
||||
};
|
||||
const handlePasswordReset = async () => {
|
||||
const res = await $api.patch('/user/pwNew', {
|
||||
id: form.value.id,
|
||||
password: password.value.new
|
||||
});
|
||||
if (res.data.data) {
|
||||
toastStore.onToast('비밀번호가 변경되었습니다.', 's');
|
||||
password.value = { current: '', new: '', confirm: '' };
|
||||
showResetPw.value = false;
|
||||
passwordError.value = false;
|
||||
} else {
|
||||
colorDuplicated.value = false;
|
||||
toastStore.onToast('비밀번호 변경 실패', 'e');
|
||||
}
|
||||
};
|
||||
|
||||
const formatDate = (isoDate) => (isoDate ? isoDate.split('T')[0] : '');
|
||||
const formatDate = (isoDate) => isoDate?.split('T')[0] || '';
|
||||
|
||||
const loadInitialData = async () => {
|
||||
const userRes = await $api.get('/user/userInfo');
|
||||
const user = userRes.data.data;
|
||||
|
||||
const colorRes = await $api.get('/user/color', { params: { type: 'YON' } });
|
||||
const serverColors = colorRes.data.data.map(c => ({
|
||||
value: c.CMNCODVAL,
|
||||
label: c.CMNCODNAM
|
||||
const user = (await $api.get('/user/userInfo')).data.data;
|
||||
const serverColors = (await $api.get('/user/color', { params: { type: 'YON' } })).data.data.map(c => ({
|
||||
value: c.CMNCODVAL, label: c.CMNCODNAM
|
||||
}));
|
||||
|
||||
const matchedColor = serverColors.find(c => c.label === user.usercolor);
|
||||
const colorCode = matchedColor ? matchedColor.value : user.color;
|
||||
const exists = serverColors.some(c => c.value === colorCode);
|
||||
colorList.value = exists ? serverColors : [{ value: colorCode, label: user.usercolor }, ...serverColors];
|
||||
colorList.value = serverColors.some(c => c.value === colorCode)
|
||||
? serverColors
|
||||
: [{ value: colorCode, label: user.usercolor }, ...serverColors];
|
||||
|
||||
const initData = {
|
||||
id: user.loginId,
|
||||
entryDate: formatDate(user.isCdt),
|
||||
birth: formatDate(user.birth),
|
||||
phone: user.phone || '',
|
||||
color: colorCode,
|
||||
mbti: user.mbit || '',
|
||||
address: {
|
||||
address: user.address || '',
|
||||
detailAddress: user.addressDetail || '',
|
||||
postcode: user.zipcode || ''
|
||||
},
|
||||
phone: user.phone || '',
|
||||
color: colorCode,
|
||||
mbti: user.mbit || ''
|
||||
}
|
||||
};
|
||||
|
||||
form.value = { ...initData };
|
||||
originalData.value = { ...initData };
|
||||
|
||||
profile.value = getProfileImageUrl(user.profile);
|
||||
profileChanged.value = false;
|
||||
|
||||
const mbtiRes = await $api.get('/user/mbti');
|
||||
mbtiList.value = mbtiRes.data.data.map(m => ({
|
||||
value: m.CMNCODVAL,
|
||||
label: m.CMNCODNAM
|
||||
}));
|
||||
mbtiList.value = mbtiRes.data.data.map(m => ({ value: m.CMNCODVAL, label: m.CMNCODNAM }));
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
const formData = new FormData();
|
||||
formData.append('entryDate', form.value.entryDate);
|
||||
formData.append('birth', form.value.birth);
|
||||
formData.append('phone', form.value.phone);
|
||||
formData.append('color', form.value.color);
|
||||
formData.append('mbti', form.value.mbti);
|
||||
formData.append('address', form.value.address.address);
|
||||
formData.append('detailAddress', form.value.address.detailAddress);
|
||||
formData.append('postcode', form.value.address.postcode);
|
||||
Object.entries(form.value).forEach(([k, v]) => {
|
||||
if (typeof v === 'object') {
|
||||
formData.append('address', v.address);
|
||||
formData.append('detailAddress', v.detailAddress);
|
||||
formData.append('postcode', v.postcode);
|
||||
} else {
|
||||
formData.append(k, v);
|
||||
}
|
||||
});
|
||||
if (uploadedFile.value) formData.append('profileFile', uploadedFile.value);
|
||||
|
||||
// 컬러 변경 시 업데이트
|
||||
if (form.value.color !== originalData.value.color) {
|
||||
if (form.value.color) {
|
||||
await $api.patch('/user/updateColorYon', {
|
||||
color: form.value.color,
|
||||
type: 'YON'
|
||||
});
|
||||
}
|
||||
if (originalData.value.color) {
|
||||
await $api.patch('/user/updateColorChange', {
|
||||
color: originalData.value.color,
|
||||
type: 'YON'
|
||||
});
|
||||
}
|
||||
if (form.value.color) await $api.patch('/user/updateColorYon', { color: form.value.color, type: 'YON' });
|
||||
if (originalData.value.color) await $api.patch('/user/updateColorChange', { color: originalData.value.color, type: 'YON' });
|
||||
}
|
||||
|
||||
await $api.patch('/user/updateInfo', formData, { isFormData: true });
|
||||
|
||||
originalData.value = { ...form.value };
|
||||
profileChanged.value = false;
|
||||
location.reload();
|
||||
toastStore.onToast('정보가 수정되었습니다.', 's');
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
loadInitialData();
|
||||
});
|
||||
onMounted(() => loadInitialData());
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user