104 lines
2.1 KiB
JavaScript
104 lines
2.1 KiB
JavaScript
// import {
|
|
// login
|
|
// } from '@/api/login.js'
|
|
|
|
// function codes() {
|
|
// // #ifdef MP-WEIXIN
|
|
// uni.login({
|
|
// success: (res) => {
|
|
// console.log(res);
|
|
// if (res.errMsg == "login:ok") {
|
|
// login({
|
|
// code: res.code,
|
|
// org_id: getApp().globalData.org_id,
|
|
// }).then(response => {
|
|
// //注册的 保存token
|
|
|
|
// if (response.data.token) {
|
|
// uni.setStorageSync('token', response.data.token)
|
|
// uni.reLaunch({
|
|
// url: '/pages/home/home'
|
|
// })
|
|
// }
|
|
// else {
|
|
// uni.reLaunch({
|
|
// url: '/pages/mine/edit-info?type=register'
|
|
// })
|
|
// }
|
|
// })
|
|
// } else {
|
|
// uni.showToast({
|
|
// title: '系统异常,请联系管理员!'
|
|
// })
|
|
// }
|
|
// }
|
|
// })
|
|
// // #endif
|
|
|
|
// }
|
|
// export default {
|
|
// codes
|
|
// }
|
|
|
|
|
|
|
|
import {
|
|
login
|
|
} from '@/api/login.js'
|
|
|
|
function codes() {
|
|
return new Promise((resolve, reject) => {
|
|
// #ifdef MP-WEIXIN
|
|
uni.login({
|
|
success: (res) => {
|
|
console.log(res);
|
|
if (res.errMsg == "login:ok") {
|
|
login({
|
|
code: res.code,
|
|
org_id: getApp().globalData.org_id,
|
|
}).then(response => {
|
|
// 注册的保存token
|
|
if (response.data.token) {
|
|
uni.setStorageSync('token', response.data.token);
|
|
resolve(response.data.token); // 返回新的 token
|
|
uni.reLaunch({
|
|
url: '/pages/home/home'
|
|
});
|
|
} else {
|
|
uni.showModal({
|
|
title: '提示',
|
|
content: '请先用户注册',
|
|
success: function(res) {
|
|
if (res.confirm) {
|
|
uni.reLaunch({
|
|
url: '/pages/mine/edit-info?type=register'
|
|
});
|
|
} else if (res.cancel) {
|
|
uni.navigateBack({
|
|
delta: 1
|
|
})
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}).catch(err => {
|
|
reject(err); // 处理请求错误
|
|
});
|
|
} else {
|
|
uni.showToast({
|
|
title: '系统异常,请联系管理员!'
|
|
});
|
|
reject(new Error('Login failed'));
|
|
}
|
|
},
|
|
fail: () => {
|
|
reject(new Error('Login failed'));
|
|
}
|
|
});
|
|
// #endif
|
|
});
|
|
}
|
|
|
|
export default {
|
|
codes
|
|
} |