Merge branch 'kangsun' into 'dev'

[FO] 개인정보변경 주소 지역,세부지역 셀렉트박스 계층형으로 변경

See merge request korea-research/korea-research!68
This commit is contained in:
이강선 매니저/ST
2025-06-30 07:26:29 +00:00
7 changed files with 154 additions and 74 deletions

View File

@@ -14,7 +14,7 @@ public class UpdateUserFrontCmd extends AuditCommand {
private Integer ownerAge;
private String tel;
private String phone;
private String regionMainCode;
private String regionSubCode;
private String regionDetailCode;
private String address;
}

View File

@@ -42,8 +42,8 @@ class UpdateUserController {
reqVO.getOwnerAge(),
reqVO.getTel1() + '-'+ reqVO.getTel2() + '-' + reqVO.getTel3(),
reqVO.getPhone1() + '-'+ reqVO.getPhone2() + '-' + reqVO.getPhone3(),
reqVO.getRegionMainCode(),
reqVO.getRegionSubCode(),
reqVO.getRegionDetailCode(),
reqVO.getAddress()
));

View File

@@ -1,8 +1,7 @@
package app.module.front.usecase.info.userUI.updateUserUI.adapters.web;
import app.module.core.config.application.enums.UiCodeType;
import app.module.core.config.application.util.CommonUtil;
import app.module.core.usecase.uicode.list.ports.UICodeListPortIn;
import app.module.core.usecase.uicode.toptier.ports.UICodeTopTierPortIn;
import app.module.front.usecase.info.userFront.getUserFront.ports.GetUserFrontPortIn;
import app.module.front.usecase.info.userFront.getUserFront.ports.application.domain.GetUserFrontCmd;
import jakarta.servlet.http.HttpServletRequest;
@@ -14,12 +13,9 @@ import org.springframework.web.bind.annotation.GetMapping;
@Controller
@RequiredArgsConstructor
class UpdateUserUIController {
private final UICodeListPortIn uiCodeListPortIn;
private final UICodeTopTierPortIn uiCodeTopTierPortIn;
private final GetUserFrontPortIn getUserPortIn;
@GetMapping(path = "/info/user")
String operate(Model model, HttpServletRequest request) {
@@ -28,9 +24,8 @@ class UpdateUserUIController {
return "redirect:/"; // 요청 처리 중단
}
model.addAttribute("regionMainList",uiCodeListPortIn.connect(UiCodeType.REGION_MAIN.getCode()));
model.addAttribute("regionSubList",uiCodeListPortIn.connect(UiCodeType.REGION_SUB.getCode()));
// 지역 + 세부지역 공통코드
model.addAttribute("regionSubList", uiCodeTopTierPortIn.connect("code.region.sub"));
model.addAttribute("userInfo",
getUserPortIn.operate(new GetUserFrontCmd(CommonUtil.getLoginUsername())).orElseThrow());

View File

@@ -38,12 +38,12 @@ public class UpdateUserReqVO {
private String phone3;
@NotBlank(message = "지역을 선택해주세요.")//"시/도는 필수 항목입니다.")
@Pattern(regexp = "^code\\.region\\.main\\.\\d+$", message = "지역을 선택해주세요.")//"시/도 형식이 올바르지 않습니다.")
private String regionMainCode;
@Pattern(regexp = "^code\\.region\\.sub\\.\\d+$", message = "지역을 선택해주세요.")//"시/도 형식이 올바르지 않습니다.")
private String regionSubCode;
@NotBlank(message = "세부 지역을 선택해주세요.")//"시/군/구는 필수 항목입니다.")
@Pattern(regexp = "^code\\.region\\.sub\\.\\d+$", message = "세부 지역을 선택해주세요.")//"시/군/구 형식이 올바르지 않습니다.")
private String regionSubCode;
@Pattern(regexp = "^code\\.region\\.detail\\.\\d+$", message = "세부 지역을 선택해주세요.")//"시/군/구 형식이 올바르지 않습니다.")
private String regionDetailCode;
@NotBlank(message = "전체 주소를 입력해주세요.")//"주소는 필수 항목입니다.")
@Size(max = 255, message = "전체 주소를 입력해주세요.")//"주소는 255자 이하여야 합니다.")

View File

@@ -11,8 +11,8 @@
owner_age = #{ownerAge},
tel = #{tel},
phone = #{phone},
region_main_code = #{regionMainCode},
region_sub_code = #{regionSubCode},
region_detail_code = #{regionDetailCode},
address = #{address},
<include refid="common.fields.UpdateBaseSet" />
WHERE seq = ${seq}

View File

@@ -258,4 +258,93 @@ $(function() {
$el.val($el.val().replace('.', ''));
}
})
})
})
/**
* 공통코드 기반의 2단계 셀렉트박스(부모/자식) UI를 구성하는 함수
*
* @param {Object} codeList - 공통코드 리스트 객체
* @param {string} parentSelector - 부모 셀렉트박스 셀렉터 (ex. '#regionSubCode')
* @param {string} childSelector - 자식 셀렉트박스 셀렉터 (ex. '#regionDetailCode')
* @param {string} selectedParentCode - 초기 선택할 부모 코드값 (ex. 'code.region.sub.31')
* @param {string} selectedChildCode - 초기 선택할 자식 코드값 (ex. 'code.region.detail.9')
*/
kri.form.setSelectBoxUiCode = function({
codeList,
parentSelector,
childSelector,
selectedParentCode = '',
selectedChildCode = ''
}) {
const $parent = $(parentSelector);
const $child = $(childSelector);
if (!codeList?.nodes || !$parent.length || !$child.length) return;
const renderOptions = ($el, list, selected, inputSelector) => {
let html = '';
list.forEach(item => {
const isCurrent = item.id === selected ? 'current' : '';
html += `<li class="option ${isCurrent}" data-value="${item.id}">${item.codeText}</li>`;
});
$el.html(html);
// 항목 클릭 시 hidden input에 값 반영
$el.find('li.option').off('click').on('click', function () {
const value = $(this).data('value');
const text = $(this).text();
// 표시 텍스트 업데이트
$el.closest('.component-select').find('.select-txt').text(text);
// 선택 클래스 처리
$el.find('li.option').removeClass('current');
$(this).addClass('current');
// hidden input 값 반영
$el.closest('.component-select').find('input[data-type="select"]').val(value).trigger('change');
});
};
let childSelectUI = null;
const loadChildren = (parentId, selectedChild = '') => {
if (!parentId) return;
const $childEl = document.querySelector(childSelector);
if($childEl.ui){
$childEl.ui.core.destroy();
}
const parent = codeList.nodes.find(n => n.id === parentId);
if (!parent?.nodes) return;
const $childList = $child.find('ul');
renderOptions($childList, parent.nodes, selectedChild);
childSelectUI = etUI.components.SelectBox();
childSelectUI.core.init($childEl, {})
};
// 초기 렌더링
const $parentList = $parent.find('ul');
renderOptions($parentList, codeList.nodes, selectedParentCode);
const $parentEl = document.querySelector(parentSelector);
const parentSelectUI = new etUI.components.SelectBox();
parentSelectUI.core.init($parentEl, {});
if (selectedParentCode) {
loadChildren(selectedParentCode, selectedChildCode);
}
// 부모 셀렉션 변경 시 자식 재로드
$parent.find('ul').on('click', 'li.option', function () {
const newParentCode = $(this).data('value');
loadChildren(newParentCode);
});
return {
getParentValue: () => parentSelectUI.getValue(),
getChildValue: () => childSelectUI?.getValue() ?? ''
};
}

View File

@@ -48,7 +48,7 @@
<div id="tel1Id" class="component-select bottom-sheet"
th:data-props-default="${userInfo.tel1}" data-props-type="bottomSheet">
<input type="hidden" th:field="*{tel1}" data-type="select">
<input type="hidden" name="tel1" th:field="*{tel1}" data-type="select">
<button type="button" class="select-box">
<span class="select-txt"></span>
</button>
@@ -130,15 +130,15 @@
<div class="select-group">
<div class="select-label">
<p class="label-txt">
도로명 주소
주소
<i class="ico-required-mark" role="img" aria-label="필수">*</i>
</p>
</div>
<div id="regionMainCodeId" class="component-select bottom-sheet" data-props-default="지역 선택"
<div id="regionSubCodeId" class="component-select bottom-sheet" data-props-default="지역 선택"
data-props-type="bottomSheet">
<input type="hidden" name="regionMainCode" data-type="select" th:value="${userInfo.regionMainCode}">
<input type="hidden" name="regionSubCode" data-type="select" th:value="${userInfo.regionSubCode}">
<button type="button" class="select-box">
<span class="select-txt">선택</span>
</button>
@@ -152,12 +152,12 @@
<div class="select-scroll">
<ul class="">
<th:block th:each="item : ${regionMainList}">
<li class="option" th:data-value="${item.id}"
th:text="${item.codeText}"
th:classappend="${item.id eq userInfo.regionMainCode ? 'current' : ''}">option1
</li>
</th:block>
<!-- <th:block th:each="item : ${regionMainList}">-->
<!-- <li class="option" th:data-value="${item.id}"-->
<!-- th:text="${item.codeText}"-->
<!-- th:classappend="${item.id eq userInfo.regionMainCode ? 'current' : ''}">option1-->
<!-- </li>-->
<!-- </th:block>-->
</ul>
</div>
</div>
@@ -167,29 +167,29 @@
<div class="select-group">
<div id="regionSubCodeId" class="component-select bottom-sheet"
data-props-default="세부지역 선택" data-props-type="bottomSheet">
<input type="hidden" th:field="*{regionSubCode}" data-type="select">
<div id="regionDetailCodeId" class="component-select bottom-sheet"
data-props-default="세부 지역 선택" data-props-type="bottomSheet" data-init="false">
<!-- <input type="hidden" name="regionDetailCode" data-type="select">-->
<input type="hidden" name="regionDetailCode" th:field="*{regionDetailCode}" data-type="select">
<button type="button" class="select-box">
<span class="select-txt">선택</span>
</button>
<div class="select-options">
<div class="select-header">
<p>세부지역 선택</p>
<p>세부 지역 선택</p>
<button type="button" class="select-close">
<span class="hide-txt">닫기</span>
</button>
</div>
<div class="select-scroll">
<ul class="">
<th:block th:each="item : ${regionSubList}">
<li class="option" th:data-value="${item.id}"
th:text="${item.codeText}"
th:classappend="${item.id eq userInfo.regionSubCode ? 'current' : ''}"
>option1
</li>
</th:block>
<!-- <th:block th:each="item : ${regionSubList}">-->
<!-- <li class="option" th:data-value="${item.id}"-->
<!-- th:text="${item.codeText}"-->
<!-- th:classappend="${item.id eq userInfo.regionSubCode ? 'current' : ''}"-->
<!-- >option1-->
<!-- </li>-->
<!-- </th:block>-->
</ul>
</div>
</div>
@@ -262,6 +262,21 @@
<section layout:fragment="script">
<script th:inline="javascript">
const regionList = [[${regionSubList}]];
const selectedRegionSubCode = /*[[${userInfo.regionSubCode}]]*/ '';
const selectedRegionDetailCode = /*[[${userInfo.regionDetailCode}]]*/ '';
$(document).ready(function () {
// 지역, 세부지역 셀렉트박스 세팅
ENV.select.regionSelect = kri.form.setSelectBoxUiCode({
codeList: regionList,
parentSelector: '#regionSubCodeId',
childSelector: '#regionDetailCodeId',
selectedParentCode: selectedRegionSubCode,
selectedChildCode: selectedRegionDetailCode
});
});
let ENV = {
httpUrl: {
root: /*[[#{uri.front.info.user.path}]]*/'rootUrl',
@@ -272,10 +287,9 @@
confirmPopup: null
},
select:{
select1:null,
select2:null,
select3:null,
select4:null
selectRegion: null,
selectTel:null,
selectPhone:null
},
submitted: false,
};
@@ -291,45 +305,25 @@
ENV.initialOwnerName = document.querySelector('input[name="ownerName"]').value;
},
_bindUI() {
console.log("bind")
ENV.module.confirmPopup = document.querySelector(".confirmPopup").ui;
const $select1 = document.querySelector('#regionMainCodeId');
ENV.select.select1 = new etUI.components.SelectBox();
ENV.select.select1.core.init($select1, {
selectItemCallback({selectValue, dataValue}){
document.querySelector('#regionMainCode').value = dataValue;
}
});
const $select2 = document.querySelector('#regionSubCodeId');
ENV.select.select2 = new etUI.components.SelectBox();
ENV.select.select2.core.init($select2, {
selectItemCallback({selectValue, dataValue}){
document.querySelector('#regionSubCode').value = dataValue;
}
});
const $select3 = document.querySelector('#tel1Id');
ENV.select.select3 = new etUI.components.SelectBox();
ENV.select.select3.core.init($select3, {
const $selectTel = document.querySelector('#tel1Id');
ENV.select.selectTel = new etUI.components.SelectBox();
ENV.select.selectTel.core.init($selectTel, {
selectItemCallback({selectValue, dataValue}){
document.querySelector('#tel1').value = dataValue;
}
});
const $select4 = document.querySelector('#phone1Id');
ENV.select.select4 = new etUI.components.SelectBox();
ENV.select.select4.core.init($select4, {
const $selectPhone = document.querySelector('#phone1Id');
ENV.select.selectPhone = new etUI.components.SelectBox();
ENV.select.selectPhone.core.init($selectPhone, {
selectItemCallback({selectValue, dataValue}){
document.querySelector('#phone1').value = dataValue;
}
});
// selectboxInstance1.setValue($('input[name=regionMainCode]').val());
},
confirmPopup() {
@@ -369,10 +363,10 @@
// f.regionSubCode.value = regionSubCodeIdElement.value;
// }
f.regionMainCode.value = ENV.select.select1.getValue();
f.regionSubCode.value = ENV.select.select2.getValue();
f.tel1.value = ENV.select.select3.getValue();
f.phone1.value = ENV.select.select4.getValue();
f.regionSubCode.value = ENV.select.regionSelect.getParentValue();
f.regionDetailCode.value = ENV.select.regionSelect.getChildValue();
f.tel1.value = ENV.select.selectTel.getValue();
f.phone1.value = ENV.select.selectPhone.getValue();
@@ -389,7 +383,9 @@
// 이름이 바뀐 경우만 팝업
ENV.module.confirmPopup.open();
} else {
location.href = '/info';
ajaxUtil._alert('개인정보 변경이 완료되었습니다.', null, () => {
location.href = '/info';
});
}
} else if (rstData.code === 'ERROR') {
ajaxUtil._alert('잠시 뒤에 다시 시도해 주세요.', null);