移动端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.8 KiB

2 months ago
<script>
export default {
onLaunch: function() {
// 静默登录
uni.login({
success(res) {
uni.$u.http.post('/login', {
code: res.code
}).then(res => {
// 获取token
const token = 'Bearer ' + res.data.data
// 全局存储令牌
// console.log(token);
uni.$u.vuex('vuex_token', token);
uni.$u.http.setConfig((config) => {
config.header = {
authorization: token
};
return config
})
// 获取用户接口数据
uni.$u.http.get('/getInfo', {}).then(res => {
console.log(res.data);
let user = {
roles: res.data.roles,
permissions: res.data.permissions,
// avatar: res.data.user.avatar,
avatar: 'https://jzhome.cn/static/gongan.png',
realName: res.data.user.realName,
sex: res.data.user.sex,
phonenumber: res.data.user.phonenumber,
deptName: res.data.user.deptName,
userType: res.data.user.userType,
}
// 全局存储用户数据
uni.$u.vuex('vuex_user', user);
// 跳转到局内注册
// if (user.userType !== "00") {
// uni.$u.route('/pages/index/off_reg');
// }
}).catch(err => {
console.log('您没有访问权限');
})
// 获取部门接口数据
uni.$u.http.get('/dept/list', {}).then(res => {
uni.$u.vuex('vuex_dept', res.data.data);
})
}).catch(err => {
console.log('访问失败');
})
}
});
},
onShow: function() {
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
}
}
</script>
<style lang="scss">
/* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
@import "@/uni_modules/uview-ui/index.scss";
page {
background-color: #F9F9F9;
}
</style>