fix: 修复浏览器缓存导致工装参数 GET 请求返回旧数据

根因: /api/fixture/param/<id> GET 没有 Cache-Control 头,F5 刷新时
浏览器直接用磁盘缓存返回旧 TestMode,导致测试页显示旧模式。

修复:
- 服务端 fixture.py: GET 响应加 Cache-Control: no-store/no-cache/must-revalidate
- 客户端 test_op.js + fixture.js: 4 处 GET fetch 全部加 ?_=Date.now() 缓存破坏参数
This commit is contained in:
wangfq
2026-06-10 14:29:14 +08:00
parent 4b91455485
commit 4c337b60ae
3 changed files with 7 additions and 5 deletions

View File

@@ -217,7 +217,9 @@ def api_get_serialnet(record_id):
def api_get_fixture_param(dnt_id):
"""获取工装测试参数"""
param = get_fixture_param(dnt_id)
return jsonify(param or {})
resp = jsonify(param or {})
resp.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0"
return resp
@bp.route("/api/fixture/param/<int:dnt_id>", methods=["POST"])

View File

@@ -196,7 +196,7 @@ function onCarChange() {
async function loadFixtureParam() {
try {
const resp = await fetch(`/api/fixture/param/${DNT_ID}`);
const resp = await fetch(`/api/fixture/param/${DNT_ID}?_=${Date.now()}`);
const param = await resp.json();
if (param && param.dnt_id) {
fillFormFromParam(param);
@@ -239,7 +239,7 @@ function fillFormFromParam(param) {
}
async function refreshParams() {
const param = await (await fetch(`/api/fixture/param/${DNT_ID}`)).json();
const param = await (await fetch(`/api/fixture/param/${DNT_ID}?_=${Date.now()}`)).json();
if (param && param.dnt_id) {
fillFormFromParam(param);
commLog('info', null, '已刷新:从数据库加载工装参数');
@@ -360,7 +360,7 @@ function startRespPolling(recordId, cmd) {
if (cmd === '4C') {
// 参数已在后端 upsert直接从 DB 加载
setTimeout(async () => {
const p = await (await fetch(`/api/fixture/param/${DNT_ID}`)).json();
const p = await (await fetch(`/api/fixture/param/${DNT_ID}?_=${Date.now()}`)).json();
if (p && p.dnt_id) fillFormFromParam(p);
}, 500);
}

View File

@@ -275,7 +275,7 @@ async function pollProgress() {
async function loadTestMode() {
try {
const resp = await fetch(`/api/fixture/param/${DNT_ID}`);
const resp = await fetch(`/api/fixture/param/${DNT_ID}?_=${Date.now()}`);
const param = await resp.json();
if (param && param.dnt_id) {
updateTestModeUI(param.TestMode);