Commit e43599c4 authored by rzf's avatar rzf

parent 8dda73e7
...@@ -50,13 +50,13 @@ const PublishModal = ({ visible, onCancel, data }) => { ...@@ -50,13 +50,13 @@ const PublishModal = ({ visible, onCancel, data }) => {
.then(data => { .then(data => {
if (data.success) { if (data.success) {
onCancel() onCancel()
message.success('发布成功!') message.success('替换成功!')
dataCenter?.type && fetchData('/page/queryPage', {}, 'queryPage') dataCenter?.type && fetchData('/page/queryPage', {}, 'queryPage')
.then((res) => { .then((res) => {
}) })
} else { } else {
message.error(data.error || '发布失败') message.error( '替换失败')
} }
}); });
} else { } else {
......
import {Menu, Modal, Popconfirm, Space, Table} from 'antd'; import { Menu, Modal, Popconfirm, Space, Table, message } from 'antd';
import React, {useContext, useEffect, useState} from 'react'; import React, { useContext, useEffect, useState } from 'react';
import TypeModal from '../modal/TypeModal' import TypeModal from '../modal/TypeModal'
import {Root} from "../dataCenter/Root"; import { NEED_UPDATE_INDEX } from "../dataCenter/action";
import { Root } from "../dataCenter/Root";
const menu = ( const menu = (
<Menu> <Menu>
...@@ -13,88 +14,76 @@ const menu = ( ...@@ -13,88 +14,76 @@ const menu = (
function RemoveType({ visible, onCancel }) { function RemoveType({ visible, onCancel }) {
const [typeModal, setTypeModal] = useState(false) const [typeModal, setTypeModal] = useState(false)
const [typeData, settypeData] = useState('')
const [oldData, setoldData] = useState('') const [oldData, setoldData] = useState('')
const { fetchData, dataCenter } = useContext(Root) const { fetchData, dataCenter, dispatch } = useContext(Root)
const changType = (data) => { const changType = (data) => {
setoldData(data) setoldData(data)
setTypeModal(true) setTypeModal(true)
} }
const changeData = (list, cb) => {
return list.map((item, index) => {
const res = cb(item);
if (item.children) res.children = changeData(item.children, item => ({
isRemove: true,
key: item.childTypeId,
typeId: item.childTypeId,
typeName: item.childTypeName,
}));
return res;
})
}
const removeType = (data) => { const removeType = (data) => {
console.log(data); fetchData('/typeManage/deleteChildType', { childTypeId: data.typeId })
.then((res) => {
if (res.success) {
message.success('刪除成功')
dispatch(NEED_UPDATE_INDEX())
queryData()
// onCancel()
}else{
message.error('刪除失败')
}
})
} }
useEffect(() => { const queryData = () => {
dataCenter?.type && fetchData('/typeManage/queryTypeForManage', {}, 'childTypeData') dataCenter?.type && fetchData('/typeManage/queryTypeForManage', {}, 'childTypeData')
.then((res) => { .then((res) => {
// console.log(res.data);
console.log(res); const newData = changeData(res.data, item => ({
key: item.typeId,
typeId: item.typeId,
typeName: item.typeName,
}));
// console.log(newData);
settypeData(newData)
}) })
}
useEffect(() => {
queryData()
}, []) }, [])
const columns = [ const columns = [
{ title: '类型名', width: 100, dataIndex: 'name', key: 'name' }, { title: '类型名', width: 100, dataIndex: 'typeName', key: 'typeName' },
{ title: 'Id', width: 100, dataIndex: 'platform', align: 'center', key: 'platform' }, { title: 'Id', width: 100, dataIndex: 'typeId', align: 'center', key: 'typeId' },
{ {
title: '操作', width: 100, key: 'operation', align: 'center', title: '操作', width: 100, key: 'operation', align: 'center',
render: (text, record) => ( render: (text, record) => (
<Space size="middle"> <Space size="middle">
<Popconfirm title="确定删除吗?" okText="确定" cancelText="取消" onConfirm={() => removeType(record)}> {record.isRemove && <Popconfirm title="确定删除吗?" okText="确定" cancelText="取消" onConfirm={() => removeType(record)}>
<a href="#">删除</a> <a href="#" >删除</a>
</Popconfirm> </Popconfirm>}
<a href="#" onClick={() => changType(record)}>修改</a> <a href="#" onClick={() => changType(record)}>修改</a>
</Space> </Space>
) )
}, },
]; ];
const data = [{
key: 1,
name: '甲类型1',
platform: 'iOS',
version: '10.3.4.5654',
upgradeNum: 500,
creator: 'Jack',
createdAt: '2014-12-24 23:12:00',
children: [
{
key: 3,
platform: '3',
name: '子类型31',
upgradeNum: 'Upgraded: 3',
},
]
}, {
key: 2,
name: '甲类型2',
platform: 'iOS',
version: '10.3.4.5654',
upgradeNum: 500,
creator: 'Jack',
createdAt: '2014-12-24 23:12:00',
children: [
{
key: 3,
platform: '32',
name: '子类型32',
upgradeNum: 'Upgraded: 3',
},
]
}, {
key: 3,
name: '甲类型3',
platform: 'iOS',
upgradeNum: 500,
children: [
{
key: 3,
platform: '33',
name: '子类型33',
upgradeNum: 'Upgraded: 3',
},
]
}];
return ( return (
<Modal <Modal
visible={visible} visible={visible}
...@@ -107,13 +96,16 @@ function RemoveType({ visible, onCancel }) { ...@@ -107,13 +96,16 @@ function RemoveType({ visible, onCancel }) {
> >
<Table <Table
columns={columns} columns={columns}
dataSource={data} dataSource={typeData}
/> />
{typeModal && <TypeModal {typeModal && <TypeModal
visible={typeModal} visible={typeModal}
onCancel={() => onCancel={() =>
setTypeModal(false) setTypeModal(false)
} }
queryData={() =>
queryData()
}
data={oldData} data={oldData}
/>} />}
</Modal> </Modal>
......
...@@ -22,14 +22,17 @@ const ToolModal = ({ visible, onCancel, data }) => { ...@@ -22,14 +22,17 @@ const ToolModal = ({ visible, onCancel, data }) => {
input = { input = {
...input, ...input,
typeId: values.type, typeId: values.type,
childType: values.childType childTypeId: values.childType
} }
console.log(input);
fetchData('/add/addToolBox', input) fetchData('/add/addToolBox', input)
.then((res) => { .then((res) => {
if (res.success) { if (res.success) {
message.success('新建成功') message.success('新建成功')
dispatch(NEED_UPDATE_INDEX()) dispatch(NEED_UPDATE_INDEX())
onCancel() onCancel()
} else {
message.error('新建失败')
} }
}) })
...@@ -40,6 +43,8 @@ const ToolModal = ({ visible, onCancel, data }) => { ...@@ -40,6 +43,8 @@ const ToolModal = ({ visible, onCancel, data }) => {
message.success('修改成功') message.success('修改成功')
dispatch(NEED_UPDATE_INDEX()) dispatch(NEED_UPDATE_INDEX())
onCancel() onCancel()
} else {
message.error('新建失败')
} }
}) })
} }
......
...@@ -5,10 +5,14 @@ import { Root } from "../dataCenter/Root"; ...@@ -5,10 +5,14 @@ import { Root } from "../dataCenter/Root";
import { NEED_UPDATE_INDEX } from "../dataCenter/action"; import { NEED_UPDATE_INDEX } from "../dataCenter/action";
const { Option } = Select; const { Option } = Select;
const { TabPane } = Tabs; const { TabPane } = Tabs;
const TypeModal = ({ visible, onCancel, data }) => { const TypeModal = ({ visible, onCancel, queryData, data }) => {
console.log(data); console.log(data);
const [form] = Form.useForm(); const [form] = Form.useForm();
if (data) {
form.setFieldsValue({
typeName: data.typeName,
});
}
const formItemLayout = { const formItemLayout = {
labelCol: { span: 4 }, labelCol: { span: 4 },
wrapperCol: { span: 18 }, wrapperCol: { span: 18 },
...@@ -19,9 +23,33 @@ const TypeModal = ({ visible, onCancel, data }) => { ...@@ -19,9 +23,33 @@ const TypeModal = ({ visible, onCancel, data }) => {
const onCreate = (values) => { const onCreate = (values) => {
if (data) { if (data) {
console.log(data);
let input = {
typeId: '',
typeName: ''
}
if (!data.isRemove) {
input = {
typeId: data.typeId,
typeName: values.typeName
}
} else {
input = {
childTypeId: data.typeId,
childTypeName: values.typeName
}
}
fetchData('/typeManage/updateType', input)
.then((res) => {
if (res.success) {
message.success('修改成功')
dispatch(NEED_UPDATE_INDEX())
queryData()
onCancel()
}
})
} else { } else {
console.log(values); console.log(values);
fetchData('/add/addType', values) fetchData('/add/addType', values)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment