import store from '../../views/pages/AppStore' import { findCodesProc } from '../api/code' 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.$formattedDate = (d, h, m) => { if (Vue.config.globalProperties.$isEmpty(d) || Vue.config.globalProperties.$isEmpty(h) || Vue.config.globalProperties.$isEmpty(m)) { return; } let day = d.split(' ')[0]; let hour = h.toString().padStart(2, '0'); let minute = m.toString().padStart(2, '0'); return day + " " + hour + ":" + minute } // 기간 형식 변경 Vue.config.globalProperties.$formattedDates = (item) => { const startDate = Vue.config.globalProperties.$formattedDate(item.bgnde, item.beginHour, item.beginMnt); const endDate = Vue.config.globalProperties.$formattedDate(item.endde, item.endHour, item.endMnt); return startDate + " ~ " + endDate; } // 공통코드 조회 Vue.config.globalProperties.$findCodeList = async function (serachRequest) { try { const response = await findCodesProc(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.$findChildCodes = async (upperCode) => { try { const searchRequest = { searchType: 'UPPER_CODE', searchText: upperCode, }; const response = await findCodesProc(searchRequest); const result = response.data.data; return result.codes; } catch (error) { console.error(`코드 조회 실패 (${upperCode}):`, error); return []; } }; // 휴가 및 출장 구분 코드 조회 Vue.config.globalProperties.$sanctnIemCodes = async () => { const lists = []; // 휴가 구분 (연차, 반차, 공가 등) const vcatnTopCodes = await Vue.config.globalProperties.$findChildCodes('sanctn_mby_vcatn'); for (let vcatnTopCode of vcatnTopCodes) { const vcatnMidCodes = await Vue.config.globalProperties.$findChildCodes(vcatnTopCode.code); for (let vcatnMidCode of vcatnMidCodes) { if (parseFloat(vcatnMidCode.codeValue) === 0.5) { const codes = await Vue.config.globalProperties.$findChildCodes(vcatnMidCode.code); lists.push(...codes); } else { lists.push(vcatnMidCode); } } } // 출장 구분 (품의서, 복명서) const bsrpCodes = await Vue.config.globalProperties.$findChildCodes('bsrp_code'); lists.push(...bsrpCodes); return lists; }; // 기본 코드 목록 초기화 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; }; }, }