提交 f2b1d547 authored 作者: 钟是志's avatar 钟是志

Merge remote-tracking branch 'origin/master'

import { getToken } from '@/webPublic/one_stop_public/utils/getToken';
import { getUserInfo } from '@/webPublic/one_stop_public/utils/token';
import { getIsBei_Dian } from '@/webPublic/zyd_public/utils/utils';
export function isJSON(str) {
if (typeof str == 'string') {
......@@ -18,7 +19,7 @@ export function isJSON(str) {
export const getSysCode = () => {
return getYunShangGuiZhouSyStemConfig().sysCode || window.specialImportantSystemConfig.sysCode;
// 钟是志 2023年8月24日 优先从localStorage里面取系统code 取不到才从配置里面取
// 解决禅道 http://scjoyedu.eicp.net:57400/zentao/task-view-165.html
// 解决禅道 http://scjoyedu.eicp.net:57400/zentao/task-view-165.html
};
// 查询系统配置
......@@ -43,16 +44,17 @@ export const getYunShangGuiZhouSyStemConfig = () => {
export const getSassApiHeader = () => {
// 解决禅道 34246 在学工、素质测评、宿管、离校的所有接口中增加请求头
if(!getSysCode() && !window.specialImportantSystemConfig.sysCode){
return {
Authorization: `bearer ${getToken()}`,
};
}else{
return {
Authorization: `bearer ${getToken()}`,
sysCode: getSysCode(),
tenant: getUserInfo().tenantCode || window.specialImportantSystemConfig.tenant || null,
// 解决禅道 http://scjoyedu.eicp.net:57400/zentao/task-view-165.html
};
}
if (!getSysCode() && !window.specialImportantSystemConfig.sysCode) {
return {
Authorization: `bearer ${getToken()}`,
env: process.env.NODE_ENV === 'development' && getIsBei_Dian() ? 'test' : undefined,
};
} else {
return {
Authorization: `bearer ${getToken()}`,
sysCode: getSysCode(),
tenant: getUserInfo().tenantCode || window.specialImportantSystemConfig.tenant || null,
};
// 解决禅道 http://scjoyedu.eicp.net:57400/zentao/task-view-165.html
}
};
import { giveFilePostDataInfoForTrue } from '@/webPublic/one_stop_public/Base16';
import { queryOauthActionPath } from '@/webPublic/one_stop_public/utils/queryConfig';
import { Modal } from 'antd';
import { getTransformApi } from '@/webPublic/one_stop_public/2022beidianke/localstorageTransform';
import { getSassApiHeader } from '@/webPublic/one_stop_public/2023yunshangguizhou/utils';
import { getToken } from '@/webPublic/one_stop_public/utils/token';
import { FormdataWrapper, apiUrl, setObjectKey } from "@/webPublic/one_stop_public/Table/globalFunction";
/**
* 钟是志
* 2024年7月12日
* 解决北电科宿管需求 http://scjoyedu.eicp.net:57400/zentao/task-view-3141.html
* 多个pdf文件合并为一个pdf文件并预览.
* 使用 pdf-lib 依赖
* */
export default function getFilesToPdfAndShow(dataList = []) {
for (let item of dataList) {
let getFileData = giveFilePostDataInfoForTrue(
{
templatePath: item.templatePath,
params: JSON.stringify({
...item.listConfig,
...setObjectKey(item.params),
}),
title: `${item.title}.${item.ext}`,
allValues: JSON.stringify({ ...item.allValues }),
},
apiUrl + `/DataColumnApi/exportWord`,
);
item.getFileData = getFileData;
}
Modal.confirm({
title: '提示',
content: '此功能耗时较长,是否确认加载?',
onOk: async () => {
let r = [];
for (let item of dataList) {
let oneFileBlod = await downloadFileReturnBlob(
item.getFileData.url,
{
...item.getFileData.datas,
token: getToken(),
},
item.title,
item.ext,
);
r.push(oneFileBlod);
}
mergePDFBlobs(r);
},
});
}
async function downloadFileReturnBlob(url, params, fileName = '导出文件', ext = 'xlsx') {
const { transformApi, headersApi } = await getTransformApi(url);
let headers = getSassApiHeader();
// if(headersApi){
// headers.apis = headersApi;
// }
return fetch(transformApi, {
method: 'POST',
body: FormdataWrapper(params),
headers,
})
.then((res) => {
return res.blob();
})
.then((data) => {
return data;
})
.catch((err) => {
console.table(err);
})
.finally(() => {
return true;
});
}
async function mergePDFBlobs(blobArray) {
if (blobArray.length < 1) {
throw new Error('No PDF blobs to merge.');
}
const pdf = await import('./pdf-lib.min');
const mergedPdf = await pdf.PDFDocument.create();
// 创建一个新的PDF文档
// 逐个处理每个Blob
for (const blob of blobArray) {
// 将Blob转换为Uint8Array
const arrayBuffer = await blob.arrayBuffer();
const pdfBytes = new Uint8Array(arrayBuffer);
// 加载现有的PDF文档
const existingPdfDoc = await pdf.PDFDocument.load(pdfBytes); // 源文件
// 复制所有页面到新文档
const pages = existingPdfDoc.getPages();
for(let i = 0; i < pages.length; i++){
const copiedPages = await mergedPdf.copyPages(existingPdfDoc, [i]);
mergedPdf.addPage(copiedPages[0]);
}
}
// 保存合并后的PDF
const pdfBytes = await mergedPdf.save();
// 创建一个Blob对象用于下载
const mergedBlob = new Blob([pdfBytes], { type: 'application/pdf' });
// 触发下载
const url = URL.createObjectURL(mergedBlob);
Modal.info({
title: '查看',
width: 1000,
content: <div>
<embed width='100%'
height='568px'
name='plugin'
id='pdfView'
src={url}
type='application/pdf'
internalinstanceid='3'
title={'查看'} />
</div>,
okText: '确定',
onCancel: () => {
window.URL.revokeObjectURL(url);
},
onOk: () => {
window.URL.revokeObjectURL(url);
},
});
}
......@@ -36,6 +36,7 @@ import {
getListWord,
upObjKey,
} from './globalFunction';
import getFilesToPdfAndShow from './getFilesToPdfAndShow';
import { getTransformApi } from '@/webPublic/one_stop_public/2022beidianke/localstorageTransform';
export function getSystemCode() {
......@@ -81,6 +82,7 @@ export function giveSmartFormGlobalProps({
renderContentRow,
getTransformApi,
upObjKey,
getFilesToPdfAndShow,
md5,
remark: {
downloadFile: '下载文件函数.',
......@@ -98,6 +100,7 @@ export function giveSmartFormGlobalProps({
'getListWord({templatePath,paramsList, title,sonTitleKey, allValuesKey, listConfig, ext,sonExt})': `批量下载文档地址 ;参数->前五个必填 templatePath,paramsList, title,sonTitleKey, allValuesKey`,
'renderContentAll(value, row, index, key, spanData, cloumnNames) ': `ant表头横向、纵向合并 ;参数->所有必填 value, row, index, key, spanData, cloumnNames 实例:render:(value, row, index)=>{return renderContentAll(value, row, index,"inst_name",spanData,cloumnNames)}`,
'renderContentRow(value, row, index, key, spanData, cloumnNames) ': `ant表头纵向合并 ;参数->所有必填 value, row, index, key, spanData, cloumnNames 实例:render:(value, row, index)=>{return renderContentRow(value, row, index,"inst_name",spanData,cloumnNames)}`,
'getFilesToPdfAndShow(dataList)':'将多个pdf 合并成一个pdf 用于预览 打印',
getTransformApi: '接口转换函数用于一站式接口地址加密',
'upObjKey({}/[{}],{lodKey:newKey})': '用于修改对象或数组对象KEY',
md5: 'md5加密函数',
......
import { useState } from 'react';
import { Modal } from 'antd';
import { giveFilePostDataInfoForTrue } from '@/webPublic/one_stop_public/Base16';
import { queryOauthActionPath } from '@/webPublic/one_stop_public/utils/queryConfig';
......@@ -8,10 +7,10 @@ import { getTransformApi } from '@/webPublic/one_stop_public/2022beidianke/local
import moment from 'moment';
import {
getSassApiHeader,
getSysCode
} from '@/webPublic/one_stop_public/2023yunshangguizhou/utils';
const apiUrl = queryOauthActionPath();
export { apiUrl };
const exportStyles = {
header: {
font: {
......@@ -955,10 +954,10 @@ export function getFileAndShow({
} catch (err) {
console.table(err);
}
}
/**
* 表头和数据导出(合并表格)
* templatePath : word文档模板地址
......@@ -1044,7 +1043,7 @@ export function getListWord({
}
}
function setObjectKey(data) {
export function setObjectKey(data) {
return (
Object.keys(data)
.reduce(
......@@ -1181,7 +1180,7 @@ function makeArrayKey(key) {
return key;
}
function FormdataWrapper(obj, fd, pre) {
export function FormdataWrapper(obj, fd, pre) {
fd = fd || new FormData();
Object.keys(obj)
.forEach(function (prop) {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论