Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model更新问题 #1128

Open
lhc0229 opened this issue Jan 17, 2022 · 1 comment
Open

model更新问题 #1128

lhc0229 opened this issue Jan 17, 2022 · 1 comment

Comments

@lhc0229
Copy link

lhc0229 commented Jan 17, 2022

import React, { Component } from 'react'
import { Page } from 'components'
import './style.less'
import { Button, Input, DatePicker, Select } from 'antd'
import PropTypes from 'prop-types'
import { connect } from 'umi'
import ProjectTable from 'components_bus/project/list/table/index'
import { history } from 'umi'
import UpdateModal from 'components_bus/project/list/updateModal/index'

@connect(({ admin_project_list, loading }) => ({ admin_project_list, loading }))
class ProjectList extends Component {
constructor(props) {
super(props)
this.dispatch = this.props.dispatch
this.loading = this.props.loading
}

componentDidMount() {
this.dispatch({
type: 'admin_project_list/getList',
payload: this.props.admin_project_list.condition,
})
}

// 搜索数据
handleSearch = () => {
this.dispatch({
type: 'admin_project_list/updateCondition',
payload: { page: 1, num: 10 },
})
}

// 更新输入框的关键字的值
handleChange = ({ target: { value } }) => {
this.dispatch({
type: 'admin_project_list/setCondition',
payload: { keyword: value },
})
}

// 重置
handleReset = () => {
this.dispatch({
type: 'admin_project_list/updateCondition',
payload: {
page: 1,
num: 10,
order: 'created_at',
desc: true,
started_at: null,
user_id: null,
ended_at: null,
keyword: null,
},
})
}

// 更改时间
handleChangeTime = (data) => {
this.dispatch({ type: 'admin_project_list/updateCondition', payload: data })
}

// 跳转详情页
handleGetDetails = (data) => {
const id = data.id
history.push({ pathname: '/project/details', query: { id } })
}

// 获取更新数据
handleUpdateData = (item) => {
const data = { ...item }
if (data.ended_at) {
data.ended_at = data.ended_at.slice(0, 10)
}
if (data.started_at) {
data.started_at = data.started_at.slice(0, 10)
}
this.dispatch({
type: 'admin_project_list/setShowUpdateModal',
payload: { value: true },
})
this.dispatch({
type: 'admin_project_list/setUpdateData',
payload: { data },
})
}

// 分页
handleChangePagination = (pagination, filters, sorter) => {
const { current, pageSize } = pagination
const { columnKey, order } = sorter
const tempDict = { page: current, num: pageSize, order: columnKey }
if (columnKey && order) {
tempDict['order'] = columnKey
tempDict['desc'] = order === 'descend'
}
this.dispatch({
type: 'admin_project_list/updateCondition',
payload: tempDict,
})
}

// 关闭修改弹窗
handleCancelUpdate = () => {
this.dispatch({
type: 'admin_project_list/setShowUpdateModal',
payload: { value: false },
})
}

// 提交更新
handleFinish = (data) => {
this.dispatch({ type: 'admin_project_list/updateData', payload: data })
}

// 获取全部用户
getAllUser = (user) => {
this.dispatch({ type: 'admin_project_list/getAllUser', payload: { user } })
}

// 更改时间
updateTime = (time, dateStrings) => {
this.dispatch({
type: 'admin_project_list/updateDataTime',
payload: { started_at: dateStrings[0], ended_at: dateStrings[1] },
})
}

//远程搜索创建用户
handleCreateUserSearch = (value) => {
this.dispatch({
type: 'admin_project_list/getAllUser',
payload: { user: value },
})
}

//根据用户id搜索用户
handleUserChange = (value) => {
this.dispatch({
type: 'admin_project_list/updateCondition',
payload: { user_id: value },
})
}

get data() {
return this.props.admin_project_list
}

render() {
return (







项目名称:



<span style={{ marginLeft: '32px', marginRight: '8px' }}>
创建人:

<Select
allowClear
style={{ width: '256px' }}
showSearch
value={this.data.condition.user_id}
placeholder="请输入创建人"
defaultActiveFirstOption={false}
showArrow={false}
filterOption={false}
onSearch={this.handleCreateUserSearch}
onChange={this.handleUserChange}
notFoundContent={null}
>
{this.data.all_user.map((d) => {
return (
<Select.Option key={d.id} value={d.id}>
{d['real_name']}
</Select.Option>
)
})}




开始时间:
<DatePicker
placeholder="请选择开始时间"
onChange={(date, dateString) => {
this.handleChangeTime({
started_at: dateString,
page: 1,
})
}}
/>


结束时间:
<DatePicker
placeholder="请选择结束时间"
onChange={(date, dateString) => {
this.handleChangeTime({ ended_at: dateString, page: 1 })
}}
/>





<Button
type="primary"
style={{ marginRight: '16px' }}
onClick={this.handleSearch}
>
查询

重置




<ProjectTable
{...this.data}
handleChangePagination={this.handleChangePagination}
handleGetDetails={this.handleGetDetails}
handleUpdateData={this.handleUpdateData}
/>





)
}
}

ProjectList.propTypes = {
admin_project_list: PropTypes.object,
location: PropTypes.object,
dispatch: PropTypes.func,
loading: PropTypes.object,
}

export default ProjectList

当我从此页面离开时,页数为2,当我从其它页面重新进入此页面时,页数还是2,证明model在页面销毁时,没有被重置,请问model更新时机以及更新机制是什么样的

@superlbr
Copy link
Collaborator

dva

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants