插件中心更新

This commit is contained in:
技术老胡 2024-11-30 11:50:10 +08:00
parent 5ba4dfdc6c
commit d6096d6ad9
5 changed files with 57 additions and 24 deletions

8
.env
View File

@ -2,11 +2,11 @@ APP_DEBUG = true
DB_TYPE = mysql
DB_HOST = 127.0.0.1
DB_NAME = test1
DB_USER = a1
DB_PASS = 123456
DB_NAME = mpay
DB_USER = admin
DB_PASS = Aa123456
DB_PORT = 3306
DB_CHARSET = utf8mb4
DB_CHARSET = utf8
DB_PREFIX = mpay_
DEFAULT_LANG = zh-cn

View File

@ -12,7 +12,13 @@ class PluginController extends BaseController
public function getPluginList()
{
$local_plugin_config = self::getPluginConfig();
$plugin_config = \Plugin::getPluginList($local_plugin_config);
$show = $this->request->get('show', 1);
$plugin_config = match ((int)$show) {
0 => \Plugin::getAllPlugins($local_plugin_config),
1 => \Plugin::getInstall($local_plugin_config),
2 => \Plugin::getUninstallPlugins($local_plugin_config),
default => []
};
if ($plugin_config) {
return json(['code' => 0, 'msg' => 'OK', 'count' => count($plugin_config), 'data' => $plugin_config]);
} else {
@ -83,11 +89,28 @@ class PluginController extends BaseController
public function pluginEnable()
{
$info = $this->request->post();
if ($this->isPluginInstall($info['platform']) == false) {
return json(backMsg(1, '插件未安装'));
}
$up_res = $this->setPlugin($info['platform'], ['state' => $info['state']]);
if ($up_res) {
return json(\backMsg(1, '失败'));
return json(backMsg(1, '失败'));
} else {
return json(\backMsg(0, '成功'));
return json(backMsg(0, '成功'));
}
}
// 检测插件是否安装
public function isPluginInstall(string $platform): bool
{
$config = self::getPluginConfig();
$platforms = [];
foreach ($config as $key => $value) {
$platforms[] = $value['platform'];
}
if (in_array($platform, $platforms)) {
return true;
} else {
return false;
}
}
// 插件选项

View File

@ -50,5 +50,5 @@ return array (
'store_sn' => '',
'type' => '30',
),
)
),
);

View File

@ -6,7 +6,8 @@ use think\facade\Log;
class Plugin
{
public static function getPluginList(array $local_plugin = []): array
// 获取全部插件(含本地)
public static function getAllPlugins(array $local_plugin = []): array
{
$app_plugin = [];
$app_plugin_all = self::getAllPlugin();
@ -15,6 +16,11 @@ class Plugin
$app_plugin = array_merge($local_plugin, $plugin_uninstall);
return $app_plugin;
}
// 获取未安装插件
public static function getUninstallPlugins(array $local_plugin = []): array
{
return self::getUninstall(self::getAllPlugin(), $local_plugin);
}
// 获取已安装插件
public static function getInstall(array $local_plugin = []): array
{
@ -53,7 +59,7 @@ class Plugin
'price' => '0.00',
'describe' => '支持微信个人收款码、赞赏码、经营码、商家码收款,监听回调',
'website' => 'https://weixin.qq.com/',
'state' => 1,
'state' => 0,
'query' =>
array(),
),
@ -65,7 +71,7 @@ class Plugin
'price' => '0.00',
'describe' => '支持支付宝个人收款码、经营码收款,监听回调',
'website' => 'https://www.alipay.com/',
'state' => 1,
'state' => 0,
'query' =>
array(),
),
@ -77,7 +83,7 @@ class Plugin
'price' => '49.00',
'describe' => '主流移动支付全能收 信用卡,花呗都能用,生意帮手收钱吧,移动收款就用它!',
'website' => 'https://www.shouqianba.com/',
'state' => 1,
'state' => 0,
'query' =>
array(
'date_end' => NULL,
@ -98,7 +104,7 @@ class Plugin
'price' => '49.00',
'describe' => '数字门店',
'website' => 'https://store.zhihuijingyingba.com/',
'state' => 1,
'state' => 0,
'query' =>
array(
'pageNo' => 1,

View File

@ -43,12 +43,19 @@
<button class="layui-btn layui-btn-primary layui-bg-gray layui-btn-sm" grp-btn lay-event="showWaitInstall">待安装</button>
</script>
<script type="text/html" id="plugin-state">
{{# if(d.install == true){ }}
<input type="checkbox" name="state" value="{{d.platform}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="pluginEnable" {{ d.state == 1 ? 'checked' : '' }} />
{{# }else{ }}
<span class="layui-badge layui-bg-gray">未安装</span>
{{# } }}
</script>
<script type="text/html" id="plugin-action">
<a href="javascript:;" class="layui-font-green" lay-event="createConfig">配置</a><div class="divider-vl"></div>
{{# if(d.install == true){ }}
<a href="javascript:;" class="layui-font-green" lay-event="pluginUpdate">更新</a><div class="divider-vl"></div>
<a href="javascript:;" class="layui-font-green" lay-event="pluginUninstall">卸载</a>
{{# }else{ }}
<a href="javascript:;" class="layui-font-green" lay-event="pluginInstall">立即安装</a>
{{# } }}
</script>
<script src="/component/layui/layui.js"></script>
<script src="/component/pear/pear.js"></script>
@ -66,14 +73,13 @@
{ title: '说明', field: 'describe', align: 'left' },
{ title: '价格', field: 'price', align: 'center', maxWidth: 180, templet: `<div>{{= d.price==0 ? '免费' : d.price }}</div>` },
{ title: '状态', field: 'state', align: 'center', maxWidth: 180, templet: `#plugin-state` },
{ title: '操作', align: 'right', maxWidth: 180, fixed: 'right', templet: `#plugin-action` },
{ title: '操作', align: 'center', maxWidth: 180, fixed: 'right', templet: `#plugin-action` },
]]
table.render({
id: 'plugin-table',
elem: '#plugin-table',
url: '/api/Plugin/getPluginList',
page: true,
skin: 'line',
cols: cols,
where: { show: 1 },
@ -84,20 +90,17 @@
// 表头工具事件
table.on('toolbar(plugin-table)', function (obj) {
if (obj.event === 'showAllPlugin') {
plugin.changClass(this);
table.reload('plugin-table', { where: { show: 0 } });
table.reload('plugin-table', { where: { show: 0 }, done: () => { plugin.changClass(obj.event) } });
} else if (obj.event === 'showInstalled') {
plugin.changClass(this);
table.reload('plugin-table', { where: { show: 1 } });
table.reload('plugin-table', { where: { show: 1 }, done: () => { plugin.changClass(obj.event) } });
} else if (obj.event === 'showWaitInstall') {
plugin.changClass(this);
table.reload('plugin-table', { where: { show: 2 } });
table.reload('plugin-table', { where: { show: 2 }, done: () => { plugin.changClass(obj.event) } });
}
});
// 单元格事件
table.on('tool(plugin-table)', function (obj) {
const id = obj.data.id;
if (obj.event === 'createConfig') {
if (obj.event === 'pluginInstall') {
layer.msg(obj.event);
} else if (obj.event === 'pluginUpdate') {
layer.msg(obj.event);
@ -117,9 +120,10 @@
let plugin = {};
// 处理点击btn切换class
plugin.changClass = (ele) => {
plugin.changClass = (event) => {
const select = 'layui-btn layui-btn-primary layui-bg-green layui-btn-sm';
const unselect = 'layui-btn layui-btn-primary layui-bg-gray layui-btn-sm';
const ele = document.querySelector(`button[lay-event="${event}"]`);
ele.className = select;
const btns = document.querySelectorAll(`button[grp-btn]`);
btns.forEach(val => {