Skip to content

Commit

Permalink
Merge pull request #762 from XiaoMi/hotfix/#760#756#749#746
Browse files Browse the repository at this point in the history
Hotfix/#760#756#749#746
  • Loading branch information
zhan8863 authored Nov 7, 2019
2 parents 724276c + 93c579b commit bd27b8a
Show file tree
Hide file tree
Showing 20 changed files with 191 additions and 131 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# 更新日志

## 2.5.3
- 修复 `<Select />` 异步多选在输入关键字时会清除已选择项的问题 [#746](https://github.com/XiaoMi/hiui/issues/746)
- 修复 `<Loading />` 在某些情况下导致页面布局发生变化的问题 [#749](https://github.com/XiaoMi/hiui/issues/749)
- 修改 `<Upload />` photo 模式、drag 模式下超出数量限制的展现形式 [#756](https://github.com/XiaoMi/hiui/issues/756)
- 修复 `<Rate />` 组件的控制台警告 [#760](https://github.com/XiaoMi/hiui/issues/760)
- 变更 `<Select />``<Tree />``<Table />` 的远程 Mock 数据地址

## 2.5.2

- 修复 `<Tabs />` 编辑模式下删除最后一个 tab 报错的问题 [#735](https://github.com/XiaoMi/hiui/issues/735)
Expand Down
8 changes: 6 additions & 2 deletions components/loading/Loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ function PortalWrapper ({ mountNode, children }) {
function open (target, { content, key, duration, size } = {}) {
let renderNode = document.createElement('div')
const mountNode = target || document.body
window.getComputedStyle(mountNode).position === 'absolute' ||
mountNode.nodeName !== 'BODY' && (
window.getComputedStyle(mountNode).position === 'absolute' ||
mountNode.style.setProperty('position', 'relative')
)
const full = !target
ReactDOM.render(
<Loading {...{ content, full, visible: true, target: mountNode, size }} />,
Expand All @@ -79,8 +81,10 @@ function open (target, { content, key, duration, size } = {}) {
function deprecatedOpen ({ target, tip } = {}) {
let renderNode = document.createElement('div')
const mountNode = target || document.body
window.getComputedStyle(mountNode).position === 'absolute' ||
mountNode.nodeName !== 'BODY' && (
window.getComputedStyle(mountNode).position === 'absolute' ||
mountNode.style.setProperty('position', 'relative')
)
const full = !target
ReactDOM.render(
<Loading {...{ tip, full, show: true, target: mountNode }} />,
Expand Down
1 change: 1 addition & 0 deletions components/locales/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default {
delete: 'Delete',
drag: 'Drag and drop files for uploading',
dragTips: 'Please click or drag and drop file upload',
dragTipsLimited: 'The number has reached the upper limit',
preview: 'Preview'
},
modal: {
Expand Down
1 change: 1 addition & 0 deletions components/locales/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default {
delete: '删除',
drag: '拖拽文件上传',
dragTips: '请点击或拖拽文件上传',
dragTipsLimited: '数量已达上限',
preview: '预览'
},
modal: {
Expand Down
1 change: 1 addition & 0 deletions components/rate/Rate.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Rate extends Component {
value
}
}
return null
}
state = {
value: 0,
Expand Down
139 changes: 76 additions & 63 deletions components/select/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Select extends Component {
const { data, value, defaultValue } = props
const dropdownItems = cloneDeep(data)
const initialValue = value === undefined ? defaultValue : value
const selectedItems = this.resetSelectedItems(initialValue, dropdownItems)
const selectedItems = this.resetSelectedItems(initialValue, dropdownItems, [])
const searchable = this.getSearchable()
this.debouncedFilterItems = debounce(this.onFilterItems.bind(this), 300)
this.clickOutsideHandel = this.clickOutside.bind(this)
Expand Down Expand Up @@ -124,7 +124,7 @@ class Select extends Component {
const selectedItems = this.resetSelectedItems(
nextProps.value || this.state.selectedItems,
nextProps.data,
true
this.state.selectedItems
)
this.setState({
selectedItems,
Expand Down Expand Up @@ -162,19 +162,19 @@ class Select extends Component {
}

isRemote () {
const { dataSource } = this.props
return dataSource && !!dataSource.url
const { dataSource, onSearch } = this.props
return onSearch || (dataSource && !!dataSource.url)
}

resetSelectedItems (value, dropdownItems = [], listChanged = false) {
resetSelectedItems (value, dropdownItems = [], reviceSelectedItems = []) {
const values = this.parseValue(value)
let selectedItems = []
dropdownItems.forEach((item) => {
if (values.includes(item.id)) {
selectedItems.push(item)
}
})
return selectedItems
return reviceSelectedItems.concat(selectedItems)
}

addOption (option) {
Expand Down Expand Up @@ -328,65 +328,75 @@ class Select extends Component {
}

remoteSearch (keyword) {
let {
url,
transformResponse,
error,
params,
headers,
mode,
data = {},
type = 'GET',
key,
jsonpCallback = 'callback',
...options
} = this.props.dataSource
keyword =
!keyword && this.autoloadFlag && this.props.autoload
? this.props.dataSource.keyword
const {onSearch, dataSource, autoload} = this.props
if (onSearch && typeof onSearch === 'function') {
this.setState({
fetching: true
})
onSearch(keyword).finally(() => {
this.setState({fetching: false})
})
} else {
let {
url,
transformResponse,
error,
params,
headers,
mode,
data = {},
type = 'GET',
key,
jsonpCallback = 'callback',
...options
} = dataSource
keyword =
!keyword && this.autoloadFlag && autoload
? dataSource.keyword
: keyword
this.autoloadFlag = false // 第一次自动加载数据后,输入的关键词即使为空也不再使用默认关键词
this.autoloadFlag = false // 第一次自动加载数据后,输入的关键词即使为空也不再使用默认关键词

const queryParams = qs.stringify(
Object.assign({}, params, key && { [key]: keyword })
)
url = url.includes('?') ? `${url}&${queryParams}` : `${url}?${queryParams}`

if (type.toUpperCase() === 'POST') {
options.body = JSON.stringify(data)
}
this.setState({
fetching: true
})
const queryParams = qs.stringify(
Object.assign({}, params, key && { [key]: keyword })
)
url = url.includes('?') ? `${url}&${queryParams}` : `${url}?${queryParams}`

if (type.toUpperCase() === 'JSONP') {
const _o = {
jsonpCallback: jsonpCallback,
jsonpCallbackFunction: jsonpCallback
if (type.toUpperCase() === 'POST') {
options.body = JSON.stringify(data)
}
fetchJsonp(url, _o)
.then((res) => res.json())
.then((json) => {
this._setDropdownItems(json, transformResponse)
})
} else {
/* eslint-disable */
fetch(url, {
method: type,
...options
this.setState({
fetching: true
})
.then((response) => response.json())
.then(
(res) => {
this._setDropdownItems(res, transformResponse)
},
(err) => {
error && error(err)
this.setState({
fetching: false
})
}
)

if (type.toUpperCase() === 'JSONP') {
const _o = {
jsonpCallback: jsonpCallback,
jsonpCallbackFunction: jsonpCallback
}
fetchJsonp(url, _o)
.then((res) => res.json())
.then((json) => {
this._setDropdownItems(json, transformResponse)
})
} else {
/* eslint-disable */
fetch(url, {
method: type,
...options
})
.then((response) => response.json())
.then(
(res) => {
this._setDropdownItems(res, transformResponse)
},
(err) => {
error && error(err)
this.setState({
fetching: false
})
}
)
}
}
}
_setDropdownItems(res, func) {
Expand All @@ -400,7 +410,7 @@ class Select extends Component {
const selectedItems = this.resetSelectedItems(
this.props.value,
dropdownItems,
true
this.state.selectedItems
)
this.setState({
dropdownItems,
Expand All @@ -412,20 +422,23 @@ class Select extends Component {
})
}
onFilterItems(keyword) {
const { onSearch, dataSource, autoload } = this.props
this.setState(
{
keyword: keyword
},
() => this.resetFocusedIndex()
)

if (this.props.dataSource && this.props.dataSource.key) {
if (dataSource && dataSource.key) {
if (
this.props.autoload ||
autoload ||
keyword.toString().length >= this.state.queryLength
) {
this.remoteSearch(keyword)
}
} else if(onSearch) {
this.remoteSearch(keyword)
}
}

Expand Down
2 changes: 1 addition & 1 deletion components/upload/UploadDrag.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class UploadDrag extends Upload {
fileList.length > 0 && <li className='hi-upload__item hi-upload__item-tips'>
<Icon name='comment-circle-o' />
<span className='hi-upload__tips--exist'>
{localeDatas.upload.dragTips}
{fileCountLimted ? localeDatas.upload.dragTipsLimited : localeDatas.upload.dragTips}
</span>
</li>
}
Expand Down
32 changes: 17 additions & 15 deletions components/upload/UploadPhoto.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,23 @@ class UploadPhoto extends Upload {
)
}
})}
<li className='hi-upload__item hi-upload__item--upload'>
<label style={{display: 'block'}}>
<input
ref={node => {
this.uploadRef = node
}}
type='file'
accept={accept}
disabled={(disabled || fileCountLimted) && 'disabled'}
onChange={e => this.uploadFiles(e.target.files)}
hidden
/>
<Icon name='plus' />
</label>
</li>
{
!fileCountLimted && <li className='hi-upload__item hi-upload__item--upload'>
<label style={{display: 'block'}}>
<input
ref={node => {
this.uploadRef = node
}}
type='file'
accept={accept}
disabled={(disabled || fileCountLimted) && 'disabled'}
onChange={e => this.uploadFiles(e.target.files)}
hidden
/>
<Icon name='plus' />
</label>
</li>
}
</ul>
{
showModal && <Preview
Expand Down
Loading

0 comments on commit bd27b8a

Please sign in to comment.