public-opinion/pagesA/login/login.vue

110 lines
3.0 KiB
Vue
Raw Normal View History

2022-07-30 16:05:50 +08:00
<template>
<view class="disjcac fc">
<image src="/static/icon/icon-login.png" style="width: 220rpx;height: 220rpx;margin: 320rpx 0 70rpx 0;" mode=""></image>
<view class="fon36 bold">洛河民意通</view>
<view class="disjcac enter-btn posir">
授权登录
<button :disabled="ifFlag" @click="bindGetUserInfo" class="posia syxzo">立即授权</button>
</view>
<view class="fon30" style="color: #484848;">如您点击授权您将同意授权免责声明</view>
</view>
</template>
<script>
export default {
data() {
return {
userInfo:'',
ifFlag:false
}
},
methods: {
//调起登录授权
bindGetUserInfo() {
if(!this.ifFlag){
this.$toolAll.tools.showToast('正在调起授权','none',6000);
this.ifFlag = true;
wx.getSetting({
success: (result)=> {
uni.hideToast();
// 判断是否授权
if (result.authSetting['scope.userInfo']) {
// 已授权
this.getUserInfoEv();
} else {
// 未授权
this.getUserInfoEv();
}
}
})
}
},
// 获取用户信息事件
getUserInfoEv(){
// #ifdef MP-WEIXIN
// 微信新版获取用户信息方式(也可用于授权手机号)
wx.getUserProfile({
lang:'zh_CN',
desc:'获取亲的昵称、头像及性别',
success: (resEnd)=> {
this.userInfo = resEnd.userInfo;
//用户已经授权过,添加用户信息
uni.login({
provider: 'weixin',
success: (rescode)=> {
this.updateUserInfo(rescode.code);
2022-07-30 16:05:50 +08:00
},
});
},
complete: () => {
this.ifFlag = false;
}
});
// #endif
},
//调用登录接口
updateUserInfo(code) {
var params = {
code:code,
nickname: this.userInfo.nickName,//用户昵称
headimgurl: this.userInfo.avatarUrl,//用户头像
country: this.userInfo.country,//用户所在国家
gender: this.userInfo.gender,//用户性别
language:this.userInfo.language,//语言
is_active:1
}
this.$requst.post('user/login',params).then(res => {
if(res.code==0){
// utype['def' => '普通用户', 'community_worker' => '社区工作人员', 'community_secretary' => '社区书记', 'area_leader' => '片区领导', 'app_manager' => '小程序端管理员']
// this.$store.commit('setRule',res.data.utype);
let dataObj = res.data;
uni.setStorageSync('token',dataObj.token);
if(dataObj.utype=='def'){
// 前往群众对应的列表页
2022-07-30 16:05:50 +08:00
uni.reLaunch({
2022-07-30 18:19:04 +08:00
url:'/pagesA/my-opinion-list/my-opinion-list'
2022-07-30 16:05:50 +08:00
})
}
if(dataObj.utype=='community_worker'){
// 前往社区对应的列表页
uni.reLaunch({
url:'/pagesA/community/opinion-handle/opinion-handle'
})
}
if(dataObj.utype=='app_manager'){
// 前往管理员对应的列表页
uni.reLaunch({
url:'/pagesA/manager/examine-list/examine-list'
})
}
2022-07-30 16:05:50 +08:00
}
},error => {})
}
}
}
</script>
<style>
</style>