import store from '../../views/pages/AppStore' import { findCodeListProc } from '../api/cmmnCode' export default { install(Vue) { // 빈값체크 Vue.config.globalProperties.$isEmpty = function (data) { if (data === undefined || data === null || data === "" || data.length === 0 || (data.constructor == Object && Object.keys(data).length === 0)) { if ((typeof data) === "number") { return false } else { return true; } } else { return false; } } // 게시물 권한 체크 Vue.config.globalProperties.$registerChk = (register) => { // 사용자 권한 확인 const roles = store.state.roles; if (roles != null && roles.length > 0) { for (let role of roles) { if (role.authority === 'ROLE_ADMIN') { return true; // 관리자인 경우 true 반환 } } } // 관리자가 아닌 경우 작성자 확인 const userId = store.state.userId; if (register === userId) { return true; // 작성자인 경우 true 반환 } else { return false; // 작성자가 아닌 경우 false 반환 } } // 공통코드 조회 Vue.config.globalProperties.$findCodeList = async function (serachRequest) { try { const response = await findCodeListProc(serachRequest); const result = response.data.data; return result.codeList; } catch (error) { if (error.response) { alert(error.response.data.message); } else { alert("에러가 발생했습니다."); } console.error(error.message); throw error; } } // 날짜 형식 변경 Vue.config.globalProperties.$formattedDate = (day, hour, min) => { let beginHour = hour ? hour.toString().padStart(2, '0') : '00'; let beginMnt = min ? min.toString().padStart(2, '0') : '00'; return day.split(' ')[0] + " " + beginHour + ":" + beginMnt } // 공통코드 조회 (부모 코드로 자식 코드 조회) Vue.config.globalProperties.$findChildCodes = async (upperCode) => { try { const searchRequest = { searchType: 'upperCd', searchText: upperCode, }; const codes = await Vue.config.globalProperties.$findCodeList(searchRequest); return Array.isArray(codes) ? codes : []; } catch (error) { console.error(`코드 조회 실패 (${upperCode}):`, error); return []; } }; // 기본 코드 목록 초기화 Vue.config.globalProperties.$defaultCodes = async () => { const codeGroups = { vcatnKndCodeList: [], // 휴가 종류 (연차/반차) bsrpCodeList: [], // 출장 종류 (해외/국내) sanctnCodeList: [], // 결재 구분 (결재/대결/전결) confmCodeList: [], // 상태 코드 (대기/결재대기/승인/반려) clsfCodeList: [], // 직급 코드 (사원/주임/대리) rspofcCodeList: [], // 직책 코드 (사원/주임/대리) }; // 휴가 종류 - depth 2 조회 const vcatnKndCodes = await Vue.config.globalProperties.$findChildCodes('sanctn_mby_vcatn'); for (const code of vcatnKndCodes) { const childCodes = await Vue.config.globalProperties.$findChildCodes(code.code); codeGroups.vcatnKndCodeList.push(...childCodes); } // 출장 종류 - depth 1 조회 const bsrpCodes = await Vue.config.globalProperties.$findChildCodes('sanctn_mby_bsrp'); codeGroups.bsrpCodeList.push(...bsrpCodes); // 결재 구분 - depth 1 조회 const sanctnCodes = await Vue.config.globalProperties.$findChildCodes('sanctn_code'); codeGroups.sanctnCodeList.push(...sanctnCodes); // 상태 코드 - depth 1 조회 const confmCodes = await Vue.config.globalProperties.$findChildCodes('confm_code'); codeGroups.confmCodeList.push(...confmCodes); // 직급 코드 - depth 1 조회 const clsfCodes = await Vue.config.globalProperties.$findChildCodes('clsf_code'); codeGroups.clsfCodeList.push(...clsfCodes); // 직책 코드 - depth 1 조회 const rspofcCodes = await Vue.config.globalProperties.$findChildCodes('rspofc_code'); codeGroups.rspofcCodeList.push(...rspofcCodes); return codeGroups; }; }, }