salix-front/src/composables/usePrintService.js

40 lines
1021 B
JavaScript
Raw Normal View History

2022-11-17 07:04:12 +00:00
import { useSession } from './useSession';
import axios from 'axios';
import { useQuasar } from 'quasar';
2024-09-23 09:06:08 +00:00
import { useI18n } from 'vue-i18n';
2022-11-17 07:04:12 +00:00
export function usePrintService() {
const quasar = useQuasar();
2024-09-23 09:06:08 +00:00
const { t } = useI18n();
2024-03-28 06:20:54 +00:00
const { getTokenMultimedia } = useSession();
2022-11-17 07:04:12 +00:00
function sendEmail(path, params) {
return axios.post(path, params).then(() =>
quasar.notify({
2024-09-23 09:06:08 +00:00
message: t('globals.notificationSent'),
2022-11-17 07:04:12 +00:00
type: 'positive',
icon: 'check',
})
);
}
2024-09-12 11:19:37 +00:00
function openReport(path, params, isNewTab = '_self') {
2024-08-23 13:30:22 +00:00
if (typeof params === 'string') params = JSON.parse(params);
2022-11-17 07:04:12 +00:00
params = Object.assign(
{
2024-03-28 06:20:54 +00:00
access_token: getTokenMultimedia(),
2022-11-17 07:04:12 +00:00
},
params
);
const query = new URLSearchParams(params).toString();
2024-09-12 11:19:37 +00:00
window.open(`api/${path}?${query}`, isNewTab);
2022-11-17 07:04:12 +00:00
}
return {
sendEmail,
openReport,
};
}