关于增加版本信息展示

This commit is contained in:
whyour 2022-11-05 11:01:58 +08:00
parent 90af5801ee
commit 23bda39812
5 changed files with 90 additions and 17 deletions

View File

@ -7,6 +7,8 @@ import SystemService from '../services/system';
import { celebrate, Joi } from 'celebrate';
import UserService from '../services/user';
import { EnvModel } from '../data/env';
import { promiseExec } from '../config/util';
const route = Router();
export default (app: Router) => {
@ -22,6 +24,15 @@ export default (app: Router) => {
const currentVersionFile = fs.readFileSync(config.versionFile, 'utf8');
const version = currentVersionFile.match(versionRegx)![1];
const lastCommitTime = (
await promiseExec('git show -s --format=%ai')
).replace('\n', '');
const lastCommitId = (
await promiseExec('git rev-parse --short HEAD')
).replace('\n', '');
const branch = (
await promiseExec('git symbolic-ref --short HEAD')
).replace('\n', '');
let isInitialized = true;
if (
@ -37,6 +48,9 @@ export default (app: Router) => {
data: {
isInitialized,
version,
lastCommitTime,
lastCommitId,
branch,
},
});
} catch (e) {

View File

@ -15,7 +15,18 @@ import './index.less';
import vhCheck from 'vh-check';
import { version, changeLogLink, changeLog } from '../version';
import { useCtx, useTheme } from '@/utils/hooks';
import { message, Badge, Modal, Avatar, Dropdown, Menu, Image } from 'antd';
import {
message,
Badge,
Modal,
Avatar,
Dropdown,
Menu,
Image,
Popover,
Descriptions,
Tooltip,
} from 'antd';
// @ts-ignore
import SockJS from 'sockjs-client';
import * as Sentry from '@sentry/react';
@ -32,6 +43,15 @@ export interface SharedContext {
reloadUser: (needLoading?: boolean) => void;
reloadTheme: () => void;
socketMessage: any;
systemInfo: TSystemInfo;
}
interface TSystemInfo {
branch: 'develop' | 'master';
isInitialized: boolean;
lastCommitId: string;
lastCommitTime: string;
version: string;
}
export default function () {
@ -40,7 +60,7 @@ export default function () {
const { theme, reloadTheme } = useTheme();
const [user, setUser] = useState<any>({});
const [loading, setLoading] = useState<boolean>(true);
const [systemInfo, setSystemInfo] = useState<{ isInitialized: boolean }>();
const [systemInfo, setSystemInfo] = useState<TSystemInfo>();
const ws = useRef<any>(null);
const [socketMessage, setSocketMessage] = useState<any>();
const [collapsed, setCollapsed] = useState(false);
@ -256,17 +276,23 @@ export default function () {
e.stopPropagation();
}}
>
<span
style={{
fontSize: isFirefox ? 9 : 12,
color: '#666',
marginLeft: 2,
zoom: isSafari ? 0.66 : 0.8,
letterSpacing: isQQBrowser ? -2 : 0,
}}
<Tooltip
title={systemInfo?.branch === 'develop' ? '开发版' : '正式版'}
>
v{version}
</span>
<Badge size="small" dot={systemInfo?.branch === 'develop'}>
<span
style={{
fontSize: isFirefox ? 9 : 12,
color: '#666',
marginLeft: 2,
zoom: isSafari ? 0.66 : 0.8,
letterSpacing: isQQBrowser ? -2 : 0,
}}
>
v{version}
</span>
</Badge>
</Tooltip>
</a>
</>
}
@ -342,6 +368,7 @@ export default function () {
reloadUser,
reloadTheme,
socketMessage,
systemInfo,
}}
/>
</ProLayout>

View File

@ -1,10 +1,17 @@
import React, { useEffect, useState } from 'react';
import { Typography, Input, Form, Button, message } from 'antd';
import { Typography, Input, Form, Button, message, Descriptions } from 'antd';
import styles from './index.less';
import { SharedContext } from '@/layouts';
import dayjs from 'dayjs';
const { Link } = Typography;
const About = () => {
enum TVersion {
'develop' = '开发版',
'master' = '正式版',
}
const About = ({ systemInfo }: { systemInfo: SharedContext['systemInfo'] }) => {
return (
<div className={styles.container}>
<img
@ -19,6 +26,17 @@ const About = () => {
task management panel that supports typescript, javaScript, python3,
and shell.
</span>
<Descriptions>
<Descriptions.Item label="版本" span={3}>
{TVersion[systemInfo.branch]} v{systemInfo.version}
</Descriptions.Item>
<Descriptions.Item label="更新时间" span={3}>
{dayjs(systemInfo.lastCommitTime).format('YYYY-MM-DD HH:mm:ss')}
</Descriptions.Item>
<Descriptions.Item label="更新ID" span={3}>
{systemInfo.lastCommitId}
</Descriptions.Item>
</Descriptions>
<div>
<Link
href="https://github.com/whyour/qinglong"

View File

@ -18,5 +18,12 @@
.desc {
margin-bottom: 10px;
}
:global {
.ant-descriptions-row > th,
.ant-descriptions-row > td {
padding-bottom: 10px;
}
}
}
}

View File

@ -40,8 +40,15 @@ const optionsWithDisabled = [
];
const Setting = () => {
const { headerStyle, isPhone, user, reloadUser, reloadTheme, socketMessage } =
useOutletContext<SharedContext>();
const {
headerStyle,
isPhone,
user,
reloadUser,
reloadTheme,
socketMessage,
systemInfo,
} = useOutletContext<SharedContext>();
const columns = [
{
title: '名称',
@ -411,7 +418,7 @@ const Setting = () => {
{
key: 'about',
label: '关于',
children: <About />,
children: <About systemInfo={systemInfo} />,
},
]}
></Tabs>