feat(web/contest): username color

This commit is contained in:
Baoshuo Ren 2023-01-14 18:24:03 +08:00
parent 452c2ca12b
commit 1ebcda02d6
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
4 changed files with 68 additions and 38 deletions

View File

@ -87,14 +87,23 @@ function queryContestData($contest, $config = []) {
$people = [];
if ($contest['extra_config']['individual_or_team'] == 'individual') {
$people = DB::selectAll([
"select contests_registrants.username, user_info.realname from contests_registrants",
$res = DB::selectAll([
"select contests_registrants.username, user_info.realname, user_info.extra, user_info.usergroup from contests_registrants",
"inner join user_info on contests_registrants.username = user_info.username",
"where", [
"contest_id" => $contest['id'],
"has_participated" => 1
]
], DB::NUM);
foreach ($res as $row) {
$extra = json_decode($row[2], true);
$people[] = [
$row[0],
trim(HTML::escape($row[1])),
null,
UOJUser::getUserColor2($row[3], $extra['username_color']),
];
}
} elseif ($contest['extra_config']['individual_or_team'] == 'team') {
$res = DB::selectAll([
"select user_info.username, null, user_info.extra from contests_registrants, user_info",
@ -106,11 +115,15 @@ function queryContestData($contest, $config = []) {
], DB::NUM);
foreach ($res as $row) {
$extra = json_decode($row[2], true);
$row[2] = [
$people[] = [
$row[0],
null,
[
'team_name' => $extra['acm']['team_name'],
'members' => $extra['acm']['members']
'members' => $extra['acm']['members'],
],
null,
];
$people[] = $row;
}
}
@ -373,7 +386,7 @@ function calcStandings($contest, $contest_data, &$score, &$standings, $cfg = [])
}
}
// standings: rank => score, penalty, [username, realname], virtual_rank, ?review
// standings: rank => score, penalty, [username, realname, null|array, null|color], virtual_rank, ?review
$standings = [];
foreach ($contest_data['people'] as $person) {
$cur = array(0, 0, $person);

View File

@ -210,6 +210,33 @@ class UOJUser {
}
}
public static function getUserColor($user) {
$extra = UOJUser::getExtra($user);
return UOJUser::getUserColor2($user['usergroup'], $extra['username_color']);
}
public static function getUserColor2($usergroup, $custom_color = null) {
if ($usergroup == 'B') {
return '#996600';
}
if ($usergroup == 'T') {
return '#707070';
}
if ($usergroup == 'S') {
return $custom_color ?: '#9d3dcf';
}
// 前管理员设置颜色为紫色、红色的,颜色改为蓝色
if ($custom_color == '#9d3dcf' || $custom_color == '#fe4c61') {
return '#0d6efd';
}
return $custom_color ?: '#0d6efd';
}
public static function getLink($user) {
if (is_string($user)) {
$info = UOJUser::query($user);
@ -221,36 +248,21 @@ class UOJUser {
}
}
$extra = UOJUser::getExtra($user);
$realname = $user['realname'];
$color = '#0d6efd';
if ($user['usergroup'] === 'B') {
$color = '#996600';
} else if (isTmpUser($user)) {
$color = '#707070';
} else {
if (isSuperUser($user)) {
$color = '#9d3dcf';
}
$color = $extra['username_color'];
// 前管理员设置颜色为紫色、红色的,颜色改为蓝色
if (($color === '#9d3dcf' || $color === '#fe4c61') && !isSuperUser($user)) {
$color = '#0d6efd';
}
}
if ($user['usertype'] == 'teacher') {
$realname .= '老师';
}
if (!Auth::check()) {
$realname = '';
}
return HTML::tag('span', [
'class' => 'uoj-username',
'data-color' => UOJUser::getUserColor($user),
// 未登录不可查看真实姓名
'data-realname' => Auth::check() ? trim(HTML::escape($realname)) : '',
'data-color' => $color,
'data-realname' => trim(HTML::escape($realname)),
], $user['username']);
}

View File

@ -35,7 +35,7 @@
function(row) {
var col_tr = '<tr>';
col_tr += '<td>' + row[3] + '</td>';
col_tr += '<td>' + getUserLink(row[2][0], row[2][1]) + '</td>';
col_tr += '<td>' + getUserLink(row[2][0], row[2][1], row[2][3]) + '</td>';
col_tr += '<td>' + '<div><span class="uoj-score" data-max="' + problems.length * 100 + '" style="color:' + getColOfScore(row[0] / problems.length) + '">' + row[0] + '</span></div>' + '<div>' + getPenaltyTimeStr(row[1]) + '</div></td>';
for (var i = 0; i < problems.length; i++) {
col = score[row[2][0]][i];

View File

@ -118,46 +118,51 @@ function getColOfScore(score) {
}
}
function getUserLink(username, realname) {
function getUserLink(username, realname, color) {
if (!username) {
return '';
}
var text = username;
var style = '';
if (username.charAt(0) == '@') {
username = username.substr(1);
}
if (realname) {
text = text + ' <span class="uoj-realname d-inline-block">(' + realname + ')</span>';
}
return '<a class="uoj-username" href="' + uojHome + '/user/' + username + '">' + text + '</a>';
if (color) {
style += 'color: ' + color + ';';
}
return '<a class="uoj-username" href="' + uojHome + '/user/' + username + '" ' + 'style="' + style + '">' + text + '</a>';
}
function getUserSpan(username, realname) {
function getUserSpan(username, realname, color) {
if (!username) {
return '';
}
var text = username;
var style = '';
if (username.charAt(0) == '@') {
username = username.substr(1);
}
if (realname) {
text = text + ' <span class="uoj-realname d-inline-block">(' + realname + ')</span>';
}
return '<span class="uoj-username">' + text + '</span>';
if (color) {
style += 'color: ' + color + ';';
}
return '<span class="uoj-username" ' + 'style="' + style + '">' + text + '</span>';
}
function replaceWithHighlightUsername() {
var username = $(this).text();
var realname = $(this).data("realname");
var color = $(this).data("color");
var new_elem_inner = '';
if ($(this).data("link") != 0) {
new_elem_inner = getUserLink(username, realname);
$(this).replaceWith(getUserLink(username, realname, color));
} else {
new_elem_inner = getUserSpan(username, realname);
$(this).replaceWith(getUserSpan(username, realname, color));
}
$(this).replaceWith($(new_elem_inner).css('color', color));
}
$.fn.uoj_honor = function() {