From 18b38e60fc156335fb9811b7dc6022851afb42fe Mon Sep 17 00:00:00 2001 From: OhYee Date: Thu, 4 Feb 2021 01:43:47 +0800 Subject: [PATCH] version page --- next.config.js | 1 + pages/version.tsx | 35 +++++++++++++++++++++++++++++++++++ utils/api.ts | 6 ++++++ utils/global.ts | 7 +++++++ 4 files changed, 49 insertions(+) create mode 100644 pages/version.tsx diff --git a/next.config.js b/next.config.js index 33f8f0a..ced1f70 100644 --- a/next.config.js +++ b/next.config.js @@ -6,5 +6,6 @@ module.exports = { }, publicRuntimeConfig: { //这里的配置既可以服务端获取到,也可以在浏览器端获取到 + version: Date.now(), }, }; diff --git a/pages/version.tsx b/pages/version.tsx new file mode 100644 index 0000000..32cd4fc --- /dev/null +++ b/pages/version.tsx @@ -0,0 +1,35 @@ +import React, { ComponentProps } from 'react'; + +import Head from 'next/head'; +import getConfig from 'next/config'; + +import Card from '@/components/card'; +import { Flex } from '@/components/container'; + +import { Context } from '@/utils/global'; + +class Version extends React.Component<{}, { version: string }> { + render() { + return ( + + {(context) => ( + + + {`版本信息|${context.blog_name}`} + + +

+ 前端部署版本 {context.front_version} +

+

+ 后端编译版本 {context.back_version} +

+
+
+ )} +
+ ); + } +} + +export default Version; diff --git a/utils/api.ts b/utils/api.ts index 996f657..627164d 100644 --- a/utils/api.ts +++ b/utils/api.ts @@ -473,3 +473,9 @@ export const qiniu_rename_image = async ( ) => { return await request('get', '/api/qiniu/image/rename', { bucket, key, new_key }, callback); }; + +export const version = async ( + callback?: RequestCallback<{version:string}>, +) => { + return await request('get', '/api/version', {}, callback); +}; \ No newline at end of file diff --git a/utils/global.ts b/utils/global.ts index 762e2f1..9762775 100644 --- a/utils/global.ts +++ b/utils/global.ts @@ -1,4 +1,7 @@ import React from 'react'; +import getConfig from 'next/config'; + +import { formatDate } from './time'; export const defaultContext: GlobalProps = { callback: () => {}, @@ -22,6 +25,8 @@ export const defaultContext: GlobalProps = { ad_show: '', ad_inner: '', ad_text: '', + front_version: formatDate(getConfig().publicRuntimeConfig.version), + back_version: 'UNKNOWN', user: { id: '000000000000000000000000', username: '', @@ -67,6 +72,8 @@ export declare interface GlobalProps { ad_show: string; ad_inner: string; ad_text: string; + front_version: string; + back_version: string; } export function getTimeTheme() {