修改系统模块版本管理

This commit is contained in:
Anyon 2020-08-03 18:05:15 +08:00
parent 794a2777a7
commit 0a8baab073
8 changed files with 85 additions and 35 deletions

View File

@ -47,4 +47,23 @@ class Module extends Controller
[$state, $message] = ModuleService::instance()->install($data['name']);
$state ? $this->success($message) : $this->error($message);
}
/**
* 查看模块更新
* @auth true
*/
public function change()
{
$data = $this->_vali(['name.require' => '模块名称不能为空!']);
$modules = ModuleService::instance()->online();
if (isset($modules[$data['name']])) {
$this->module = $modules[$data['name']];
foreach ($this->module['changes'] as $key => &$change) {
$change['datetime'] = preg_replace("|^(\d{4})\.(\d{2})\.(\d{2}).*?$|", '$1年$2月$3日', $key);
}
$this->fetch();
} else {
$this->error('未查询到模块更新记录!');
}
}
}

View File

@ -17,7 +17,7 @@
return [
'name' => 'admin',
'author' => 'Anyon',
'version' => '2020.08.03.00',
'version' => '2020.08.01.00',
'content' => 'ThinkAdmin 系统基础模块',
'changes' => [
'2020.08.03.00' => [

View File

@ -0,0 +1,30 @@
<form class="layui-form layui-card" action="{:request()->url()}" data-auto="true" method="post" autocomplete="off">
<div class="layui-card-body padding-left-40">
<table class="layui-table">
<tr>
<td>模块名称</td>
<td>{$module.name}</td>
</tr>
<tr>
<td>模块描述</td>
<td>{$module.content}</td>
</tr>
<tr>
<td>最新版本</td>
<td>{$module.version}</td>
</tr>
</table>
<ul class="layui-timeline margin-top-30 margin-bottom-30" style="max-height:400px;overflow:auto">
{foreach $module.changes as $key=>$vo}
<li class="layui-timeline-item">
<i class="layui-icon layui-timeline-axis">&#xe63f;</i>
<div class="layui-timeline-content layui-text">
<h3 class="layui-timeline-title">{$vo.datetime|default=''}</h3>
<p>模块版本:{$key|default=''}</p>
<p>更新描述:{$vo.content|default=''}</p>
</div>
</li>
{/foreach}
</ul>
</div>
</form>

View File

@ -22,7 +22,7 @@
<td class='text-left nowrap'>
{if isset($vo.local)} {$vo.local.version}
{if $vo.version > $vo.local.version}
<span class="color-red margin-left-5">{$vo.local.version}</span>
<span data-title="查看模块版本" data-modal="{:url('change')}?name={$vo.name}" class="color-red margin-left-5">{$vo.version}</span>
{else}
<span class="color-desc margin-left-5">{$vo.type_desc}</span>
{/if}

8
composer.lock generated
View File

@ -879,12 +879,12 @@
"source": {
"type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "0cf2b63422aff3efe9ad200b21af1ef88339726a"
"reference": "d799064954094a3ca5d548d2b6e1e575a4dbeac5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/0cf2b63422aff3efe9ad200b21af1ef88339726a",
"reference": "0cf2b63422aff3efe9ad200b21af1ef88339726a",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/d799064954094a3ca5d548d2b6e1e575a4dbeac5",
"reference": "d799064954094a3ca5d548d2b6e1e575a4dbeac5",
"shasum": "",
"mirrors": [
{
@ -928,7 +928,7 @@
],
"description": "ThinkPHP v6.0 Development Library",
"homepage": "http://thinkadmin.top",
"time": "2020-08-03T09:30:04+00:00"
"time": "2020-08-03T09:33:56+00:00"
},
{
"name": "zoujingli/wechat-developer",

View File

@ -903,12 +903,12 @@
"source": {
"type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "0cf2b63422aff3efe9ad200b21af1ef88339726a"
"reference": "d799064954094a3ca5d548d2b6e1e575a4dbeac5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/0cf2b63422aff3efe9ad200b21af1ef88339726a",
"reference": "0cf2b63422aff3efe9ad200b21af1ef88339726a",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/d799064954094a3ca5d548d2b6e1e575a4dbeac5",
"reference": "d799064954094a3ca5d548d2b6e1e575a4dbeac5",
"shasum": "",
"mirrors": [
{
@ -924,7 +924,7 @@
"ext-json": "*",
"topthink/framework": "^6.0"
},
"time": "2020-08-03T09:30:04+00:00",
"time": "2020-08-03T09:33:56+00:00",
"type": "library",
"extra": {
"think": {

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php
// This file is automatically generated at:2020-08-03 17:36:09
// This file is automatically generated at:2020-08-03 18:04:42
declare (strict_types = 1);
return array (
0 => 'think\\admin\\Library',

View File

@ -48,6 +48,25 @@ class ModuleService extends Service
return $online;
}
/**
* 获取线上模块数据
* @return array
*/
public function online(): array
{
$data = $this->app->cache->get('moduleOnlineData', []);
if (!empty($data)) return $data;
$server = InstallService::instance()->getServer();
$result = json_decode(HttpExtend::get("{$server}/admin/api.update/version"), true);
if (isset($result['code']) && $result['code'] > 0 && isset($result['data']) && is_array($result['data'])) {
$this->app->cache->set('moduleOnlineData', $result['data'], 1800);
return $result['data'];
} else {
return [];
}
}
/**
* 安装或更新模块
* @param string $name 模块名称
@ -55,7 +74,7 @@ class ModuleService extends Service
*/
public function install($name): array
{
$this->app->cache->set('module-online-data', []);
$this->app->cache->set('moduleOnlineData', []);
$data = InstallService::instance()->grenerateDifference(["app/{$name}"]);
if (empty($data)) {
return [0, '没有需要安装的文件', []];
@ -77,35 +96,17 @@ class ModuleService extends Service
}
}
/**
* 获取线上模块数据
* @return array
*/
public function online(): array
{
$data = $this->app->cache->get('module-online-data', []);
if (!empty($data)) return $data;
$server = InstallService::instance()->getServer();
$result = json_decode(HttpExtend::get("{$server}/admin/api.update/version"), true);
if (isset($result['code']) && $result['code'] > 0 && isset($result['data']) && is_array($result['data'])) {
$this->app->cache->set('module-online-data', $result['data'], 1800);
return $result['data'];
} else {
return [];
}
}
/**
* 获取系统模块信息
* @param array $data
* @return array
*/
public function getModules(): array
public function getModules(array $data = []): array
{
$data = [];
foreach (NodeService::instance()->getModules() as $name) {
if (is_array($ver = $this->getModuleVersion($name))) {
if (preg_match('|^\d{4}\.\d{2}\.\d{2}\.\d{2}$|', $ver['version'])) {
$data[$name] = $ver;
if (is_array($version = $this->getModuleVersion($name))) {
if (preg_match('|^\d{4}\.\d{2}\.\d{2}\.\d{2}$|', $version['version'])) {
$data[$name] = $version;
}
}
}