1- import BrandLogo from '@/components/BrandLogo' ;
2- import { APP_NAME , GITHUB_URL , WEBSITE_DOC } from '@/constants/appConfig' ;
3- import i18n from '@/i18n' ;
4- import React from 'react' ;
1+ import React , { useEffect , useMemo } from 'react' ;
52import styles from './index.less' ;
3+ // import i18n from '@/i18n';
4+ import BrandLogo from '@/components/BrandLogo' ;
5+ import { APP_NAME , WEBSITE_DOC } from '@/constants/appConfig' ;
66// import { formatDate, getUserTimezoneTimestamp } from '@/utils/date';
77import { Button , Radio , Space } from 'antd' ;
8+ import configService from '@/service/config' ;
9+ import { DownloadOutlined } from '@ant-design/icons' ;
10+ import { IUpdateDetectionData } from '../index' ;
11+ import { IUpdateDetectionRef , UpdatedStatusEnum } from '../UpdateDetection' ;
12+
13+ interface IProps {
14+ updateDetectionData : IUpdateDetectionData | null ;
15+ updateDetectionRef : React . MutableRefObject < IUpdateDetectionRef > | null ;
16+ }
817
918// 关于我们
10- export default function AboutUs ( ) {
11- const [ updateRule , setUpdateRule ] = React . useState ( 1 ) ; // 1:自动下载并安装更新 2:仅在新版本发布时提醒我
12- const onChangeUpdateRul = ( ) => {
13- setUpdateRule ( updateRule === 1 ? 2 : 1 ) ;
19+ export default function AboutUs ( props : IProps ) {
20+ const { updateDetectionData, updateDetectionRef } = props ;
21+ const [ updateRule , setUpdateRule ] = React . useState < 'manual' | 'auto' > ( updateDetectionData ?. type || 'manual' ) ;
22+
23+ const onChangeUpdateRul = ( e ) => {
24+ configService . setAppUpdateType ( e . target . value ) . then ( ( ) => {
25+ setUpdateRule ( e . target . value ) ;
26+ } ) ;
1427 } ;
1528
29+ useEffect ( ( ) => {
30+ setUpdateRule ( updateDetectionData ?. type || 'manual' ) ;
31+ } , [ updateDetectionData ?. type ] )
32+
1633 const jumpDoc = ( ) => {
1734 window . open ( WEBSITE_DOC , '_blank' ) ;
1835 } ;
1936
37+ const updateButton = useMemo ( ( ) => {
38+ if ( ! updateDetectionData ?. needUpdate ) {
39+ return false ;
40+ }
41+ switch ( updateDetectionData ?. updatedStatusEnum ) {
42+ case UpdatedStatusEnum . NOT_UPDATED :
43+ return (
44+ < Button
45+ onClick = { ( ) => {
46+ updateDetectionRef ?. current ?. openDownload ( ) ;
47+ } }
48+ icon = { < DownloadOutlined /> }
49+ type = "primary"
50+ >
51+ 开始下载
52+ </ Button >
53+ ) ;
54+ case UpdatedStatusEnum . UPDATING :
55+ return (
56+ < Button type = "primary" loading >
57+ 下载中
58+ </ Button >
59+ ) ;
60+ // 超时后端如何处理 TODO:
61+ case UpdatedStatusEnum . TIMEOUT :
62+ return (
63+ < Button
64+ onClick = { ( ) => {
65+ updateDetectionRef ?. current ?. openDownload ( ) ;
66+ } }
67+ icon = { < DownloadOutlined /> }
68+ type = "primary"
69+ loading
70+ >
71+ 超时重新下载
72+ </ Button >
73+ ) ;
74+ case UpdatedStatusEnum . UPDATED :
75+ return (
76+ < Button icon = { < DownloadOutlined /> } type = "primary" >
77+ 立即重启
78+ </ Button >
79+ ) ;
80+ default :
81+ return false ;
82+ }
83+ } , [ updateDetectionData ] ) ;
84+
2085 return (
2186 < div className = { styles . aboutUs } >
2287 < div className = { styles . versionsInfo } >
@@ -26,21 +91,29 @@ export default function AboutUs() {
2691 < span className = { styles . appName } > { APP_NAME } </ span >
2792 < span > { __APP_VERSION__ } </ span >
2893 </ div >
29- < div className = { styles . newVersion } > 发现新版本10.0.0</ div >
30- < div className = { styles . updateButton } >
31- < Button type = "primary" > 立即更新</ Button >
32- < Button onClick = { jumpDoc } > 查看更新日志</ Button >
94+ < div className = { styles . newVersion } >
95+ { updateDetectionData ?. needUpdate ? (
96+ < span > 发现新版本{ updateDetectionData ?. version } </ span >
97+ ) : (
98+ < span > 已是最新版本</ span >
99+ ) }
33100 </ div >
101+ { updateDetectionData ?. desktop && (
102+ < div className = { styles . updateButton } >
103+ { updateButton }
104+ < Button onClick = { jumpDoc } > 查看更新日志</ Button >
105+ </ div >
106+ ) }
34107 </ div >
35108 </ div >
36109 < div className = { styles . updateRule } >
37110 < div className = { styles . updateRuleTitle } > 软件更新</ div >
38111 < Radio . Group className = { styles . updateRuleGroup } onChange = { onChangeUpdateRul } value = { updateRule } >
39112 < Space direction = "vertical" >
40- < Radio className = { styles . updateRuleRadio } value = { 1 } >
113+ < Radio className = { styles . updateRuleRadio } value = "auto" >
41114 新版自动下载并安装更新
42115 </ Radio >
43- < Radio className = { styles . updateRuleRadio } value = { 2 } >
116+ < Radio className = { styles . updateRuleRadio } value = "manual" >
44117 仅在新版本发布时提醒我
45118 </ Radio >
46119 </ Space >
0 commit comments