<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="18" 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 {
|
loginPost,
|
getUserInfo,
|
sendSMsPost,
|
ywWxAuthorize,
|
getRecordByUserPoint
|
} 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 {
|
name: 'login',
|
data () {
|
return {
|
form: { phone: '', code: '' },
|
ywinfo: {},
|
downTime: 0,
|
code: '',
|
devMockTip: devWechatMock.enabled ? `开发模式:模拟 openid ${devWechatMock.openId}` : ''
|
}
|
},
|
onLoad (option) {
|
uni.setStorageSync('userType', 0)
|
const ywinfo = uni.getStorageSync('ywinfo') || {}
|
if (ywinfo.ywid && (ywinfo.type || ywinfo.type == 0)) {
|
this.ywinfo = ywinfo
|
uni.setStorageSync('ywinfo', {})
|
}
|
if (option.ywid || option.ywid == 0) {
|
uni.setStorageSync('ywinfo', {
|
type: option.type,
|
ywid: option.ywid
|
})
|
}
|
},
|
onShow () {
|
const that = this
|
runWechatOAuthFlow({
|
authorizeApi: ywWxAuthorize,
|
fallbackCode: this.code,
|
onSuccess: (res) => {
|
if (res.data.openid) {
|
that.$store.commit('setOpenId', res.data.openid)
|
}
|
if (res.data.token && res.data.token != '') {
|
that.$store.commit('setToken', res.data.token)
|
getUserInfo().then(ress => {
|
that.$store.commit('setUserInfo', ress.data)
|
})
|
const ywinfo = this.ywinfo
|
if (ywinfo.ywid && (ywinfo.type || ywinfo.type == 0)) {
|
getRecordByUserPoint({ pointCode: ywinfo.ywid }).then(res => {
|
if (res.data && res.data.id) {
|
uni.redirectTo({ url: '/pages/polling/point?id=' + res.data.id })
|
} else {
|
uni.redirectTo({ url: '/pages/polling/empty?message=' + res.message })
|
}
|
})
|
} else {
|
setTimeout(() => {
|
uni.redirectTo({ url: '/pages/index' })
|
}, 300)
|
}
|
}
|
}
|
})
|
},
|
methods: {
|
...mapMutations(['setToken', 'setUserInfo']),
|
goRoleSelect () {
|
uni.redirectTo({ url: '/pages/roleSelect?switch=1' })
|
},
|
onLogin () {
|
const { form } = this
|
if (!form.phone) return uni.showToast({ title: '手机号不能为空', icon: 'none' })
|
if (!form.code) return uni.showToast({ title: '验证码不能为空', icon: 'none' })
|
|
loginPost({
|
...form,
|
openid: this.$store.state.openId
|
}).then(res => {
|
if (res.code === 200) {
|
this.setToken(res.data)
|
getUserInfo().then(ress => {
|
this.setUserInfo(ress.data)
|
const ywinfo = this.ywinfo
|
if (ywinfo.ywid && (ywinfo.type || ywinfo.type == 0)) {
|
getRecordByUserPoint({ pointCode: ywinfo.ywid }).then(res => {
|
if (res.data && res.data.id) {
|
uni.redirectTo({ url: '/pages/polling/point?id=' + res.data.id })
|
} else {
|
uni.redirectTo({ url: '/pages/polling/empty?message=' + res.message })
|
}
|
})
|
} else {
|
uni.redirectTo({ url: '/pages/index' })
|
}
|
})
|
}
|
})
|
},
|
sendSms () {
|
requestLoginSmsCode(this, this.form.phone, sendSMsPost, { phone: this.form.phone, userType: 0 })
|
}
|
}
|
}
|
</script>
|