调整 message_util 的发送text方法名,方便替换wcf.send_text。加入了虚拟群组管理功能;
This commit is contained in:
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