拆约:绑定身份的标签支持自行删除(chips + 确认弹窗 + 正主校验端点)

This commit is contained in:
2026-11-12 01:52:20 +08:00
parent 72f358f7c5
commit c6cf66a214
5 changed files with 103 additions and 2 deletions
+9
View File
@@ -97,6 +97,15 @@ const bindChaishu = (name, branch, uid) => {
return post('/chaishu/bind', uid ? { uid } : { name, branch });
};
/**
* 删除自己拆书帮身份上的一个标签
* @param {string} tag
* @returns {Promise}
*/
const deleteChaishuTag = (tag) => {
return post('/chaishu/tags/delete', { tag });
};
module.exports = {
wechatLogin,
login,
+29 -1
View File
@@ -1,5 +1,5 @@
// pages/edit-profile/index.js
const { getProfile, updateProfile, uploadAvatar, getChaishuBranches, bindChaishu } = require('../../api/user');
const { getProfile, updateProfile, uploadAvatar, getChaishuBranches, bindChaishu, deleteChaishuTag } = require('../../api/user');
const { chooseImages, getFullImageUrl } = require('../../utils/helpers');
Page({
@@ -161,6 +161,34 @@ Page({
}
},
onDeleteChaishuTag(e) {
const tag = e.currentTarget.dataset.tag;
if (!tag) return;
wx.showModal({
title: '删除标签',
content: `确定删除标签「${tag}」吗?`,
confirmColor: '#07c160',
success: (m) => {
if (!m.confirm) return;
this.doDeleteChaishuTag(tag);
},
});
},
async doDeleteChaishuTag(tag) {
try {
const res = await deleteChaishuTag(tag);
if (res.success) {
wx.showToast({ title: '已删除', icon: 'success' });
this.loadProfile();
} else {
wx.showToast({ title: res.message || '删除失败', icon: 'none' });
}
} catch (err) {
wx.showToast({ title: err.message || '删除失败', icon: 'none' });
}
},
async handleChooseAvatar() {
try {
const [tempFilePath] = await chooseImages(1);
@@ -141,7 +141,12 @@
</view>
<view class="chaishu-row" wx:if="{{chaishu.tags.length}}">
<text class="chaishu-key">标签</text>
<text class="chaishu-val chaishu-tags">{{chaishu.tags}}</text>
<view class="chaishu-tags-wrap">
<view class="chaishu-tag-chip" wx:for="{{chaishu.tags}}" wx:key="*this">
<text class="chaishu-tag-text">{{item}}</text>
<text class="chaishu-tag-del" data-tag="{{item}}" catchtap="onDeleteChaishuTag">×</text>
</view>
</view>
</view>
</view>
@@ -140,6 +140,33 @@
color: #4a90e2;
}
.chaishu-tags-wrap {
flex: 1;
display: flex;
flex-wrap: wrap;
gap: 12rpx;
}
.chaishu-tag-chip {
display: flex;
align-items: center;
padding: 6rpx 16rpx;
background-color: #e8f2fd;
border-radius: 24rpx;
}
.chaishu-tag-text {
font-size: 24rpx;
color: #4a90e2;
}
.chaishu-tag-del {
margin-left: 10rpx;
font-size: 28rpx;
color: #999999;
padding: 0 4rpx;
}
.chaishu-bind-btn {
margin-top: 20rpx;
width: 100%;
+32
View File
@@ -1515,6 +1515,38 @@ app.post('/chaishu/bind', (req, res) => {
}
});
// 删除自己身份上的一个标签(仅绑定正主可删)
app.post('/chaishu/tags/delete', (req, res) => {
try {
const userId = req.headers['x-user-id'];
if (!userId) {
return res.json({ success: false, message: '未登录' });
}
const user = db.prepare('SELECT chaishu_uid FROM users WHERE id = ?').get(userId);
if (!user || !user.chaishu_uid) {
return res.json({ success: false, message: '尚未绑定拆书帮身份' });
}
const { tag } = req.body || {};
if (!tag || typeof tag !== 'string') {
return res.json({ success: false, message: '标签不能为空' });
}
const m = db.prepare('SELECT uid, tags FROM chaishu_members WHERE uid = ?').get(user.chaishu_uid);
if (!m) {
return res.json({ success: false, message: '会员不存在' });
}
const tags = safeParseJson(m.tags, []);
if (!tags.includes(tag)) {
return res.json({ success: false, message: '标签不存在' });
}
const next = tags.filter(t => t !== tag);
db.prepare('UPDATE chaishu_members SET tags = ? WHERE uid = ?').run(JSON.stringify(next), m.uid);
res.json({ success: true, data: { tags: next } });
} catch (error) {
console.error('删除拆书帮标签失败:', error);
res.json({ success: false, message: '删除拆书帮标签失败' });
}
});
// 初始化数据库并启动服务器
initDatabase();