mirror of
https://gitee.com/technical-laohu/mpay.git
synced 2025-09-20 10:46:38 +08:00
插件中心更新
This commit is contained in:
parent
860a87b20c
commit
af607036a5
@ -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) {
|
||||
if ($index === null) {
|
||||
return false; // 插件不存在
|
||||
}
|
||||
unset($plugin_config[$index]);
|
||||
}
|
||||
$config = \array_values($plugin_config);
|
||||
$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 = [])
|
||||
|
@ -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);
|
||||
}
|
||||
// 请求外部资源
|
||||
|
@ -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 });
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
Loading…
Reference in New Issue
Block a user