Browse Source

修改注册,修改appid获取

new_Demand_20231129
战立标 2 years ago
parent
commit
9c2ed048cb
  1. 2
      src/api/user.js
  2. 12
      src/components/Perfect/index.vue
  3. 33
      src/router/index.js
  4. 6
      src/router/router.config.js
  5. 8
      src/store/modules/app.js
  6. 19
      src/utils/request.js
  7. 8
      src/views/login/index.vue
  8. 14
      src/views/register/index.less
  9. 98
      src/views/register/index.vue
  10. 65
      src/views/userInfo/index.vue

2
src/api/user.js

@ -33,7 +33,7 @@ export function register(data) {
return request({ return request({
url: `/auth/publicuser/register`, url: `/auth/publicuser/register`,
method: 'post', method: 'post',
message: '提交用户信息中...', message: '登录中...',
data data
}) })
} }

12
src/components/Perfect/index.vue

@ -1,5 +1,5 @@
<template> <template>
<van-dialog <!-- <van-dialog
v-model="show" v-model="show"
title="温馨提示" title="温馨提示"
confirm-button-text="立即注册" confirm-button-text="立即注册"
@ -9,11 +9,11 @@
show-cancel-button show-cancel-button
> >
<div class="tips">请先填写居民信息完成注册</div> <div class="tips">请先填写居民信息完成注册</div>
</van-dialog> </van-dialog>-->
</template> </template>
<script> <script>
import { checkWxmpRegister } from '@/api/user' // import { checkWxmpRegister } from '@/api/user'
export default { export default {
name: 'Perfect', name: 'Perfect',
@ -24,12 +24,12 @@ export default {
}, },
mounted() { mounted() {
console.log(this.$store.state.app.userInfo, 'this.$store.state.app') // console.log(this.$store.state.app.userInfo, 'this.$store.state.app')
checkWxmpRegister({ /* checkWxmpRegister({
userId: this.$store.state.app.userInfo.userId userId: this.$store.state.app.userInfo.userId
}).then(res => { }).then(res => {
this.show = !res this.show = !res
}) })*/
} }
} }
</script> </script>

33
src/router/index.js

@ -2,7 +2,7 @@ import Vue from 'vue'
import Router from 'vue-router' import Router from 'vue-router'
import store from '@/store' import store from '@/store'
import { constantRouterMap } from './router.config.js' import { constantRouterMap } from './router.config.js'
import { login } from '@/api/user' import { checkWxmpRegister, login } from '@/api/user'
import { title } from '@/config' import { title } from '@/config'
const whiteList = ['/login'] const whiteList = ['/login']
@ -50,6 +50,14 @@ function paramsFormat(params) {
} }
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
let urlParams = getQueryParams()
if (urlParams.appId) {
store.commit('SET_APP_ID', urlParams.appId)
localStorage.setItem('appId', urlParams.appId)
} else {
store.commit('SET_APP_ID', localStorage.getItem('appId'))
}
console.log(store.state.app.appId, 'store.state.app.appId')
if (to.params.type) { if (to.params.type) {
document.title = to.params.type === 'edit' ? '编辑' : '注册' document.title = to.params.type === 'edit' ? '编辑' : '注册'
} else { } else {
@ -57,7 +65,15 @@ router.beforeEach((to, from, next) => {
} }
if (localStorage.getItem('token')) { if (localStorage.getItem('token')) {
store.dispatch('getUserInfo').then(() => { store.dispatch('getUserInfo').then(() => {
next() checkWxmpRegister({
userId: store.state.app.userInfo.userId
}).then(res => {
if (res) {
next()
} else {
next('/register')
}
})
}) })
} else { } else {
if (getQueryStringByName('code')) { if (getQueryStringByName('code')) {
@ -77,7 +93,7 @@ router.beforeEach((to, from, next) => {
.replace(/:{"}/g, ':{}') .replace(/:{"}/g, ':{}')
console.log(state) console.log(state)
let path = `${location.origin}${location.pathname === '/' ? '' : location.pathname}` let path = `${location.origin}${location.pathname === '/' ? '' : location.pathname}`
if (state) { if (state && state != 'undefined') {
state = JSON.parse(state) state = JSON.parse(state)
console.log(state, 'state') console.log(state, 'state')
console.log(`${path}/#${state.path}?${paramsFormat(state.query)}`, 'sss') console.log(`${path}/#${state.path}?${paramsFormat(state.query)}`, 'sss')
@ -97,4 +113,15 @@ router.beforeEach((to, from, next) => {
} }
}) })
function getQueryParams() {
const url = window.location.href
const paramArr = url.slice(url.indexOf('?') + 1).split('&')
const params = {}
paramArr.map(param => {
const [key, val] = param.split('=')
params[key] = decodeURIComponent(val)
})
return params
}
export default router export default router

6
src/router/router.config.js

@ -49,5 +49,11 @@ export const constantRouterMap = [
name: 'appealDetail', name: 'appealDetail',
component: () => import('@/views/appealDetail'), component: () => import('@/views/appealDetail'),
meta: { title: '详情', keepAlive: false } meta: { title: '详情', keepAlive: false }
},
{
path: '/register',
name: 'register',
component: () => import('@/views/register'),
meta: { title: '注册', keepAlive: false }
} }
] ]

8
src/store/modules/app.js

@ -1,11 +1,15 @@
import { getUserWechatByUserId } from '@/api/user' import {checkWxmpRegister, getUserWechatByUserId} from '@/api/user'
const state = { const state = {
userInfo: {} userInfo: {},
appId: ''
} }
const mutations = { const mutations = {
SET_USER_INFO(state, userInfo) { SET_USER_INFO(state, userInfo) {
state.userInfo = userInfo state.userInfo = userInfo
},
SET_APP_ID(state, appId) {
state.appId = appId
} }
} }
const actions = { const actions = {

19
src/utils/request.js

@ -3,7 +3,7 @@ import { Toast, Dialog } from 'vant'
// 根据环境不同引入不同api地址 // 根据环境不同引入不同api地址
import { baseApi } from '@/config' import { baseApi } from '@/config'
import router from '@/router' import router from '@/router'
import route from '@/router' import store from '@/store'
import { Tips } from '@/utils/index' import { Tips } from '@/utils/index'
// create an axios instance // create an axios instance
const service = axios.create({ const service = axios.create({
@ -20,17 +20,20 @@ service.interceptors.request.use(
// loading // loading
Tips.loading(config.message) Tips.loading(config.message)
} }
config.headers['source'] = 'dev' config.headers['source'] = process.env.NODE_ENV !== 'production' ? 'dev' : 'prod'
if (localStorage.getItem('token')) { if (localStorage.getItem('token')) {
config.headers['Token'] = localStorage.getItem('token') config.headers['Token'] = localStorage.getItem('token')
} }
if (store.state.app.appId) {
config.headers['AppId'] = store.state.app.appId
}
config.baseURL = config.baseURL + '/' config.baseURL = config.baseURL + '/'
return config return config
}, },
error => { error => {
// do something with request error // do something with request error
console.log(error) // for debug console.log(error) // for debug
return Promise.reject(error) return Promise.reject(error)
} }
) )
@ -38,7 +41,6 @@ service.interceptors.request.use(
service.interceptors.response.use( service.interceptors.response.use(
response => { response => {
Toast.clear() Toast.clear()
console.log(route)
const res = response.data const res = response.data
if (res.status && res.status !== 200) { if (res.status && res.status !== 200) {
Tips.error(res.msg) Tips.error(res.msg)
@ -48,10 +50,11 @@ service.interceptors.response.use(
return Promise.resolve(res.data) return Promise.resolve(res.data)
} else { } else {
let loginCode = [10007, 401, 10001, 10005, 10006] let loginCode = [10007, 401, 10001, 10005, 10006]
console.log(loginCode, 'loginCode', loginCode.includes(res.code))
if (loginCode.includes(res.code)) { if (loginCode.includes(res.code)) {
localStorage.removeItem('token') localStorage.removeItem('token')
router.replace('/login?redirect=' + route.path + '&params=' + JSON.stringify(route.query)) router.replace(
'/login?redirect=' + router.currentRoute.path + '&params=' + JSON.stringify(router.currentRoute.query)
)
} }
Tips.error(res.msg) Tips.error(res.msg)
return Promise.reject(res || 'error') return Promise.reject(res || 'error')
@ -63,7 +66,9 @@ service.interceptors.response.use(
if (error.response.status === 401) { if (error.response.status === 401) {
Dialog({ message: '登录过期,请重新登录' }).then(() => { Dialog({ message: '登录过期,请重新登录' }).then(() => {
localStorage.removeItem('token') localStorage.removeItem('token')
router.replace('/login?redirect=' + route.path + '&params=' + JSON.stringify(route.query)) router.replace(
'/login?redirect=' + router.currentRoute.path + '&params=' + JSON.stringify(router.currentRoute.query)
)
}) })
} else { } else {
Tips.error(error.response.data.message) Tips.error(error.response.data.message)

8
src/views/login/index.vue

@ -3,7 +3,7 @@
</template> </template>
<script> <script>
import { wxId } from '@/config' import {wxId} from '@/config'
export default { export default {
name: 'login', name: 'login',
@ -21,8 +21,8 @@ export default {
login() { login() {
console.log('login') console.log('login')
let state = { let state = {
path: this.$route.query.redirect, path: this.$route.query.redirect ? this.$route.query.redirect : '',
query: this.$route.query.params query: this.$route.query.params ? this.$route.query.params : ''
} }
let path = `${location.origin}${location.pathname === '/' ? '' : location.pathname}` let path = `${location.origin}${location.pathname === '/' ? '' : location.pathname}`
let url = `//open.weixin.qq.com/connect/oauth2/authorize?appid=${wxId}&redirect_uri=${encodeURI( let url = `//open.weixin.qq.com/connect/oauth2/authorize?appid=${wxId}&redirect_uri=${encodeURI(
@ -35,6 +35,6 @@ export default {
} }
</script> </script>
<style scoped lang="less"> <style lang="less" scoped>
@import './index'; @import './index';
</style> </style>

14
src/views/register/index.less

@ -0,0 +1,14 @@
.block {
border-radius: 8px;
overflow: hidden;
margin-bottom: 10px;
}
/deep/ .van-cell__title {
width: 6.2em;
flex: 0 0 6.2em;
margin-right: 12px
}
.gender {
display: flex;
}

98
src/views/register/index.vue

@ -0,0 +1,98 @@
<template>
<div class="container">
<div class="block">
<van-field v-model="phone" label="手机号" placeholder="请输入" required />
<van-field v-model="smsCode" label="验证码" placeholder="请输入" required>
<template #button>
<van-button v-if="time === 60" round size="mini" type="info" @click="getCode">获取验证码</van-button>
<van-button v-else disabled round size="mini" type="info">{{ time }}s后重试</van-button>
</template>
</van-field>
</div>
<van-button block color="linear-gradient(to right, #81B5FB, #3E92FF)" round @click="submit">注册</van-button>
</div>
</template>
<script>
import { register, sendsmscode } from '@/api/user'
var leftTime
export default {
name: 'userInfo',
data() {
return {
form: {},
time: 60,
userInfo: {},
phone: '',
smsCode: '',
surName: '',
gender: '',
userId: ''
}
},
mounted() {
this.init()
},
destroyed() {
clearInterval(leftTime)
},
methods: {
init() {
this.type = this.$route.params.type ? this.$route.params.type : ''
this.userInfo = this.$store.state.app.userInfo
this.gender = this.userInfo.gender
this.surName = this.userInfo.realName || this.userInfo.nickname
},
submit() {
let params = {
phone: this.phone,
smsCode: this.smsCode,
surName: this.surName,
appid: this.$store.state.app.appId
}
if (!params.phone) {
this.$toast.fail('请输入手机号')
return
}
if (!params.smsCode) {
this.$toast.fail('请输入验证码')
return
}
register(params).then(res => {
localStorage.setItem('token', res.token)
this.$toast.success('登录成功')
let path = '/'
this.$router.replace(path)
})
},
getCode() {
if (!this.phone) {
this.$toast.fail('请输入手机号')
return false
}
if (!/1[3456789]\d{9}/.test(this.phone)) {
this.$toast.fail('手机号格式错误')
return false
}
sendsmscode({
phone: this.phone
}).then(() => {
leftTime = setInterval(() => {
if (this.time > 0) {
this.time--
} else {
this.time = 60
clearInterval(leftTime)
}
}, 1000)
})
}
}
}
</script>
<style lang="less" scoped>
@import './index';
</style>

65
src/views/userInfo/index.vue

@ -335,14 +335,15 @@ export default {
// //
getAllAgencyStreet() { getAllAgencyStreet() {
getAllAgencyStreet({}).then(res => { getAllAgencyStreet({}).then(res => {
console.log(res, 'resresres')
this.streetOptions = res this.streetOptions = res
? res.map(item => { ? res.map(item => {
return { return {
label: item.organizationName, label: item.organizationName,
value: item.id, value: item.id,
customerId: item.customerId customerId: item.customerId
} }
}) })
: [] : []
this.communityOptions = [] this.communityOptions = []
console.log(this.city) console.log(this.city)
@ -365,11 +366,11 @@ export default {
}).then(res => { }).then(res => {
this.communityOptions = res this.communityOptions = res
? res.map(item => { ? res.map(item => {
return { return {
label: item.organizationName, label: item.organizationName,
value: item.id value: item.id
} }
}) })
: [] : []
// this.quarterOptions = [] // this.quarterOptions = []
}) })
@ -381,12 +382,12 @@ export default {
}).then(res => { }).then(res => {
this.quarterOptions = res this.quarterOptions = res
? res.map(item => { ? res.map(item => {
return { return {
label: item.label, label: item.label,
value: item.value, value: item.value,
gridId: item.pid gridId: item.pid
} }
}) })
: [] : []
// this.buildingOptions = [] // this.buildingOptions = []
}) })
@ -398,11 +399,11 @@ export default {
}).then(res => { }).then(res => {
this.buildingOptions = res this.buildingOptions = res
? res.map(item => { ? res.map(item => {
return { return {
label: item.label, label: item.label,
value: item.value value: item.value
} }
}) })
: [] : []
// this.unitOptions = [] // this.unitOptions = []
}) })
@ -414,11 +415,11 @@ export default {
}).then(res => { }).then(res => {
this.unitOptions = res this.unitOptions = res
? res.map(item => { ? res.map(item => {
return { return {
label: item.label, label: item.label,
value: item.value value: item.value
} }
}) })
: [] : []
// this.houseOptions = [] // this.houseOptions = []
}) })
@ -430,11 +431,11 @@ export default {
}).then(res => { }).then(res => {
this.houseOptions = res this.houseOptions = res
? res.map(item => { ? res.map(item => {
return { return {
label: item.label, label: item.label,
value: item.value value: item.value
} }
}) })
: [] : []
}) })
} }

Loading…
Cancel
Save