调整 message_util 的发送text方法名,方便替换wcf.send_text。加入了虚拟群组管理功能;
This commit is contained in:
282
admin/dashboard/blueprints/virtual_group.py
Normal file
282
admin/dashboard/blueprints/virtual_group.py
Normal file
@@ -0,0 +1,282 @@
|
||||
import logging
|
||||
import uuid
|
||||
from flask import Blueprint, jsonify, request, current_app, render_template
|
||||
from .auth import login_required
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
virtual_group_bp = Blueprint('virtual_group', __name__)
|
||||
|
||||
# 添加虚拟群组管理视图
|
||||
@virtual_group_bp.route('/virtual_group')
|
||||
@login_required
|
||||
def virtual_group():
|
||||
return render_template('virtual_group_management.html')
|
||||
|
||||
@virtual_group_bp.route('/api/virtual_groups', methods=['GET'])
|
||||
@login_required
|
||||
def get_virtual_groups():
|
||||
"""获取所有虚拟群组"""
|
||||
try:
|
||||
server = current_app.dashboard_server
|
||||
redis_client = server.db_manager.get_redis_connection()
|
||||
|
||||
# 从Redis获取虚拟群组数据
|
||||
chat_groups_json = redis_client.get("group_virtual:chat_groups")
|
||||
if not chat_groups_json:
|
||||
return jsonify({"success": True, "data": {"chatGroups": []}})
|
||||
|
||||
import json
|
||||
chat_groups = json.loads(chat_groups_json)
|
||||
|
||||
# 确保群组名称是最新的
|
||||
for chat_group in chat_groups.get("chatGroups", []):
|
||||
for group in chat_group.get("groups", []):
|
||||
group_id = group.get("id")
|
||||
if group_id:
|
||||
group_name = server.contact_manager.get_nickname(group_id)
|
||||
if group_name:
|
||||
group["name"] = group_name
|
||||
|
||||
return jsonify({"success": True, "data": chat_groups})
|
||||
except Exception as e:
|
||||
logger.error(f"获取虚拟群组失败: {e}")
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
|
||||
|
||||
@virtual_group_bp.route('/api/virtual_groups', methods=['POST'])
|
||||
@login_required
|
||||
def create_virtual_group():
|
||||
"""创建新的虚拟群组"""
|
||||
try:
|
||||
server = current_app.dashboard_server
|
||||
redis_client = server.db_manager.get_redis_connection()
|
||||
data = request.json
|
||||
|
||||
group_name = data.get('name')
|
||||
if not group_name:
|
||||
return jsonify({"success": False, "error": "群组名称不能为空"}), 400
|
||||
|
||||
# 从Redis获取现有虚拟群组
|
||||
import json
|
||||
chat_groups_json = redis_client.get("group_virtual:chat_groups")
|
||||
if chat_groups_json:
|
||||
chat_groups = json.loads(chat_groups_json)
|
||||
else:
|
||||
chat_groups = {"chatGroups": []}
|
||||
|
||||
# 创建新的虚拟群组
|
||||
new_group = {
|
||||
"id": str(uuid.uuid4()),
|
||||
"name": group_name,
|
||||
"groups": []
|
||||
}
|
||||
|
||||
chat_groups["chatGroups"].append(new_group)
|
||||
|
||||
# 保存回Redis
|
||||
redis_client.set("group_virtual:chat_groups", json.dumps(chat_groups, ensure_ascii=False))
|
||||
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"message": f"虚拟群组 {group_name} 创建成功",
|
||||
"data": new_group
|
||||
})
|
||||
except Exception as e:
|
||||
logger.error(f"创建虚拟群组失败: {e}")
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
|
||||
|
||||
@virtual_group_bp.route('/api/virtual_groups/<group_id>', methods=['DELETE'])
|
||||
@login_required
|
||||
def delete_virtual_group(group_id):
|
||||
"""删除虚拟群组"""
|
||||
try:
|
||||
server = current_app.dashboard_server
|
||||
redis_client = server.db_manager.get_redis_connection()
|
||||
|
||||
# 从Redis获取现有虚拟群组
|
||||
import json
|
||||
chat_groups_json = redis_client.get("group_virtual:chat_groups")
|
||||
if not chat_groups_json:
|
||||
return jsonify({"success": False, "error": "虚拟群组不存在"}), 404
|
||||
|
||||
chat_groups = json.loads(chat_groups_json)
|
||||
|
||||
# 查找并删除指定的虚拟群组
|
||||
found = False
|
||||
for i, group in enumerate(chat_groups.get("chatGroups", [])):
|
||||
if group.get("id") == group_id:
|
||||
del chat_groups["chatGroups"][i]
|
||||
found = True
|
||||
break
|
||||
|
||||
if not found:
|
||||
return jsonify({"success": False, "error": "虚拟群组不存在"}), 404
|
||||
|
||||
# 保存回Redis
|
||||
redis_client.set("group_virtual:chat_groups", json.dumps(chat_groups, ensure_ascii=False))
|
||||
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"message": "虚拟群组删除成功"
|
||||
})
|
||||
except Exception as e:
|
||||
logger.error(f"删除虚拟群组失败: {e}")
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
|
||||
|
||||
@virtual_group_bp.route('/api/virtual_groups/<group_id>/groups', methods=['POST'])
|
||||
@login_required
|
||||
def add_group_to_virtual(group_id):
|
||||
"""向虚拟群组添加微信群"""
|
||||
try:
|
||||
server = current_app.dashboard_server
|
||||
redis_client = server.db_manager.get_redis_connection()
|
||||
data = request.json
|
||||
|
||||
wx_group_id = data.get('wx_group_id')
|
||||
if not wx_group_id:
|
||||
return jsonify({"success": False, "error": "微信群ID不能为空"}), 400
|
||||
|
||||
# 检查微信群是否存在
|
||||
group_name = server.contact_manager.get_nickname(wx_group_id)
|
||||
if not group_name:
|
||||
return jsonify({"success": False, "error": "微信群不存在或未被机器人识别"}), 404
|
||||
|
||||
# 从Redis获取现有虚拟群组
|
||||
import json
|
||||
chat_groups_json = redis_client.get("group_virtual:chat_groups")
|
||||
if not chat_groups_json:
|
||||
return jsonify({"success": False, "error": "虚拟群组不存在"}), 404
|
||||
|
||||
chat_groups = json.loads(chat_groups_json)
|
||||
|
||||
# 查找指定的虚拟群组
|
||||
found = False
|
||||
for chat_group in chat_groups.get("chatGroups", []):
|
||||
if chat_group.get("id") == group_id:
|
||||
# 检查群是否已在虚拟群组中
|
||||
for group in chat_group.get("groups", []):
|
||||
if group.get("id") == wx_group_id:
|
||||
return jsonify({"success": False, "error": "该微信群已在虚拟群组中"}), 400
|
||||
|
||||
# 添加微信群到虚拟群组
|
||||
chat_group["groups"].append({
|
||||
"id": wx_group_id,
|
||||
"name": group_name
|
||||
})
|
||||
found = True
|
||||
break
|
||||
|
||||
if not found:
|
||||
return jsonify({"success": False, "error": "虚拟群组不存在"}), 404
|
||||
|
||||
# 保存回Redis
|
||||
redis_client.set("group_virtual:chat_groups", json.dumps(chat_groups, ensure_ascii=False))
|
||||
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"message": f"微信群 {group_name} 已添加到虚拟群组",
|
||||
"data": {
|
||||
"id": wx_group_id,
|
||||
"name": group_name
|
||||
}
|
||||
})
|
||||
except Exception as e:
|
||||
logger.error(f"向虚拟群组添加微信群失败: {e}")
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
|
||||
|
||||
@virtual_group_bp.route('/api/virtual_groups/<group_id>/groups/<wx_group_id>', methods=['DELETE'])
|
||||
@login_required
|
||||
def remove_group_from_virtual(group_id, wx_group_id):
|
||||
"""从虚拟群组移除微信群"""
|
||||
try:
|
||||
server = current_app.dashboard_server
|
||||
redis_client = server.db_manager.get_redis_connection()
|
||||
|
||||
# 从Redis获取现有虚拟群组
|
||||
import json
|
||||
chat_groups_json = redis_client.get("group_virtual:chat_groups")
|
||||
if not chat_groups_json:
|
||||
return jsonify({"success": False, "error": "虚拟群组不存在"}), 404
|
||||
|
||||
chat_groups = json.loads(chat_groups_json)
|
||||
|
||||
# 查找指定的虚拟群组和微信群
|
||||
found_group = False
|
||||
found_wx_group = False
|
||||
for chat_group in chat_groups.get("chatGroups", []):
|
||||
if chat_group.get("id") == group_id:
|
||||
found_group = True
|
||||
for i, group in enumerate(chat_group.get("groups", [])):
|
||||
if group.get("id") == wx_group_id:
|
||||
del chat_group["groups"][i]
|
||||
found_wx_group = True
|
||||
break
|
||||
break
|
||||
|
||||
if not found_group:
|
||||
return jsonify({"success": False, "error": "虚拟群组不存在"}), 404
|
||||
|
||||
if not found_wx_group:
|
||||
return jsonify({"success": False, "error": "该微信群不在虚拟群组中"}), 404
|
||||
|
||||
# 保存回Redis
|
||||
redis_client.set("group_virtual:chat_groups", json.dumps(chat_groups, ensure_ascii=False))
|
||||
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"message": "微信群已从虚拟群组移除"
|
||||
})
|
||||
except Exception as e:
|
||||
logger.error(f"从虚拟群组移除微信群失败: {e}")
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
|
||||
|
||||
@virtual_group_bp.route('/api/virtual_groups/<group_id>', methods=['PUT'])
|
||||
@login_required
|
||||
def update_virtual_group(group_id):
|
||||
"""更新虚拟群组信息"""
|
||||
try:
|
||||
server = current_app.dashboard_server
|
||||
redis_client = server.db_manager.get_redis_connection()
|
||||
data = request.json
|
||||
|
||||
group_name = data.get('name')
|
||||
if not group_name:
|
||||
return jsonify({"success": False, "error": "群组名称不能为空"}), 400
|
||||
|
||||
# 从Redis获取现有虚拟群组
|
||||
import json
|
||||
chat_groups_json = redis_client.get("group_virtual:chat_groups")
|
||||
if not chat_groups_json:
|
||||
return jsonify({"success": False, "error": "虚拟群组不存在"}), 404
|
||||
|
||||
chat_groups = json.loads(chat_groups_json)
|
||||
|
||||
# 查找并更新指定的虚拟群组
|
||||
found = False
|
||||
for chat_group in chat_groups.get("chatGroups", []):
|
||||
if chat_group.get("id") == group_id:
|
||||
chat_group["name"] = group_name
|
||||
found = True
|
||||
break
|
||||
|
||||
if not found:
|
||||
return jsonify({"success": False, "error": "虚拟群组不存在"}), 404
|
||||
|
||||
# 保存回Redis
|
||||
redis_client.set("group_virtual:chat_groups", json.dumps(chat_groups, ensure_ascii=False))
|
||||
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"message": "虚拟群组更新成功",
|
||||
"data": {
|
||||
"id": group_id,
|
||||
"name": group_name
|
||||
}
|
||||
})
|
||||
except Exception as e:
|
||||
logger.error(f"更新虚拟群组失败: {e}")
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
@@ -128,11 +128,10 @@ class DashboardServer:
|
||||
from admin.dashboard.blueprints.system import system_bp
|
||||
from admin.dashboard.blueprints.main import main_bp
|
||||
from admin.dashboard.blueprints.plugin_routes import plugin_routes
|
||||
from blueprints.virtual_group import virtual_group_bp
|
||||
|
||||
# 将服务器实例存储在应用上下文中
|
||||
app.dashboard_server = self
|
||||
|
||||
# 注册蓝图
|
||||
# 在app.register_blueprint部分添加
|
||||
app.register_blueprint(virtual_group_bp, url_prefix='/virtual_group')
|
||||
app.register_blueprint(auth_bp)
|
||||
app.register_blueprint(main_bp)
|
||||
app.register_blueprint(contacts_bp)
|
||||
|
||||
@@ -166,6 +166,11 @@
|
||||
<i class="el-icon-s-tools"></i>
|
||||
<span slot="title">插件管理</span>
|
||||
</el-menu-item>
|
||||
<!-- 在导航菜单中添加虚拟群组管理 -->
|
||||
<el-menu-item index="12" @click="navigateTo('/virtual_group')">
|
||||
<i class="el-icon-connection"></i>
|
||||
<span slot="title">虚拟群组管理</span>
|
||||
</el-menu-item>
|
||||
</el-menu>
|
||||
</div>
|
||||
|
||||
@@ -229,7 +234,8 @@
|
||||
'7': '/messages',
|
||||
'9': '/wx_logs',
|
||||
'10': '/contacts',
|
||||
'11': '/plugins_manage'
|
||||
'11': '/plugins_manage',
|
||||
'12': '/virtual_group'
|
||||
};
|
||||
|
||||
// 如果当前不在对应页面,则跳转
|
||||
|
||||
364
admin/dashboard/templates/virtual_group_management.html
Normal file
364
admin/dashboard/templates/virtual_group_management.html
Normal file
@@ -0,0 +1,364 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}虚拟群组管理 - 机器人管理后台{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<!-- 虚拟群组管理 -->
|
||||
<div>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="24">
|
||||
<el-card shadow="hover">
|
||||
<div slot="header" class="clearfix">
|
||||
<span>虚拟群组管理</span>
|
||||
<el-button
|
||||
type="primary"
|
||||
size="small"
|
||||
style="float: right; margin-left: 10px;"
|
||||
@click="showCreateVirtualGroupDialog">
|
||||
创建虚拟群组
|
||||
</el-button>
|
||||
<el-input
|
||||
placeholder="搜索虚拟群组..."
|
||||
v-model="searchQuery"
|
||||
style="width: 200px; float: right"
|
||||
clearable>
|
||||
</el-input>
|
||||
</div>
|
||||
|
||||
<!-- 虚拟群组列表 -->
|
||||
<el-table
|
||||
:data="filteredVirtualGroups"
|
||||
style="width: 100%"
|
||||
border>
|
||||
<el-table-column type="expand">
|
||||
<template slot-scope="props">
|
||||
<el-table
|
||||
:data="props.row.groups"
|
||||
style="width: 100%">
|
||||
<el-table-column label="微信群ID" prop="id" width="280"></el-table-column>
|
||||
<el-table-column label="微信群名称" prop="name"></el-table-column>
|
||||
<el-table-column label="操作" width="120">
|
||||
<template slot-scope="scope">
|
||||
<el-button
|
||||
size="mini"
|
||||
type="danger"
|
||||
@click="removeGroupFromVirtual(props.row.id, scope.row.id)">移除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div style="margin-top: 10px;">
|
||||
<el-button size="small" type="primary" @click="showAddGroupDialog(props.row)">添加微信群</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="虚拟群组名称" prop="name"></el-table-column>
|
||||
<el-table-column label="包含群数量">
|
||||
<template slot-scope="scope">
|
||||
{% raw %}{{ scope.row.groups.length }}{% endraw %} 个群
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="200">
|
||||
<template slot-scope="scope">
|
||||
<el-button
|
||||
size="mini"
|
||||
type="primary"
|
||||
@click="editVirtualGroup(scope.row)">编辑</el-button>
|
||||
<el-button
|
||||
size="mini"
|
||||
type="danger"
|
||||
@click="deleteVirtualGroup(scope.row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 创建虚拟群组对话框 -->
|
||||
<el-dialog
|
||||
title="创建虚拟群组"
|
||||
:visible.sync="createVirtualGroupDialogVisible"
|
||||
width="30%">
|
||||
<el-form :model="virtualGroupForm" :rules="virtualGroupRules" ref="virtualGroupForm">
|
||||
<el-form-item label="群组名称" prop="name">
|
||||
<el-input v-model="virtualGroupForm.name" placeholder="请输入虚拟群组名称"></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<span slot="footer" class="dialog-footer">
|
||||
<el-button @click="createVirtualGroupDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="submitCreateVirtualGroup">确定</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 编辑虚拟群组对话框 -->
|
||||
<el-dialog
|
||||
title="编辑虚拟群组"
|
||||
:visible.sync="editVirtualGroupDialogVisible"
|
||||
width="30%">
|
||||
<el-form :model="editVirtualGroupForm" :rules="virtualGroupRules" ref="editVirtualGroupForm">
|
||||
<el-form-item label="群组名称" prop="name">
|
||||
<el-input v-model="editVirtualGroupForm.name" placeholder="请输入虚拟群组名称"></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<span slot="footer" class="dialog-footer">
|
||||
<el-button @click="editVirtualGroupDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="submitEditVirtualGroup">确定</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 添加微信群对话框 -->
|
||||
<el-dialog
|
||||
title="添加微信群到虚拟群组"
|
||||
:visible.sync="addGroupDialogVisible"
|
||||
width="50%">
|
||||
<el-form :model="addGroupForm" :rules="addGroupRules" ref="addGroupForm">
|
||||
<el-form-item label="选择微信群" prop="wx_group_id">
|
||||
<el-select
|
||||
v-model="addGroupForm.wx_group_id"
|
||||
filterable
|
||||
placeholder="请选择微信群"
|
||||
style="width: 100%">
|
||||
<el-option
|
||||
v-for="group in availableGroups"
|
||||
:key="group.wxid"
|
||||
:label="group.name"
|
||||
:value="group.wxid">
|
||||
<span style="float: left">{% raw %}{{ group.name }}{% endraw %}</span>
|
||||
<span style="float: right; color: #8492a6; font-size: 13px">{% raw %}{{ group.wxid }}{% endraw %}</span>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<span slot="footer" class="dialog-footer">
|
||||
<el-button @click="addGroupDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="submitAddGroup">确定</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
new Vue({
|
||||
el: '#app',
|
||||
mixins: [baseApp],
|
||||
data() {
|
||||
return {
|
||||
virtualGroups: [],
|
||||
searchQuery: '',
|
||||
// 创建虚拟群组相关数据
|
||||
createVirtualGroupDialogVisible: false,
|
||||
virtualGroupForm: {
|
||||
name: ''
|
||||
},
|
||||
virtualGroupRules: {
|
||||
name: [
|
||||
{ required: true, message: '请输入虚拟群组名称', trigger: 'blur' }
|
||||
]
|
||||
},
|
||||
// 编辑虚拟群组相关数据
|
||||
editVirtualGroupDialogVisible: false,
|
||||
editVirtualGroupForm: {
|
||||
id: '',
|
||||
name: ''
|
||||
},
|
||||
// 添加微信群相关数据
|
||||
addGroupDialogVisible: false,
|
||||
currentVirtualGroupId: '',
|
||||
addGroupForm: {
|
||||
wx_group_id: ''
|
||||
},
|
||||
addGroupRules: {
|
||||
wx_group_id: [
|
||||
{ required: true, message: '请选择微信群', trigger: 'change' }
|
||||
]
|
||||
},
|
||||
availableGroups: [],
|
||||
allGroups: []
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
filteredVirtualGroups() {
|
||||
if (!this.searchQuery) return this.virtualGroups;
|
||||
const query = this.searchQuery.toLowerCase();
|
||||
return this.virtualGroups.filter(group =>
|
||||
group.name.toLowerCase().includes(query)
|
||||
);
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.currentView = '12'; // 设置当前视图为虚拟群组管理
|
||||
this.loadVirtualGroups();
|
||||
this.loadAllGroups();
|
||||
},
|
||||
methods: {
|
||||
loadVirtualGroups() {
|
||||
axios.get('/virtual_group/api/virtual_groups')
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
this.virtualGroups = response.data.data.chatGroups || [];
|
||||
} else {
|
||||
this.$message.error('加载虚拟群组失败');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('加载虚拟群组失败:', error);
|
||||
this.$message.error('加载虚拟群组失败');
|
||||
});
|
||||
},
|
||||
loadAllGroups() {
|
||||
axios.get('/contacts/api/groups')
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
const groups = response.data.data.groups;
|
||||
this.allGroups = Object.entries(groups).map(([wxid, name]) => ({
|
||||
wxid,
|
||||
name: name || wxid
|
||||
}));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('加载群组列表失败:', error);
|
||||
this.$message.error('加载群组列表失败');
|
||||
});
|
||||
},
|
||||
showCreateVirtualGroupDialog() {
|
||||
this.virtualGroupForm = { name: '' };
|
||||
this.createVirtualGroupDialogVisible = true;
|
||||
this.$nextTick(() => {
|
||||
this.$refs.virtualGroupForm && this.$refs.virtualGroupForm.clearValidate();
|
||||
});
|
||||
},
|
||||
submitCreateVirtualGroup() {
|
||||
this.$refs.virtualGroupForm.validate(valid => {
|
||||
if (valid) {
|
||||
axios.post('/virtual_group/api/virtual_groups', this.virtualGroupForm)
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
this.$message.success('创建虚拟群组成功');
|
||||
this.createVirtualGroupDialogVisible = false;
|
||||
this.loadVirtualGroups();
|
||||
} else {
|
||||
this.$message.error(response.data.error || '创建虚拟群组失败');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('创建虚拟群组失败:', error);
|
||||
this.$message.error('创建虚拟群组失败');
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
editVirtualGroup(group) {
|
||||
this.editVirtualGroupForm = {
|
||||
id: group.id,
|
||||
name: group.name
|
||||
};
|
||||
this.editVirtualGroupDialogVisible = true;
|
||||
this.$nextTick(() => {
|
||||
this.$refs.editVirtualGroupForm && this.$refs.editVirtualGroupForm.clearValidate();
|
||||
});
|
||||
},
|
||||
submitEditVirtualGroup() {
|
||||
this.$refs.editVirtualGroupForm.validate(valid => {
|
||||
if (valid) {
|
||||
axios.put(`/virtual_group/api/virtual_groups/${this.editVirtualGroupForm.id}`, {
|
||||
name: this.editVirtualGroupForm.name
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
this.$message.success('更新虚拟群组成功');
|
||||
this.editVirtualGroupDialogVisible = false;
|
||||
this.loadVirtualGroups();
|
||||
} else {
|
||||
this.$message.error(response.data.error || '更新虚拟群组失败');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('更新虚拟群组失败:', error);
|
||||
this.$message.error('更新虚拟群组失败');
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
deleteVirtualGroup(group) {
|
||||
this.$confirm(`确定要删除虚拟群组 "${group.name}" 吗?`, '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
axios.delete(`/virtual_group/api/virtual_groups/${group.id}`)
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
this.$message.success('删除虚拟群组成功');
|
||||
this.loadVirtualGroups();
|
||||
} else {
|
||||
this.$message.error(response.data.error || '删除虚拟群组失败');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('删除虚拟群组失败:', error);
|
||||
this.$message.error('删除虚拟群组失败');
|
||||
});
|
||||
}).catch(() => {});
|
||||
},
|
||||
showAddGroupDialog(virtualGroup) {
|
||||
this.currentVirtualGroupId = virtualGroup.id;
|
||||
this.addGroupForm = { wx_group_id: '' };
|
||||
|
||||
// 过滤掉已经在虚拟群组中的微信群
|
||||
const existingGroupIds = virtualGroup.groups.map(g => g.id);
|
||||
this.availableGroups = this.allGroups.filter(g => !existingGroupIds.includes(g.wxid));
|
||||
|
||||
this.addGroupDialogVisible = true;
|
||||
this.$nextTick(() => {
|
||||
this.$refs.addGroupForm && this.$refs.addGroupForm.clearValidate();
|
||||
});
|
||||
},
|
||||
submitAddGroup() {
|
||||
this.$refs.addGroupForm.validate(valid => {
|
||||
if (valid) {
|
||||
axios.post(`/virtual_group/api/virtual_groups/${this.currentVirtualGroupId}/groups`, {
|
||||
wx_group_id: this.addGroupForm.wx_group_id
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
this.$message.success('添加微信群成功');
|
||||
this.addGroupDialogVisible = false;
|
||||
this.loadVirtualGroups();
|
||||
} else {
|
||||
this.$message.error(response.data.error || '添加微信群失败');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('添加微信群失败:', error);
|
||||
this.$message.error('添加微信群失败');
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
removeGroupFromVirtual(virtualGroupId, wxGroupId) {
|
||||
this.$confirm('确定要从虚拟群组中移除该微信群吗?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
axios.delete(`/virtual_group/api/virtual_groups/${virtualGroupId}/groups/${wxGroupId}`)
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
this.$message.success('移除微信群成功');
|
||||
this.loadVirtualGroups();
|
||||
} else {
|
||||
this.$message.error(response.data.error || '移除微信群失败');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('移除微信群失败:', error);
|
||||
this.$message.error('移除微信群失败');
|
||||
});
|
||||
}).catch(() => {});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user