pmg1989 / dva-admin

dva admin antd dashboard
https://pmg1989.github.io
MIT License
284 stars 93 forks source link

感觉项目的结构组织的有点混乱,对 redux 的使用好像很不规范呀? #18

Closed xyzdata closed 7 years ago

xyzdata commented 7 years ago

找半天,才发现 reducers 都被放到了components 中, route 里面放了 UI components!

反正我看得一头雾水,不知道能否提供一个该项目的源码学习的项目路径图?

PS: redux 刚刚使用,不对之处还望指正!

pmg1989 commented 7 years ago

嗯,开发过程中,确实有对dva项目的目录结构进行了细微调整,只是components中放的并不是你所的reducers。建议你先学习下dva,可能对项目的目录结构就会有些理解了,谢谢。

xyzdata commented 7 years ago

请问 如何将 table 的 item 数据,自动填充到弹出的 modal 里面?

image

由于你使用了封装的 <DropOption /> 组件, 我不知道如何将 table 的 record 数据,传递给 modal !


        {
            title: '操作',
            key: 'operation',
            width: 100,
            render: (text, record) => {
                return(
                    <DropOption 
                        onMenuClick={e => handleMenuClick(record, e)} 
                        menuOptions={[
                            {key: '1', name: '更新'},
                            {key: '2', name: '删除'}
                        ]}
                        datas={record}
                    />
                )
            }
        }
xyzdata commented 7 years ago

onMenuClick 将 record 数据传递给了 List 的 onEditItem(record);

onMenuClick={e => handleMenuClick(record, e)}


    const handleMenuClick = (record, e) => {
        if (e.key === '1') {
            onEditItem(record);
        } else if (e.key === '2') {
            confirm({
                title: '确定删除此记录吗?',
                onOk () {
                    onDeleteItem(record.id);
                }
            });
        }
    };

List 的 数据源


    // table props
    const listProps = {
        dataSource: list,
        loading: loading.effects['user/query'],
        pagination,
        location,
        isMotion,
        onChange (page) {
            const { query, pathname } = location;
            dispatch(routerRedux.push({
                pathname,
                query: {
                    ...query,
                    page: page.current,
                    pageSize: page.pageSize
                }
            }))
        },
        onDeleteItem (id) {
            console.log(`id`, id);
            dispatch({
                type: 'user/delete',
                payload: id
            })
        },
        onEditItem (item) {
            console.log(`item`, item);
            dispatch({
                type: 'user/showModal',
                payload: {
                    modalType: 'update',
                    currentItem: item
                }
            })
        },
        rowSelection: {
            selectedRowKeys,
            onChange: (keys) => {
                dispatch({
                    type: 'user/updateState',
                    payload: {
                        selectedRowKeys: keys
                    }
                })
            }
        }
    };
xyzdata commented 7 years ago

Modal props 数据源

dataSource: list,


    // modal props
    const modalProps = {
        item:` 
            ${
                modalType === 'create'
                ? {}
                : currentItem
            }
        `,
        visible: modalVisible,
        maskClosable: false,
        confirmLoading: loading.effects['user/update'],
        title: `
            ${modalType === 'create'
            ? '创建 User'
            : '更新 User'}
        `,
        dataSource: list,
        wrapClassName: 'vertical-center-modal',
        onOk(data) {
            console.log(` onOk(data) =`, data);
            dispatch({type: `user/${modalType}`, payload: data});
        },
        onCancel() {
            dispatch({type: 'user/hideModal'});
        }
    };
xyzdata commented 7 years ago

完全转晕了!

Anybody can help ?