0
0
Fork 0
salix-front-mindshore-fork2/src/App.vue

91 lines
2.0 KiB
Vue
Raw Normal View History

2022-03-24 14:02:30 +00:00
<script setup>
import axios from 'axios';
2022-03-24 14:02:30 +00:00
import { useQuasar } from 'quasar';
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import { useSession } from 'src/composables/useSession';
2022-03-24 14:02:30 +00:00
const quasar = useQuasar();
const router = useRouter();
const session = useSession();
const { t } = useI18n();
const { isLoggedIn } = session;
2022-03-24 14:02:30 +00:00
quasar.iconMapFn = (iconName) => {
if (iconName.startsWith('vn:')) {
const name = iconName.substring(3);
return {
cls: `icon-${name}`,
};
}
};
function responseError(error) {
let message = error.message;
let logOut = false;
switch (error.response?.status) {
case 401:
message = 'login.loginError';
if (isLoggedIn()) {
message = 'errors.statusUnauthorized';
logOut = true;
}
break;
case 403:
message = 'errors.statusUnauthorized';
break;
case 500:
message = 'errors.statusInternalServerError';
break;
case 502:
message = 'errors.statusBadGateway';
break;
case 504:
message = 'errors.statusGatewayTimeout';
break;
}
let translatedMessage = t(message);
if (!translatedMessage) translatedMessage = message;
quasar.notify({
message: translatedMessage,
type: 'negative',
});
if (logOut) {
session.destroy();
router.push({ path: '/login' });
}
2022-08-08 10:15:54 +00:00
return Promise.resolve(error);
}
2022-10-18 12:58:41 +00:00
axios.interceptors.response.use((response) => {
const { method } = response.config;
const isSaveRequest = method === 'post' || method === 'patch';
if (isSaveRequest) {
quasar.notify({
message: t('globals.dataSaved'),
type: 'positive',
icon: 'check',
});
}
return response;
}, responseError);
2022-03-24 14:02:30 +00:00
</script>
2022-03-24 12:33:14 +00:00
<template>
2022-03-24 13:57:11 +00:00
<router-view />
2022-03-24 12:33:14 +00:00
</template>
2022-03-24 14:02:30 +00:00
<style lang="scss">
.body--light {
background-color: #eee;
}
</style>