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.
128 lines
2.7 KiB
128 lines
2.7 KiB
import store from "../store.js" |
|
import request from './request.js' |
|
import alert from './alert.js' |
|
|
|
const login = { |
|
checkAuth(callback) { |
|
console.log(1); |
|
if (this.getLocalUserInfo()) { |
|
console.log(2); |
|
callback(true) |
|
} else { |
|
console.log(3); |
|
callback(false); |
|
console.log('未获取到用户本地数据,去获取授权设置', 22222222) |
|
this.askLogin() |
|
} |
|
}, |
|
|
|
getLocalUserInfo() { |
|
const user = uni.getStorageSync("token"); |
|
console.log('从本地存储中获取用户数据', user, 11111111); |
|
if (!user) return false; |
|
if (!user.token) return false; |
|
store.commit('saveToken', user); |
|
return true |
|
}, |
|
|
|
noCase() { |
|
alert.showError('案件不存在'); |
|
setTimeout(() => { |
|
uni.switchTab({ |
|
url: '/pages/case/caseList/caseList' |
|
}); |
|
}, 1500); |
|
}, |
|
|
|
askLogin() { |
|
uni.showModal({ |
|
title: '尚未登录', |
|
content: '前往授权登录页面吗?', |
|
success(res) { |
|
console.log(res) |
|
if (res.confirm) { |
|
uni.navigateTo({ |
|
url: '/pages/login/login' |
|
}) |
|
} |
|
} |
|
}) |
|
}, |
|
|
|
getUserProfile(data) { |
|
const that = this; |
|
console.log(data); |
|
// return |
|
wx.getUserProfile({ |
|
lang: 'zh_CN', |
|
desc: '用于完善会员资料', |
|
success (res) { |
|
that.login(data,res) |
|
}, |
|
fail (e) { |
|
console.error('获取用户身份信息失败了', e); |
|
alert.showError('获取失败') |
|
} |
|
}) |
|
}, |
|
|
|
login(data) { |
|
const that = this; |
|
uni.showLoading({ |
|
title: '登录中', |
|
}); |
|
wx.login({ |
|
success: res => { |
|
console.log(res, '----------- login获取的 -----------') |
|
const code = res.code; |
|
console.log(res.code); |
|
request.post('/api/Accounts/SignIn', { |
|
wechatToken:code, |
|
username:data.name, |
|
password:data.password |
|
}, function(data, res) { |
|
uni.hideLoading(); |
|
console.log(data, res ,'----------后端传回来的----------') |
|
if(res.status==500){ |
|
return alert.showError("用户名或密码错误") |
|
} |
|
uni.setStorageSync("token", res) |
|
store.commit('saveToken', res) |
|
console.log(store.state.token); |
|
request.get("/api/Accounts/Profile", {}, (data, res) => { |
|
console.log(res); |
|
uni.setStorageSync("user", res) |
|
uni.reLaunch({ |
|
url: "/pages/index/index", |
|
|
|
}) |
|
}) |
|
|
|
}) |
|
}, |
|
fail: err => { |
|
console.error(err, 8877897) |
|
} |
|
}) |
|
}, |
|
|
|
logout() { |
|
store.state.user = { |
|
user: null, |
|
path: '/pages/login/login' |
|
} |
|
store.commit('saveToken', null) |
|
// uni.setStorageSync("token",null); |
|
uni.clearStorage(); |
|
uni.reLaunch({ |
|
url: '/pages/login/login' |
|
}) |
|
|
|
console.log('退出登录。。。', this.user) |
|
}, |
|
|
|
|
|
|
|
} |
|
|
|
export default login
|
|
|