测试机型iphone6s,iphone12 无法查询订单;安卓手机,苹果14可以查询订单,服务器用的tomcat7,
出行通知
加载中...
// 获取URL参数
function getQueryParam(name) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(name);
}
// 初始化微信商家小票
function wxInit() {
if (window.parent) {
try {
const mchData = {
action: 'onIframeReady',
displayStyle: 'SHOW_CUSTOM_PAGE',
height:960
};
const postData = JSON.stringify(mchData);
window.parent.postMessage(postData, 'https://payapp.weixin.qq.com');
} catch (error) {
console.log('微信初始化失败:', error);
}
}
}
// 获取出行通知信息
async function getTravelNotice() {
const outTradeNo = getQueryParam('out_trade_no');
const container = document.getElementById('contentContainer');
if (!outTradeNo) {
container.innerHTML = '<div class="no-data">缺少必要的参数</div>';
return;
}
try {
const baseUrl = "";
// 构建请求URL - 根据实际情况调整路径
const apiUrl = '/mobile/line/getTravelNoticeByOutTradeNo.jhtml?' +
new URLSearchParams({ outTradeNo: outTradeNo });
const response = await fetch(baseUrl+apiUrl);
const data = await response.json();
if (data && data.success) {
container.innerHTML = data.output || '<div class="no-data">暂无数据</div>';
} else {
container.innerHTML = '<div class="no-data">系统繁忙,请稍后再试~</div>';
}
// 初始化微信功能
wxInit();
} catch (error) {
console.error('请求失败:', error);
container.innerHTML = '<div class="no-data">网络错误,请检查连接</div>';
}
}
// 返回功能
function setupBackButton() {
const backBtn = document.getElementById('backBtn');
const referrer = document.referrer;
// 如果有上一页,显示返回按钮
if (referrer && referrer !== window.location.href) {
backBtn.style.display = 'block';
backBtn.onclick = function() {
window.history.back();
};
}
}
// 图片懒加载(简化版)
function lazyLoadImages() {
const images = document.querySelectorAll('.content-list img');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
if (img.dataset.src) {
img.src = img.dataset.src;
}
observer.unobserve(img);
}
});
});
images.forEach(img => observer.observe(img));
}
// 页面加载完成后执行
document.addEventListener('DOMContentLoaded', function() {
// 1. 确保body可滚动
document.body.style.overflow = 'auto';
document.body.style.height = 'auto';
// 2. 确保html元素可滚动
document.documentElement.style.overflow = 'auto';
document.documentElement.style.height = 'auto';
// 3. 检测是否在iframe中
if (window.self !== window.top) {
// 在小票链接中
console.log('在小票链接环境中');
// 尝试与父页面通信调整高度
const sendHeight = () => {
const height = document.documentElement.scrollHeight;
try {
window.parent.postMessage({
type: 'iframeHeight',
height: height,
source: 'ticketPage'
}, '*');
} catch (e) {
console.log('无法与父页面通信');
}
};
// 初始发送高度
setTimeout(sendHeight, 100);
// 内容变化时重新发送高度
const observer = new MutationObserver(sendHeight);
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true
});
}
// 4. 启用iOS弹性滚动
const style = document.createElement('style');
style.textContent = `
* {
-webkit-overflow-scrolling: touch !important;
}
body {
overscroll-behavior-y: auto !important;
}
`;
document.head.appendChild(style);
getTravelNotice();
// 监听内容变化,设置图片懒加载
const observer = new MutationObserver(function() {
lazyLoadImages();
});
observer.observe(document.getElementById('contentContainer'), {
childList: true,
subtree: true
});
});

将body的script移到header问题解决了