update
This commit is contained in:
@@ -546,14 +546,41 @@
|
|||||||
document.getElementById('result-table').style.display = 'block';
|
document.getElementById('result-table').style.display = 'block';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 自动抓取全部职位代码并获取详情
|
// 追加成功行
|
||||||
function fetchAllPositions() {
|
function appendResultRow(item) {
|
||||||
|
const tbody = document.getElementById('data-table-body');
|
||||||
|
const tr = document.createElement('tr');
|
||||||
|
tr.innerHTML = `
|
||||||
|
<td>${item.sbmc || ''}</td>
|
||||||
|
<td>${item.dsmc || ''}</td>
|
||||||
|
<td>${item.zpdwmc || ''}</td>
|
||||||
|
<td>${item.zwmc || ''}</td>
|
||||||
|
<td>${item.zwdm || ''}</td>
|
||||||
|
<td>${item.zprs || 0}</td>
|
||||||
|
<td>${item.bkrs || 0}</td>
|
||||||
|
<td>${item.competition_ratio || '0.00'}</td>
|
||||||
|
`;
|
||||||
|
tbody.appendChild(tr);
|
||||||
|
document.getElementById('result-table').style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 追加失败行
|
||||||
|
function appendErrorRow(code, msg) {
|
||||||
|
const tbody = document.getElementById('data-table-body');
|
||||||
|
const tr = document.createElement('tr');
|
||||||
|
tr.innerHTML = `<td colspan="8" style="color:red;">职位代码 ${code}: ${msg}</td>`;
|
||||||
|
tbody.appendChild(tr);
|
||||||
|
document.getElementById('result-table').style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 自动抓取全部职位代码并逐条获取详情(流式展示,避免超时)
|
||||||
|
async function fetchAllPositions() {
|
||||||
const dsdm = document.getElementById('dsdm').value;
|
const dsdm = document.getElementById('dsdm').value;
|
||||||
const examid = document.getElementById('examid').value.trim();
|
const examid = document.getElementById('examid').value.trim();
|
||||||
const bmid = document.getElementById('bmid').value.trim();
|
const bmid = document.getElementById('bmid').value.trim();
|
||||||
const userid = document.getElementById('userid').value.trim();
|
const userid = document.getElementById('userid').value.trim();
|
||||||
const cookieData = buildCookiesPayload('result-message');
|
const cookieData = buildCookiesPayload('result-message');
|
||||||
const aa = lastAa || Date.now().toString();
|
const aa = lastAa;
|
||||||
|
|
||||||
if (!dsdm) {
|
if (!dsdm) {
|
||||||
showMessage('dsdm-message', '请先选择地区', 'error');
|
showMessage('dsdm-message', '请先选择地区', 'error');
|
||||||
@@ -563,36 +590,57 @@
|
|||||||
showMessage('dsdm-message', '请先填写examid、bmid和userid', 'error');
|
showMessage('dsdm-message', '请先填写examid、bmid和userid', 'error');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!lastAa) {
|
if (!aa) {
|
||||||
showMessage('dsdm-message', '请先获取地区选项', 'error');
|
showMessage('result-message', '请先点击“获取地区选项”生成aa', 'error');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!cookieData) {
|
if (!cookieData) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
showMessage('result-message', '正在自动抓取全部职位,请稍候...', 'info');
|
// 清空旧数据
|
||||||
|
lastResults = [];
|
||||||
|
const tbody = document.getElementById('data-table-body');
|
||||||
|
tbody.innerHTML = '';
|
||||||
|
document.getElementById('result-table').style.display = 'block';
|
||||||
|
showMessage('result-message', '正在获取职位代码列表...', 'info');
|
||||||
|
|
||||||
fetch('/crawler/fetchAllPositions', {
|
// 获取全部职位代码
|
||||||
|
const listResp = await fetch('/crawler/getZwdmList', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
|
||||||
},
|
|
||||||
body: `dsdm=${encodeURIComponent(dsdm)}&examid=${encodeURIComponent(examid)}&bmid=${encodeURIComponent(bmid)}&userid=${encodeURIComponent(userid)}&aa=${encodeURIComponent(aa)}&cookies=${encodeURIComponent(JSON.stringify(cookieData))}`
|
body: `dsdm=${encodeURIComponent(dsdm)}&examid=${encodeURIComponent(examid)}&bmid=${encodeURIComponent(bmid)}&userid=${encodeURIComponent(userid)}&aa=${encodeURIComponent(aa)}&cookies=${encodeURIComponent(JSON.stringify(cookieData))}`
|
||||||
})
|
}).then(r => r.json()).catch(e => ({ code: 0, msg: e.message }));
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
if (listResp.code !== 1 || !Array.isArray(listResp.data) || listResp.data.length === 0) {
|
||||||
if (data.code === 1) {
|
showMessage('result-message', listResp.msg || '未获取到职位代码', 'error');
|
||||||
lastResults = data.data;
|
return;
|
||||||
displayResults(data.data);
|
|
||||||
showMessage('result-message', `成功获取 ${data.data.length} 条职位信息`, 'success');
|
|
||||||
} else {
|
|
||||||
showMessage('result-message', data.msg || '获取失败', 'error');
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.catch(error => {
|
const codes = listResp.data.map(it => it.zwdm);
|
||||||
showMessage('result-message', '请求失败: ' + error.message, 'error');
|
showMessage('result-message', `共 ${codes.length} 个职位,开始逐条获取...`, 'info');
|
||||||
});
|
|
||||||
|
// 逐条获取职位详情
|
||||||
|
for (let i = 0; i < codes.length; i++) {
|
||||||
|
const code = codes[i];
|
||||||
|
const infoResp = await fetch('/crawler/getPositionInfo', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
|
body: `zwdm=${encodeURIComponent(code)}&examid=${encodeURIComponent(examid)}&cookies=${encodeURIComponent(JSON.stringify(cookieData))}`
|
||||||
|
}).then(r => r.json()).catch(e => ({ code: 0, msg: e.message }));
|
||||||
|
|
||||||
|
if (infoResp.code === 1 && infoResp.data) {
|
||||||
|
const item = infoResp.data;
|
||||||
|
lastResults.push(item);
|
||||||
|
appendResultRow(item);
|
||||||
|
} else {
|
||||||
|
appendErrorRow(code, infoResp.msg || '获取失败');
|
||||||
|
}
|
||||||
|
|
||||||
|
showMessage('result-message', `进度:${i + 1}/${codes.length}`, 'info');
|
||||||
|
}
|
||||||
|
|
||||||
|
showMessage('result-message', `完成,共 ${lastResults.length} 条成功,失败 ${codes.length - lastResults.length} 条`, 'success');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导出CSV
|
// 导出CSV
|
||||||
|
|||||||
Reference in New Issue
Block a user