diff --git a/.gitignore b/.gitignore index b604ccf9..f862e1a0 100755 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ !/resources/help/theme/default /config/character.js /config/profile.js -/config/help.js \ No newline at end of file +/config/help.js +/config/cfg.js diff --git a/apps/character/ProfileList.js b/apps/character/ProfileList.js index 18487d40..d03b41cd 100644 --- a/apps/character/ProfileList.js +++ b/apps/character/ProfileList.js @@ -1,14 +1,17 @@ import lodash from 'lodash' import { autoRefresh, getTargetUid } from './ProfileCommon.js' -import { Common, Profile } from '../../components/index.js' +import { ProfileRank } from '../../models/index.js' +import { Common, Profile, Data } from '../../components/index.js' export async function profileList (e) { let uid = await getTargetUid(e) if (!uid) { return true } - - let profiles = Profile.getAll(uid) || {} + let rank = false + if (e.group_id) { + rank = await ProfileRank.create({ group: e.group_id, uid, qq: e.user_id }) + } let servName = Profile.getServName(uid) let hasNew = false let newCount = 0 @@ -20,7 +23,9 @@ export async function profileList (e) { msg = '获取角色面板数据成功' newChar = e.newChar } - lodash.forEach(profiles || {}, (profile) => { + const cfg = await Data.importCfg('cfg') + const groupRank = cfg?.diyCfg?.groupRank || false + await Profile.forEach(uid, async function (profile) { if (!profile.hasData) { return true } @@ -31,6 +36,9 @@ export async function profileList (e) { tmp.level = profile.level || 1 tmp.cons = profile.cons tmp.isNew = 0 + if (rank) { + tmp.groupRank = await rank.getRank(profile) + } if (newChar[char.name]) { tmp.isNew = 1 newCount++ @@ -62,6 +70,7 @@ export async function profileList (e) { chars, servName, hasNew, - msg + msg, + groupRank }, { e, scale: 1.6 }) } diff --git a/components/Profile.js b/components/Profile.js index 639f23ea..912e477f 100644 --- a/components/Profile.js +++ b/components/Profile.js @@ -108,6 +108,16 @@ let Profile = { return false }, + async forEach (uid, fn) { + let profiles = Profile.getAll(uid) + for (let id in profiles) { + let ret = await fn(profiles[id], id) + if (ret === false) { + return false + } + } + }, + inputProfile (uid, e) { let { avatar, inputData } = e let char = Character.get(avatar) diff --git a/config/system/cfg_system.js b/config/system/cfg_system.js new file mode 100644 index 00000000..44bc0e2d --- /dev/null +++ b/config/system/cfg_system.js @@ -0,0 +1,2 @@ +export const groupRank = false +export const isSys = true diff --git a/models/ProfileRank.js b/models/ProfileRank.js new file mode 100644 index 00000000..bee5570a --- /dev/null +++ b/models/ProfileRank.js @@ -0,0 +1,42 @@ +import { Format } from '../components/index.js' +import lodash from 'lodash' + +export default class ProfileRank { + constructor (data) { + this.group = data.group || data.groupId + this.qq = data.qq + this.uid = data.uid + '' + } + + static async create (data) { + return new ProfileRank(data) + } + + key (profile, type) { + return `miao:rank:${this.group}:${type}:${profile.id}` + } + + async getRank (profile, force = false) { + const key = this.key(profile, 'mark') + let rank = await redis.zRank(key, this.uid) + if (!rank || force) { + let mark = profile.getArtisMark(false) + if (mark) { + await redis.zAdd(key, { score: mark._mark, value: this.uid }) + rank = await redis.zRank(key, this.uid) + } + } + if (lodash.isNumber(rank)) { + let count = await redis.zCard(key) + let mark = await redis.zScore(key, this.uid) + return { + rank: rank + 1, + count, + value: Format.comma(mark, 1), + _value: mark, + pct: Format.percent(Math.max(0.01, Math.min(0.999, (count - rank) / count))) + } + } + return false + } +} diff --git a/models/index.js b/models/index.js index 9a270cd3..8342fa88 100644 --- a/models/index.js +++ b/models/index.js @@ -10,6 +10,7 @@ import ProfileReq from './ProfileReq.js' import ProfileData from './ProfileData.js' import ProfileArtis from './ProfileArtis.js' import ProfileDmg from './ProfileDmg.js' +import ProfileRank from './ProfileRank.js' import Material from './Material.js' import Weapon from './Weapon.js' import User from './User.js' @@ -28,6 +29,7 @@ export { ProfileData, ProfileArtis, ProfileDmg, + ProfileRank, Material, Weapon, User, diff --git a/resources/character/imgs/rank-bg.png b/resources/character/imgs/rank-bg.png new file mode 100644 index 00000000..d4598f59 Binary files /dev/null and b/resources/character/imgs/rank-bg.png differ diff --git a/resources/character/profile-list.css b/resources/character/profile-list.css index 0d687745..5e715c14 100644 --- a/resources/character/profile-list.css +++ b/resources/character/profile-list.css @@ -18,6 +18,7 @@ body, } .char-item { margin: 5px 0; + position: relative; } .char-item .name { margin-top: 5px; @@ -44,6 +45,44 @@ body, border-radius: 50%; margin-right: 3px; } +.char-item .group-rank { + position: absolute; + background: url('./imgs/rank-bg.png') left top no-repeat; + background-size: auto 100%; + left: 0; + top: 0; + margin-top: -5px; + width: 74px; + height: 74px; +} +.char-item .group-rank span { + position: absolute; + font-size: 12px; + width: 16px; + height: 16px; + bottom: 0; + left: 50%; + margin-left: -7px; + text-align: center; + transform: scale(0.8); + display: none; + text-shadow: 0 0 2px #b26f08; +} +.char-item .group-rank.rank-1 { + background-position: 25% 0; +} +.char-item .group-rank.rank-2 { + background-position: 50% 0; +} +.char-item .group-rank.rank-3 { + background-position: 75% 0; +} +.char-item .group-rank.rank-4 { + background-position: 100% 0; +} +.char-item .group-rank.rank-4 span { + display: block; +} .char-icon { width: 64px; height: 64px; @@ -78,4 +117,7 @@ body, border-radius: 50%; margin-right: 3px; } +.no-rank .group-rank { + display: none; +} /*# sourceMappingURL=profile-list.css.map */ \ No newline at end of file diff --git a/resources/character/profile-list.html b/resources/character/profile-list.html index 47fbaea2..7cda2d14 100644 --- a/resources/character/profile-list.html +++ b/resources/character/profile-list.html @@ -15,7 +15,7 @@
{{msg+", "}}更新角色时请不要出场对应角色,以获取准确面板数据
你可以使用#{{demo}}面板#{{demo}}伤害#{{demo}}圣遗物命令来查看面板信息了
-
+
{{each chars char}}
@@ -24,6 +24,13 @@ style="background-image:url({{_res_path}}{{char.face}})">
{{char.abbr}}{{char.cons}} + {{if char.groupRank}} + {{set gr = char.groupRank}} + {{set rank = gr.rank > 9 ? 10:(gr.rank <=3 ? gr.rank : 4)}} +
+ {{gr.rank}} +
+ {{/if}}
{{/each}}
diff --git a/resources/character/profile-list.less b/resources/character/profile-list.less index ae04dd3b..8d4f6ea5 100644 --- a/resources/character/profile-list.less +++ b/resources/character/profile-list.less @@ -22,6 +22,7 @@ body, .container { .char-item { margin: 5px 0; + position: relative; .name { margin-top: 5px; @@ -52,6 +53,52 @@ body, .container { margin-right: 3px; } } + + .group-rank { + position: absolute; + background: url('./imgs/rank-bg.png') left top no-repeat; + background-size: auto 100%; + left: 0; + top: 0; + margin-top: -5px; + width: 74px; + height: 74px; + + span { + position: absolute; + font-size: 12px; + width: 16px; + height: 16px; + bottom: 0; + left: 50%; + margin-left: -7px; + text-align: center; + transform: scale(.8); + display: none; + text-shadow: 0 0 2px #b26f08; + + } + + &.rank-1 { + background-position: 25% 0; + } + + &.rank-2 { + background-position: 50% 0; + } + + &.rank-3 { + background-position: 75% 0; + } + + &.rank-4 { + background-position: 100% 0; + + span { + display: block; + } + } + } } .char-icon { @@ -92,4 +139,8 @@ body, .container { border-radius: 50%; margin-right: 3px; } +} + +.no-rank .group-rank { + display: none; } \ No newline at end of file diff --git a/tools/char-data-sprider.js b/tools/char-data-sprider.js index 60ad1b00..88ddeb06 100644 --- a/tools/char-data-sprider.js +++ b/tools/char-data-sprider.js @@ -265,4 +265,4 @@ let eta = { 流浪者: '2022-12-07 11:00:00', 珐露珊: '2022-12-07 11:00:00' } -await down('73,74', true) +await down('75,76', true)