import React, {Component} from 'react'
|
import { is, fromJS } from 'immutable'
|
import { Modal, notification, Timeline, Icon, Button, Typography } from 'antd'
|
import moment from 'moment'
|
|
import Api from '@/api'
|
import options from '@/store/options.js'
|
import Utils from '@/utils/utils.js'
|
import './index.scss'
|
|
const { Paragraph } = Typography
|
|
class DataSource extends Component {
|
state = {
|
visible: false,
|
versions: null,
|
version: null,
|
error: false
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
verup = () => {
|
let _param = {
|
func: 's_get_sversions_sys',
|
}
|
|
Api.getSystemConfig(_param).then(result => {
|
if (!result.status) {
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
return
|
}
|
|
let edition_int = ''
|
if (options.sysType === 'SSO') {
|
edition_int = result.edition_int_sso
|
} else if (options.sysType === 'local' && window.GLOB.systemType !== 'production') {
|
edition_int = result.edition_int_local
|
} else {
|
if (result.edition_int_sso < result.edition_int_local) {
|
edition_int = result.edition_int_sso
|
} else {
|
edition_int = result.edition_int_local
|
}
|
}
|
if (edition_int === '') {
|
notification.warning({
|
top: 92,
|
message: '未查询到更新版本信息!',
|
duration: 5
|
})
|
return
|
}
|
|
let sysType = options.sysType.toLowerCase()
|
|
if (window.GLOB.systemType === 'production' || sysType !== 'local') {
|
sysType = ''
|
}
|
|
let param = {
|
func: 's_get_sversions_sys_epc',
|
edition_int: edition_int,
|
sys_type: sysType
|
}
|
|
Api.getCloudConfig(param).then(res => {
|
if (!res.status) {
|
notification.warning({
|
top: 92,
|
message: res.message,
|
duration: 5
|
})
|
return
|
} else if (!res.data || res.data.length === 0) {
|
notification.success({
|
top: 92,
|
message: '已经是最新的版本了。',
|
duration: 2
|
})
|
return
|
}
|
|
res.data = res.data.map((item, i) => {
|
item.status = i === 0 ? 'loading' : 'waiting'
|
item.index = i
|
return item
|
})
|
this.setState({versions: res.data, version: res.data[0], visible: true}, () => {
|
this.queryScript()
|
})
|
})
|
})
|
}
|
|
queryScript = () => {
|
const { version } = this.state
|
|
let _param = {
|
func: 's_get_sVersiondetail_Up',
|
VersionName: version.id,
|
BID: ''
|
}
|
|
Api.getCloudConfig(_param).then(res => {
|
delete res.message
|
delete res.status
|
|
res.func = 's_sVersion_Local_add'
|
res.VersionName = version.id
|
|
Api.getLocalConfig(res).then(result => {
|
if (!result.status) {
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
this.execError()
|
return
|
} else if (!result.vid) {
|
notification.warning({
|
top: 92,
|
message: '当前应用需要升级系统接口,请联系管理员!',
|
duration: 5
|
})
|
this.execError()
|
return
|
}
|
|
this.setState({version: {...version, BID: result.vid}})
|
|
let sql = `select ID,KeyWords,Remark,TypeName,Sort,SrcID from (select * from sVersionDetail_Local where BID='${result.vid}' and deleted=0 and status=0 ) tmptable order by Sort`
|
|
let param = {
|
func: 'sPC_Get_TableData',
|
obj_name: 'data',
|
arr_field: 'ID,KeyWords,Remark,TypeName,Sort,SrcID',
|
BID: '',
|
}
|
|
param.LText = Utils.formatOptions(sql)
|
param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
|
param.secretkey = Utils.encrypt(param.LText, param.timestamp)
|
param.DateCount = ''
|
|
Api.getLocalConfig(param).then(response => {
|
if (!response.status) {
|
notification.warning({
|
top: 92,
|
message: response.message,
|
duration: 5
|
})
|
this.execError()
|
return
|
} else if (!response.data || response.data.length === 0) {
|
this.next()
|
} else {
|
this.loopRequest(response.data)
|
}
|
}, () => { this.execError() })
|
}, () => { this.execError() })
|
}, () => { this.execError() })
|
}
|
|
loopRequest = (scripts) => {
|
const { version } = this.state
|
|
if (!version) return
|
|
let script = scripts.shift()
|
let param = {
|
func: 's_get_sVersionDetail_Ltext',
|
SrcID: script.SrcID,
|
ID: script.ID,
|
BID: version.BID
|
}
|
|
let ssoParam = {
|
func: 's_sDataDictb_TBBack',
|
SrcID: script.SrcID,
|
ID: script.ID,
|
BID: version.BID
|
}
|
|
let localParam = {
|
func: 's_sDataDictb_TBBack',
|
SrcID: script.SrcID,
|
ID: script.ID,
|
BID: version.BID
|
}
|
|
Api.getCloudConfig(param).then(res => {
|
delete res.message
|
delete res.status
|
|
localParam = {...localParam, ...res}
|
|
if (res.LTextOut) {
|
localParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
|
localParam.secretkey = Utils.encrypt(localParam.LTextOut, localParam.timestamp)
|
localParam.open_key = Utils.encryptOpenKey(localParam.secretkey, localParam.timestamp)
|
}
|
|
if (res.UpType === 'SSO' && window.GLOB.mainSystemApi) {
|
ssoParam = {...ssoParam, ...res}
|
delete ssoParam.UpType
|
|
ssoParam.rduri = window.GLOB.mainSystemApi
|
|
if (res.LTextOut) {
|
ssoParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
|
ssoParam.secretkey = Utils.encrypt(ssoParam.LTextOut, ssoParam.timestamp)
|
ssoParam.open_key = Utils.encryptOpenKey(ssoParam.secretkey, ssoParam.timestamp)
|
}
|
} else {
|
delete localParam.UpType
|
ssoParam = null
|
}
|
|
this.execLocal(localParam, ssoParam, scripts)
|
}, () => {
|
this.execError()
|
})
|
}
|
|
execSso = (ssoParam, scripts) => {
|
Api.getLocalConfig(ssoParam).then(res => {
|
if (!res.status) {
|
notification.warning({
|
top: 92,
|
message: res.message,
|
duration: 5
|
})
|
this.execWarning()
|
this.setState({}, () => {
|
if (scripts.length === 0) {
|
this.next()
|
} else {
|
this.loopRequest(scripts)
|
}
|
})
|
} else {
|
if (scripts.length === 0) {
|
this.next()
|
} else {
|
this.loopRequest(scripts)
|
}
|
}
|
}, () => {
|
this.execError()
|
})
|
}
|
|
execLocal = (localParam, ssoParam, scripts) => {
|
Api.getLocalConfig(localParam).then(res => {
|
if (!res.status) {
|
notification.warning({
|
top: 92,
|
message: res.message,
|
duration: 5
|
})
|
this.execWarning()
|
this.setState({}, () => {
|
if (scripts.length === 0) {
|
this.next()
|
} else {
|
this.loopRequest(scripts)
|
}
|
})
|
} else if (ssoParam) {
|
this.execSso(ssoParam, scripts)
|
} else {
|
if (scripts.length === 0) {
|
this.next()
|
} else {
|
this.loopRequest(scripts)
|
}
|
}
|
}, () => {
|
this.execError()
|
})
|
}
|
|
execWarning = () => {
|
const { version } = this.state
|
|
if (!version) return
|
|
this.setState({version: {...version, warning: true}})
|
}
|
|
execError = () => {
|
const { version } = this.state
|
|
if (!version) return
|
|
this.setState({error: true, versions: this.state.versions.map(item => {
|
if (version.id === item.id) {
|
item.status = 'error'
|
}
|
return item
|
})})
|
}
|
|
next = () => {
|
const { version, versions } = this.state
|
|
if (!version || !versions) return
|
|
let sql = `declare @Vid nvarchar(50) set @Vid='' select top 1 @Vid=id from sVersionDetail_Local where BID='${version.BID}' and Status =10 if @Vid='' begin delete sVersion_Local where id ='${version.BID}' delete sVersionDetail_Local where bid ='${version.BID}' end else begin update sVersion_Local set deleted=1,Modifydate=getdate(),ModifyUserID=@UserID@ where id ='${version.BID}' end`
|
|
let param = {
|
func: 'sPC_TableData_InUpDe',
|
exec_type: 'y',
|
ID: version.BID
|
}
|
|
param.LText = Utils.formatOptions(sql)
|
param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
|
param.secretkey = Utils.encrypt('', param.timestamp)
|
|
Api.getLocalConfig(param).then(response => {
|
if (!response.status) {
|
notification.warning({
|
top: 92,
|
message: response.message,
|
duration: 5
|
})
|
return
|
}
|
})
|
|
let nextver = versions[version.index + 1]
|
let _versions = versions.map(item => {
|
if (version.id === item.id) {
|
item.status = 'done'
|
item.warning = version.warning === true
|
}
|
return item
|
})
|
|
if (nextver) {
|
this.setState({
|
version: nextver,
|
versions: _versions
|
}, () => {
|
this.queryScript()
|
})
|
} else {
|
this.setState({
|
version: null,
|
versions: _versions
|
})
|
notification.success({
|
top: 92,
|
message: '升级已完成。',
|
duration: 3
|
})
|
}
|
}
|
|
stop = () => {
|
this.setState({
|
version: null,
|
versions: null,
|
visible: false,
|
error: false
|
})
|
}
|
|
skip = () => {
|
const { version, versions } = this.state
|
|
let nextver = versions[version.index + 1]
|
|
this.setState({
|
version: nextver,
|
error: false
|
}, () => {
|
this.queryScript()
|
})
|
}
|
|
reset = () => {
|
const { version } = this.state
|
|
this.setState({versions: this.state.versions.map(item => {
|
if (version.id === item.id) {
|
item.status = 'loading'
|
}
|
return item
|
}), error: false}, () => {
|
this.queryScript()
|
})
|
}
|
|
render () {
|
const { visible, versions, error, version } = this.state
|
|
return (
|
<>
|
<div style={{padding: '5px 25px'}} onClick={this.verup}>应用升级</div>
|
<Modal
|
wrapClassName="version-up-modal"
|
title="应用升级"
|
visible={visible}
|
width={800}
|
closable={false}
|
maskClosable={false}
|
footer={[
|
error && version && versions && versions.length > (version.index + 1) ? <Button key="skip" className="mk-orange" onClick={this.skip}>跳过</Button> : null,
|
error && version ? <Button key="reset" type="primary" onClick={this.reset}>重新执行</Button> : null,
|
<Button key="close" onClick={this.stop}>关闭</Button>,
|
]}
|
destroyOnClose
|
>
|
<Timeline>
|
{versions && versions.map(item => {
|
let icon = <Icon type="clock-circle-o" style={{ fontSize: '16px' }} />
|
if (item.status === 'loading') {
|
icon = <Icon type="sync" spin style={{ fontSize: '16px' }} />
|
} else if (item.status === 'done') {
|
if (item.warning) {
|
icon = <Icon type="warning" style={{ fontSize: '16px', color: 'orange' }}/>
|
} else {
|
icon = <Icon type="check-circle" style={{ fontSize: '16px', color: '#52c41a' }} />
|
}
|
}
|
return (
|
<Timeline.Item key={item.id} dot={icon}>{item.ProgramName}(<Paragraph style={{display: 'inline-block', marginBottom: '0px'}} copyable>{item.id}</Paragraph>)</Timeline.Item>
|
)
|
})}
|
</Timeline>
|
</Modal>
|
</>
|
)
|
}
|
}
|
|
export default DataSource
|