Skip to content

Commit 42a6996

Browse files
committed
fix:绝世奇遇cdn请求优化
1 parent 1ce660e commit 42a6996

7 files changed

Lines changed: 103 additions & 16 deletions

File tree

docs/project/treasure-layout.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# 奇遇珍卷布局数据规则
2+
3+
## 背景
4+
5+
奇遇珍卷的绝世奇遇布局来自 `@jx3box/jx3box-common/data/treasure_perfect.json`,运行时默认会请求:
6+
7+
`https://cdn.jsdelivr.net/npm/@jx3box/jx3box-common/data/treasure_perfect.json`
8+
9+
这个无版本 jsDelivr URL 可能因为 CDN 或浏览器缓存短时间指向旧 npm 版本。曾出现本地包已更新到 `9.2.6`,线上无版本 URL 仍返回 `9.2.5`,导致新增绝世奇遇 `id=163` 缺失。
10+
11+
## 当前规则
12+
13+
- 远程布局有效且包含本地包内所有绝世奇遇 id 时,以远程 `items` 顺序为准。
14+
- 远程布局缺少本地包内的 id 时,视为远程可能落后或缓存未刷新,以本地包内 `items` 顺序补齐缺失项。
15+
- 补齐时,同 id 的远程配置会覆盖本地配置,避免远程已有样式更新被本地旧配置挡住。
16+
- 远程存在本地没有的额外 id 时会保留;远程完整时按远程顺序展示,远程缺本地项时额外 id 追加在补齐列表末尾。
17+
18+
## 层级规则
19+
20+
绝世奇遇图片层级不再读取 JSON 内的 `zIndex`。页面渲染时直接使用 `items` 数组索引作为 `z-index`,因此调整遮挡关系应调整 `treasure_perfect.json``perfect.items` 的顺序。
21+
22+
## 维护建议
23+
24+
- 发布 `@jx3box/jx3box-common` 新版本后,建议 purge 相关 jsDelivr URL:
25+
- `https://purge.jsdelivr.net/npm/@jx3box/jx3box-common/data/treasure_perfect.json`
26+
- `https://purge.jsdelivr.net/npm/@jx3box/jx3box-common@latest/data/treasure_perfect.json`
27+
- 如果对实时性要求更高,可通过 `VUE_APP_ADVENTURE_TREASURE_LAYOUT_URL` 指向固定版本 URL 或自有数据地址。
28+
- 后续调整奇遇珍卷逻辑时,请先阅读本文件和项目根目录的 `AGENTS.md`(如果存在)。

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
"dependencies": {
3333
"@element-plus/icons-vue": "^2.3.2",
34-
"@jx3box/jx3box-common": "^9.2.5",
34+
"@jx3box/jx3box-common": "^9.2.6",
3535
"@jx3box/jx3box-data": "^3.9.5",
3636
"@jx3box/jx3box-editor": "^3.2.7",
3737
"@jx3box/jx3box-emotion": "^1.3.0",

src/assets/js/treasure/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function buildPerfectAchievements(adventureList = [], achievedIds, layout) {
3232
const achievementsList = [];
3333
let actNum = 0;
3434

35-
getTreasurePerfectItems(layout).forEach((layoutItem, index) => {
35+
getTreasurePerfectItems(layout).forEach((layoutItem) => {
3636
const id = Number(layoutItem.id || layoutItem.dwID);
3737
const adventure = adventureMap[id];
3838
if (!id || !adventure) return;
@@ -43,7 +43,6 @@ function buildPerfectAchievements(adventureList = [], achievedIds, layout) {
4343
...adventure,
4444
isAct,
4545
hasClass: layoutItem.key || "",
46-
zIndex: layoutItem.zIndex || (index + 1),
4746
layout: layoutItem,
4847
});
4948
});

src/assets/js/treasure/layout.js

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,69 @@ function isValidTreasureLayout(layout) {
1313
return Array.isArray(layout?.perfect?.items);
1414
}
1515

16+
function getLayoutItems(layout = {}) {
17+
return Array.isArray(layout?.perfect?.items) ? layout.perfect.items : [];
18+
}
19+
20+
function getLayoutItemId(item = {}) {
21+
return Number(item.id || item.dwID);
22+
}
23+
24+
function hasAllBaseItems(baseItems = [], overrideItems = []) {
25+
const overrideItemIds = new Set(overrideItems.map(getLayoutItemId).filter(Boolean));
26+
return baseItems.every((item) => overrideItemIds.has(getLayoutItemId(item)));
27+
}
28+
29+
function mergeTreasureLayout(baseLayout = treasurePerfect, overrideLayout = {}) {
30+
const baseItems = getLayoutItems(baseLayout);
31+
const overrideItems = getLayoutItems(overrideLayout);
32+
33+
if (hasAllBaseItems(baseItems, overrideItems)) {
34+
return {
35+
...baseLayout,
36+
...overrideLayout,
37+
perfect: {
38+
...(baseLayout.perfect || {}),
39+
...(overrideLayout.perfect || {}),
40+
items: overrideItems,
41+
},
42+
};
43+
}
44+
45+
const overrideItemMap = overrideItems.reduce((map, item) => {
46+
const id = getLayoutItemId(item);
47+
if (id) map[id] = item;
48+
return map;
49+
}, {});
50+
const mergedItemIds = new Set();
51+
const items = baseItems.map((baseItem) => {
52+
const id = getLayoutItemId(baseItem);
53+
mergedItemIds.add(id);
54+
return {
55+
...baseItem,
56+
...(overrideItemMap[id] || {}),
57+
};
58+
});
59+
60+
overrideItems.forEach((item) => {
61+
const id = getLayoutItemId(item);
62+
if (!mergedItemIds.has(id)) items.push(item);
63+
});
64+
65+
return {
66+
...baseLayout,
67+
...overrideLayout,
68+
perfect: {
69+
...(baseLayout.perfect || {}),
70+
...(overrideLayout.perfect || {}),
71+
items,
72+
},
73+
};
74+
}
75+
1676
function normalizeLayoutResponse(res) {
1777
const layout = res?.data?.data || res?.data || res;
18-
return isValidTreasureLayout(layout) ? layout : treasurePerfect;
78+
return isValidTreasureLayout(layout) ? mergeTreasureLayout(treasurePerfect, layout) : treasurePerfect;
1979
}
2080

2181
export function getAdventureTreasureLayout(options = {}) {
@@ -35,8 +95,8 @@ export function getAdventureTreasureLayout(options = {}) {
3595
}
3696

3797
export function getTreasurePerfectItems(layout = treasurePerfect) {
38-
const items = layout?.perfect?.items;
39-
return Array.isArray(items) ? items : treasurePerfect?.perfect?.items || [];
98+
const items = getLayoutItems(layout);
99+
return items.length ? items : getLayoutItems(treasurePerfect);
40100
}
41101

42102
export function getTreasurePerfectItemMap(layout = treasurePerfect) {

src/views/adventure/treasure/miniprogram/PortraitContent.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<img
5555
class="u-item__img"
5656
:class="perfectItemClass(item)"
57-
:style="perfectImageStyle(item)"
57+
:style="perfectImageStyle(item, index)"
5858
:src="getCdnImgUrl(perfectItemImage(item))"
5959
/>
6060
<div class="m-item__text" :class="perfectItemClass(item)" :style="perfectLabelStyle(item)">
@@ -238,11 +238,11 @@ export default {
238238
perfectItemClass(item = {}) {
239239
return this.perfectItemLayout(item).key || item.hasClass || "";
240240
},
241-
perfectImageStyle(item = {}) {
241+
perfectImageStyle(item = {}, index = 0) {
242242
const layout = this.perfectItemLayout(item);
243243
return {
244244
...toTreasureCssStyle(layout.imageStyle),
245-
zIndex: Number(item.zIndex || layout.zIndex || 1),
245+
zIndex: index,
246246
};
247247
},
248248
perfectLabelStyle(item = {}) {

src/views/adventure/treasure/pc/LandscapeContent.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
<img
112112
class="u-item__img"
113113
:class="perfectItemClass(item)"
114-
:style="perfectImageStyle(item)"
114+
:style="perfectImageStyle(item, index)"
115115
:src="getCdnImgUrl(perfectItemImage(item))"
116116
/>
117117
<div class="m-item__text" :class="perfectItemClass(item)" :style="perfectLabelStyle(item)">
@@ -244,11 +244,11 @@ export default {
244244
perfectItemClass(item = {}) {
245245
return this.perfectItemLayout(item).key || item.hasClass || "";
246246
},
247-
perfectImageStyle(item = {}) {
247+
perfectImageStyle(item = {}, index = 0) {
248248
const layout = this.perfectItemLayout(item);
249249
return {
250250
...toTreasureCssStyle(layout.imageStyle),
251-
zIndex: Number(item.zIndex || layout.zIndex || 1),
251+
zIndex: index,
252252
};
253253
},
254254
perfectLabelStyle(item = {}) {

0 commit comments

Comments
 (0)