新增管理端登录方法和场景示例
This commit is contained in:
@@ -20,8 +20,11 @@ export const user = {
|
||||
const actions = {
|
||||
std: "/app/appwechatuser/check",
|
||||
qujing: "/app/appwechatuserqujing/check",
|
||||
admin: "/app/appwechatusertog/userinfo"
|
||||
}
|
||||
return http.post(actions[way]).then(res => {
|
||||
return http.post(actions[way], null, {
|
||||
params: {corpId: process.env.NODE_ENV == "development" ? "ww596787bb70f08288" : undefined},
|
||||
}).then(res => {
|
||||
if (res?.data) {
|
||||
commit('setUser', res.data)
|
||||
return Promise.all([])
|
||||
@@ -64,16 +67,36 @@ export const user = {
|
||||
})
|
||||
} else return Promise.reject("缺少登录code")
|
||||
},
|
||||
getAdminToken({commit}, params) {
|
||||
const {corpId = process.env.NODE_ENV == "development" ? "ww596787bb70f08288" : undefined} = params
|
||||
if (params?.code) {
|
||||
return http.post("/auth/wechat-2g/token", params, {
|
||||
headers: {"Authorization": "Basic d2VjaGF0OndlY2hhdA=="},
|
||||
params: {corpId},
|
||||
withoutToken: true
|
||||
}).then(res => {
|
||||
if (res?.access_token) {
|
||||
const token = [res?.token_type, res?.access_token].join(" ").trim()
|
||||
commit("setToken", token)
|
||||
return token
|
||||
} else {
|
||||
uni.showToast({title: res?.msg})
|
||||
return Promise.reject(res?.msg)
|
||||
}
|
||||
})
|
||||
} else return Promise.reject("缺少登录code")
|
||||
},
|
||||
autoLogin({dispatch}, params = {nickName: '微信用户'}) {
|
||||
const {loginWay = 'std'} = params
|
||||
return dispatch("getCode").then(code => dispatch("getToken", {...params, code})).then(() => dispatch('getUserInfo', loginWay))
|
||||
const {loginWay = 'std', phoneCode} = params
|
||||
if (loginWay == "admin") {
|
||||
return phoneCode ? dispatch("getCode", params).then(code => dispatch('getAdminToken', {...params, code})).then(() => dispatch('getUserInfo', loginWay)) : Promise.reject("缺少手机号授权")
|
||||
} else return dispatch("getCode").then(code => dispatch("getToken", {...params, code})).then(() => dispatch('getUserInfo', loginWay))
|
||||
},
|
||||
authCheck({state, dispatch, rootState}, {checkType, modulePath}) {
|
||||
//用于进入应用的权限判断
|
||||
//checkType 1、登录认证 2、居民认证 3、党员认证 4、丰都个人认证
|
||||
//判断是否需要校验认证信息
|
||||
let {user: userInfo, token} = rootState
|
||||
console.log();
|
||||
if (!checkType) {
|
||||
//如果需要校验认证信息,必定要先验证是否登录
|
||||
uni.navigateTo({url: modulePath});
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
<div class="home">
|
||||
<div class="header-bg">
|
||||
<div class="header-info">
|
||||
<div class="wrap" @click="handleLogin()">
|
||||
<div class="wrap">
|
||||
<div class="user-img-div">
|
||||
<open-data type="userAvatarUrl" lang="zh_CN" class="user-img"></open-data>
|
||||
</div>
|
||||
<div class="user-info">
|
||||
<div class="user-info" @click="handleLogin()">
|
||||
<div class="option">
|
||||
<template v-if="!user.id">
|
||||
<p>登录</p>
|
||||
@@ -19,6 +19,7 @@
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<button class="phoneBtn" open-type="getPhoneNumber" @getphonenumber="handleAdminLogin">管理账号登录</button>
|
||||
</div>
|
||||
<input class="codeText" v-model="search" placeholder="搜索要查找的应用"/>
|
||||
</div>
|
||||
@@ -63,6 +64,11 @@ export default {
|
||||
this.autoLogin();
|
||||
} else this.$u.toast("已登录,无需重新登录!")
|
||||
},
|
||||
handleAdminLogin({detail: {code: phoneCode}}) {
|
||||
if (!this.token) {
|
||||
this.autoLogin({corpId: "ww596787bb70f08288", loginWay: 'admin', phoneCode});
|
||||
} else this.$u.toast("已登录,无需重新登录!")
|
||||
},
|
||||
handleGotoApp(app) {
|
||||
uni.navigateTo({url: `${app.path}`})
|
||||
},
|
||||
@@ -201,5 +207,13 @@ export default {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.phoneBtn {
|
||||
font-size: 34px;
|
||||
font-weight: 600;
|
||||
color: #333333;
|
||||
line-height: 54px;
|
||||
background: transparent;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user