import React, {Component} from 'react'
|
// import { fromJS } from 'immutable'
|
import { Spin, notification, Button, Table, Modal } from 'antd'
|
|
import Api from '@/api'
|
import Utils from '@/utils/utils.js'
|
import asyncComponent from '@/utils/asyncComponent'
|
import './index.scss'
|
|
const Header = asyncComponent(() => import('@/mob/header'))
|
const MutilForm = asyncComponent(() => import('./mutilform'))
|
|
class AppManage extends Component {
|
state = {
|
loading: false,
|
applist: [],
|
appsublist: [],
|
columns: [
|
{ title: '应用名称', dataIndex: 'remark', key: 'remark', align: 'center' },
|
{ title: '应用参数', dataIndex: 'kei_no', key: 'kei_no', align: 'center' },
|
{
|
title: 'Action',
|
key: 'action',
|
align: 'center',
|
render: (text, record) => (<Button type="link" onClick={() => this.deleteApp(record)} style={{color: '#ff4d4f'}}>删除</Button>),
|
},
|
],
|
subcolumns: [
|
{
|
title: '应用类型', dataIndex: 'typename', key: 'typename', align: 'center'
|
},
|
{
|
title: '语言', dataIndex: 'lang', key: 'lang', align: 'center',
|
render: (text, record) => text === 'en-US' ? '英文' : '中文'
|
},
|
{
|
title: '登录', dataIndex: 'login_types', key: 'login_types', align: 'center',
|
render: (text, record) => text === 'false' ? '不需要' : '需要'
|
},
|
{
|
title: '权限管理', dataIndex: 'role_type', key: 'role_type', align: 'center',
|
render: (text, record) => text === 'false' ? '不需要' : '需要'
|
},
|
{
|
title: '短连接', dataIndex: 'link_type', key: 'link_type', align: 'center',
|
render: (text, record) => text === 'false' ? '不启用' : '启用'
|
},
|
{
|
title: 'Action',
|
key: 'action',
|
align: 'center',
|
render: (text, record) => (
|
<div>
|
<Button type="link" onClick={() => this.deleteSubApp(record)} style={{color: '#ff4d4f'}}>删除</Button>
|
<Button type="link" onClick={() => this.jumpMenu(record)}>编辑应用</Button>
|
</div>
|
)
|
},
|
],
|
selectApp: null,
|
selectSubApp: null,
|
selectedRowKeys: [],
|
selectedSubRowKeys: [],
|
}
|
|
UNSAFE_componentWillMount() {
|
document.body.className = ''
|
this.getAppList()
|
}
|
|
/**
|
* @description 组件销毁,清除state更新
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
}
|
|
getAppList = () => {
|
let param = {
|
func: 's_get_kei'
|
}
|
|
Api.getCloudConfig(param).then(result => {
|
if (result.status) {
|
this.setState({
|
loading: false,
|
applist: result.data.map(item => {
|
item.sublist = item.data_detail || []
|
item.sublist = item.sublist.map(cell => {
|
cell.ID = cell.d_id
|
return cell
|
})
|
|
return item
|
})
|
})
|
|
} else {
|
this.setState({
|
loading: false
|
})
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
}
|
})
|
}
|
|
deleteApp = (record) => {
|
console.log(record)
|
}
|
|
deleteSubApp = (record) => {
|
console.log(record)
|
}
|
|
jumpMenu = (card) => {
|
console.log(card)
|
// let _type = 'mob'
|
// if (card.type === 'pc') {
|
// _type = 'pc'
|
// }
|
// this.props.history.replace(`/mobdesign/${card.uuid}/${_type}/${card.keiNo}/${card.name}`)
|
}
|
|
/**
|
*
|
*/
|
onSelectChange = selectedRowKeys => {
|
const { applist } = this.state
|
let selectApp = applist.filter(item => item.ID === selectedRowKeys[0])[0]
|
|
this.setState({ selectedRowKeys, selectApp })
|
}
|
|
/**
|
*
|
*/
|
onSubChange = selectedSubRowKeys => {
|
this.setState({ selectedSubRowKeys })
|
}
|
|
/**
|
* @description 点击整行,触发切换, 判断是否可选,单选或多选,进行对应操作
|
*/
|
changeRow = (record) => {
|
this.setState({ selectedRowKeys: [record.ID], selectApp: record, appsublist: record.sublist || [] })
|
}
|
|
/**
|
* @description 点击整行,触发切换, 判断是否可选,单选或多选,进行对应操作
|
*/
|
changeSubRow = (record) => {
|
this.setState({ selectedSubRowKeys: [record.ID], selectSubApp: record })
|
}
|
|
trigerApp = (type) => {
|
if ((type === 'appedit' && !this.state.selectApp) || (type === 'subappedit' && !this.state.selectSubApp)) {
|
notification.warning({
|
top: 92,
|
message: '请选择需要编辑的应用!',
|
duration: 5
|
})
|
return
|
}
|
|
this.setState({
|
visible: type
|
})
|
}
|
|
|
submitCard = () => {
|
const { card } = this.state
|
|
this.mobcardRef.handleConfirm().then(res => {
|
this.setState({
|
confirmloading: true
|
})
|
|
let param = {
|
func: 's_kei_addupt',
|
ID: card ? card.uuid : Utils.getuuid(),
|
TypeName: res.type,
|
remark: res.name,
|
kei_no: res.keiNo
|
}
|
|
Api.getCloudConfig(param).then(result => {
|
if (result.status) {
|
notification.success({
|
top: 92,
|
message: card ? '修改成功!' : '添加成功!',
|
duration: 5
|
})
|
|
this.setState({
|
confirmloading: false,
|
visible: false,
|
loading: true
|
})
|
this.getMobCards()
|
} else {
|
this.setState({
|
confirmloading: false
|
})
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
}
|
}, () => {
|
this.setState({
|
confirmloading: false
|
})
|
})
|
})
|
}
|
|
render () {
|
const { loading, visible, columns, applist, appsublist, selectedRowKeys, selectedSubRowKeys, subcolumns, selectApp, selectSubApp } = this.state
|
|
return (
|
<div className="mk-app-manage">
|
<Header view="manage" />
|
{loading ?
|
<div className="loading-mask">
|
<div className="ant-spin-blur"></div>
|
<Spin />
|
</div> : null
|
}
|
<div className="app-table">
|
<div className="app-action">
|
<Button className="mk-green" onClick={() => this.trigerApp('appplus')}>添加</Button>
|
<Button className="mk-purple" onClick={() => this.trigerApp('appedit')}>修改</Button>
|
</div>
|
<Table
|
rowKey="ID"
|
columns={columns}
|
dataSource={applist}
|
pagination={false}
|
rowSelection={{ type: 'radio', selectedRowKeys, onChange: this.onSelectChange }}
|
onRow={(record) => ({ onClick: () => {this.changeRow(record)} })}
|
/>
|
</div>
|
<div className="app-table">
|
<div className="sub-app-title"><span>子应用</span></div>
|
<div className="app-action">
|
<Button className="mk-green" onClick={() => this.trigerApp('subappplus')}>添加</Button>
|
<Button className="mk-purple" onClick={() => this.trigerApp('subappedit')}>修改</Button>
|
</div>
|
<Table
|
rowKey="ID"
|
columns={subcolumns}
|
dataSource={appsublist}
|
pagination={false}
|
rowSelection={{ type: 'radio', selectedRowKeys: selectedSubRowKeys, onChange: this.onSubChange }}
|
onRow={(record) => ({ onClick: () => {this.changeSubRow(record)} })}
|
/>
|
</div>
|
<Modal
|
// className="mob-card-modal"
|
title={'编辑应用'}
|
width={'600px'}
|
maskClosable={false}
|
visible={!!visible}
|
onCancel={() => this.setState({visible: ''})}
|
confirmLoading={this.state.confirmloading}
|
onOk={this.submitCard}
|
cancelText="取消"
|
okText="确定"
|
destroyOnClose
|
>
|
<MutilForm card={visible === 'appedit' ? selectApp : (visible === 'subappedit' ? selectSubApp : '')} wrappedComponentRef={(inst) => this.mobcardRef = inst} inputSubmit={this.submitCard} />
|
</Modal>
|
</div>
|
)
|
}
|
}
|
|
export default AppManage
|