Skip to content

Commit

Permalink
fix: 修复 h5 细节
Browse files Browse the repository at this point in the history
  • Loading branch information
jimczj committed Aug 17, 2018
1 parent 1858b7a commit 471e0ad
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/components/badge/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ $badge-dot-size: 20px;
height: $badge-height;
line-height: $badge-height;
position: absolute;
right: 0;
right: -6PX;
top: -$badge-border-radius;
transform: translate(50%, 0);
padding: 0 $spacing-h-sm;
Expand Down
18 changes: 14 additions & 4 deletions src/components/input-number/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types'
import AtIcon from '../../components/icon/index'
import './index.scss'

Taro.initNativeApi(Taro)
/**
* @author:chenzeji
* @description 数字输入框
Expand All @@ -15,6 +16,7 @@ import './index.scss'
* @prop onChange {Function} 监听事件改变函数
*/
class AtInputNumber extends Taro.Component {
// 实现两数相加并保留小数点后最短尾数
static addNum (num1, num2) {
let sq1, sq2
try {
Expand All @@ -30,27 +32,35 @@ class AtInputNumber extends Taro.Component {
const m = Math.pow(10, Math.max(sq1, sq2))
return (Math.round(num1 * m) + Math.round(num2 * m)) / m
}
// 格式化数字,处理01变成1,并且不处理1. 这种情况
static parseValue (num) {
const numStr = num.toString()
if (numStr.indexOf('0') === 0 && numStr.indexOf('.') === -1) {
return parseFloat(num)
}
return num
}
handleMinus () {
const { disabled, value, min, step } = this.props
if (disabled) return
let nextValue = AtInputNumber.addNum(value, -step)
nextValue = nextValue > min ? nextValue : min
this.props.onChange(nextValue)
this.props.onChange(AtInputNumber.parseValue(nextValue))
}
handlePlus () {
const { disabled, value, max, step } = this.props
if (disabled) return
let nextValue = AtInputNumber.addNum(value, step)
nextValue = nextValue < max ? nextValue : max
this.props.onChange(nextValue)
this.props.onChange(AtInputNumber.parseValue(nextValue))
}
handleInput (e) {
const { value } = e.target
const { disabled, min, max } = this.props
if (disabled) return
let nextValue = value < max ? value : max
nextValue = nextValue > min ? nextValue : min
this.props.onChange(nextValue)
this.props.onChange(AtInputNumber.parseValue(nextValue))
}
render () {
const { width, disabled, value, min, max, size } = this.props
Expand All @@ -65,7 +75,7 @@ class AtInputNumber extends Taro.Component {
</View>
<Input className='at-input-number__input'
style={inputStyle}
type='number'
type='digit'
value={value}
disabled={disabled}
onInput={this.handleInput.bind(this)}
Expand Down
2 changes: 2 additions & 0 deletions src/components/nav-bar/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ $spacing-h: 5PX;
&__right_view {
flex: 2;
overflow: hidden;
height: 100%;
text-align: right;
}

Expand All @@ -59,6 +60,7 @@ $spacing-h: 5PX;

&__container {
width: 50%;
height: 100%;
display: inline-block;
text-align: center;
box-sizing: border-box;
Expand Down
24 changes: 16 additions & 8 deletions src/components/tab-bar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,28 @@ class AtTabBar extends Taro.Component {
key={item.title}
onClick={this.handleClick.bind(this, i)}
>
<AtBadge dot={item.dot} value={item.text} max={item.max}>
{
item.iconType
? <View className='at-tab-bar__icon'>
{
item.iconType
? <AtBadge dot={item.dot} value={item.text} max={item.max}>
<View className='at-tab-bar__icon'>
<AtIcon
value={current === i && item.selectedIconType ? item.selectedIconType : item.iconType}
size={iconSize}
color={current === i ? selectedColor : color}
/>
</View>
: null
}
<View className='at-tab-bar__title' style={titleStyle}>{item.title}</View>
</AtBadge>
</AtBadge>
: null
}
<View>
<AtBadge
dot={item.iconType ? '' : item.dot}
value={item.iconType ? '' : item.text}
max={item.iconType ? '' : item.max}
>
<View className='at-tab-bar__title' style={titleStyle}>{item.title}</View>
</AtBadge>
</View>
</View>
})
}
Expand Down

0 comments on commit 471e0ad

Please sign in to comment.