Skip to content

Commit

Permalink
更新login的实现。
Browse files Browse the repository at this point in the history
修改部分element的ui和回调方法
  • Loading branch information
kala888 committed Nov 18, 2019
1 parent c18e044 commit 545388a
Show file tree
Hide file tree
Showing 17 changed files with 140 additions and 96 deletions.
11 changes: 5 additions & 6 deletions src/app.js
Expand Up @@ -3,10 +3,9 @@ import Taro, { Component } from '@tarojs/taro'
import { Provider } from '@tarojs/redux'
import NiceRouter from '@/nice-router/nice-router'
import Config from '@/utils/config'
import NavigationService from '@/nice-router/navigation.service'
import { View } from '@tarojs/components'

import './app.scss'
import HomePage from './pages/home/home-page'
import dva from './dva'
import models from './models/model-center'

Expand All @@ -28,9 +27,9 @@ NiceRouter.start({ config: Config, container: dvaApp })
initial()

class App extends Component {
componentWillMount() {
NavigationService.dispatch('app/wxLogin')
}
// componentWillMount() {
// NavigationService.dispatch('app/wxLogin')
// }

componentDidMount() {
if (Taro.canIUse('getUpdateManager')) {
Expand Down Expand Up @@ -122,7 +121,7 @@ class App extends Component {
render() {
return (
<Provider store={store}>
<HomePage />
<View />
</Provider>
)
}
Expand Down
19 changes: 8 additions & 11 deletions src/components/navigation-box-bar.js
@@ -1,13 +1,13 @@
import Taro from '@tarojs/taro'
import { AtBadge } from 'taro-ui'
import m_ from '@/utils/mini-lodash'
import toNumber from 'lodash/toNumber'
import { Image, View } from '@tarojs/components'
import NavigationService from '@/nice-router/navigation.service'
import classNames from 'classnames'

import './biz/styles.scss'

import commerceIcon from '../assets/icon/icon_liansuo@2x.png'

export default class NavigationBoxBar extends Taro.PureComponent {
static options = {
addGlobalClass: true,
Expand All @@ -24,24 +24,21 @@ export default class NavigationBoxBar extends Taro.PureComponent {
list.length > 0 && (
<View className={rootClass} customStyle={customStyle}>
{list.map((it, index) => {
const { icon, title, value } = it
const { icon, imageUrl, title, badge } = it
const isLast = index === list.length - 1
const itemRender = (
return (
<View key={it.id} className='navigation-bar-item'>
<View className='navigation-box' onClick={() => this.handleClick(it)}>
<View className='navigation-box' onClick={this.handleClick.bind(this, it)}>
<View className='navigation-box-img'>
<Image mode='widthFix' src={icon} />
<AtBadge value={badge}>
<Image mode='widthFix' src={icon || imageUrl || commerceIcon} />
</AtBadge>
</View>
<View className='navigation-box-txt'>{title}</View>
</View>
{!isLast && <View className='navigation-bar-item-break' />}
</View>
)
return m_.isNumber(value) && value > 0 ? (
<AtBadge value={toNumber(value)}>{itemRender}</AtBadge>
) : (
itemRender
)
})}
</View>
)
Expand Down
2 changes: 1 addition & 1 deletion src/genericpage/elements/ele-break-line.js
Expand Up @@ -8,7 +8,7 @@ import EleHelper from '../ele-helper'
export default class EleBreakLine extends Taro.PureComponent {
static defaultProps = {
color: '#ddd',
height: 2,
height: 1,
text: '',
fontColor: '#ddd',
customStyle: {},
Expand Down
1 change: 1 addition & 0 deletions src/genericpage/elements/ele-button.js
Expand Up @@ -91,6 +91,7 @@ export default class EleButton extends Taro.PureComponent {
return
}

console.log('btnType is', btnType, 'just do view action')
NavigationService.view(linkToUrl)
}

Expand Down
15 changes: 13 additions & 2 deletions src/genericpage/elements/ele-fab.js
Expand Up @@ -2,6 +2,7 @@ import Taro from '@tarojs/taro'
import { Text, View } from '@tarojs/components'
import { AtFab, AtIcon } from 'taro-ui'
import ServerImage from '@/components/image/server-image'
import NavigationService from '@/nice-router/navigation.service'

import './ele.scss'
import EleHelper from '../ele-helper'
Expand All @@ -13,14 +14,24 @@ export default class EleFab extends Taro.PureComponent {
icon: null,
customStyle: {},
className: null,
linkToUrl: null,
}

handleClick = () => {
const { onClick, linkToUrl } = this.props
if (onClick) {
onClick()
return
}
NavigationService.view(linkToUrl)
}

render() {
const { imageUrl, text, icon, customStyle, className } = this.props
const { imageUrl, text, icon, customStyle, className, size } = this.props
const rootClass = EleHelper.classNames('ele-fab', className)
return (
<View className={rootClass}>
<AtFab>
<AtFab size={size} onClick={this.handleClick}>
{icon ? (
<AtIcon className='more-action-icon' value={icon} size={20} color='grey' />
) : (
Expand Down
2 changes: 1 addition & 1 deletion src/genericpage/form/ele-form.scss
Expand Up @@ -27,7 +27,7 @@
.at-input__container {
box-sizing: border-box;
//padding-left: 20px;
flex: 1;
min-width: 170px;
}
}

Expand Down
31 changes: 21 additions & 10 deletions src/genericpage/form/ele-image-picker.js
Expand Up @@ -25,6 +25,7 @@ export default class EleImagePicker extends Taro.PureComponent {
}

uploadNewFiles = (files = []) => {
const { formKey, name } = this.props
const todoList = files.filter((it) => {
const { url = '' } = it
return url.startsWith('http://tmp') || url.startsWith('wxfile://tmp')
Expand All @@ -43,17 +44,27 @@ export default class EleImagePicker extends Taro.PureComponent {
onSuccess: (result) => {
const { remoteFile, sourceFile } = result

this.setState((preState) => {
const newFiles = preState.files.map((it) => {
if (it.url === sourceFile) {
return {
url: remoteFile,
this.setState(
(preState) => {
const newFiles = preState.files.map((it) => {
if (it.url === sourceFile) {
return {
url: remoteFile,
}
}
}
return it
})
return { files: newFiles }
})
return it
})
return { files: newFiles }
},
() => {
console.log('1111', name, formKey, this.state.files)
Taro.eventCenter.trigger('form-value-changed', {
name,
value: this.state.files,
formKey,
})
}
)
},
})
}
Expand Down
10 changes: 8 additions & 2 deletions src/genericpage/form/ele-input.js
Expand Up @@ -21,10 +21,15 @@ export default class EleInput extends Taro.PureComponent {
customStyle: {},
maxLength: 2000,
defaultValue: null,
focus: null,
}

handleChange = (value) => {
const { name, formKey } = this.props
const { name, formKey, onChange } = this.props
if (onChange) {
onChange(value)
return
}
Taro.eventCenter.trigger('form-value-changed', {
name,
value,
Expand All @@ -33,7 +38,7 @@ export default class EleInput extends Taro.PureComponent {
}

render() {
const { name, title, type, placeholder, className, maxLength, defaultValue, customStyle } = this.props
const { name, title, type, placeholder, className, maxLength, focus, defaultValue, customStyle } = this.props
const inputType = type === 'money' ? 'digit' : type
const rootClass = EleHelper.classNames('ele-input', className)
return (
Expand All @@ -48,6 +53,7 @@ export default class EleInput extends Taro.PureComponent {
placeholderStyle='font-size:24rpx;color:#999'
maxLength={maxLength}
value={defaultValue}
focus={focus}
customStyle={customStyle}
/>
)
Expand Down
48 changes: 35 additions & 13 deletions src/genericpage/form/ele-picker.js
@@ -1,5 +1,6 @@
import Taro from '@tarojs/taro'
import { AtIcon } from 'taro-ui'
import isArray from 'lodash/isArray'
import { Label, Picker, View } from '@tarojs/components'

import './ele-form.scss'
Expand All @@ -12,21 +13,37 @@ export default class ElePicker extends Taro.PureComponent {
mode: 'date',
displayMode: 'right-brief',
range: null,
rangeKey: 'title',
valueKey: 'value',
displayProperty: 'title',
valueProperty: 'value',
customStyle: {},
className: null,
name: '',
}

state = {
displayValue: '',
displayValue: null,
}

handleChange = (e) => {
const { name, range, rangeKey, formKey, valueKey } = this.props
const { name, range, formKey, displayProperty, valueProperty } = this.props
const { value } = e.detail
const selected = range ? range[value] : value
const displayValue = selected[rangeKey] || selected
let selected = value
let displayValue = value
let selectedValue = null

if (isArray(value)) {
selected = value.map((it, idx) => {
if (range) {
return range[idx][it]
}
return it
})
displayValue = selected.map((it) => it[displayProperty] || it).join('-')
} else if (range) {
selected = range[value]
displayValue = selected[displayProperty]
selectedValue = selected[valueProperty]
}

this.setState(
{
Expand All @@ -35,25 +52,30 @@ export default class ElePicker extends Taro.PureComponent {
() =>
Taro.eventCenter.trigger('form-value-changed', {
name,
value: selected[valueKey] || selected,
value: selectedValue || selected,
formKey,
})
)
}

render() {
const { title, brief, mode, range, rangeKey, className, customStyle } = this.props

const value = this.state.displayValue
const { title, brief, mode, range, displayProperty, className, customStyle, onColumnChange } = this.props
const { displayValue } = this.state
const rootClass = EleHelper.classNames('ele-picker', className)

return (
<Picker mode={mode} onChange={this.handleChange} range={range} rangeKey={rangeKey}>
<Picker
mode={mode}
onChange={this.handleChange}
range={range}
rangeKey={displayProperty}
onColumnChange={onColumnChange}
>
<View className={rootClass} style={customStyle}>
<Label className='label-text ele-picker-left'>{title}</Label>
<View className='ele-picker-right'>
{value ? (
<View className='ele-picker-right-value'>{value}</View>
{displayValue ? (
<View className='ele-picker-right-value'>{displayValue}</View>
) : (
<View className='ele-picker-right-brief'>{brief}</View>
)}
Expand Down
9 changes: 8 additions & 1 deletion src/genericpage/form/ele-textarea.js
Expand Up @@ -30,12 +30,19 @@ export default class EleTextarea extends Taro.PureComponent {
{
value,
},
() =>
() => {
const { onChange } = this.props
if (onChange) {
onChange(value)
return
}

Taro.eventCenter.trigger('form-value-changed', {
name,
value,
formKey,
})
}
)
}

Expand Down

0 comments on commit 545388a

Please sign in to comment.