1+ import React , { useEffect , useMemo } from 'react' ;
2+ import styles from './index.less' ;
3+ // import i18n from '@/i18n';
14import BrandLogo from '@/components/BrandLogo' ;
2- import { APP_NAME , GITHUB_URL } from '@/constants/appConfig' ;
5+ import { APP_NAME , WEBSITE_DOC } from '@/constants/appConfig' ;
6+ // import { formatDate, getUserTimezoneTimestamp } from '@/utils/date';
7+ import { Button , Radio , Space } from 'antd' ;
8+ import configService from '@/service/config' ;
9+ import { DownloadOutlined , RedoOutlined } from '@ant-design/icons' ;
10+ import { IUpdateDetectionData } from '../index' ;
11+ import { IUpdateDetectionRef , UpdatedStatusEnum } from '../UpdateDetection' ;
312import i18n from '@/i18n' ;
4- import React from 'react' ;
5- import styles from './index.less' ;
6- import { formatDate , getUserTimezoneTimestamp } from '@/utils/date' ;
13+
14+ interface IProps {
15+ updateDetectionData : IUpdateDetectionData | null ;
16+ updateDetectionRef : React . MutableRefObject < IUpdateDetectionRef > | null ;
17+ }
718
819// 关于我们
9- export default function AboutUs ( ) {
20+ export default function AboutUs ( props : IProps ) {
21+ const { updateDetectionData, updateDetectionRef } = props ;
22+ const [ updateRule , setUpdateRule ] = React . useState < 'manual' | 'auto' > ( updateDetectionData ?. type || 'manual' ) ;
23+
24+ const onChangeUpdateRul = ( e ) => {
25+ configService . setAppUpdateType ( e . target . value ) . then ( ( ) => {
26+ setUpdateRule ( e . target . value ) ;
27+ } ) ;
28+ } ;
29+
30+ useEffect ( ( ) => {
31+ setUpdateRule ( updateDetectionData ?. type || 'manual' ) ;
32+ } , [ updateDetectionData ?. type ] )
33+
34+ const jumpDoc = ( ) => {
35+ window . open ( WEBSITE_DOC , '_blank' ) ;
36+ } ;
37+
38+ const updateButton = useMemo ( ( ) => {
39+ if ( ! updateDetectionData ?. needUpdate ) {
40+ return false ;
41+ }
42+ switch ( updateDetectionData ?. updatedStatusEnum ) {
43+ case UpdatedStatusEnum . NOT_UPDATED :
44+ return (
45+ < Button
46+ onClick = { ( ) => {
47+ updateDetectionRef ?. current ?. openDownload ( ) ;
48+ } }
49+ icon = { < DownloadOutlined /> }
50+ type = "primary"
51+ >
52+ { i18n ( 'setting.button.startDownloading' ) }
53+ </ Button >
54+ ) ;
55+ case UpdatedStatusEnum . UPDATING :
56+ return (
57+ < Button type = "primary" loading >
58+ { i18n ( 'setting.button.beDownloading' ) }
59+ </ Button >
60+ ) ;
61+ // 超时后端如何处理 TODO:
62+ case UpdatedStatusEnum . TIMEOUT :
63+ return (
64+ < Button
65+ onClick = { ( ) => {
66+ updateDetectionRef ?. current ?. openDownload ( ) ;
67+ } }
68+ icon = { < DownloadOutlined /> }
69+ type = "primary"
70+ loading
71+ >
72+ { i18n ( 'setting.button.redownload' ) }
73+ </ Button >
74+ ) ;
75+ // case UpdatedStatusEnum.UPDATED:
76+ // return (
77+ // <Button icon={<RedoOutlined />} type="primary">
78+ // {i18n('setting.button.restart')}
79+ // </Button>
80+ // );
81+ default :
82+ return false ;
83+ }
84+ } , [ updateDetectionData ] ) ;
85+
1086 return (
1187 < div className = { styles . aboutUs } >
12- < BrandLogo size = { 60 } className = { styles . brandLogo } />
13- < div className = { styles . brief } >
88+ < div className = { styles . versionsInfo } >
89+ < BrandLogo size = { 98 } className = { styles . brandLogo } />
90+ < div >
91+ < div className = { styles . currentVersion } >
92+ < span className = { styles . appName } > { APP_NAME } </ span >
93+ < span > { __APP_VERSION__ } </ span >
94+ </ div >
95+ < div className = { styles . newVersion } >
96+ { updateDetectionData ?. needUpdate ? (
97+ UpdatedStatusEnum . UPDATED === updateDetectionData ?. updatedStatusEnum ?
98+ < span > { i18n ( 'setting.text.RestartingInstall' ) } </ span >
99+ :
100+ < span > { i18n ( 'setting.text.discoverNewVersion' , updateDetectionData ?. version ) } </ span >
101+ ) : (
102+ < span > { i18n ( 'setting.text.isLatestVersion' ) } </ span >
103+ ) }
104+ </ div >
105+ { updateDetectionData ?. desktop && (
106+ < div className = { styles . updateButton } >
107+ { updateButton }
108+ < Button onClick = { jumpDoc } > { i18n ( 'setting.button.changeLog' ) } </ Button >
109+ </ div >
110+ ) }
111+ </ div >
112+ </ div >
113+ < div className = { styles . updateRule } >
114+ < div className = { styles . updateRuleTitle } > { i18n ( 'setting.title.updateRule' ) } </ div >
115+ < Radio . Group className = { styles . updateRuleGroup } onChange = { onChangeUpdateRul } value = { updateRule } >
116+ < Space direction = "vertical" >
117+ < Radio className = { styles . updateRuleRadio } value = "auto" >
118+ { i18n ( 'setting.text.autoUpdate' ) }
119+ </ Radio >
120+ < Radio className = { styles . updateRuleRadio } value = "manual" >
121+ { i18n ( 'setting.text.manualUpdate' ) }
122+ </ Radio >
123+ </ Space >
124+ </ Radio . Group >
125+ </ div >
126+ { /* <div className={styles.brief}>
14127 <div className={styles.appName}>{APP_NAME}</div>
15128 <div className={styles.env}>
16129 {i18n('setting.text.currentEnv')}:{__ENV__}
@@ -22,7 +135,7 @@ export default function AboutUs() {
22135 <a target="blank" href={GITHUB_URL} className={styles.log}>
23136 {i18n('setting.text.viewingUpdateLogs')}
24137 </a>
25- </ div >
138+ </div> */ }
26139 </ div >
27140 ) ;
28141}
0 commit comments