From af607036a52fd930cdbc3728ff9fe0573b9a48ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=8A=80=E6=9C=AF=E8=80=81=E8=83=A1?= <1094551889@qq.com> Date: Mon, 2 Dec 2024 16:54:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=92=E4=BB=B6=E4=B8=AD=E5=BF=83=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/PluginController.php | 46 ++++++++++++++++++++----- extend/Plugin.php | 4 +-- view/plugin/index.html | 27 +++++++++++++-- 3 files changed, 63 insertions(+), 14 deletions(-) diff --git a/app/controller/api/PluginController.php b/app/controller/api/PluginController.php index 9ffd505..88d224d 100644 --- a/app/controller/api/PluginController.php +++ b/app/controller/api/PluginController.php @@ -25,6 +25,22 @@ class PluginController extends BaseController return json(['code' => 1, 'msg' => '无数据记录', 'count' => 0, 'data' => []]); } } + // 卸载插件 + public function uninstallPlugin() + { + $platform = $this->request->post('platform'); + $classname = $this->request->post('classname'); + if (!$platform || !$classname) { + return json(backMsg(1, '请选择插件')); + } + $res1 = $this->delPlugin($platform); + $res2 = $this->delPluginFile($classname); + if ($res1 && $res2) { + return json(backMsg(0, '卸载成功')); + } else { + return json(backMsg(1, '插件不存在')); + } + } // 添加插件 public function addPlugin(array $option = []) { @@ -46,22 +62,34 @@ class PluginController extends BaseController $this->savePluginConfig($plugin_config, '支付插件列表'); return 0; } - // 删除插件 - public function delPlugin($plugin_name = '') + // 删除插件配置 + private function delPlugin(string $plugin_name = '') { $plugin_config = self::getPluginConfig(); - $keys = []; - foreach ($plugin_config as $index => $value) { + $index = null; + foreach ($plugin_config as $i => $value) { if ($value['platform'] == $plugin_name) { - $keys[] = $index; + $index = $i; } } - foreach ($keys as $index) { - unset($plugin_config[$index]); + if ($index === null) { + return false; // 插件不存在 } - $config = \array_values($plugin_config); + unset($plugin_config[$index]); + $config = array_values($plugin_config); $this->savePluginConfig($config, '支付插件列表'); - return 0; + return true; + } + // 删除插件类库文件 + private function delPluginFile(string $file_name = '') + { + $plugin_path = root_path() . '/extend/payclient/' . $file_name . '.php'; + if (file_exists($plugin_path)) { + unlink($plugin_path); + return true; + } else { + return false; + } } // 修改插件 public function setPlugin($platform = '', $option = []) diff --git a/extend/Plugin.php b/extend/Plugin.php index 0676005..667f8aa 100644 --- a/extend/Plugin.php +++ b/extend/Plugin.php @@ -49,13 +49,13 @@ class Plugin // 获取平台所有支持插件 public static function getAllPlugin(): array { - $app_plugin = self::getHttpResponse(self::$siteUrl . '/mpay/getPlugins/'); + $app_plugin = self::getHttpResponse(self::$siteUrl . '/mpay/getplugins'); return json_decode($app_plugin, true); } // 获取通知消息 public static function getNotifyMessage(): array { - $message = self::getHttpResponse(self::$siteUrl . '/mpay/message/'); + $message = self::getHttpResponse(self::$siteUrl . '/mpay/message'); return json_decode($message, true); } // 请求外部资源 diff --git a/view/plugin/index.html b/view/plugin/index.html index bc71e99..38ac50b 100644 --- a/view/plugin/index.html +++ b/view/plugin/index.html @@ -101,11 +101,18 @@ table.on('tool(plugin-table)', function (obj) { const id = obj.data.id; if (obj.event === 'pluginInstall') { - layer.msg(obj.event); + layer.msg('功能开发中,有需要请联系作者'); } else if (obj.event === 'pluginUpdate') { - layer.msg(obj.event); + layer.msg('功能开发中,有需要请联系作者'); } else if (obj.event === 'pluginUninstall') { - layer.msg(obj.event); + layer.confirm('卸载之后无法恢复,确认吗?', { icon: 3, title: '卸载插件' }, function (index) { + layer.close(index); + config = { + platform: obj.data.platform, + classname: obj.data.class_name + } + plugin.uninstall(config); + }); } }); // 启用状态 @@ -146,6 +153,20 @@ layer.msg(rec_info.msg, { icon: 2, time: 1200 }, () => { obj.elem.checked = !obj.elem.checked }); } } + // 卸载插件 + plugin.uninstall = async (config) => { + const res = await fetch('/api/Plugin/uninstallPlugin', { method: 'post', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(config) }); + if (res.status !== 200) { + layer.msg('请求失败,请重试!', { tips: 2, time: 1200 }); + return false; + } + const rec_info = await res.json(); + if (rec_info.code === 0) { + layer.msg(rec_info.msg, { icon: 1, time: 1200 }, () => { table.reload('plugin-table'); }); + } else { + layer.msg(rec_info.msg, { icon: 2, time: 1200 }); + } + } });