@jx3box/jx3box-ui 2.4.18 → 2.4.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/comment/CommentContentSimple.vue +1 -0
- package/src/header/box-menu.js +28 -4
- package/src/header/box.vue +1 -10
- package/src/header/box2.vue +1 -1
- package/src/header/search.vue +9 -1
- package/src/header/utils.js +5 -3
- package/tests/header-menu-search.test.js +47 -0
package/package.json
CHANGED
package/src/header/box-menu.js
CHANGED
|
@@ -2,7 +2,8 @@ import axios from "axios";
|
|
|
2
2
|
import { flatten } from "lodash";
|
|
3
3
|
import JX3BOX from "@jx3box/jx3box-common/data/jx3box.json";
|
|
4
4
|
|
|
5
|
-
const BOX_MENU_CACHE_KEY = "jx3box:box-menu:app-
|
|
5
|
+
const BOX_MENU_CACHE_KEY = "jx3box:box-menu:app-v2";
|
|
6
|
+
let pendingMenu = null;
|
|
6
7
|
|
|
7
8
|
function readCache() {
|
|
8
9
|
try {
|
|
@@ -23,14 +24,16 @@ export function loadBoxMenu(fallback = []) {
|
|
|
23
24
|
const cached = readCache();
|
|
24
25
|
if (cached) return Promise.resolve(cached);
|
|
25
26
|
|
|
26
|
-
return
|
|
27
|
+
if (pendingMenu) return pendingMenu;
|
|
28
|
+
pendingMenu = axios
|
|
27
29
|
.get(JX3BOX.__imgPath + "logo/app.json")
|
|
28
30
|
.then((res) => {
|
|
29
31
|
const source = flatten(Object.values(res.data || {}));
|
|
30
32
|
const data = source.map((item) => ({
|
|
31
33
|
img: item.key + ".svg",
|
|
32
34
|
uuid: item.key,
|
|
33
|
-
|
|
35
|
+
label: item.label,
|
|
36
|
+
abbr: item.abbr || item.label,
|
|
34
37
|
href: item.link,
|
|
35
38
|
client: item.client || ["std", "origin"],
|
|
36
39
|
}));
|
|
@@ -38,5 +41,26 @@ export function loadBoxMenu(fallback = []) {
|
|
|
38
41
|
writeCache(result);
|
|
39
42
|
return result;
|
|
40
43
|
})
|
|
41
|
-
.catch(() => fallback)
|
|
44
|
+
.catch(() => fallback)
|
|
45
|
+
.finally(() => {
|
|
46
|
+
pendingMenu = null;
|
|
47
|
+
});
|
|
48
|
+
return pendingMenu;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function findBoxMenuLink(menu, keyword, client = "std") {
|
|
52
|
+
const query = String(keyword || "").trim().toLowerCase();
|
|
53
|
+
if (!query) return null;
|
|
54
|
+
const matches = menu.filter((item) => {
|
|
55
|
+
const clients = (Array.isArray(item.client) ? item.client : String(item.client || "").split(","))
|
|
56
|
+
.map((value) => String(value).trim().toLowerCase())
|
|
57
|
+
.filter(Boolean);
|
|
58
|
+
const visible = item.status == null || !!item.status;
|
|
59
|
+
const matchedClient = !clients.length || clients.includes("all") || clients.includes(client.toLowerCase());
|
|
60
|
+
return visible && matchedClient && [item.label, item.abbr].some(
|
|
61
|
+
(name) => name && name.trim().toLowerCase() === query
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
const links = [...new Set(matches.map((item) => item.href).filter(Boolean))];
|
|
65
|
+
return links.length === 1 ? links[0] : null;
|
|
42
66
|
}
|
package/src/header/box.vue
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
<li v-for="(item, i) in list" :key="i" :class="{ 'u-app-start': item.lf }">
|
|
16
16
|
<a class="u-item" :href="item.href" :target="getTarget(item.href)">
|
|
17
17
|
<img class="u-pic" :src="getBoxIcon(item.img)" />
|
|
18
|
-
<span class="u-txt" :title="item.abbr">{{
|
|
18
|
+
<span class="u-txt" :title="item.label || item.abbr">{{ item.abbr || item.label }}</span>
|
|
19
19
|
</a>
|
|
20
20
|
</li>
|
|
21
21
|
</ul>
|
|
@@ -37,12 +37,6 @@ import { trimSlash } from "./utils";
|
|
|
37
37
|
import { loadBoxMenu } from "./box-menu";
|
|
38
38
|
|
|
39
39
|
const { __imgPath, __cdn } = JX3BOX;
|
|
40
|
-
const shortNames = {
|
|
41
|
-
talent: "奇穴模拟",
|
|
42
|
-
talent2: "镇派模拟",
|
|
43
|
-
meridians: "经脉模拟",
|
|
44
|
-
topic: "资料片",
|
|
45
|
-
};
|
|
46
40
|
export default {
|
|
47
41
|
name: "Box",
|
|
48
42
|
mixins: [i18nMixin],
|
|
@@ -98,9 +92,6 @@ export default {
|
|
|
98
92
|
let web_url = __cdn + "logo/logo-dark/" + val;
|
|
99
93
|
return web_url;
|
|
100
94
|
},
|
|
101
|
-
getDisplayName: function (item) {
|
|
102
|
-
return shortNames[item.uuid] || item.abbr;
|
|
103
|
-
},
|
|
104
95
|
getTarget: function (val) {
|
|
105
96
|
if (window.innerWidth < 768 || val?.startsWith("/")) {
|
|
106
97
|
return "_self";
|
package/src/header/box2.vue
CHANGED
package/src/header/search.vue
CHANGED
|
@@ -27,6 +27,8 @@
|
|
|
27
27
|
<script>
|
|
28
28
|
import JX3BOX from "@jx3box/jx3box-common/data/jx3box.json";
|
|
29
29
|
import { searchJump } from "./utils";
|
|
30
|
+
import { loadBoxMenu } from "./box-menu";
|
|
31
|
+
import box from "../../assets/data/box.json";
|
|
30
32
|
import i18nMixin from "../../i18n/mixin";
|
|
31
33
|
// import searchIcon from "@/assets/img/components/common/header/search-key-slash.svg";
|
|
32
34
|
export default {
|
|
@@ -37,6 +39,7 @@ export default {
|
|
|
37
39
|
},
|
|
38
40
|
data: function () {
|
|
39
41
|
return {
|
|
42
|
+
menu: [],
|
|
40
43
|
isPhone: window.innerWidth < 720 ? true : false,
|
|
41
44
|
url: JX3BOX.__Root + "search",
|
|
42
45
|
client: location.href.includes("origin") ? "origin" : "std",
|
|
@@ -54,10 +57,15 @@ export default {
|
|
|
54
57
|
isPhone: this.isPhone,
|
|
55
58
|
url: this.url,
|
|
56
59
|
client: this.client,
|
|
60
|
+
menu: this.menu,
|
|
57
61
|
});
|
|
58
62
|
},
|
|
59
63
|
},
|
|
60
|
-
created: function () {
|
|
64
|
+
created: function () {
|
|
65
|
+
loadBoxMenu(box).then((menu) => {
|
|
66
|
+
this.menu = menu;
|
|
67
|
+
});
|
|
68
|
+
},
|
|
61
69
|
};
|
|
62
70
|
</script>
|
|
63
71
|
|
package/src/header/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ElNotification } from "element-plus";
|
|
2
2
|
import JX3BOX from "@jx3box/jx3box-common/data/jx3box.json";
|
|
3
3
|
import searchMap from "./search_map.json";
|
|
4
|
+
import { findBoxMenuLink } from "./box-menu";
|
|
4
5
|
import { tGlobal } from "../../i18n";
|
|
5
6
|
|
|
6
7
|
const { __Root } = JX3BOX;
|
|
@@ -77,8 +78,9 @@ export function dispatchEventStorage() {
|
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
// search 跳转公共函数
|
|
80
|
-
export function searchJump({ searchValue, isPhone = false, client = "std", url }) {
|
|
81
|
+
export function searchJump({ searchValue, isPhone = false, client = "std", url, menu = [] }) {
|
|
81
82
|
searchValue = searchValue.trim().toLowerCase();
|
|
83
|
+
const menuLink = findBoxMenuLink(menu, searchValue, client);
|
|
82
84
|
|
|
83
85
|
// 检查输入是否为纯数字
|
|
84
86
|
if (/^\d+$/.test(searchValue)) {
|
|
@@ -90,10 +92,10 @@ export function searchJump({ searchValue, isPhone = false, client = "std", url }
|
|
|
90
92
|
} else {
|
|
91
93
|
window.location.href = targetUrl;
|
|
92
94
|
}
|
|
93
|
-
} else if (searchMap[searchValue]) {
|
|
95
|
+
} else if (searchMap[searchValue] || menuLink) {
|
|
94
96
|
// 如果是 searchMap 中的关键词,跳转到对应的 URL
|
|
95
97
|
const target = isPhone ? "_self" : "_blank";
|
|
96
|
-
const targetUrl = searchMap[searchValue];
|
|
98
|
+
const targetUrl = searchMap[searchValue] || menuLink;
|
|
97
99
|
|
|
98
100
|
if (target === "_blank") {
|
|
99
101
|
window.open(targetUrl, "_blank");
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const assert = require('node:assert/strict');
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const test = require('node:test');
|
|
5
|
+
const source = fs.readFileSync(path.join(__dirname, '../src/header/box-menu.js'), 'utf8')
|
|
6
|
+
.replace(/^import .+;$/gm, '').replace(/export function /g, 'function ');
|
|
7
|
+
const { findBoxMenuLink } = Function(source + ';return {findBoxMenuLink};')();
|
|
8
|
+
const menu = [
|
|
9
|
+
{label: '技能合集', abbr: '招式', href: '/bps/kungfu', client: ['std', 'origin']},
|
|
10
|
+
{label: '技改历史', abbr: 'PVE技改', href: '/bps/changelog'},
|
|
11
|
+
{label: '技改历史', abbr: 'PVP技改', href: '/pvp/changelog'},
|
|
12
|
+
{label: '万宝楼', abbr: '万宝楼', href: '/std', client: 'std'},
|
|
13
|
+
{label: '万宝楼', abbr: '万宝楼', href: '/origin', client: ['origin']},
|
|
14
|
+
{label: '隐藏入口', abbr: '隐藏', href: '/hidden', status: false},
|
|
15
|
+
];
|
|
16
|
+
test('full names and abbreviations match, including case and whitespace', () => {
|
|
17
|
+
assert.equal(findBoxMenuLink(menu, '技能合集'), '/bps/kungfu');
|
|
18
|
+
assert.equal(findBoxMenuLink(menu, '招式'), '/bps/kungfu');
|
|
19
|
+
assert.equal(findBoxMenuLink(menu, ' pve技改 '), '/bps/changelog');
|
|
20
|
+
assert.equal(findBoxMenuLink(menu, 'PVP技改'), '/pvp/changelog');
|
|
21
|
+
});
|
|
22
|
+
test('client filtering disambiguates links and ambiguous or hidden names do not redirect', () => {
|
|
23
|
+
assert.equal(findBoxMenuLink(menu, '万宝楼', 'std'), '/std');
|
|
24
|
+
assert.equal(findBoxMenuLink(menu, '万宝楼', 'origin'), '/origin');
|
|
25
|
+
for (const query of ['技改历史', '隐藏', '', '技', '攻略内容']) {
|
|
26
|
+
assert.equal(findBoxMenuLink(menu, query), null);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
test('search keeps numeric, legacy keyword and ordinary search behavior', () => {
|
|
30
|
+
const utils = fs.readFileSync(path.join(__dirname, '../src/header/utils.js'), 'utf8')
|
|
31
|
+
.replace(/^import .+;$/gm, '').replace(/export function /g, 'function ');
|
|
32
|
+
const opened = [];
|
|
33
|
+
const forms = [];
|
|
34
|
+
const document = {
|
|
35
|
+
createElement: () => ({ children: [], appendChild(child) { this.children.push(child); }, submit() { forms.push(this); } }),
|
|
36
|
+
body: { appendChild() {}, removeChild() {} },
|
|
37
|
+
};
|
|
38
|
+
const searchJump = Function('JX3BOX', 'findBoxMenuLink', 'searchMap', 'window', 'document', utils + ';return searchJump;')(
|
|
39
|
+
{__Root: 'https://www.jx3box.com/'}, findBoxMenuLink, {'qq机器人': '/qqbot'},
|
|
40
|
+
{open: (url) => opened.push(url)}, document
|
|
41
|
+
);
|
|
42
|
+
const run = (searchValue) => searchJump({searchValue, menu, url: '/search', client: 'std'});
|
|
43
|
+
run('招式'); run('123'); run('qq机器人'); run('攻略内容');
|
|
44
|
+
assert.deepEqual(opened, ['/bps/kungfu', 'https://www.jx3box.com/post/123', '/qqbot']);
|
|
45
|
+
assert.equal(forms[0].action, '/search');
|
|
46
|
+
assert.deepEqual(forms[0].children.map(({name, value}) => [name, value]), [['q', '攻略内容'], ['client', 'std']]);
|
|
47
|
+
});
|