插件群状态弹窗支持按群开启/关闭,复用原有群权限缓存管理逻辑
This commit is contained in:
@@ -194,6 +194,18 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="group_id" label="群ID" min-width="210" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column label="操作" width="100" align="center">
|
||||
<template slot-scope="scope">
|
||||
<el-button
|
||||
size="mini"
|
||||
type="danger"
|
||||
plain
|
||||
:disabled="groupStatusLoading || !pluginGroupStatusData.supports_group_switch"
|
||||
@click="togglePluginGroupSwitch(scope.row, false)">
|
||||
关闭
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
</el-col>
|
||||
@@ -214,6 +226,18 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="group_id" label="群ID" min-width="210" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column label="操作" width="100" align="center">
|
||||
<template slot-scope="scope">
|
||||
<el-button
|
||||
size="mini"
|
||||
type="success"
|
||||
plain
|
||||
:disabled="groupStatusLoading || !pluginGroupStatusData.supports_group_switch"
|
||||
@click="togglePluginGroupSwitch(scope.row, true)">
|
||||
开启
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
</el-col>
|
||||
@@ -240,7 +264,8 @@
|
||||
configFormat: 'toml',
|
||||
pluginGroupStatusVisible: false,
|
||||
groupStatusLoading: false,
|
||||
pluginGroupStatusData: null
|
||||
pluginGroupStatusData: null,
|
||||
currentGroupStatusPlugin: null
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -425,9 +450,11 @@
|
||||
this.pluginGroupStatusVisible = true;
|
||||
this.groupStatusLoading = true;
|
||||
this.pluginGroupStatusData = null;
|
||||
// 记录当前正在查看群状态的插件,供“开启/关闭后刷新”复用。
|
||||
this.currentGroupStatusPlugin = plugin;
|
||||
|
||||
// 统一使用插件模块名查询,和启用/禁用/重载接口参数保持一致。
|
||||
axios.get('/api/plugins/group_status', {
|
||||
return axios.get('/api/plugins/group_status', {
|
||||
params: {
|
||||
plugin_name: plugin.module_name
|
||||
}
|
||||
@@ -456,6 +483,48 @@
|
||||
.finally(() => {
|
||||
this.groupStatusLoading = false;
|
||||
});
|
||||
},
|
||||
togglePluginGroupSwitch(group, enable) {
|
||||
if (!this.currentGroupStatusPlugin || !group || !group.group_id) {
|
||||
this.$message.error('缺少必要参数,无法切换');
|
||||
return;
|
||||
}
|
||||
|
||||
const actionText = enable ? '开启' : '关闭';
|
||||
const pluginName = this.currentGroupStatusPlugin.name || this.currentGroupStatusPlugin.module_name;
|
||||
const groupName = group.group_name || group.group_id;
|
||||
|
||||
this.$confirm(`确定要${actionText}群 "${groupName}" 的插件 "${pluginName}" 吗?`, '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
this.groupStatusLoading = true;
|
||||
// 调用后端切换接口,后端内部复用 GroupBotManager 的原有缓存+Redis策略。
|
||||
axios.post('/api/plugins/group_status/toggle', {
|
||||
plugin_name: this.currentGroupStatusPlugin.module_name,
|
||||
group_id: group.group_id,
|
||||
status: enable ? 'enabled' : 'disabled'
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
this.$message.success(`${actionText}成功`);
|
||||
// 切换后重新拉取当前插件群状态,保证统计与列表一致。
|
||||
return this.showPluginGroupStatus(this.currentGroupStatusPlugin);
|
||||
} else {
|
||||
this.$message.error(response.data.message || `${actionText}失败`);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(`${actionText}插件群状态出错:`, error);
|
||||
this.$message.error(`${actionText}插件群状态出错`);
|
||||
})
|
||||
.finally(() => {
|
||||
this.groupStatusLoading = false;
|
||||
});
|
||||
}).catch(() => {
|
||||
this.$message.info('已取消操作');
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user