From b254300c69b4986cdbc93348dff844fc00297d3d Mon Sep 17 00:00:00 2001 From: chenhui0212 Date: Wed, 27 Feb 2019 17:17:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/workspace.xml | 416 +++++++++++++++++++------------- src/api/user.js | 4 + src/app.js | 2 + src/components/index.js | 1 + src/components/timer/index.js | 95 ++++++++ src/components/timer/index.scss | 9 + src/pages/auth/login.js | 0 src/pages/auth/login.scss | 0 src/pages/auth/reg.js | 97 ++++++++ src/pages/auth/reg.scss | 17 ++ 10 files changed, 468 insertions(+), 173 deletions(-) create mode 100644 src/components/timer/index.js create mode 100644 src/components/timer/index.scss create mode 100644 src/pages/auth/login.js create mode 100644 src/pages/auth/login.scss create mode 100644 src/pages/auth/reg.js create mode 100644 src/pages/auth/reg.scss diff --git a/.idea/workspace.xml b/.idea/workspace.xml index c536092db..52257a852 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,35 +2,17 @@ - - - - - - - - - - - - + + + + + + - - + - - - - - - - - - - - @@ -47,8 +29,49 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -57,13 +80,28 @@ - + - - - - - + + + + + + + + + + + + + + + + + + + + @@ -80,42 +118,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -136,6 +138,9 @@ $color-brand color-brand $color-brand-primary + btn + btns + handleSubmit @@ -144,24 +149,32 @@ - @@ -182,6 +195,12 @@ + + + + + + @@ -200,14 +219,7 @@ - - - - - - - - + @@ -215,6 +227,13 @@ + + + + + + + @@ -236,20 +255,6 @@ - - - - - - - - - - - - - - @@ -303,15 +308,15 @@ - - + @@ -338,9 +343,6 @@ - - - @@ -354,16 +356,6 @@ - - - - - - - - - - @@ -435,13 +427,6 @@ - - - - - - - @@ -449,26 +434,6 @@ - - - - - - - - - - - - - - - - - - - - @@ -488,16 +453,6 @@ - - - - - - - - - - @@ -512,16 +467,6 @@ - - - - - - - - - - @@ -544,13 +489,6 @@ - - - - - - - @@ -558,13 +496,6 @@ - - - - - - - @@ -582,6 +513,145 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/api/user.js b/src/api/user.js index 4d8261fa9..de39f4b99 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -7,3 +7,7 @@ export function login (data) { export function logout () { return req.post('/user.logout') } + +export function reg (data) { + return req.post('/user.reg', data) +} diff --git a/src/app.js b/src/app.js index d825c2b54..f303b4169 100644 --- a/src/app.js +++ b/src/app.js @@ -24,6 +24,8 @@ class App extends Component { 'pages/cart/checkout', 'pages/category/index', + 'pages/auth/login', + 'pages/auth/reg', 'pages/member/index', 'pages/member/favorite', diff --git a/src/components/index.js b/src/components/index.js index 190dd2cdf..ce18586d8 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -9,6 +9,7 @@ export { default as AddressPicker } from './address/picker' export { default as TabBar } from './tab-bar' export { default as SearchPanel } from './search' +export { default as Timer } from './timer' export { default as SpCheckbox } from './checkbox' export { default as SpCell } from './cell' diff --git a/src/components/timer/index.js b/src/components/timer/index.js new file mode 100644 index 000000000..8e0507a64 --- /dev/null +++ b/src/components/timer/index.js @@ -0,0 +1,95 @@ +import Taro, { Component } from '@tarojs/taro' +import { Text } from '@tarojs/components' +import { classNames } from '@/utils' +import './index.scss' + +export default class Timer extends Component { + static options = { + addGlobalClass: true + } + + static defaultProps = { + duration: 60, + defaultMsg: '发送验证码', + msg: '重新发送' + } + + constructor (props) { + super(props) + this.state = { + countDur: props.duration, + sent: false + } + } + + componentDidMount () { + } + + componentWillUnmount () { + this.stop() + } + + handleClick = () => { + if (this.timer) return + + if (!this.timer) { + this.start() + } + this.setState({ + sent: true + }) + } + + start () { + this.stop() + const next = () => { + this.timer = setTimeout(() => { + const countDur = this.state.countDur - 1 + this.props.onUpdateTimer && this.props.onUpdateTimer(countDur) + this.setState({ + countDur + }) + if (countDur > 0) { + next() + } else { + this.stop() + this.setState({ + countDur: this.props.duration + }) + this.props.onStop && this.props.onStop() + } + }, 1000) + } + + if (this.props.onStart(this.state.countDur) !== false) { + next() + } + } + + stop () { + if (this.timer) { + clearTimeout(this.timer) + this.timer = null + } + } + + render () { + const { timer } = this + const { countDur, sent } = this.state + const { timerMsg, className } = this.props + const msg = timerMsg || (timer + ? `${countDur}s` + : sent + ? this.props.msg + : this.props.defaultMsg) + + return ( + + {msg} + + ) + } +} diff --git a/src/components/timer/index.scss b/src/components/timer/index.scss new file mode 100644 index 000000000..eb928e73d --- /dev/null +++ b/src/components/timer/index.scss @@ -0,0 +1,9 @@ +@import '../../style/imports'; + +.mobile-timer { + color: $color-red !important; + font-size: $font-size-small !important; + &__counting { + color: $color-gray !important; + } +} diff --git a/src/pages/auth/login.js b/src/pages/auth/login.js new file mode 100644 index 000000000..e69de29bb diff --git a/src/pages/auth/login.scss b/src/pages/auth/login.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/pages/auth/reg.js b/src/pages/auth/reg.js new file mode 100644 index 000000000..b8219d768 --- /dev/null +++ b/src/pages/auth/reg.js @@ -0,0 +1,97 @@ +import Taro, { Component } from '@tarojs/taro' +import { View, Text } from '@tarojs/components' +import { AtForm, AtInput, AtButton } from 'taro-ui' +// import { SpCell } from '@/components' +import S from '@/spx' +import api from '@/api' + +import './reg.scss' + +export default class Reg extends Component { + constructor (props) { + super(props) + + this.state = { + info: {} + } + } + + handleSubmit = (e) => { + const { value } = e.detail + const data = { + ...this.state.info, + ...value + } + if (!data.mobile || !/1\d{10}/.test(data.mobile)) { + return S.toast('请输入正确的手机号') + } + + if (!data.code) { + return S.toast('请选择验证码') + } + + if (!data.password) { + return S.toast('请输入密码') + } + console.log(data, 19) + const { UserInfo } = api.user.reg(data) + console.log(UserInfo) + } + + handleChange = (name, val) => { + const { info } = this.state + info[name] = val + console.log(info) + } + + handleClickAgreement = () => { + console.log("用户协议") + } + + render () { + const { info } = this.state + + return ( + + + + + + + + + + 同意协议并注册 + + 已阅读并同意 + + 《用户协议》 + + + + + + ) + } +} diff --git a/src/pages/auth/reg.scss b/src/pages/auth/reg.scss new file mode 100644 index 000000000..4eb759719 --- /dev/null +++ b/src/pages/auth/reg.scss @@ -0,0 +1,17 @@ +@import "../../style/imports"; + +.address-edit { + &__form { + background: #fff; + padding: $edge-size; + margin: 0 0 $edge-margin; + + } + .accountAgreement{ + width: 100%; + text-align: center; + &__text { + color: $color-brand-primary; + } + } +}