
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
import store from '../../views/pages/AppStore'
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;
}
}
/**
* FROM: 2025-03-25 13:32
* TO : 2025.03.25
*/
Vue.config.globalProperties.$dotFormatDate = (dateString) => {
if (!dateString) return '';
const dateOnly = dateString.split(' ')[0];
return dateOnly.replace(/-/g, '.');
}
// 정규식을 사용하여 모든 HTML 태그 제거
Vue.config.globalProperties.$stripHtml = (html) => {
if (!html) return '';
// 환경 확인 (브라우저 vs 서버)
if (typeof window !== 'undefined' && window.DOMParser) {
try {
// 브라우저 환경에서는 DOMParser 사용
const doc = new DOMParser().parseFromString(html, 'text/html');
return doc.body.textContent || '';
} catch (e) {
// DOMParser 실패시 정규식 방식으로 폴백
console.warn('DOMParser failed, falling back to regex', e);
}
}
// 서버 환경이거나 DOMParser 실패 시 정규식 사용
let text = html.replace(/<[^>]*>/g, '');
// 일반적인 HTML 엔티티 처리
const entityMap = {
' ': ' ',
'&': '&',
'<': '<',
'>': '>',
'"': '"',
''': "'",
'—': '—',
'–': '–',
'°': '°'
};
// 정의된 엔티티 변환
Object.keys(entityMap).forEach(entity => {
const regex = new RegExp(entity, 'g');
text = text.replace(regex, entityMap[entity]);
});
// 남은 숫자 엔티티 제거 ({ 형식)
text = text.replace(/&#[0-9]+;/g, '');
// 남은 이름 있는 엔티티 제거 (… 등)
text = text.replace(/&[a-zA-Z]+;/g, '');
return text;
};
// 게시물 권한 체크
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.$processTitle = (title) => {
if (!title) return '';
return title.trim().replace(/\s+/g, ' ');
}
},
}