<template>
|
<view class="cu-login">
|
<view class="cu-auth-topbar">
|
<view class="cu-auth-topbar__btn" @click="goRoleSelect">
|
<u-icon name="reload" color="#2080f7" size="22" />
|
</view>
|
</view>
|
|
<view class="cu-login__brand">
|
<view class="cu-login__title">商户登录</view>
|
<view class="cu-login__sub">阜宁文体中心 · 商户服务平台</view>
|
</view>
|
|
<view v-if="devMockTip" class="cu-login__tip">{{ devMockTip }}</view>
|
|
<view class="cu-input-wrap">
|
<input v-model="form.phone" maxlength="11" type="number" placeholder="请输入手机号" />
|
</view>
|
<view class="cu-input-wrap">
|
<input v-model="form.code" placeholder="请输入验证码" />
|
<view v-if="downTime == 0" class="cu-sms-btn" @click="sendSms">获取验证码</view>
|
<view v-else class="cu-sms-btn cu-sms-btn--disabled">{{ downTime }}s</view>
|
</view>
|
|
<view class="cu-btn cu-btn--primary" @click="onLogin">登录</view>
|
</view>
|
</template>
|
|
<script>
|
import { customerLogin, customerGetUserInfo, customerWxAuthorize, customerSendLoginSms } from '@/api'
|
import { devWechatMock } from '@/utils/config.js'
|
import { runWechatOAuthFlow } from '@/utils/wechatAuth.js'
|
import { requestLoginSmsCode } from '@/utils/loginSms.js'
|
import { mapMutations } from 'vuex'
|
|
export default {
|
data () {
|
return {
|
form: { phone: '', code: '' },
|
downTime: 0,
|
devMockTip: devWechatMock.enabled ? `开发模式:模拟 openid ${devWechatMock.openId}` : ''
|
}
|
},
|
onShow () {
|
uni.setStorageSync('userType', 1)
|
runWechatOAuthFlow({
|
authorizeApi: customerWxAuthorize,
|
onSuccess: (res) => {
|
if (res.data.openid) this.setOpenId(res.data.openid)
|
if (res.data.token) {
|
this.setToken(res.data.token)
|
this.setUserType(1)
|
customerGetUserInfo().then(r => this.setUserInfo(r.data))
|
uni.redirectTo({ url: '/pages/customer/index' })
|
}
|
}
|
})
|
},
|
methods: {
|
...mapMutations(['setToken', 'setUserInfo', 'setOpenId', 'setUserType']),
|
goRoleSelect () {
|
uni.redirectTo({ url: '/pages/roleSelect?switch=1' })
|
},
|
onLogin () {
|
if (!this.form.phone || !this.form.code) {
|
return uni.showToast({ title: '请填写手机号和验证码', icon: 'none' })
|
}
|
customerLogin({ ...this.form, openid: this.$store.state.openId, userType: 1 }).then(res => {
|
if (res.code === 200) {
|
this.setToken(res.data)
|
this.setUserType(1)
|
customerGetUserInfo().then(r => this.setUserInfo(r.data))
|
uni.redirectTo({ url: '/pages/customer/index' })
|
}
|
})
|
},
|
sendSms () {
|
requestLoginSmsCode(this, this.form.phone, customerSendLoginSms)
|
}
|
}
|
}
|
</script>
|