Skip to content

Commit 3f516cf

Browse files
committed
fix: build时间为用户所在时区的时间
1 parent f5748d0 commit 3f516cf

11 files changed

Lines changed: 40 additions & 17 deletions

File tree

chat2db-client/.umirc.prod.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { formatDate } from './src/utils/date';
21
import { defineConfig } from 'umi';
32
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
43
// const UMI_PublicPath = process.env.UMI_PublicPath || './static/front/';

chat2db-client/.umirc.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { formatDate } from './src/utils/date';
1+
import { transitionTimezoneTimestamp } from './src/utils/date';
22
import { defineConfig } from 'umi';
33
import { getLang } from '@/utils/localStorage';
44
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
@@ -50,8 +50,9 @@ export default defineConfig({
5050
],
5151
favicons: ['logo.ico'],
5252
define: {
53-
__ENV: process.env.UMI_ENV,
54-
__BUILD_TIME__: formatDate(new Date(), 'yyyyMMddhhmmss'),
53+
__ENV__: process.env.UMI_ENV,
54+
__BUILD_TIME__: transitionTimezoneTimestamp(new Date().getTime()),
5555
__APP_VERSION__: process.env.npm_config_app_version || '0.0.0',
56+
__APP_PORT__: process.env.npm_config_app_port
5657
},
5758
});

chat2db-client/.vscode/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,21 @@
2121
"Iconfont",
2222
"JDBC",
2323
"KEYPAIR",
24+
"Mddhhmmss",
2425
"SQLSERVER",
2526
"USERANDPASSWORD",
27+
"ahooks",
2628
"antd",
2729
"chatgpt",
2830
"datas",
2931
"datasource",
3032
"dbhub",
33+
"echarts",
34+
"favicons",
35+
"pgsql",
36+
"remaininguses",
37+
"sortablejs",
38+
"umijs",
3139
"uuidv",
3240
"wireframe"
3341
]

chat2db-client/src/blocks/Setting/About/index.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
.log {
2222
margin-top: 4px;
23-
color: var(--custom-primary-color);
23+
color: var(--color-primary);
2424
cursor: pointer;
2525

2626
&:hover {

chat2db-client/src/blocks/Setting/About/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { APP_NAME, GITHUB_URL } from '@/constants/appConfig';
33
import i18n from '@/i18n';
44
import React from 'react';
55
import styles from './index.less';
6+
import { formatDate, getUserTimezoneTimestamp } from '@/utils/date';
67

78
// 关于我们
89
export default function AboutUs() {
@@ -12,11 +13,11 @@ export default function AboutUs() {
1213
<div className={styles.brief}>
1314
<div className={styles.appName}>{APP_NAME}</div>
1415
<div className={styles.env}>
15-
{i18n('setting.text.currentEnv')}:{__ENV}
16+
{i18n('setting.text.currentEnv')}:{__ENV__}
1617
</div>
1718
<div className={styles.version}>
18-
{i18n('setting.text.currentVersion')}:v{'2.0.1' || __APP_VERSION__} build
19-
{__BUILD_TIME__}
19+
{i18n('setting.text.currentVersion')}:v{__APP_VERSION__} build
20+
{formatDate(getUserTimezoneTimestamp(__BUILD_TIME__), 'yyyyMMddhhmmss')}
2021
</div>
2122
<a target="blank" href={GITHUB_URL} className={styles.log}>
2223
{i18n('setting.text.viewingUpdateLogs')}

chat2db-client/src/components/Iconfont/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import classnames from 'classnames';
44
import styles from './index.less';
55

66
// 只有本地开发时使用cdn,发布线上时要下载iconfont到 /assets/font
7-
if (__ENV === 'local') {
7+
if (__ENV__ === 'local') {
88
let container = `
99
/* 在线链接服务仅供平台体验和调试使用,平台不承诺服务的稳定性,企业客户需下载字体包自行发布使用并做好备份。 */
1010
@font-face {

chat2db-client/src/components/TestVersion/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default memo<IProps>(function TestVersion(props) {
5151

5252
const openNotification = (responseText: any) => {
5353
try {
54-
const needToBeUpdated = isVersionHigher(responseText.version, '2.0.1');
54+
const needToBeUpdated = isVersionHigher(responseText.version, __APP_VERSION__);
5555
if (needToBeUpdated) {
5656
const key = `open${Date.now()}`;
5757
const btn = (

chat2db-client/src/layouts/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ declare global {
3434
}
3535
const __APP_VERSION__: string;
3636
const __BUILD_TIME__: string;
37-
const __ENV: string;
37+
const __ENV__: string;
38+
const __APP_PORT__: string;
3839
}
3940

4041
const initConfig = () => {
@@ -152,7 +153,7 @@ function AppContainer() {
152153
.testService()
153154
.then(() => {
154155
clearInterval(time);
155-
// if (__ENV === 'desktop') {
156+
// if (__ENV__ === 'desktop') {
156157
// window.location.href = 'http://127.0.0.1:10824/'
157158
// }
158159
setStartSchedule(2);

chat2db-client/src/service/base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const noNeedToastErrorCode = [ErrorCode.NEED_LOGGED_IN];
4242
const mockUrl = 'https://yapi.alibaba.com/mock/1000160';
4343

4444
// 桌面端的服务器地址
45-
const desktopServiceUrl = `http://127.0.0.1:${process.env.APP_PORT || '10824'}`;
45+
const desktopServiceUrl = `http://127.0.0.1:${__APP_PORT__ || '10824'}`;
4646

4747
// 非桌面端的服务器地址
4848
const prodServiceUrl = location.origin;
@@ -108,7 +108,7 @@ request.interceptors.request.use((url, options) => {
108108

109109
request.interceptors.response.use(async (response, options) => {
110110
const res = await response.clone().json();
111-
if (__ENV === 'desktop') {
111+
if (__ENV__ === 'desktop') {
112112
const DBHUB = response.headers.get('DBHUB') || '';
113113
if (DBHUB) {
114114
localStorage.setItem('DBHUB', DBHUB);

chat2db-client/src/utils/date.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export function formatDate(date:any, fmt = 'yyyy-MM-dd') {
1+
export function formatDate(date: any, fmt = 'yyyy-MM-dd') {
22
if (!date) {
33
return '';
44
}
@@ -8,7 +8,7 @@ export function formatDate(date:any, fmt = 'yyyy-MM-dd') {
88
if (!(date instanceof Date) || isNaN(date.getTime())) {
99
return '';
1010
}
11-
var o:any = {
11+
var o: any = {
1212
'M+': date.getMonth() + 1,
1313
'd+': date.getDate(),
1414
'h+': date.getHours(),
@@ -18,8 +18,20 @@ export function formatDate(date:any, fmt = 'yyyy-MM-dd') {
1818
S: date.getMilliseconds(),
1919
};
2020
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
21-
for (var k in o)
21+
for (var k in o)
2222
if (new RegExp('(' + k + ')').test(fmt))
2323
fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length));
2424
return fmt;
25+
}
26+
27+
// 带有时区的时间戳转换为0时区时间戳
28+
export function transitionTimezoneTimestamp(timestamp: number) {
29+
const timezoneOffset = new Date().getTimezoneOffset() * 60 * 1000
30+
return timestamp + timezoneOffset
31+
}
32+
33+
// 通过0时区的时间戳计算出用户的时间戳
34+
export function getUserTimezoneTimestamp(timestamp: number | string) {
35+
const timezoneOffset = new Date().getTimezoneOffset() * 60 * 1000
36+
return +timestamp - timezoneOffset
2537
}

0 commit comments

Comments
 (0)