如果需要请看我的AJAX写法- sessionStorage.removeItem('suanming_request_in_progress');// 定义属相与图标的映射关系const zodiacIcons= {"鼠": "🐭","牛": "🐂","虎": "🐅","兔": "🐇","龙": "🐉","蛇": "🐍","马": "🐎","羊": "🐏","猴": "🐒","鸡": "🐓","狗": "🐕","猪": "🐷"};// 为“开始算命”按钮添加点击事件处理函数$('.suanming').on('click', function () {layer.closeAll(); //疯狂模式,关闭所有层recordOperationLog('算命查询');const requestFlagKey = 'suanming_request_in_progress';if (sessionStorage.getItem(requestFlagKey)) {layer.msg('请求正在处理中,请稍后...', { icon: 0, time: 2000, area: 'auto', type: 0, anim: 6 });return false;}sessionStorage.setItem(requestFlagKey, 'true');const selectedYear = $('#lunarYear').val();const selectedMonth = $('#lunarMonth').val();const selectedDay = $('#lunarDay').val();const selectedHourInfo = $('#lunarHour').val();// 检查是否所有选项都已选择if (selectedYear && selectedMonth && selectedDay && selectedHourInfo) {$.ajax({url: '/ecmsapi/index.php?mod=duomeiti&act=suanming',type: "POST",data: {year: selectedYear,month: selectedMonth,day: selectedDay,hour: selectedHourInfo},dataType: 'json',success: function (res) {sessionStorage.removeItem(requestFlagKey); if (res.code === 1) {sessionStorage.removeItem('suanming_request_in_progress');var resdataperson = res.data.person;var resdatapersonff = res.data.lhlinfo;var tableHtml = '<div style="display: table; border-collapse: collapse; width:99.5%;">';function generateRow(label, value) {if (typeof value ==='string') {value = marked.parse(value);}let contentCellClass = '';let styleBlock = '';if (label === '八字分析') {contentCellClass = 'class="aicontent"';styleBlock = '<style>.aicontent { color: #333; font-size: 14px; }.aicontent h3 { color: green; font-weight: bold; margin-top: 20px; margin-bottom: 10px; font-size: 14px;border-bottom: 1px #cccccc dashed;background: url(/skin/img/meiwen_title_icon.gif) 0% 1px no-repeat;text-indent: 8px; }.aicontent h4 {font-size: 14px;padding: 8px;margin-left: -8px;}.aicontent h5{font-size: 14px;margin-bottom: 5px;}.aicontent p{line-height: 15px;margin-top: 5px;}</style>';value = value.replace(/<h([3-5])>(.*?)<\/h\1>/g, function (match, tag, content) {if (content.indexOf(':') === -1) {return '<h' + tag + '>' + content + ':</h' + tag + '>';}return match;});// 对 strong 标签内的文本进行判断并添加冒号const strongRegex = /<strong>([^<:]*?)<\/strong>/g;value = value.replace(strongRegex, function (match, p1) {if (p1.indexOf(':') === -1) {return '<strong>' + p1 + ':</strong>';}return match;});}return styleBlock + '<div style="display: table-row-group;">' +'<div style="display: table-row;">' +'<div style="display: table-cell; border: 1px solid #ccc; text-align: center; vertical-align: middle; background-color: #f0f0f0; font-weight: bold; padding: 8px; white-space: nowrap;">' + label + '</div>' +'<div style="display: table-cell; border: 1px solid #ccc; text-align: left; padding: 8px; word-wrap: break-word; word-break: break-all;line-height: 15px;"'+ contentCellClass + '> ' + value + '</div>' +'</div>' +'</div>';}var weight = '';if (resdataperson.baziinfo) {weight = '<font style="color:#ff0000;">'+resdataperson.baziinfo.totalWeight + '两</font> (' + '年:' + resdataperson.baziinfo.yearWeight + '+月:' + resdataperson.baziinfo.monthWeight + '+日:' + resdataperson.baziinfo.dayWeight + '+时:' + resdataperson.baziinfo.hourWeight + ')';}var horoscope = resdataperson.baziinfo ? resdataperson.baziinfo.horoscope : '';var ganzhiDate = resdataperson.ganzhiinfo ? resdataperson.ganzhiinfo.year + '年' + resdataperson.ganzhiinfo.month+'月' + resdataperson.ganzhiinfo.day+'日' + resdataperson.ganzhiinfo.hour+'时': '';var hunyininfo = resdataperson.userbaseinfo ? '<font style="font-weight:bold;color:#0ba111;">姓名</font>:'+resdataperson.userbaseinfo.username + ',<i class="fa fa-birthday-cake" style="font-size: 13px;color: red;margin-right: 3px;"></i><font style="font-weight:bold;color:#0ba111;">年龄</font>:' + resdataperson.userbaseinfo.age+'岁,<font style="font-weight:bold;color:#0ba111;">属相</font>:' + resdataperson.userbaseinfo.zodiac+''+zodiacIcons[resdataperson.userbaseinfo.zodiac]+',<font style="font-weight:bold;color:#0ba111;">农历</font>:' + resdataperson.userbaseinfo.lunar+',<font style="font-weight:bold;color:#0ba111;">公历</font>:' + resdataperson.userbaseinfo.gregoria: '';var combinedInfo = '' + hunyininfo+'<br><br><font style="font-weight:bold;color:#0ba111;">八字精批</font>:' + horoscope + '<br><br><font style="font-weight:bold;color:#0ba111;">天干地支</font>:' + ganzhiDate+',<font style="font-weight:bold;color:#0ba111;">骨重</font>:'+weight+',<font style="font-weight:bold;color:#0ba111;">星座</font>:' + resdataperson.userbaseinfo.constellation+'座';tableHtml += generateRow('综合信息', combinedInfo);tableHtml += generateRow('八字分析', resdataperson.baziinfo ? resdataperson.baziinfo.horoscopeai : '');var wuxinginfo = '';if (resdataperson.wuxinginfo) {wuxinginfo = resdataperson.wuxinginfo.year + ' ' + resdataperson.wuxinginfo.month + ' ' + resdataperson.wuxinginfo.day + ' ' + resdataperson.wuxinginfo.hour;}var wuxingcount = '';if (resdataperson.wuxingcount) {var weakInfo = resdataperson.wuxingcount.wuxingtext ? resdataperson.wuxingcount.wuxingtext.weakInfo : '';var strongInfo = resdataperson.wuxingcount.wuxingtext ? resdataperson.wuxingcount.wuxingtext.strongInfo : '';wuxingcount = weakInfo+ ',' + strongInfo;}var wuxingInfo00 = '<font style="font-weight:bold;color:#0ba111;">五行统计</font>:' + wuxinginfo + '<br><br><font style="font-weight:bold;color:#0ba111;">五行分析</font>:' + wuxingcount;tableHtml += generateRow('五行信息', wuxingInfo00);let hunyinInfoStr = '';if (resdataperson.hunyininfo && resdataperson.hunyininfo.hunyininfo) {for (const key in resdataperson.hunyininfo.hunyininfo) {if (resdataperson.hunyininfo.hunyininfo.hasOwnProperty(key)) {hunyinInfoStr += key + ': ' + resdataperson.hunyininfo.hunyininfo[key] + '<br><br>';}}}tableHtml += generateRow('婚姻信息', hunyinInfoStr);let xingzuoInfoStr = '';if (resdataperson.xingzuoinfo.wuxinginfo) {xingzuoInfoStr += '星座:' + resdataperson.xingzuoinfo.constellation+' ';resdataperson.xingzuoinfo.wuxinginfo.forEach((item, index) => {if (item.type!== '今日概述') {if (item.type === '财运指数') {xingzuoInfoStr += '<br>';}xingzuoInfoStr += '' + item.type + ':' + item.content+' ';}});const todayOverview = resdataperson.xingzuoinfo.wuxinginfo.find(item => item.type === '今日概述');if (todayOverview) {xingzuoInfoStr += '<br><br><font style="font-weight:bold;color:#0ba111;">今日概述</font>:' + todayOverview.content;}}tableHtml += generateRow('星座信息', xingzuoInfoStr);let baseinfo = resdatapersonff.lhlresult.baseinfo;let dateInfo = '<font style="font-weight:bold;color:#0ba111;">今</font>:' + baseinfo.日期+' '+ baseinfo.农历.trim()+' ' + baseinfo.干支+'';let yiInfo = '<font style="color:#0ba111;font-weight:bold;">宜</font>:' + baseinfo.宜.join('、');let jiInfo = '<font style="color:#ff0000;font-weight:bold;">忌</font>:' + baseinfo.忌.join('、');let combinedInfoaaa = dateInfo + '<br>' + yiInfo + '<br>' + jiInfo;tableHtml += generateRow('今日日历', combinedInfoaaa);tableHtml += '</div>';parent.layer.open({type: 1,title: ['算命查询', 'background-image: linear-gradient(to right, #E91E63, #e90a0a); color: #fff;'],content: tableHtml,area: ['820px', '630px'],scrollbar: true,shadeClose: true,moveOut:true,success: function (layero, index) {$('.layui-layer-title', layero).html('('+res.data.username+')算命查询结果');}});}}});} else {layer.msg('请完整选择农历年、月、日和时辰。', { icon: 5, time: 2000, area: 'auto', type: 0, anim: 5 }); }});
复制代码 |