fix: 修复插件bug
This commit is contained in:
@@ -12,9 +12,12 @@ declare (strict_types=1);
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
namespace app\admin\controller\system;
|
namespace app\admin\controller\system;
|
||||||
|
|
||||||
use app\admin\service\AuthService;
|
use app\admin\service\AuthService;
|
||||||
|
use app\common\exception\OperateException;
|
||||||
use GuzzleHttp\Exception\TransferException;
|
use GuzzleHttp\Exception\TransferException;
|
||||||
use process\Monitor;
|
use process\Monitor;
|
||||||
|
use Psr\SimpleCache\InvalidArgumentException;
|
||||||
use support\Response;
|
use support\Response;
|
||||||
use system\File;
|
use system\File;
|
||||||
use system\Http;
|
use system\Http;
|
||||||
@@ -23,8 +26,8 @@ use app\AdminController;
|
|||||||
use think\db\exception\DataNotFoundException;
|
use think\db\exception\DataNotFoundException;
|
||||||
use think\db\exception\DbException;
|
use think\db\exception\DbException;
|
||||||
use think\db\exception\ModelNotFoundException;
|
use think\db\exception\ModelNotFoundException;
|
||||||
|
use think\facade\Db;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
use app\common\library\DataBase;
|
|
||||||
use app\common\model\system\AdminRules;
|
use app\common\model\system\AdminRules;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,11 +43,6 @@ class Plugin extends AdminController
|
|||||||
*/
|
*/
|
||||||
protected mixed $limit = 500;
|
protected mixed $limit = 500;
|
||||||
|
|
||||||
/**
|
|
||||||
* 错误信息
|
|
||||||
* @var mixed
|
|
||||||
*/
|
|
||||||
static mixed $ServerBody = '';
|
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@@ -69,7 +67,7 @@ class Plugin extends AdminController
|
|||||||
/**
|
/**
|
||||||
* 安装插件
|
* 安装插件
|
||||||
* @return Response|void
|
* @return Response|void
|
||||||
* @throws \Exception|\Psr\SimpleCache\InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function install()
|
public function install()
|
||||||
{
|
{
|
||||||
@@ -83,7 +81,13 @@ class Plugin extends AdminController
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$pluginZip = self::downLoad($name, ['name' => $name, 'token' => input('token')]);
|
$pluginZip = self::downLoad($name, [
|
||||||
|
'name' => $name,
|
||||||
|
'token' => input('token'),
|
||||||
|
'version' => input('version'),
|
||||||
|
'app' => config('app.version'),
|
||||||
|
]);
|
||||||
|
|
||||||
ZipArchives::unzip($pluginZip, plugin_path(), '', true);
|
ZipArchives::unzip($pluginZip, plugin_path(), '', true);
|
||||||
$listFiles = File::mutexCompare(File::getCopyDirs($name), root_path(), $pluginPath, true);
|
$listFiles = File::mutexCompare(File::getCopyDirs($name), root_path(), $pluginPath, true);
|
||||||
if (!empty($listFiles)) {
|
if (!empty($listFiles)) {
|
||||||
@@ -95,29 +99,31 @@ class Plugin extends AdminController
|
|||||||
self::pluginMenu($name);
|
self::pluginMenu($name);
|
||||||
self::executeSql($name);
|
self::executeSql($name);
|
||||||
self::enabled($name);
|
self::enabled($name);
|
||||||
|
} catch (OperateException $e) {
|
||||||
|
recursive_delete($pluginPath);
|
||||||
|
return $this->error($e->getMessage(), '/', $e->getData(), $e->getCode());
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
recursive_delete($pluginPath);
|
recursive_delete($pluginPath);
|
||||||
return $this->error($th->getMessage(), null, self::$ServerBody, $th->getCode());
|
return $this->error($th->getMessage(), '/', [], $th->getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->success('插件安装成功', null, get_plugin_config($name, true));
|
return $this->success('插件安装成功', '/', get_plugin_config($name, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 卸载插件
|
* 卸载插件
|
||||||
* @return Response|void
|
* @return Response|void
|
||||||
* @throws \Exception|\Psr\SimpleCache\InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function uninstall()
|
public function uninstall()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (request()->isAjax()) {
|
if (request()->isAjax()) {
|
||||||
|
|
||||||
$name = input('name');
|
$name = input('name');
|
||||||
$config = get_plugin_config($name, true);
|
$config = get_plugin_config($name, true);
|
||||||
if (empty($config) || $config['status']) {
|
if (empty($config) || $config['status']) {
|
||||||
return $this->error('插件不存在或未禁用');
|
return $this->error('请先禁用插件后再卸载');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -142,9 +148,8 @@ class Plugin extends AdminController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 插件升级
|
* 插件升级
|
||||||
* @return mixed|void
|
* @return Response|void
|
||||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
* @throws \Exception
|
|
||||||
*/
|
*/
|
||||||
public function upgrade()
|
public function upgrade()
|
||||||
{
|
{
|
||||||
@@ -166,7 +171,13 @@ class Plugin extends AdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$pluginPath = plugin_path($name);
|
$pluginPath = plugin_path($name);
|
||||||
$pluginZip = self::downLoad($name, ['name' => $name, 'token' => $token, 'version' => $version]);
|
$pluginZip = self::downLoad($name, [
|
||||||
|
'name' => $name,
|
||||||
|
'token' => $token,
|
||||||
|
'version' => $version,
|
||||||
|
'app' => config('app.version')
|
||||||
|
]);
|
||||||
|
|
||||||
$formIndex = ZipArchives::unzip($pluginZip, plugin_path(), 'config.json');
|
$formIndex = ZipArchives::unzip($pluginZip, plugin_path(), 'config.json');
|
||||||
$upgradeInfo = json_decode($formIndex, true);
|
$upgradeInfo = json_decode($formIndex, true);
|
||||||
|
|
||||||
@@ -190,8 +201,10 @@ class Plugin extends AdminController
|
|||||||
self::pluginMenu($name);
|
self::pluginMenu($name);
|
||||||
self::executeSql($name);
|
self::executeSql($name);
|
||||||
self::enabled($name);
|
self::enabled($name);
|
||||||
|
} catch (OperateException $e) {
|
||||||
|
return $this->error($e->getMessage(), '/', $e->getData(), $e->getCode());
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
return $this->error($th->getMessage(), null, self::$ServerBody, $th->getCode());
|
return $this->error($th->getMessage(), '/', [], $th->getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->success('插件更新成功', null, $data);
|
return $this->success('插件更新成功', null, $data);
|
||||||
@@ -202,7 +215,8 @@ class Plugin extends AdminController
|
|||||||
* 启用插件
|
* 启用插件
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws \Exception|\Psr\SimpleCache\InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function enabled(string $name): bool
|
public static function enabled(string $name): bool
|
||||||
{
|
{
|
||||||
@@ -232,7 +246,7 @@ class Plugin extends AdminController
|
|||||||
* 禁用插件
|
* 禁用插件
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function disabled(string $name): bool
|
public static function disabled(string $name): bool
|
||||||
@@ -276,7 +290,7 @@ class Plugin extends AdminController
|
|||||||
/**
|
/**
|
||||||
* 修改插件配置
|
* 修改插件配置
|
||||||
* @return Response
|
* @return Response
|
||||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function config(): Response
|
public function config(): Response
|
||||||
{
|
{
|
||||||
@@ -344,26 +358,20 @@ class Plugin extends AdminController
|
|||||||
*/
|
*/
|
||||||
public static function downLoad(string $name, array $extends): string
|
public static function downLoad(string $name, array $extends): string
|
||||||
{
|
{
|
||||||
try {
|
|
||||||
|
|
||||||
$query = get_plugin_query();
|
$query = get_plugin_query();
|
||||||
$response = Http::get($query, $extends);
|
$response = Http::get($query, $extends);
|
||||||
$body = json_decode($response, true);
|
$body = json_decode($response, true);
|
||||||
$url = '';
|
|
||||||
if (isset($body['data']['url'])) {
|
if (isset($body['data']['url'])) {
|
||||||
$url = $body['data']['url'];
|
$url = $body['data']['url'];
|
||||||
}
|
}
|
||||||
if (!empty($url) && stristr($url, 'download')) {
|
|
||||||
|
if (isset($url) && stristr($url, 'download')) {
|
||||||
$content = file_get_contents($url);
|
$content = file_get_contents($url);
|
||||||
$filePath = plugin_path() . $name . '.zip';
|
$filePath = plugin_path() . $name . '.zip';
|
||||||
write_file($filePath, $content);
|
write_file($filePath, $content);
|
||||||
} else {
|
} else {
|
||||||
self::$ServerBody = $body['data'];
|
throw new OperateException($body['msg'], $body['code'], $body['data'] ?? []);
|
||||||
throw new \Exception($body['msg'], $body['code']);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (TransferException $th) {
|
|
||||||
throw new \Exception(__("安装包下载失败"), -111);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $filePath;
|
return $filePath;
|
||||||
@@ -373,12 +381,23 @@ class Plugin extends AdminController
|
|||||||
* 执行SQL脚本文件
|
* 执行SQL脚本文件
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $type
|
* @param string $type
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function executeSql(string $name, string $type = 'install')
|
public static function executeSql(string $name, string $type = 'install')
|
||||||
{
|
{
|
||||||
$pluginPath = plugin_path($name);
|
$pluginPath = plugin_path($name);
|
||||||
$sqlFile = $pluginPath . $type . '.sql';
|
$sqlFile = $pluginPath . $type . '.sql';
|
||||||
DataBase::importSql($sqlFile);
|
$sql = file_get_contents($sqlFile);
|
||||||
|
$queries = explode(';', $sql);
|
||||||
|
$queries = str_replace("__PREFIX__", get_env('DATABASE_PREFIX'), $queries);
|
||||||
|
foreach ($queries as $query) {
|
||||||
|
$query = trim($query);
|
||||||
|
if (empty($query)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 执行SQL语句
|
||||||
|
Db::execute($query);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -18,14 +18,14 @@ body,.layui-fluid {
|
|||||||
text-indent: 1em;
|
text-indent: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pluginCenter .fa-user {
|
.pluginCenter .fa-user, .fa-sign-out {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 15px;
|
right: 15px;
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
top: 6px;
|
top: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pluginCenter .fa-user:hover {
|
.pluginCenter .fa-user:hover, .fa-sign-out:hover {
|
||||||
color: #FF5722;
|
color: #FF5722;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,13 +43,13 @@ body,.layui-fluid {
|
|||||||
padding: 10px;
|
padding: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.layui-dropdown.upgrade-version {
|
.layui-dropdown.upgrade-version,.layui-dropdown.install-version {
|
||||||
min-width: 80px!important;
|
min-width: 80px!important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.upgrade-version .layui-menu li {
|
.upgrade-version .layui-menu li, .layui-dropdown.install-version li {
|
||||||
width: 80px;
|
width: 80px;
|
||||||
line-height: 15px;
|
line-height: 20px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
@@ -181,3 +181,8 @@ button[lay-filter="formSearch"] {
|
|||||||
padding-left: 3px;
|
padding-left: 3px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.layui-table-cell .layui-icon-down {
|
||||||
|
font-size: 10px;
|
||||||
|
top: 0!important;
|
||||||
|
}
|
||||||
@@ -1,22 +1,20 @@
|
|||||||
/* 插件管理模块 */
|
/* 插件管理模块 */
|
||||||
layui.define(['i18n'], function (exports) {
|
layui.define(['admin','show'], function (exports) {
|
||||||
|
|
||||||
var $ = layui.jquery;
|
let $ = layui.jquery;
|
||||||
var table = layui.table;
|
let table = layui.table;
|
||||||
var i18n = layui.i18n;
|
let form = layui.form;
|
||||||
var form = layui.form;
|
let admin = layui.admin;
|
||||||
var notice = layui.notice;
|
let show = layui.show;
|
||||||
|
|
||||||
i18n.render(layui.admin.getStorage('language') || 'zh-CN');
|
let plugin = {
|
||||||
var area = [$(window).width() > 800 ? '660px' : '85%', $(window).height() > 800 ? '680px' : '85%'];
|
apiUrl: app_Config.api,
|
||||||
|
baseUrl: app_Config.app,
|
||||||
var plugin = {
|
data:{}, // 插件数据
|
||||||
apiUrl: _global_.api,
|
|
||||||
baseUrl: _global_.app,
|
|
||||||
request: function (name, version, url) {
|
request: function (name, version, url) {
|
||||||
|
|
||||||
let index = layer.load();
|
let index = layer.load();
|
||||||
let token = layui.admin.getStorage('api_cross_token') || null;
|
let token = admin.getStorage('api_cross_token') || null;
|
||||||
if (token == null || token === 'undefined') {
|
if (token == null || token === 'undefined') {
|
||||||
layer.close(index);
|
layer.close(index);
|
||||||
plugin.login();
|
plugin.login();
|
||||||
@@ -28,49 +26,19 @@ layui.define(['i18n'], function (exports) {
|
|||||||
version: version,
|
version: version,
|
||||||
token: token,
|
token: token,
|
||||||
}, function (res) {
|
}, function (res) {
|
||||||
|
|
||||||
let data;
|
|
||||||
layer.closeAll();
|
layer.closeAll();
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
|
show.msg(res.msg);
|
||||||
layer.msg(res.msg);
|
|
||||||
let index = layui.sessionData('api_install_index').index,
|
|
||||||
elems = $('tr[data-index="' + index + '"]');
|
|
||||||
if (url.indexOf('install') !== -1) {
|
|
||||||
let c = '', h = '<input type="checkbox" lay-filter="pluginStatus" data-url="';
|
|
||||||
h += plugin.baseUrl + '/system/Plugin/status" value="' + name + '" lay-skin="switch" checked="">';
|
|
||||||
$(elems).find('[data-field="status"]').children('div').html(h);
|
|
||||||
data = res.data || [];
|
|
||||||
if (data.config) {
|
|
||||||
c += '<a class="layui-table-text" data-title="' + i18n.prop('配置插件') + '"'
|
|
||||||
c += 'data-area="' + data.area + '" data-maxmin="true"';
|
|
||||||
c += 'data-url="' + plugin.baseUrl + '/system/Plugin/config?name=' + name + '" '
|
|
||||||
c += 'lay-event="edit">' + i18n.prop('配置') + '</a>';
|
|
||||||
c += '<div class="layui-divider layui-divider-vertical"></div> ';
|
|
||||||
}
|
|
||||||
c += '<a class="layui-table-text uninstall" style="color:red"'
|
|
||||||
c += 'data-url="' + plugin.baseUrl + '/system/Plugin/uninstall/?name=' + name + '">' + i18n.prop('卸载') + '</a> ';
|
|
||||||
$(elems).find('td:last').children('div').html(c);
|
|
||||||
window.plugins[name] = res.data;
|
window.plugins[name] = res.data;
|
||||||
} else {
|
table.reloadData('lay-tableList');
|
||||||
elems.find('.layui-upgrade-elem').remove();
|
|
||||||
elems.find('.layui-form-switch').addClass('bubble');
|
|
||||||
elems.find('.layui-form-switch').trigger('click', ['stopPropagation']);
|
|
||||||
}
|
|
||||||
|
|
||||||
form.render();
|
|
||||||
top.layui.admin.reloadLayout();
|
top.layui.admin.reloadLayout();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
notice.error({
|
show.error(res.msg);
|
||||||
message: res.msg,
|
|
||||||
})
|
|
||||||
// 登录超时
|
// 登录超时
|
||||||
if (res.code === -101) {
|
if (res.code === -101) {
|
||||||
plugin.login();
|
plugin.login();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 付费插件
|
// 付费插件
|
||||||
if (res.code === -102) {
|
if (res.code === -102) {
|
||||||
plugin.pay(res.data);
|
plugin.pay(res.data);
|
||||||
@@ -82,19 +50,20 @@ layui.define(['i18n'], function (exports) {
|
|||||||
}
|
}
|
||||||
, upgrade: function (data, token, url) {
|
, upgrade: function (data, token, url) {
|
||||||
let html = '<blockquote class="layui-elem-quote layui-elem-upgrade">温馨提示<br/>';
|
let html = '<blockquote class="layui-elem-quote layui-elem-upgrade">温馨提示<br/>';
|
||||||
html += '<span class="upgrade-title">确认升级 《' + data.pluginName + '》 '+data.v+' 版本吗?</span><br/>';
|
html += '<span class="upgrade-title">确认升级 《' + data.pluginName + '》 ' + data.version + ' 版本吗?</span><br/>';
|
||||||
html += '1、请务必做好服务器代码和数据库备份<br/>';
|
html += '1、请务必做好服务器代码和数据库备份<br/>';
|
||||||
html += '2、升级后如出现冗余数据,请根据需要移除即可<br/>';
|
html += '2、升级后如出现冗余数据,请根据需要移除即可<br/>';
|
||||||
html += '3、请勿跨版本升级,如必要请参考插件使用文档<br/>';
|
html += '3、请勿跨版本升级,如必要请参考插件使用文档<br/>';
|
||||||
html += '4、已部署完成的插件,请确保服务器Web权限可读写<br/>';
|
html += '4、已部署完成的插件,请确保服务器Web权限可读写<br/>';
|
||||||
html += '5、生产环境下更新维护插件,请勿在流量高峰期操作<br/>';
|
html += '5、生产环境下更新维护插件,请勿在流量高峰期操作<br/>';
|
||||||
html += '</blockquote>';
|
html += '</blockquote>';
|
||||||
var confirm = layer.confirm(html, {
|
let confirm = layer.confirm(html, {
|
||||||
title: i18n.prop('更新提示'),
|
title: '更新提示',
|
||||||
}, function () {
|
}, function () {
|
||||||
layer.close(confirm);
|
layer.close(confirm);
|
||||||
plugin.request(data.name, data.v, plugin.getUrl('Plugin', 'upgrade'));
|
plugin.request(data.name, data.version, plugin.getUrl('Plugin', 'upgrade'));
|
||||||
}, function () {});
|
}, function () {
|
||||||
|
});
|
||||||
}
|
}
|
||||||
, login: function () {
|
, login: function () {
|
||||||
layer.open({
|
layer.open({
|
||||||
@@ -106,16 +75,13 @@ layui.define(['i18n'], function (exports) {
|
|||||||
success: function (index, layero) {
|
success: function (index, layero) {
|
||||||
form.on('submit(login)', function (data) {
|
form.on('submit(login)', function (data) {
|
||||||
$.post(plugin.apiUrl + '/user/login',
|
$.post(plugin.apiUrl + '/user/login',
|
||||||
|
|
||||||
data.field, function (res) {
|
data.field, function (res) {
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
layui.admin.setStorage('api_cross_token', res.data.token);
|
admin.setStorage('api_cross_token', res.data.token);
|
||||||
layer.closeAll();
|
layer.closeAll();
|
||||||
plugin.againClick();
|
plugin.againClick();
|
||||||
} else {
|
} else {
|
||||||
notice.error({
|
show.error(res.msg);
|
||||||
message: res.msg,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}, 'json')
|
}, 'json')
|
||||||
|
|
||||||
@@ -126,12 +92,12 @@ layui.define(['i18n'], function (exports) {
|
|||||||
}
|
}
|
||||||
, clearLogin: function () {
|
, clearLogin: function () {
|
||||||
layer.msg('清除登录信息成功');
|
layer.msg('清除登录信息成功');
|
||||||
layui.admin.setStorage('api_cross_token', null);
|
admin.setStorage('api_cross_token', null);
|
||||||
}
|
}
|
||||||
, pay: function (data) {
|
, pay: function (data) {
|
||||||
layer.open({
|
layer.open({
|
||||||
type: 2,
|
type: 2,
|
||||||
title: i18n.prop('立即支付'),
|
title: '立即支付',
|
||||||
area: ['500px', '550px'],
|
area: ['500px', '550px'],
|
||||||
offset: "30px",
|
offset: "30px",
|
||||||
resize: false,
|
resize: false,
|
||||||
@@ -139,7 +105,6 @@ layui.define(['i18n'], function (exports) {
|
|||||||
shadeClose: true,
|
shadeClose: true,
|
||||||
content: data.pay_url,
|
content: data.pay_url,
|
||||||
success: function (index, layero) {
|
success: function (index, layero) {
|
||||||
// 父类消息监听
|
|
||||||
window.onmessage = function (res) {
|
window.onmessage = function (res) {
|
||||||
let data = res.data;
|
let data = res.data;
|
||||||
if (res.data !== null && data.code === 200) {
|
if (res.data !== null && data.code === 200) {
|
||||||
@@ -151,20 +116,14 @@ layui.define(['i18n'], function (exports) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
, againClick: function () {
|
, againClick: function () {
|
||||||
try {
|
if (plugin.data == null || plugin.data === 'undefined') {
|
||||||
|
return false;
|
||||||
var index = layui.sessionData('api_install_index').index,
|
|
||||||
install = $('tr[data-index="' + index + '"]').children().find('.install');
|
|
||||||
if (install.length <= 0) {
|
|
||||||
install = $('[layui-value="' + index + '"]');
|
|
||||||
}
|
}
|
||||||
if (install && index != null) {
|
plugin.request(plugin.data.name, plugin.data.version, plugin.getUrl('Plugin', 'install'));
|
||||||
$(install).trigger("click");
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
}
|
||||||
|
, install(name, version) {
|
||||||
|
plugin.data = {name: name, version: version};
|
||||||
|
plugin.request(name, version, plugin.getUrl('Plugin', 'install'));
|
||||||
}
|
}
|
||||||
, uninstall: function (name, tables) {
|
, uninstall: function (name, tables) {
|
||||||
let appURL = plugin.baseUrl;
|
let appURL = plugin.baseUrl;
|
||||||
@@ -172,28 +131,13 @@ layui.define(['i18n'], function (exports) {
|
|||||||
name: name,
|
name: name,
|
||||||
tables: tables,
|
tables: tables,
|
||||||
}, function (res) {
|
}, function (res) {
|
||||||
|
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
layer.msg(res.msg);
|
show.msg(res.msg);
|
||||||
let index = layui.sessionData('api_install_index').index,
|
|
||||||
elems = $('tr[data-index="' + index + '"]');
|
|
||||||
$(elems).find('[data-field="status"]').children('div').html('--');
|
|
||||||
let html = '<a class="layui-table-text install" data-url="' + appURL;
|
|
||||||
html += '/system/Plugin/install/name/' + name + '">' + i18n.prop('安装') + '</a>';
|
|
||||||
let plugin = table.cache['lay-tableList'][index];
|
|
||||||
if (typeof plugin.demourl != 'undefined') {
|
|
||||||
html += '<div class="layui-divider layui-divider-vertical"></div>';
|
|
||||||
html += '<a class="layui-table-text" target="_blank" href="';
|
|
||||||
html += plugin.demourl + '">' + i18n.prop('演示') + '</a>';
|
|
||||||
}
|
|
||||||
delete window.plugins[name];
|
delete window.plugins[name];
|
||||||
$(elems).find('td:last').children('div').html(html);
|
table.reloadData('lay-tableList');
|
||||||
} else {
|
} else {
|
||||||
notice.error({
|
show.error(res.msg);
|
||||||
message: res.msg,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
layer.close(window.unIndex);
|
layer.close(window.unIndex);
|
||||||
}, 'json');
|
}, 'json');
|
||||||
}
|
}
|
||||||
@@ -206,12 +150,12 @@ layui.define(['i18n'], function (exports) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var index = $(that).parents('tr').attr('data-index');
|
let index = $(that).parents('tr').attr('data-index');
|
||||||
index = table.cache['lay-tableList'][index];
|
index = table.cache['lay-tableList'][index];
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
, getHtml: function () {
|
, getHtml: function () {
|
||||||
var html = '<form class="layui-form layui-form-fixed" style="padding-right:15px;" >';
|
let html = '<form class="layui-form layui-form-fixed" style="padding-right:15px;" >';
|
||||||
html += '<blockquote class="layui-elem-quote layui-elem-plugin">';
|
html += '<blockquote class="layui-elem-quote layui-elem-plugin">';
|
||||||
html += '</blockquote><div style="height:20px;"></div>';
|
html += '</blockquote><div style="height:20px;"></div>';
|
||||||
html += '<div class="layui-form-item">';
|
html += '<div class="layui-form-item">';
|
||||||
@@ -236,7 +180,7 @@ layui.define(['i18n'], function (exports) {
|
|||||||
*/
|
*/
|
||||||
$('.layui-plugin-select').click(function () {
|
$('.layui-plugin-select').click(function () {
|
||||||
|
|
||||||
var that = $(this);
|
let that = $(this);
|
||||||
|
|
||||||
if (that.hasClass('active') && !that.hasClass('first')) {
|
if (that.hasClass('active') && !that.hasClass('first')) {
|
||||||
that.removeClass('active');
|
that.removeClass('active');
|
||||||
@@ -246,14 +190,13 @@ layui.define(['i18n'], function (exports) {
|
|||||||
that.addClass('active');
|
that.addClass('active');
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = {}, elem = $('.active');
|
let data = {}, elem = $('.active');
|
||||||
elem.each(function (e, n) {
|
elem.each(function (e, n) {
|
||||||
var value = $(n).attr('data-value') || ''
|
let type = $(n).parent().attr('name');
|
||||||
, type = $(n).parent().attr('name');
|
data[type] = $(n).attr('data-value') || '';
|
||||||
data[type] = value;
|
|
||||||
})
|
})
|
||||||
|
|
||||||
var b = ['type', 'pay', 'label'];
|
let b = ['type', 'pay', 'label'];
|
||||||
|
|
||||||
for (let i in b) {
|
for (let i in b) {
|
||||||
if (!data[b[i]]) {
|
if (!data[b[i]]) {
|
||||||
@@ -274,11 +217,8 @@ layui.define(['i18n'], function (exports) {
|
|||||||
*/
|
*/
|
||||||
$(document).on("click", ".install", function () {
|
$(document).on("click", ".install", function () {
|
||||||
let name = plugin.getTableData(this)['name'];
|
let name = plugin.getTableData(this)['name'];
|
||||||
layui.sessionData('api_install_index', {
|
let version = plugin.getTableData(this)['version'];
|
||||||
key: 'index',
|
plugin.install(name, version);
|
||||||
value: plugin.getTableData(this)['LAY_INDEX'],
|
|
||||||
});
|
|
||||||
plugin.request(name, null, plugin.getUrl('Plugin', 'install'));
|
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -297,9 +237,7 @@ layui.define(['i18n'], function (exports) {
|
|||||||
error: function (res) {
|
error: function (res) {
|
||||||
$(obj.elem).prop('checked', !obj.elem.checked);
|
$(obj.elem).prop('checked', !obj.elem.checked);
|
||||||
form.render('checkbox');
|
form.render('checkbox');
|
||||||
notice.error({
|
show.msg(res.msg);
|
||||||
message: res.msg,
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
success: function (res) {
|
success: function (res) {
|
||||||
layer.msg(res.msg);
|
layer.msg(res.msg);
|
||||||
@@ -316,7 +254,7 @@ layui.define(['i18n'], function (exports) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
layui.admin.event.request(that, objs, options);
|
admin.event.request(that, objs, options);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -326,8 +264,8 @@ layui.define(['i18n'], function (exports) {
|
|||||||
*/
|
*/
|
||||||
$(document).on("click", ".uninstall", function (obj) {
|
$(document).on("click", ".uninstall", function (obj) {
|
||||||
|
|
||||||
var name = plugin.getTableData(this)['name'];
|
let name = plugin.getTableData(this)['name'];
|
||||||
var html = '<form class="layui-form layui-form-fixed" style="padding-right:15px;background: #f2f2f2;" >';
|
let html = '<form class="layui-form layui-form-fixed" style="padding-right:15px;background: #f2f2f2;" >';
|
||||||
html += '<blockquote class="layui-elem-quote layui-elem-uninstall">温馨提示<br/>';
|
html += '<blockquote class="layui-elem-quote layui-elem-uninstall">温馨提示<br/>';
|
||||||
html += '确认卸载 《 ' + name + ' 》 吗?<br/>';
|
html += '确认卸载 《 ' + name + ' 》 吗?<br/>';
|
||||||
html += '1、卸载前请自行备份插件数据库 !<br/>';
|
html += '1、卸载前请自行备份插件数据库 !<br/>';
|
||||||
@@ -341,13 +279,10 @@ layui.define(['i18n'], function (exports) {
|
|||||||
html += '<button type="submit" class="layui-btn layui-btn-normal" lay-submit lay-filter="start">确定</button>';
|
html += '<button type="submit" class="layui-btn layui-btn-normal" lay-submit lay-filter="start">确定</button>';
|
||||||
html += '<button type="button" class="layui-btn layui-btn-primary" sa-event="closeDialog" >关闭</button>';
|
html += '<button type="button" class="layui-btn layui-btn-primary" sa-event="closeDialog" >关闭</button>';
|
||||||
html += '</div></form> ';
|
html += '</div></form> ';
|
||||||
layui.sessionData('api_install_index', {
|
|
||||||
key: 'index',
|
|
||||||
value: plugin.getTableData(this)['LAY_INDEX'],
|
|
||||||
});
|
|
||||||
layer.open({
|
layer.open({
|
||||||
type: 1,
|
type: 1,
|
||||||
title: i18n.prop('卸载插件'),
|
title: '卸载插件',
|
||||||
shadeClose: true,
|
shadeClose: true,
|
||||||
area: ['380px', '300px'],
|
area: ['380px', '300px'],
|
||||||
content: html,
|
content: html,
|
||||||
@@ -378,7 +313,7 @@ layui.define(['i18n'], function (exports) {
|
|||||||
* @param that
|
* @param that
|
||||||
*/
|
*/
|
||||||
$('#pluginInstall').click(function (res) {
|
$('#pluginInstall').click(function (res) {
|
||||||
table.reload('lay-tableList', {
|
table.reloadData('lay-tableList', {
|
||||||
url: plugin.baseUrl + '/system/Plugin/index',
|
url: plugin.baseUrl + '/system/Plugin/index',
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
@@ -388,7 +323,7 @@ layui.define(['i18n'], function (exports) {
|
|||||||
* @param that
|
* @param that
|
||||||
*/
|
*/
|
||||||
$('#pluginCache').click(function (res) {
|
$('#pluginCache').click(function (res) {
|
||||||
var confirm = layer.confirm('确定要更新缓存吗?', {
|
let confirm = layer.confirm('确定要更新缓存吗?', {
|
||||||
title: '更新提示'
|
title: '更新提示'
|
||||||
}, function () {
|
}, function () {
|
||||||
$.get(plugin.baseUrl + plugin.getUrl('Admin', 'clear?type=plugin'), {}, function (res) {
|
$.get(plugin.baseUrl + plugin.getUrl('Admin', 'clear?type=plugin'), {}, function (res) {
|
||||||
@@ -396,9 +331,7 @@ layui.define(['i18n'], function (exports) {
|
|||||||
layer.msg(res.msg);
|
layer.msg(res.msg);
|
||||||
layer.close(confirm);
|
layer.close(confirm);
|
||||||
} else {
|
} else {
|
||||||
notice.error({
|
show.error(res.msg);
|
||||||
message: res.msg,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user