Inbox Message & bugs
This commit is contained in:
@@ -326,13 +326,14 @@
|
||||
|
||||
// User card — custom fixed-position tooltip (more reliable than Semantic UI popup)
|
||||
var cardCache = {};
|
||||
var $card = $('<div id="jUserCard" style="position:fixed;background:#fff;border:1px solid #ddd;border-radius:6px;padding:12px 16px;box-shadow:0 4px 16px rgba(0,0,0,.15);z-index:9999;min-width:180px;display:none;pointer-events:none;"></div>').appendTo('body');
|
||||
var $card = $('<div id="jUserCard" style="position:fixed;background:#fff;border:1px solid #ddd;border-radius:6px;padding:12px 16px;box-shadow:0 4px 16px rgba(0,0,0,.15);z-index:9999;min-width:180px;display:none;"></div>').appendTo('body');
|
||||
|
||||
function showCard(u, x, y) {
|
||||
$card.html(
|
||||
'<div style="font-weight:700;font-size:1em;margin-bottom:4px;">' + (u.username || '') + '</div>' +
|
||||
'<div style="color:#888;font-size:.88em;">发帖: ' + (u.discussionsCount || 0) +
|
||||
' 回复: ' + (u.commentsCount || 0) + '</div>'
|
||||
' 回复: ' + (u.commentsCount || 0) + '</div>' +
|
||||
'<div style="margin-top:8px;"><a class="open-msg-modal" data-uid="' + u.id + '" data-uname="' + (u.username||'') + '" style="font-size:.85em;color:#2185d0;cursor:pointer;"><i class="envelope icon"></i>发私信</a></div>'
|
||||
).css({ left: x + 14, top: y + 14 }).show();
|
||||
}
|
||||
|
||||
@@ -340,7 +341,7 @@
|
||||
var userId = $(this).data('user-id');
|
||||
if (!userId) return;
|
||||
if (cardCache[userId]) { showCard(cardCache[userId], e.clientX, e.clientY); return; }
|
||||
$.getJSON('/user_api/user/' + userId, function(res) {
|
||||
$.getJSON('/msg_api/user-card/' + userId, function(res) {
|
||||
if (res && res.code === 10000 && res.data) {
|
||||
cardCache[userId] = res.data;
|
||||
showCard(res.data, e.clientX, e.clientY);
|
||||
@@ -349,8 +350,12 @@
|
||||
}).on('mousemove', '.user-card-trigger', function(e) {
|
||||
if ($card.is(':visible')) $card.css({ left: e.clientX + 14, top: e.clientY + 14 });
|
||||
}).on('mouseleave', '.user-card-trigger', function() {
|
||||
$card.hide();
|
||||
// Delay hide so user can click links inside card
|
||||
setTimeout(function() {
|
||||
if (!$card.is(':hover')) $card.hide();
|
||||
}, 300);
|
||||
});
|
||||
$card.on('mouseleave', function() { $card.hide(); });
|
||||
});
|
||||
|
||||
function voteDiscussion(action) {
|
||||
@@ -391,6 +396,69 @@
|
||||
|
||||
</script>
|
||||
<script type="text/javascript" charset="UTF-8" src="/static/js/user/discussions.js"></script>
|
||||
|
||||
<#-- 私信弹窗 Modal -->
|
||||
<div class="ui small modal" id="sendMsgModal">
|
||||
<div class="header"><i class="envelope icon"></i> 发送私信给 <span id="msgModalUsername"></span></div>
|
||||
<div class="content">
|
||||
<div class="ui form">
|
||||
<div class="field">
|
||||
<textarea id="msgModalContent" rows="4" placeholder="输入消息内容..." style="resize:none;"></textarea>
|
||||
</div>
|
||||
<div id="msgModalError" class="ui red message" style="display:none;"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui cancel button">取消</div>
|
||||
<div class="ui primary button" id="msgModalSendBtn">
|
||||
<i class="send icon"></i>发送
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var _msgReceiverId = null;
|
||||
var _msgCsrfToken = $('meta[name="_csrf"]').attr('content');
|
||||
var _msgCsrfHeader = $('meta[name="_csrf_header"]').attr('content');
|
||||
|
||||
// Open modal when user clicks 发私信 in user card
|
||||
$(document).on('click', '.open-msg-modal', function() {
|
||||
_msgReceiverId = $(this).data('uid');
|
||||
var uname = $(this).data('uname');
|
||||
$('#msgModalUsername').text(uname);
|
||||
$('#msgModalContent').val('');
|
||||
$('#msgModalError').hide();
|
||||
$('#jUserCard').hide();
|
||||
$('#sendMsgModal').modal('show');
|
||||
});
|
||||
|
||||
$('#msgModalSendBtn').on('click', function() {
|
||||
var content = $('#msgModalContent').val().trim();
|
||||
if (!content) { $('#msgModalError').text('消息内容不能为空').show(); return; }
|
||||
var $btn = $(this).addClass('loading disabled');
|
||||
var headers = {};
|
||||
headers[_msgCsrfHeader] = _msgCsrfToken;
|
||||
$.ajax({
|
||||
url: '/msg_api/messages/send',
|
||||
type: 'POST',
|
||||
headers: headers,
|
||||
data: { receiverId: _msgReceiverId, content: content },
|
||||
success: function(resp) {
|
||||
$btn.removeClass('loading disabled');
|
||||
if (resp && resp.code === 10000) {
|
||||
$('#sendMsgModal').modal('hide');
|
||||
massage('私信发送成功!', 'success', '');
|
||||
} else {
|
||||
$('#msgModalError').text((resp && resp.msg) || '发送失败,请重试').show();
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$btn.removeClass('loading disabled');
|
||||
$('#msgModalError').text('请求失败,请确认已登录').show();
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user