Skip to content

Commit

Permalink
fix(view): 修复badge传参为空字符的情况
Browse files Browse the repository at this point in the history
  • Loading branch information
cos2004 committed Aug 17, 2018
1 parent 53555f9 commit a6fc736
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/components/badge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default class AtBadge extends Taro.Component {
}

formatValue (value, maxValue) {
if (value === '' || value === null) return ''
const numValue = +value
if (loadash.isNaN(numValue)) {
return value
Expand All @@ -27,10 +28,12 @@ export default class AtBadge extends Taro.Component {
} = this.props
const rootClassName = ['at-badge']

const val = this.formatValue(value, maxValue)

return (
<View className={rootClassName}>
{this.props.children}
{dot ? <View className='at-badge__dot'></View> : <View className='at-badge__num'>{this.formatValue(value, maxValue)}</View>}
{dot ? <View className='at-badge__dot'></View> : val !== '' && <View className='at-badge__num'>{val}</View>}
</View>
)
}
Expand Down
7 changes: 4 additions & 3 deletions src/pages/view/badge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ export default class BadgePage extends Taro.Component {

}
}

/** eslint-disable */
render () {
const dot = '···'
return (
<View className='page'>
{/* S Header */}
Expand Down Expand Up @@ -91,12 +92,12 @@ export default class BadgePage extends Taro.Component {
<View className='panel__content'>
<View className='badge-item'>
<View className='subitem'>
<AtBadge value='···'>
<AtBadge value={dot}>
<AtButton size='small' circle>按钮</AtButton>
</AtBadge>
</View>
<View className='subitem'>
<AtBadge value='···'>
<AtBadge value={dot}>
<AtButton size='small'>按钮</AtButton>
</AtBadge>
</View>
Expand Down

0 comments on commit a6fc736

Please sign in to comment.