优化2.0标准版代码

master
Godblessyou 9 months ago
parent 5817404f72
commit 81e755d8fc

@ -0,0 +1,48 @@
var pageNumber;
$('#mytab').bootstrapTable({
toolbar: '#toolbar', //工具按钮用哪个容器
striped: true, //是否显示行间隔色
cache: false, //是否使用缓存默认为true所以一般情况下需要设置一下这个属性*
pagination: true, //是否显示分页(*
sidePagination: "server", //分页方式client客户端分页server服务端分页*
paginationPreText : '上一页',
paginationNextText : '下一页',
pageNumber: 1, //初始化加载第一页,默认第一页
pageSize: 10, //每页的记录行数(*
pageList: [5,10,15,20,50,1000],//可供选择的每页的行数(*
height: $(window).height()-109, //行高如果没有设置height属性表格自动根据记录条数觉得表格高度
columns:[
{
title:'审核日期',
field:'reviewDate',
align:'center',
},
{
title:'审核人',
field:'reviewNo',
align:'center',
},
{
title:'审核盘号',
field:'reviewPh',
align:'center',
},
{
title:'审核病历数',
field:'reviewBLnum',
align:'center',
},
{
title:'审核结果',
field:'reviewResult',
align:'center',
},
],
locale:'zh-CN',//中文支持,
data: [ // 写死的数据
{ reviewDate: '2024-03-01', reviewNo: '苏华丽', reviewPh: 990, reviewBLnum: 43032, reviewResult: '已通过' },
{ reviewDate: '2024-06-01', reviewNo: '苏华丽', reviewPh: 935, reviewBLnum: 42241, reviewResult: '已通过' },
{ reviewDate: '2024-09-01', reviewNo: '苏华丽', reviewPh: 910, reviewBLnum: 46534, reviewResult: '已通过' },
{ reviewDate: '2024-12-01', reviewNo: '苏华丽', reviewPh: 976, reviewBLnum: 45849, reviewResult: '已通过' },
],
})

@ -0,0 +1,194 @@
let pageNum = 1;//自动跳转页码默认为0
let currentPage = 0;//当前页码
//初始化函数
$(function(){
//加载iframe
$("#megerIframe").prop("src",path+"/commom/showMegerRecordIframeBlood?patientId="+$("#patientId").val()+"&flag=file_path");
initAssort();
})
function initAssort(){
$.ajax({
type: 'post',
url: path+'/commom/selectIsPowerByUser',
dataType:'json',
success:function (data) {
let html = "";
let xh = 1;
if(data.length > 0){
for(let i = 0; i < data.length; i++){
if( i != data.length - 1){
html +=
'<div class="assort-div">\n' +
' <div class="assort-title-one-div">\n' +
' <button type="button" id="'+ data[i].assortId +'" class="btn btn-sm assort-btn" onclick="indexCatalogue(event)">' + (xh++) + '.' + data[i++].assortName +'</button>\n' +
' </div>\n' +
' <div style="width: 4%"></div>\n' +
' <div class="assort-title-two-div">\n' +
' <button type="button" id="'+ data[i].assortId +'" class="btn btn-sm assort-btn" onclick="indexCatalogue(event)">' + (xh++) + '.' + data[i].assortName +'</button>\n' +
' </div>\n' +
'</div>';
}else{
html +=
'<div class="assort-div">\n' +
' <div class="assort-title-one-div">\n' +
' <button type="button" id="'+ data[i].assortId +'" class="btn btn-sm assort-btn" onclick="indexCatalogue(event)">' + (xh++) + '.' + data[i].assortName +'</button>\n' +
' </div>\n' +
'</div>';
}
}
$("#assortHtml").html(html);
}
}
})
}
let assortId = "";
let assortName = "";
let rightContentHtml = "";
let base64DataArray = [];
let assortIdArray = [];
let assortTexteArray = [];
let pageDataArray = [];
function indexCatalogue(event){
const button = event.target; // 获取触发事件的按钮元素
assortId = button.id;
assortName = button.textContent; // 获取按钮的文本内容
turningPage(assortName,false);
}
function turningPage(assortName, backPageFlag){
// 获取父页面中的iframe
const parentIframe = document.getElementById('megerIframe');
// 访问iframe的内容窗口
const childWindow = parentIframe.contentWindow;
// 获取子页面中的nestedIframe
const nestedIframe = childWindow.document.getElementById('showMegerPdfIframe');
//获取子页面的上传文件属性
const pdfUpFile = childWindow.document.getElementById('pdf-file-input');
// 获取当前的src属性值
let currentSrc = nestedIframe.src;
//获取选中的目录分类的图像base64
getBlobAsBase64(currentSrc).then(base64Data => {
base64DataArray.push(base64Data);
})
// 定义需要更改的参数及其新值
const paramToChange = 'page';
let newValue = ++pageNum;
// 使用正则表达式替换参数值
const newSrc = currentSrc.replace(new RegExp(`${paramToChange}=([^&]*)`), `${paramToChange}=${newValue}`);
// 生成当前的时间戳
const timestamp = new Date().getTime();
// 检查是否已存在时间戳参数
const hasTimestamp = newSrc.includes('timestamp=');
// 更新或添加时间戳参数
let finalSrc;
if (hasTimestamp) {
// 替换现有的时间戳参数
finalSrc = newSrc.replace(/timestamp=([0-9]+)/, `timestamp=${timestamp}`);
} else {
// 添加新的时间戳参数
finalSrc = `${newSrc}&timestamp=${timestamp}`;
}
// 设置新的src属性值
nestedIframe.src = finalSrc;
// 重新加载nestedIframe
nestedIframe.contentWindow.location.reload(true);
if(!backPageFlag){
if (pdfUpFile.files.length > 0) {
currentPage++;
//拼接右侧内容
rightContentHtml =
'<div id="page_' + currentPage + '" class="index-div">\n' +
' <p class="index-btn">'+ currentPage +'_' + assortName + '</p>\n' +
'</div>';
// 检查ID是否存在
if ($("#page_" + currentPage).length) {
// 替换旧的HTML内容
let newHtml = '<p class="index-btn">'+ currentPage +'_' + assortName + '</p>\n';
$("#page_" + currentPage).html(newHtml);
} else {
// 新增HTML内容
$("#rightContentHtml").append(rightContentHtml);
}
//放入数据
assortIdArray.push(assortId);
assortTexteArray.push(currentPage +'_' + assortName)
pageDataArray.push(currentPage);
} else {
toastr.warning("请先上传pdf文件")
}
}
}
async function getBlobAsBase64(blobUrl) {
const response = await fetch(blobUrl);
const blob = await response.blob();
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result);
reader.onerror = reject;
reader.readAsDataURL(blob);
});
}
function backPage(){
Common.confirm({
title: "提示",
message: "是否要回上一页?",
operate: function (result) {
if (result) {
pageNum = pageNum - 2;
currentPage--;
turningPage(assortName,true);
}
}
})
}
function submitIndex(){
if(base64DataArray.length == 0){
return toastr.warning("索引分类为空,请先对图像进行索引分类")
}
var patientId = $("#patientId").val();
Common.confirm({
title: "提示",
message: "确认提交以上索引分类吗?",
operate: function (result) {
if (result) {
$.ajax({
type: 'post',
contentType: 'application/json; charset=utf-8', // 设置内容类型为 application/json
url: path+'/commom/savePdfPage',
data: JSON.stringify({
base64Data: base64DataArray,
assortIdData: assortIdArray,
pageData: pageDataArray,
patientId: patientId
}),
success:function(data){
if(data.code == 0){
toastr.warning("合并成功!")
//记录已提交的索引分类
//saveSubmitAssort(patientId);
}
}
})
}
}
})
}
function saveSubmitAssort(patientId){
$.ajax({
type: 'post',
contentType: 'application/json; charset=utf-8', // 设置内容类型为 application/json
url: path+'/commom/saveSubmitAssortLog',
data: JSON.stringify({
patientId: patientId,
assortIdData: assortIdArray,
assortTexteData: assortTexteArray,
pageData: pageDataArray,
}),
success:function(data){
}
})
}

@ -0,0 +1,90 @@
let pdfUrl = '';
let pageNum = 1;
$().ready(function (data) {
document.getElementById('pdf-file-input').addEventListener('change', function(event) {
const file = event.target.files[0];
if (file) {
const fileReader = new FileReader();
fileReader.onload = function() {
pdfUrl = URL.createObjectURL(new Blob([this.result], { type: 'application/pdf' }));
document.getElementById('showMegerPdfIframe').src = `${pdfUrl}#page=${pageNum}&timestamp=${Date.now()}`;
//updatePage();
};
fileReader.readAsArrayBuffer(file);
}
});
// document.getElementById('download-page').addEventListener('click', function() {
// const iframe = document.getElementById('iframe1');
// const pdfUrl = iframe.src;
// const pageNum = getSelectedPageNumber(); // 假设有一个函数getSelectedPageNumber()来获取当前页码
//
// if (pdfUrl) {
// getBlobAsBase64(pdfUrl).then(base64Data => {
// fetch(path + '/commom/savePdfPage', {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json'
// },
// body: JSON.stringify({ base64Data, pageNum })
// })
// .then(response => response.json())
// .then(data => {
// if(data.status == 'success'){
// toastr.success(data.message);
// }
// })
// .catch(error => {
// toastr.error(error);
// });
// })
// }
// });
// document.getElementById('next-page-btn').addEventListener('click', function() {
// pageNum++;
// updatePage();
// });
//
// document.getElementById('prev-page-btn').addEventListener('click', function() {
// if (pageNum > 1) {
// pageNum--;
// updatePage();
// }
// });
});
function updatePage() {
if (pdfUrl) {
document.getElementById('current-page').textContent = pageNum;
const iframe = document.getElementById('showMegerPdfIframe');
// 重新创建 iframe 元素以强制重新加载
const newIframe = document.createElement('iframe');
newIframe.id = 'showMegerPdfIframe';
newIframe.width = '100%';
newIframe.height = '100%';
newIframe.src = `${pdfUrl}#page=${pageNum}&timestamp=${Date.now()}`;
// 替换旧的 iframe 元素
iframe.parentNode.replaceChild(newIframe, iframe)
}
}
var iframe = document.getElementById("showMegerPdfIframe");
if (iframe.attachEvent) {
iframe.attachEvent("onreadystatechange", function () {
//此事件在内容没有被载入时候也会被触发,所以我们要判断状态
//有时候会比较怪异 readyState状态会跳过 complete 所以我们loaded状态也要判断
if (iframe.readyState === "complete" || iframe.readyState == "loaded") {
//代码能执行到这里说明已经载入成功完毕了
//要清除掉事件
iframe.detachEvent("onreadystatechange", arguments.callee);
//这里是回调函数
}
});
} else {
iframe.addEventListener("load", function () {
$("#iframeLoad").val(1);
//代码能执行到这里说明已经载入成功完毕了
this.removeEventListener("load", arguments.call, false);
}, false);
}
Loading…
Cancel
Save