feat(auth): 实现第三方登录集成
- 在 careerfair.vue 中新增 thirdLogin 方法处理单点登录逻辑 - 修改 goDetail 方法,在跳转前执行第三方登录验证 - 在 packageB/train/index.vue 中增加 onLoad 钩子调用 thirdLogin - 修改 jumps 方法,确保页面跳转前完成登录验证 - 在 request.js 中注释掉全局错误提示,避免重复提示 - 优化 videoDetail.vue 中的 getHeart 方法,移除冗余跳转逻辑 - 在 videoList.vue 中新增 playVideo 前的登录校验 - 统一多个页面中的 thirdLogin 实现,确保登录态一致性
This commit is contained in:
@@ -58,9 +58,58 @@ const { $api, navTo, vacanciesTo, formatTotal, config } = inject('globalFunction
|
|||||||
import useUserStore from '@/stores/useUserStore';
|
import useUserStore from '@/stores/useUserStore';
|
||||||
import useDictStore from '@/stores/useDictStore';
|
import useDictStore from '@/stores/useDictStore';
|
||||||
|
|
||||||
function jumps(url){
|
onLoad(() => {
|
||||||
|
thirdLogin()
|
||||||
|
});
|
||||||
|
|
||||||
|
async function jumps(url){
|
||||||
|
if(await thirdLogin()){
|
||||||
navTo(url);
|
navTo(url);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function thirdLogin(){
|
||||||
|
let form={}
|
||||||
|
if (uni.getStorageSync('userInfo').isCompanyUser=='1') {
|
||||||
|
form={
|
||||||
|
usertype: '1',
|
||||||
|
idno: uni.getStorageSync('userInfo').idCard,
|
||||||
|
name: uni.getStorageSync('userInfo').name,
|
||||||
|
enterprisecode:"",
|
||||||
|
enterprisename: "",
|
||||||
|
contactperson: "",
|
||||||
|
contactphone: "",
|
||||||
|
}
|
||||||
|
}else if (uni.getStorageSync('userInfo').isCompanyUser=='0') {
|
||||||
|
form={
|
||||||
|
usertype: "2",
|
||||||
|
enterprisecode: uni.getStorageSync('userInfo').idCard,
|
||||||
|
enterprisename: uni.getStorageSync('userInfo').name,
|
||||||
|
contactperson: "",
|
||||||
|
contactphone: "",
|
||||||
|
idno: "",
|
||||||
|
name: ""
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'none',
|
||||||
|
title: '请先登录'
|
||||||
|
})
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var resLogin = await $api.myRequest('/auth/login2/ks',form,'post',10100);
|
||||||
|
if (resLogin.code=='200') {
|
||||||
|
uni.setStorageSync('Padmin-Token', resLogin.data.access_token)
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'none',
|
||||||
|
title: '单点异常'
|
||||||
|
})
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="stylus" scoped>
|
<style lang="stylus" scoped>
|
||||||
|
|||||||
@@ -202,12 +202,10 @@ function getData() {
|
|||||||
function getHeart() {
|
function getHeart() {
|
||||||
const raw = uni.getStorageSync("Padmin-Token");
|
const raw = uni.getStorageSync("Padmin-Token");
|
||||||
const token = typeof raw === "string" ? raw.trim() : "";
|
const token = typeof raw === "string" ? raw.trim() : "";
|
||||||
const headers = token ? { Authorization: raw.startsWith("Bearer ") ? raw : `Bearer ${token}` }: {}
|
const headers = token ? { Authorization: raw.startsWith("Bearer ") ? raw : `Bearer ${token}` }: {};
|
||||||
$api.myRequest("/dashboard/auth/heart", {}, "POST", 10100, headers).then((resData) => {
|
$api.myRequest("/dashboard/auth/heart", {}, "POST", 10100, headers).then((resData) => {
|
||||||
if (resData.code == 200) {
|
if (resData.code == 200) {
|
||||||
getUserInfo();
|
getUserInfo();
|
||||||
} else {
|
|
||||||
navTo('/packageB/login')
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -218,6 +216,7 @@ function getUserInfo(){
|
|||||||
$api.myRequest('/system/user/login/user/info', {},'get',10100,header).then((resData) => {
|
$api.myRequest('/system/user/login/user/info', {},'get',10100,header).then((resData) => {
|
||||||
userId.value=resData.info.userId
|
userId.value=resData.info.userId
|
||||||
getData()
|
getData()
|
||||||
|
updateVideoInfo()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function getDictionary(){
|
function getDictionary(){
|
||||||
@@ -277,6 +276,9 @@ function updateVideoInfo(){
|
|||||||
'Authorization':uni.getStorageSync('Padmin-Token'),
|
'Authorization':uni.getStorageSync('Padmin-Token'),
|
||||||
'Content-Type': "application/x-www-form-urlencoded"
|
'Content-Type': "application/x-www-form-urlencoded"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$api.myRequest("/dashboard/auth/heart", {}, "POST", 10100, header).then((resData) => {
|
||||||
|
if (resData.code == 200) {
|
||||||
if(videoInfo.value.isCollect===null && videoInfo.value.process ===null){
|
if(videoInfo.value.isCollect===null && videoInfo.value.process ===null){
|
||||||
$api.myRequest('/train/public/videoUser/add', paramsData,'post',9100,header).then((resData) => {
|
$api.myRequest('/train/public/videoUser/add', paramsData,'post',9100,header).then((resData) => {
|
||||||
console.log("视频播放时长更新成功")
|
console.log("视频播放时长更新成功")
|
||||||
@@ -287,6 +289,8 @@ function updateVideoInfo(){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
// 计算并上报停留时长
|
// 计算并上报停留时长
|
||||||
function reportPageDuration() {
|
function reportPageDuration() {
|
||||||
const duration = Date.now() - pageEnterTime.value // 毫秒
|
const duration = Date.now() - pageEnterTime.value // 毫秒
|
||||||
|
|||||||
@@ -80,7 +80,8 @@ const getItemBackgroundStyle = (imageName) => ({
|
|||||||
});
|
});
|
||||||
const trainVideoImgUrl=config.trainVideoImgUrl
|
const trainVideoImgUrl=config.trainVideoImgUrl
|
||||||
|
|
||||||
onLoad(() => {
|
onLoad(async () => {
|
||||||
|
await thirdLogin()
|
||||||
getDataList('refresh');
|
getDataList('refresh');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -135,9 +136,54 @@ function getDataList(type = 'add') {
|
|||||||
|
|
||||||
|
|
||||||
// 播放视频
|
// 播放视频
|
||||||
function playVideo(video) {
|
async function playVideo(video) {
|
||||||
|
if(await thirdLogin()){
|
||||||
navTo(`/packageB/train/video/videoDetail?id=${video.videoId}`);
|
navTo(`/packageB/train/video/videoDetail?id=${video.videoId}`);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function thirdLogin(){
|
||||||
|
let form={}
|
||||||
|
if (uni.getStorageSync('userInfo').isCompanyUser=='1') {
|
||||||
|
form={
|
||||||
|
usertype: '1',
|
||||||
|
idno: uni.getStorageSync('userInfo').idCard,
|
||||||
|
name: uni.getStorageSync('userInfo').name,
|
||||||
|
enterprisecode:"",
|
||||||
|
enterprisename: "",
|
||||||
|
contactperson: "",
|
||||||
|
contactphone: "",
|
||||||
|
}
|
||||||
|
}else if (uni.getStorageSync('userInfo').isCompanyUser=='0') {
|
||||||
|
form={
|
||||||
|
usertype: "2",
|
||||||
|
enterprisecode: uni.getStorageSync('userInfo').idCard,
|
||||||
|
enterprisename: uni.getStorageSync('userInfo').name,
|
||||||
|
contactperson: "",
|
||||||
|
contactphone: "",
|
||||||
|
idno: "",
|
||||||
|
name: ""
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'none',
|
||||||
|
title: '请先登录'
|
||||||
|
})
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var resLogin = await $api.myRequest('/auth/login2/ks',form,'post',10100);
|
||||||
|
if (resLogin.code=='200') {
|
||||||
|
uni.setStorageSync('Padmin-Token', resLogin.data.access_token)
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'none',
|
||||||
|
title: '单点异常'
|
||||||
|
})
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="stylus" scoped>
|
<style lang="stylus" scoped>
|
||||||
|
|||||||
@@ -143,13 +143,59 @@
|
|||||||
// startDate: currentDate,
|
// startDate: currentDate,
|
||||||
// });
|
// });
|
||||||
// weekList.value = result;
|
// weekList.value = result;
|
||||||
|
if(thirdLogin()){
|
||||||
getHeart();
|
getHeart();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
onShow(() => {
|
onShow(() => {
|
||||||
// 更新自定义tabbar选中状态
|
// 更新自定义tabbar选中状态
|
||||||
tabbarManager.updateSelected(1);
|
tabbarManager.updateSelected(1);
|
||||||
});
|
});//
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async function thirdLogin(){
|
||||||
|
let form={}
|
||||||
|
if (uni.getStorageSync('userInfo').isCompanyUser=='1') {
|
||||||
|
form={
|
||||||
|
usertype: '1',
|
||||||
|
idno: uni.getStorageSync('userInfo').idCard,
|
||||||
|
name: uni.getStorageSync('userInfo').name,
|
||||||
|
enterprisecode:"",
|
||||||
|
enterprisename: "",
|
||||||
|
contactperson: "",
|
||||||
|
contactphone: "",
|
||||||
|
}
|
||||||
|
}else if (uni.getStorageSync('userInfo').isCompanyUser=='0') {
|
||||||
|
form={
|
||||||
|
usertype: "2",
|
||||||
|
enterprisecode: uni.getStorageSync('userInfo').idCard,
|
||||||
|
enterprisename: uni.getStorageSync('userInfo').name,
|
||||||
|
contactperson: "",
|
||||||
|
contactphone: "",
|
||||||
|
idno: "",
|
||||||
|
name: ""
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'none',
|
||||||
|
title: '请先登录'
|
||||||
|
})
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var resLogin = await $api.myRequest('/auth/login2/ks',form,'post',10100);
|
||||||
|
if (resLogin.code=='200') {
|
||||||
|
uni.setStorageSync('Padmin-Token', resLogin.data.access_token)
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'none',
|
||||||
|
title: '单点异常'
|
||||||
|
})
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// 监听退出登录事件,显示微信登录弹窗
|
// 监听退出登录事件,显示微信登录弹窗
|
||||||
@@ -168,7 +214,9 @@
|
|||||||
// 可以在这里添加登录成功后的处理逻辑
|
// 可以在这里添加登录成功后的处理逻辑
|
||||||
};
|
};
|
||||||
|
|
||||||
function goDetail(jobFairId){
|
async function goDetail(jobFairId){
|
||||||
|
if(await thirdLogin()){
|
||||||
|
debugger
|
||||||
if(state.current != 3){
|
if(state.current != 3){
|
||||||
navTo('/packageA/pages/exhibitors/exhibitors?jobFairId=' + jobFairId)
|
navTo('/packageA/pages/exhibitors/exhibitors?jobFairId=' + jobFairId)
|
||||||
}else{
|
}else{
|
||||||
@@ -182,6 +230,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function toSelectDate() {
|
function toSelectDate() {
|
||||||
navTo("/packageA/pages/selectDate/selectDate", {
|
navTo("/packageA/pages/selectDate/selectDate", {
|
||||||
|
|||||||
@@ -246,10 +246,10 @@ export function myRequest(url, data = {}, method = 'GET', port = 9100, headers =
|
|||||||
}
|
}
|
||||||
// 显示具体的错误信息
|
// 显示具体的错误信息
|
||||||
const errorMsg = msg || '请求出现异常,请联系工作人员'
|
const errorMsg = msg || '请求出现异常,请联系工作人员'
|
||||||
uni.showToast({
|
// uni.showToast({
|
||||||
title: errorMsg,
|
// title: errorMsg,
|
||||||
icon: 'none'
|
// icon: 'none'
|
||||||
})
|
// })
|
||||||
const err = new Error(errorMsg)
|
const err = new Error(errorMsg)
|
||||||
err.error = resData
|
err.error = resData
|
||||||
reject(err)
|
reject(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user