fix: space关注按钮移除隐藏逻辑,自关注改为toast提示

- 自己的space也显示关注按钮,不再隐藏
- 点击关注自己时toast'不能关注自己',不发请求
- 自己的space下,发消息/更多按钮保持隐藏
This commit is contained in:
2026-06-03 01:13:01 +08:00
parent 58aabb9bf0
commit fb9724faed

View File

@ -35,10 +35,8 @@
<!-- 右:操作按钮 -->
<div class="space-header-actions">
{{if .IsOwnSpace}}
<!-- 本人无关注按钮 -->
{{else}}
<button id="space-follow-btn" class="space-action-btn primary" data-uid="{{.SpaceUser.ID}}">+ 关注</button>
<button id="space-follow-btn" class="space-action-btn primary" data-uid="{{.SpaceUser.ID}}" data-current-uid="{{.CurrentUID}}">+ 关注</button>
{{if not .IsOwnSpace}}
<button class="space-action-btn">发消息</button>
<button class="space-action-btn icon-only" title="更多"></button>
{{end}}
@ -576,10 +574,11 @@
{{template "layout/footer.html" .}}
<!-- 访客空间:关注按钮交互 -->
{{if and (not .IsOwnSpace) (or (eq .ActiveTab "following") (eq .ActiveTab "followers"))}}
<!-- 关注按钮交互 -->
{{if or (eq .ActiveTab "following") (eq .ActiveTab "followers")}}
<script nonce="{{.CSPNonce}}">
(function() {
var currentUID = {{.CurrentUID}} || 0;
var cards = document.querySelectorAll('.space-user-card');
if (!cards.length) return;
@ -605,7 +604,7 @@
if (state === 'following' || state === 'mutual') btn.classList.add('followed');
}
// 批量获取并更新每个卡片关注状态
// 批量获取并更新每个卡片关注状态(仅非自己)
cards.forEach(function(card) {
var btn = card.querySelector('.space-follow-btn');
if (!btn || btn.disabled) return;
@ -618,6 +617,10 @@
});
btn.addEventListener('click', function() {
if (currentUID && parseInt(targetUid) === currentUID) {
showToast('不能关注自己');
return;
}
btn.classList.add('waiting');
var xhr = new XMLHttpRequest();
xhr.open('POST', '/api/users/' + targetUid + '/follow', true);
@ -637,6 +640,12 @@
var topFollowBtn = document.getElementById('space-follow-btn');
if (topFollowBtn) {
var topUid = topFollowBtn.getAttribute('data-uid');
if (currentUID && parseInt(topUid) === currentUID) {
topFollowBtn.textContent = '+ 关注';
topFollowBtn.addEventListener('click', function() {
showToast('不能关注自己');
});
} else {
fetch('/api/users/' + topUid + '/follow-status')
.then(function(res) { return res.json(); })
.then(function(data) {
@ -670,6 +679,7 @@
xhr.send();
});
}
}
})();
</script>
{{end}}