添加 刷新通讯录功能,用于解决冗余数据问题。

This commit is contained in:
liuwei
2025-05-07 11:38:45 +08:00
parent 9a2d9f3f12
commit 19d56afc8d
5 changed files with 175 additions and 8 deletions

View File

@@ -163,4 +163,21 @@ def api_group_members(roomid):
})
except Exception as e:
logger.error(f"获取群成员列表失败: {e}")
return jsonify({"success": False, "error": str(e)}), 500
return jsonify({"success": False, "error": str(e)}), 500
@contacts_bp.route('/api/update', methods=['POST'])
@login_required
def api_contacts_update():
"""更新通讯录信息API"""
try:
server = current_app.dashboard_server
# 假设 contact_manager 有 update_contacts 方法用于同步通讯录
result = server.robot.refresh_contacts_db()
if result:
return jsonify({"success": True, "message": "通讯录更新成功"})
else:
return jsonify({"success": False, "message": "通讯录更新失败"}), 500
except Exception as e:
logger.error(f"更新通讯录失败: {e}")
return jsonify({"success": False, "message": f"更新通讯录失败: {str(e)}"}), 500

View File

@@ -45,6 +45,7 @@ class DashboardServer:
self.plugin_manager = robot_instance.plugin_manager
self.plugin_registry = robot_instance.plugin_registry
self.client: WechatAPIClient = robot_instance.ipad_bot
self.robot = robot_instance
# # 设置用户信息
# self.user_data = {

View File

@@ -17,6 +17,13 @@
{% raw %}@click="refreshContacts"{% endraw %}>
刷新数据
</el-button>
<el-button
type="success"
size="small"
style="float: right; margin-left: 10px;"
{% raw %}@click="updateContacts"{% endraw %}>
更新通讯录
</el-button>
<el-input
placeholder="搜索联系人..."
{% raw %}v-model="searchQuery"{% endraw %}
@@ -631,7 +638,22 @@
handleGroupMembersCurrentChange(page) {
this.groupMembersCurrentPage = page;
}
}
},
updateContacts() {
this.$message.info('正在更新通讯录...');
axios.post('/api/contacts/update')
.then(res => {
if (res.data.success) {
this.$message.success('通讯录更新成功!');
this.refreshContacts();
} else {
this.$message.error(res.data.message || '通讯录更新失败');
}
})
.catch(() => {
this.$message.error('通讯录更新请求失败');
});
},
});
</script>