feat: refs #7936 enhance downloadFile function to support opening in a new tab
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
a33cec4a34
commit
ad9063704c
|
@ -2,16 +2,25 @@ import { useSession } from 'src/composables/useSession';
|
||||||
import { getUrl } from './getUrl';
|
import { getUrl } from './getUrl';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { exportFile } from 'quasar';
|
import { exportFile } from 'quasar';
|
||||||
|
import useOpenURL from './useOpenURL';
|
||||||
|
|
||||||
const { getTokenMultimedia } = useSession();
|
const { getTokenMultimedia } = useSession();
|
||||||
const token = getTokenMultimedia();
|
const token = getTokenMultimedia();
|
||||||
|
|
||||||
export async function downloadFile(id, model = 'dms', urlPath = '/downloadFile', url) {
|
export async function downloadFile(
|
||||||
|
id,
|
||||||
|
model = 'dms',
|
||||||
|
urlPath = '/downloadFile',
|
||||||
|
url,
|
||||||
|
newTab = true
|
||||||
|
) {
|
||||||
const appUrl = (await getUrl('', 'lilium')).replace('/#/', '');
|
const appUrl = (await getUrl('', 'lilium')).replace('/#/', '');
|
||||||
const response = await axios.get(
|
const targetUrl =
|
||||||
url ?? `${appUrl}/api/${model}/${id}${urlPath}?access_token=${token}`,
|
url ?? `${appUrl}/api/${model}/${id}${urlPath}?access_token=${token}`;
|
||||||
{ responseType: 'blob' }
|
|
||||||
);
|
if (newTab) return useOpenURL(targetUrl);
|
||||||
|
|
||||||
|
const response = await axios.get(targetUrl, { responseType: 'blob' });
|
||||||
|
|
||||||
const contentDisposition = response.headers['content-disposition'];
|
const contentDisposition = response.headers['content-disposition'];
|
||||||
const matches = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(contentDisposition);
|
const matches = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(contentDisposition);
|
||||||
|
|
|
@ -206,7 +206,8 @@ const isAgricultural = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
function showPdfInvoice() {
|
function showPdfInvoice() {
|
||||||
if (isAgricultural()) openReport(`InvoiceIns/${entityId.value}/invoice-in-pdf`);
|
if (isAgricultural())
|
||||||
|
openReport(`InvoiceIns/${entityId.value}/invoice-in-pdf`, null, '_blank');
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendPdfInvoiceConfirmation() {
|
function sendPdfInvoiceConfirmation() {
|
||||||
|
|
Loading…
Reference in New Issue