@jx3box/jx3box-ui 2.4.17 → 2.4.19
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/assets/css/header/box.less +40 -25
- package/package.json +1 -1
- package/src/header/box-menu.js +28 -4
- package/src/header/box.vue +1 -7
- 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
|
@@ -77,6 +77,8 @@
|
|
|
77
77
|
color: #666;
|
|
78
78
|
.db;
|
|
79
79
|
white-space: nowrap;
|
|
80
|
+
overflow: hidden;
|
|
81
|
+
text-overflow: ellipsis;
|
|
80
82
|
}
|
|
81
83
|
.u-mark {
|
|
82
84
|
color: #fff;
|
|
@@ -132,7 +134,8 @@
|
|
|
132
134
|
}
|
|
133
135
|
}
|
|
134
136
|
|
|
135
|
-
|
|
137
|
+
// The mobile box is selected at 768px in CommonHeader.vue.
|
|
138
|
+
@media screen and (max-width: 768px) {
|
|
136
139
|
.c-header-jx3box {
|
|
137
140
|
padding-top: 16px;
|
|
138
141
|
background: #1d2128;
|
|
@@ -140,40 +143,16 @@
|
|
|
140
143
|
}
|
|
141
144
|
|
|
142
145
|
.c-jx3box {
|
|
143
|
-
height: calc(100vh - @header-height);
|
|
144
146
|
.u-list {
|
|
145
147
|
border-top: none;
|
|
146
|
-
padding: 0 16px 18px;
|
|
147
|
-
display: grid;
|
|
148
|
-
grid-template-columns: repeat(4, 1fr);
|
|
149
|
-
justify-content: center;
|
|
150
|
-
.w(100%);
|
|
151
|
-
box-sizing: border-box;
|
|
152
|
-
gap: 10px;
|
|
153
|
-
margin: 0 !important;
|
|
154
|
-
&::after {
|
|
155
|
-
flex: 1;
|
|
156
|
-
}
|
|
157
|
-
li {
|
|
158
|
-
padding: 4px;
|
|
159
|
-
.mr(0);
|
|
160
|
-
.mb(0);
|
|
161
|
-
}
|
|
162
148
|
}
|
|
163
149
|
.u-item {
|
|
164
|
-
.size(68px);
|
|
165
|
-
.auto(x);
|
|
166
|
-
padding: 7px;
|
|
167
150
|
border-radius: 10px;
|
|
168
151
|
border-color: rgba(255, 255, 255, 0.08);
|
|
169
152
|
background: #292e37;
|
|
170
153
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.16);
|
|
171
154
|
transition: border-color 0.2s ease, background-color 0.2s ease, transform 0.2s ease;
|
|
172
155
|
|
|
173
|
-
.u-pic {
|
|
174
|
-
.size(28px);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
156
|
.u-txt {
|
|
178
157
|
color: #d4d7de;
|
|
179
158
|
}
|
|
@@ -192,6 +171,39 @@
|
|
|
192
171
|
background: rgba(255, 255, 255, 0.06);
|
|
193
172
|
color: #d4d7de;
|
|
194
173
|
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
@media screen and (max-width: @phone) {
|
|
178
|
+
.c-jx3box {
|
|
179
|
+
height: calc(100vh - @header-height);
|
|
180
|
+
.u-list {
|
|
181
|
+
padding: 0 16px 18px;
|
|
182
|
+
display: grid;
|
|
183
|
+
grid-template-columns: repeat(4, 1fr);
|
|
184
|
+
justify-content: center;
|
|
185
|
+
.w(100%);
|
|
186
|
+
box-sizing: border-box;
|
|
187
|
+
gap: 10px;
|
|
188
|
+
margin: 0 !important;
|
|
189
|
+
&::after {
|
|
190
|
+
flex: 1;
|
|
191
|
+
}
|
|
192
|
+
li {
|
|
193
|
+
padding: 4px;
|
|
194
|
+
.mr(0);
|
|
195
|
+
.mb(0);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
.u-item {
|
|
199
|
+
.size(68px);
|
|
200
|
+
.auto(x);
|
|
201
|
+
padding: 7px;
|
|
202
|
+
|
|
203
|
+
.u-pic {
|
|
204
|
+
.size(28px);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
195
207
|
.u-app-start {
|
|
196
208
|
clear: none;
|
|
197
209
|
}
|
|
@@ -207,6 +219,9 @@
|
|
|
207
219
|
.u-pic {
|
|
208
220
|
.size(22px);
|
|
209
221
|
}
|
|
222
|
+
.u-txt {
|
|
223
|
+
font-size: 11px;
|
|
224
|
+
}
|
|
210
225
|
}
|
|
211
226
|
}
|
|
212
227
|
}
|
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>
|
|
@@ -92,12 +92,6 @@ export default {
|
|
|
92
92
|
let web_url = __cdn + "logo/logo-dark/" + val;
|
|
93
93
|
return web_url;
|
|
94
94
|
},
|
|
95
|
-
getDisplayName: function (name) {
|
|
96
|
-
const chars = Array.from(String(name || "").trim());
|
|
97
|
-
if (chars.length === 5) return chars.slice(0, 3).join("");
|
|
98
|
-
if (chars.length === 4) return chars.slice(0, 2).join("");
|
|
99
|
-
return chars.join("");
|
|
100
|
-
},
|
|
101
95
|
getTarget: function (val) {
|
|
102
96
|
if (window.innerWidth < 768 || val?.startsWith("/")) {
|
|
103
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
|
+
});
|