-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
391 lines (361 loc) · 12 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>装备改修助手</title>
<link rel="stylesheet" href="lib/assistor.css">
</head>
<body>
<!--
+-----------------------+ Page +-----------------------+
| |
| +---+ Category List +--+ +--+ Enhance Today +---+ |
| | | | | |
| | +--+ Category#1 +--+ | | Equip#2->[UpgradeTo] | |
| | | | | | -------------------- | |
| | +---------------+--+ | | [ship1][ship2][ship3]| |
| | |[ ] Equip#1 | | | | |
| | +---------------+ | | | |
| | |[x] Equip#2 | | | Equip#5->[UpgradeTo] | |
| | +---------------+ | | -------------------- | |
| | | | [ship1][ship3] | |
| | +--+ Category#2 +--+ | | | |
| | | | | | | |
| | +---------------+--+ | | ...... | |
| | |[x] Equip#3 | | | | |
| | +---------------+ | | | |
| | | | | |
| | ...... | | | |
| | | | | |
| +----------------------+ +----------------------+ |
| |
+------------------------------------------------------+
+----------------------+ Remark +----------------------+
| Suppose it's MON today. |
| Only Equip#2 can enhance today. |
+------------------------------------------------------+
-->
<div id="app" class="container">
<title-panel></title-panel>
<category-list :c-map="categoryMap"
:e-map="equipMap"></category-list>
<enhance-today :e-map="equipMap"></enhance-today>
</div>
<template id="titlePanel">
<div class="title-panel">
<span>
# title #
</span>
<span>
# OPTIONS icon #
</span>
</div>
</template>
<template id="categoryList">
<div :class="customStyle">
<h2># categoryList #</h2>
<category v-for="(cEntity, cIdx) in cMap" :key="cIdx"
:c-entity="cEntity[1]"
:c-idx="cIdx"
:equip-map="equipFilterBy(cEntity[1].equipIds)">
</category>
</div>
</template>
<template id="enhanceToday">
<div :class="customStyle">
<div># FORMATTED & CALCULATED selected equips #</div>
<enabled-equip
v-for="(entry, idx) in qFiltered" :key="idx"
:e-name="entry[0]" :assists="entry[1]">
</enabled-equip>
</div>
</template>
<template id="category">
<div>
<h3 @click="display=!display">{{ cName }}</h3>
<transition-group tag="ul">
<!-- @cb-changed事件发生时, 调用方法updateEquipIds -->
<equip v-show="display"
v-for="(eid, idx) in equipIds" :key="eid"
:eid="eid"
:idx="idx"
:e-entity="findEquipBy(eid)"
@cb-changed="updateEquipIds">
</equip>
</transition-group>
</div>
</template>
<template id="equip">
<li>
<label>
<!-- checkbox状态发生变化时, 调用方法cbChanged,
该方法发出事件'cb-changed', 交由上一层category处理 -->
<input type="checkbox"
v-model="cbChecked"
:value="eid"
@change="cbChanged">
<code>{{ eEntity.name }}</code>
</label>
</li>
</template>
<template id="enabledEquip">
<div class="search-entity">
<div class="equip-name">{{ eName }}</div>
<div class="assists">
<div class="assist"
v-for="(assist, idx) in assists"
:class="colorArr[idx]"
:key="idx">
{{ assist.aName }}
</div>
</div>
</div>
</template>
<script src="lib/vue.js"></script>
<script src="lib/equips.js"></script>
<script src="lib/js.store/jsstore.js"></script>
<script src="lib/initJsDb.js"></script>
<!--suppress JSAnnotator -->
<script>
const TOOLS = {
jpDate: function() {
const JP_TIMEZONE = 9;
let curr = new Date();
return new Date(
curr.getUTCFullYear(),
curr.getUTCMonth(),
curr.getUTCDate(),
curr.getUTCHours() + JP_TIMEZONE,
curr.getUTCMinutes(),
curr.getUTCSeconds()
);
},
colorShuffle: function(arrLength) {
if(arrLength === 0) {
return [];
}
const COLOR_CLAZZ_ARR = ['red', 'yellow', 'green', 'blue', 'purple'];
let limitShuffle = function(limit = 0) {
let copy = COLOR_CLAZZ_ARR.slice();
let currIdx = copy.length;
let randIdx;
while(0 !== currIdx) {
randIdx = Math.floor(Math.random() * currIdx);
currIdx--;
[copy[currIdx], copy[randIdx]] = [copy[randIdx], copy[currIdx]];
}
// !!0 表示 false, 使用.slice()创建一个数组的新副本
if(!!limit && limit < copy.length) {
return (copy.slice(0, limit));
} else {
return copy;
}
};
let newArr = [];
let limitBorder = arrLength;
do {
if(limitBorder > COLOR_CLAZZ_ARR.length) {
newArr.push(limitShuffle(COLOR_CLAZZ_ARR));
} else {
newArr.push(limitShuffle(COLOR_CLAZZ_ARR, limitBorder))
}
limitBorder = limitBorder - COLOR_CLAZZ_ARR.length;
} while(limitBorder > 0);
return (newArr.flat());
},
};
// 组件equip, 基础组件, 是组件Category的组成部分
let comEquip = {
template: '#equip',
data() {
return {
cbChecked: false
}
},
props: ['eid', 'eEntity', 'idx'],
methods: {
cbChanged() {
// 发出事件checkbox-changed, 附带参数idx, eid, cbChecked
this.$emit('cb-changed', this.idx, this.eid, this.cbChecked);
}
}
};
// 组件category
// 组件category下每一个子组件equip都附带参数: idx, eid,
let comCategory = {
template: '#category',
data() {
return {
reducedArr: [],
selectedEquipIdArr: [],
display: false
};
},
props: ['cEntity', 'equipMap', 'cIdx'],
methods: {
updateEquipIds: function(eIdx, eid, isChecked) {
if(isChecked) {
this.selectedEquipIdArr[eIdx] = eid;
} else {
this.selectedEquipIdArr[eIdx] = undefined;
}
this.reducedArr = this.selectedEquipIdArr.filter(elem => {
return !!(elem);
});
this.$eventBus.$emit('update-today-enhance', this.cIdx, this.reducedArr);
},
findEquipBy(eid) {
return this.equipMap.get(eid);
}
},
computed: {
cName: function() {
return this.cEntity.name;
},
equipIds: function() {
return this.cEntity.equipIds;
}
},
components: {
equip: comEquip
}
};
let comEnabledEquip = {
template: '#enabledEquip',
props: ['eName', 'assists'],
computed: {
colorArr: function() {
return (TOOLS.colorShuffle(this.assists.length));
}
},
};
// 组件title-panel
Vue.component('titlePanel', {
template: '#titlePanel'
});
// 组件category-list
// 附带参数: cMap, eMap
Vue.component('categoryList', {
template: '#categoryList',
data() {
return {
customStyle: {
'list-panel': true
}
}
},
props: ['cMap', 'eMap'],
methods: {
equipFilterBy: function(eidArr) {
let equipsInACategory = new Map();
eidArr.forEach(eid => {
equipsInACategory.set(eid, this.eMap.get(eid));
});
return equipsInACategory;
}
},
components: {
category: comCategory,
}
});
// 组件enhance-today
Vue.component('enhanceToday', {
template: '#enhanceToday',
data() {
return {
checkedEquipIdxArr: [],
qFiltered: undefined,
customStyle: {
'list-panel': true
}
}
},
props: ['eMap'],
methods: {
calc(reducedIdxArr) { // 返回当天可以改修的装备; 应当使用新的实体, 来包装已经经过计算筛选的数据
let debugFlag = true;
let debug = (flag, msg) => {
if(flag) {
console.log(msg);
}
};
let weekday = TOOLS.jpDate().getDay();
//在WHERE中使用数组陈列条件强化AND, 原始查询语句为:
// SELECT * FROM assist WHERE accessDayStr = ${ weekday } AND eid IN [ ... ]
//使用查询条件:
// where: {
// accessDayStr: { like: `%${ weekday }%` },
// eid: { in: this.localReducedIdxArr.flat() }
// }
//在 eid : [] 的情况下会返回单一契合 accessDayStr条件的数据数组, 与实际需求不符
debug(debugFlag, '--- calc() 执行开始 ---');
return connection.select({
from: 'assist',
where: [
{accessDayStr: {like: `%${ weekday }%`}},
{eid: {in: reducedIdxArr.flat()}}
],
join: {
with: 'equipName',
on: 'assist.eid=equipName.eid'
},
order: [
{by: 'assist.eid', type: 'asc'},
{by: 'assist.uid', type: 'asc'}
]
}).then(results => {
// results will be array of objects.
if(results.length > 0) {
debug(debugFlag, `> ${ JSON.stringify(results) }`); //TODO 预定删除本行调试, 在控制台中反馈的内容仅为[object, Object]
debug(debugFlag, `> 选中装备数: ${ results.length }\n> ${ reducedIdxArr.flat().join(', ') }`);
} else if(results.length === 0) {
debug(debugFlag, '没有查询到相关数据 / 没有装备被勾选');
}
// 遍历查询结果, 创建过滤一些字段查询结果, TODO 还可以进一步完善, 对写入的数据进行格式化, 将相同装备ID的数据分为一组, 方便数据进行展示
let filtered = new Map();
results.forEach(function(item) {
if(!filtered.has(item.equipName)) {
filtered.set(item.equipName, []);
}
let entry = filtered.get(item.equipName);
entry.push({uid: item.uid, aName: item.assistName});
});
debug(debugFlag, `> ${ JSON.stringify([...filtered]) }`);
this.qFiltered = filtered;
}).catch(error => {
console.error(error.message);
});
}
},
created() {
// 每一次点击, 触发'update-today-enhance', 自动计算
this.$eventBus.$on('update-today-enhance', (cIdx, reducedArr) => {
this.checkedEquipIdxArr[cIdx] = reducedArr;
let reducedIdxArr = this.checkedEquipIdxArr.filter((elem = []) => {
return !!(elem.length);
});
this.calc(reducedIdxArr);
});
},
components: {
enabledEquip: comEnabledEquip
}
});
// 全局事件总线, 可以传递很多东西, 不仅仅是数据
Vue.prototype.$eventBus = new Vue();
// 文件/lib/equips.js存在一个字符串数组META, 其中包含了两个元素
// META[0], META[1]转化为JSON后, 可以序列化为Map, 作为数据源供调用与查询
const vm = new Vue({
el: '#app',
computed: {
categoryMap() {
return new Map(JSON.parse(META[0]));
},
equipMap() {
return new Map(JSON.parse(META[1]));
}
}
});
</script>
</body>
</html>