perf: 新增查看更新日志

This commit is contained in:
kuaifan 2024-10-26 10:35:52 +08:00
parent d6a7c19cbf
commit 244991e8e8
4 changed files with 98 additions and 19 deletions

View File

@ -1059,24 +1059,38 @@ class SystemController extends AbstractController
* @apiGroup system * @apiGroup system
* @apiName get__updatelog * @apiName get__updatelog
* *
* @apiParam {Number} [take] 获取数量10-100
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误 * @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述) * @apiSuccess {String} msg 返回信息(错误描述)
* @apiSuccess {Object} data 返回数据 * @apiSuccess {Object} data 返回数据
*/ */
public function get__updatelog() public function get__updatelog()
{ {
$take = min(100, max(10, intval(Request::input('take'))));
$logPath = base_path('CHANGELOG.md'); $logPath = base_path('CHANGELOG.md');
$logContent = "";
$logVersion = ""; $logVersion = "";
$logContent = "";
$logResults = [];
if (file_exists($logPath)) { if (file_exists($logPath)) {
$logContent = file_get_contents($logPath); $content = file_get_contents($logPath);
preg_match("/## \[(.*?)\]/", $logContent, $matchs); $sections = preg_split("/## \[(.*?)\]/", $content, -1, PREG_SPLIT_DELIM_CAPTURE);
if ($matchs) { for ($i = 1; $i < count($sections) && count($logResults) < $take; $i += 2) {
$logVersion = $matchs[1] === "Unreleased" ? $matchs[1] : "v{$matchs[1]}"; $logResults[] = [
'title' => $sections[$i],
'content' => $sections[$i + 1]
];
} }
} }
if ($logResults) {
$logVersion = $logResults[0]['title'];
$logContent = implode("\n", array_map(function($item) {
return "## " . $item['title'] . $item['content'];
}, $logResults));
}
return Base::retSuccess('success', [ return Base::retSuccess('success', [
'updateLog' => $logContent ?: false, 'logVersion' => $logVersion,
'updateLog' => $logContent,
]); ]);
} }

View File

@ -16,17 +16,15 @@
v-for="(item, key) in menu" v-for="(item, key) in menu"
:key="key" :key="key"
:class="classNameRoute(item.path, item.divided)" :class="classNameRoute(item.path, item.divided)"
@click="toggleRoute(item.path)">{{$L(item.name)}}</li> @click="toggleRoute(item.path)">
<li <template v-if="item.path === 'version'">
v-if="!!clientNewVersion" <AutoTip disabled>{{$L(item.name)}}</AutoTip>
class="flex" <Badge v-if="!!clientNewVersion" :text="clientNewVersion"/>
:class="classNameRoute('version', true)" </template>
@click="toggleRoute('version')"> <template v-else-if="item.path === 'version-show'">
<AutoTip disabled>{{$L('版本')}}: {{version}}</AutoTip> <AutoTip>{{$L(item.name)}}: {{version}}</AutoTip>
<Badge :text="clientNewVersion"/> </template>
</li> <span v-else>{{$L(item.name)}}</span>
<li v-else class="version divided" @click="onVersion">
<AutoTip>{{$L('版本')}}: {{version}}</AutoTip>
</li> </li>
</ul> </ul>
</div> </div>
@ -101,6 +99,8 @@ export default {
]) ])
} }
menu.push(...[ menu.push(...[
{path: 'version', name: '更新日志', divided: true},
{path: 'version-show', name: '版本'},
{path: 'clearCache', name: '清除缓存', divided: true}, {path: 'clearCache', name: '清除缓存', divided: true},
{path: 'logout', name: '退出登录'}, {path: 'logout', name: '退出登录'},
]) ])
@ -163,8 +163,8 @@ export default {
}); });
break; break;
case 'version': case 'version-show':
Store.set('updateNotification', null); this.onVersion();
break; break;
case 'privacy': case 'privacy':
@ -176,6 +176,10 @@ export default {
break; break;
default: default:
if (path === 'version' && !!this.clientNewVersion) {
Store.set('updateNotification', null);
return
}
this.goForward({name: 'manage-setting-' + path}); this.goForward({name: 'manage-setting-' + path});
break; break;
} }
@ -201,6 +205,7 @@ export default {
classNameRoute(path, divided) { classNameRoute(path, divided) {
return { return {
"flex": true,
"active": this.windowLandscape && this.routeName === `manage-setting-${path}`, "active": this.windowLandscape && this.routeName === `manage-setting-${path}`,
"divided": !!divided "divided": !!divided
}; };

View File

@ -0,0 +1,55 @@
<template>
<div class="setting-item submit">
<div class="version-box">
<div v-if="loadIng" class="version-load">{{$L('加载中...')}}</div>
<VMPreview v-else :value="updateLog"/>
</div>
</div>
</template>
<style lang="scss">
.version-box {
overflow: auto;
padding: 24px 34px;
.version-load {
font-size: 16px;
}
.vuepress-markdown-body {
padding: 0 !important;
color: inherit;
}
}
</style>
<script>
import VMPreview from "../../../components/VMEditor/preview.vue";
export default {
components: {VMPreview},
data() {
return {
loadIng: 0,
updateLog: '',
}
},
mounted() {
this.getLog();
},
methods: {
getLog() {
this.loadIng++;
this.$store.dispatch("call", {
url: 'system/get/updatelog',
data: {
take: 20
}
}).then(({data}) => {
this.updateLog = data.updateLog;
}).catch(({msg}) => {
$A.messageError(msg);
}).finally(_ => {
this.loadIng--;
});
},
}
}
</script>

View File

@ -94,6 +94,11 @@ export default [
path: 'system', path: 'system',
component: () => import('./pages/manage/setting/system.vue'), component: () => import('./pages/manage/setting/system.vue'),
}, },
{
name: 'manage-setting-version',
path: 'version',
component: () => import('./pages/manage/setting/version.vue'),
},
{ {
name: 'manage-setting-delete', name: 'manage-setting-delete',
path: 'delete', path: 'delete',