하석형 하석형 05-13
250513 하석형 공통코드관리 기능 동작 시 작성내역 감지 처리
@7104d803b58eb8f25e77394a06be49d33fc8b602
client/views/pages/adm/preferences/commonCodeManagement/CommonCodeManagement.vue
--- client/views/pages/adm/preferences/commonCodeManagement/CommonCodeManagement.vue
+++ client/views/pages/adm/preferences/commonCodeManagement/CommonCodeManagement.vue
@@ -84,7 +84,7 @@
                 <button :class="{
                   'btn sm': true,
                   'red': !isFormDisabled,
-                }" :disabled="isFormDisabled" @click="fnDel" v-if="pageAuth.delAuthrt == 'Y' && originCode != null">
+                }" :disabled="isFormDisabled" @click="fnDel" v-if="pageAuth.delAuthrt == 'Y' && originCode.cd != null">
                   삭제
                 </button>
             </div>
@@ -95,6 +95,7 @@
 </template>
 
 <script>
+import _ from "lodash";
 import draggable from "vuedraggable";
 import Hierachy from "../../../../component/hierachy/HierachyDraggable.vue";
 
@@ -121,8 +122,8 @@
       iconPath: 'ico_folder_3d',
       selectedCd: null, // 선택된 코드
       newCode: {}, // 신규 코드 등록
-      viewCode: {}, // 사용자에게 보여질 코드
-      originCode: null, // 변경전 코드
+      viewCode: {cd: null}, // 사용자에게 보여질 코드
+      originCode: {cd: null}, // 변경전 코드
 
       submitStts: true,
     };
@@ -153,6 +154,10 @@
       }
     },
     fnViewDetail(cd) {
+      // 내용이 변경된 경우
+      if(this.isChanged()) {
+        return;
+      }
       this.selectedCd = cd;
       this.findByCd();
     },
@@ -164,7 +169,7 @@
         const res = await findByCd(params);
         if (res.status == 200) {
           this.viewCode = res.data.data.code;
-          this.originCode = this.viewCode.cd;
+          this.originCode = _.cloneDeep(this.viewCode); // 변경전 코드
           this.submitStts = false;
         }
       } catch (error) {
@@ -182,11 +187,18 @@
         alert("시스템에서 제공하는 정보는 수정할 수 없습니다.");
         return;
       }
+
+      // 변경전 코드와 비교
+      if(_.isEqual(this.viewCode, this.originCode)) {
+        alert("변경할 내용이 없습니다.");
+        return false;
+      }
+
       // 유효성 검사
       if (this.validation() == false) {
         return false;
       }
-      this.viewCode.originCd = this.originCode;
+      this.viewCode.originCd = this.originCode.cd;
       // 신규 등록 및 수정 설정
       const action = this.viewCode.originCd ? update : save;
       try {
@@ -239,14 +251,18 @@
     },
     // 최상위 신규 객체 생성
     topAdd() {
-      if (this.selectedCd != null) {
-        if (!confirm("작성 중인 공통코드정보는 저장되지 않습니다.\n계속 하시겠습니까?")) {
-          return;
-        }
+      // 내용이 변경된 경우
+      if(this.isChanged()) {
+        return;
       }
+      // if (this.selectedCd != null) {
+      //   if (!confirm("작성 중인 공통코드정보는 저장되지 않습니다.\n계속 하시겠습니까?")) {
+      //     return;
+      //   }
+      // }
       this.selectedCd = null; // 선택된 코드 초기화
-      this.viewCode = JSON.parse(JSON.stringify(this.newCode));
-      this.originCode = this.viewCode.cd; // null
+      this.viewCode = _.cloneDeep(this.newCode);
+      this.originCode = _.cloneDeep(this.viewCode); // 변경전 코드
       this.submitStts = true;
     },
     // 하위 신규 객체 생성
@@ -256,16 +272,20 @@
         alert("상위 코드를 지정하세요.");
         return;
       } else {
-        if (!confirm("작성 중인 공통코드정보는 저장되지 않습니다.\n계속 하시겠습니까?")) {
+        // 내용이 변경된 경우
+        if(this.isChanged()) {
           return;
         }
+        // if (!confirm("작성 중인 공통코드정보는 저장되지 않습니다.\n계속 하시겠습니까?")) {
+        //   return;
+        // }
       }
       const upCd = this.viewCode.cd;
       const upCdNm = this.viewCode.cdNm;
-      this.viewCode = JSON.parse(JSON.stringify(this.newCode));
+      this.viewCode = _.cloneDeep(this.newCode);
       this.viewCode.upCd = upCd;
       this.viewCode.upCdNm = upCdNm;
-      this.originCode = null;
+      this.originCode = _.cloneDeep(this.viewCode); // 변경전 코드
       this.submitStts = true;
     },
     validation() {
@@ -289,7 +309,8 @@
     // axios: 목록 수정
     async fnListUpdate() {
       try {
-        if (!confirm("공통코드 목록을 저장하시겠습니까?\n 작성 중인 공통코드정보는 저장되지 않습니다.")) {
+        // 내용이 변경된 경우
+        if(this.isChanged()) {
           return;
         }
         const res = await updateListProc(this.codeList);
@@ -307,6 +328,16 @@
         }
       }
     },
+
+    // 변경 감지
+    isChanged() {
+      if(!_.isEqual(this.viewCode, this.originCode)) {
+        if (!confirm("작성 중인 공통코드정보는 저장되지 않습니다.\n계속 하시겠습니까?")) {
+          return true;
+        }
+      }
+      return false;
+    }
   },
   watch: {},
   computed: {
Add a comment
List