officialAccount/pages/login/callback.vue

368 lines
9.6 KiB
Vue
Raw Normal View History

2025-05-28 17:36:42 +08:00
<template>
2025-06-03 17:29:22 +08:00
<view class="login-container">
2025-06-19 17:03:31 +08:00
<image class="imge" src="https://www.focusnu.com/media/directive/index/nu.png" />
2025-06-09 17:33:50 +08:00
<view class="font">
页面跳转中请稍后...
</view>
2025-06-03 17:29:22 +08:00
<!-- 底部的栏为啥这样写是因为要做左右拉动 -->
<!-- <view class="botton-view">
<view v-for="(item,index) in itemArray" class="array-father">
<view :class="itemTarget===index ? `bottom-button-target` : `bottom-button`" @click="itemTarget=index">
<view class="">
{{item}}
</view>
</view>
2025-06-19 17:03:31 +08:00
<view v-if="itemTarget===index" class="blue-heng"></view>
2025-06-03 17:29:22 +08:00
</view>
</view> -->
</view>
<!-- <view class="callback-container">
回调成功{{ceshi.name}}{{ceshi.openid}} -->
2025-05-28 17:36:42 +08:00
<!-- {{look}} -->
<!-- <text v-if="!userInfo">授权中...</text>
<view v-else>
<text>OpenID: {{ openid }}</text>
<text v-if="userInfo.nickname">昵称: {{ userInfo.nickname }}</text>
<image v-if="userInfo.headimgurl" :src="userInfo.headimgurl" class="avatar" />
</view> -->
2025-06-03 17:29:22 +08:00
<!-- <view v-for="(item,index) in jigouArray" :key="index">
2025-05-28 17:36:42 +08:00
<view style="font-size: 30rpx;margin-top: 10rpx;font-weight: 700;" @click="jigouClick(item)">
{{item.departName}}
</view>
<image style="width: 60rpx;height: 60rpx;"
:src="`https://www.focusnu.com/nursing-unit/sys/common/static/${item.picUrl}`" />
</view>
<view v-for="(item,index) in secondArray" :key="index" @click="jumpto">
<view style="font-size: 30rpx;margin-top: 10rpx;font-weight: 700;">
{{item.nuName}}
</view>
2025-06-03 17:29:22 +08:00
</view>
</view> -->
2025-05-28 17:36:42 +08:00
</template>
<script setup>
import {
onLoad
} from '@dcloudio/uni-app';
2025-06-20 17:32:20 +08:00
// import { base_url } from '@/request/index.js'
// import request from '@/request/index.js';
2025-05-28 17:36:42 +08:00
import {
reactive,
ref
} from 'vue';
2025-06-20 17:32:20 +08:00
import {
getOpenid,
getMessage
} from '@/api/loginApi.js'
// import {getList} from "@/api/loginApi.js"
2025-06-03 17:29:22 +08:00
2025-06-20 17:32:20 +08:00
// const itemArray = ["NU", "动态", "我的"];
// const itemTarget = ref(0);
// // const {
// // fetchUserInfo,
// // openid,
// // userInfo
// // } = useWeChatAuth();
2025-05-28 17:36:42 +08:00
2025-06-20 17:32:20 +08:00
// const ceshi = reactive({
// name: "",
// openid: "",
// accessToken: ""
// })
// // const jumpto = () => {
// // console.log("???")
// // uni.navigateTo({
// // url: "/pages/pay/index"
// // });
// // }
// const getOpenId = (code) => {
// const url = `${base_url}/weixin/wechat/callback?code=${encodeURIComponent(code)}`;
2025-05-28 17:36:42 +08:00
2025-06-20 17:32:20 +08:00
// fetch(url)
// .then(res => res.json())
// .then(data => {
// ceshi.name = data.data.nickname
// ceshi.openid = data.data.openid
// ceshi.accessToken = data.accessToken
// uni.setStorage({
// key: 'openid',
// data: {
// openid: data.data.openid,
// accessToken: data.accessToken,
// }
// });
// getUserMessage()
2025-05-28 17:36:42 +08:00
2025-06-20 17:32:20 +08:00
// })
// .catch(err => {
// console.error("❌ 获取用户信息失败:", err);
// });
// }
// // const serve = ref("")
// const look = ref("")
// const getUserMessage = () => {
// const url =
// `${base_url}/h5Api/nuBizAdvisoryInfo/queryWeixinInfo?openId=${encodeURIComponent(ceshi.openid)}`;
// fetch(url)
// .then(res => res.json())
// .then(data => {
// console.log("个人信息打印", data)
// uni.setStorageSync('token', data.result.token);
// uni.setStorageSync('serverUrl', data.result.serverUrl);
// console.log("???token存储",data.result.token)
// // const post = `${uni.getStorageSync('serverUrl')}/weiXinPay/getJsApiInfo`;
// // const pay = {
// // access_token: ceshi.accessToken,
// // };
// // fetch(post, {
// // method: 'POST',
// // headers: {
// // 'Content-Type': 'application/json'
// // },
// // body: JSON.stringify(pay)
// // })
// // .then(res => res.json())
// // .then(data => {
// // // secondArray.value = [...data.result];
// // console.log("???调取微信", data)
2025-06-03 17:29:22 +08:00
2025-06-20 17:32:20 +08:00
// // })
// // .catch(err => {
// // console.error('请求失败:', err);
// // });
// // const urlpost = `${data.result.serverUrl}/weiXinPay/getUserInfo`;
// // const payload = {
// // openid: ceshi.openid,
// // access_token: ceshi.accessToken,
// // // serverUrl: serve.value
// // };
// // console.log("???/", payload)
// // fetch(urlpost, {
// // method: 'POST',
// // headers: {
// // 'Content-Type': 'application/json'
// // },
// // body: JSON.stringify(payload)
// // })
// // .then(res => res.json())
// // .then(data => {
// // // secondArray.value = [...data.result];
// // look.value = data
// // console.log("", data)
// // })
// // .catch(err => {
// // console.error('请求失败:', err);
// // });
2025-05-28 17:36:42 +08:00
2025-06-20 17:32:20 +08:00
// if(!data.result.tel){
// uni.redirectTo({
// url: `/pages/login/phonebumber`
// });
// }else{
// uni.redirectTo({
// url: `/pages/login/threeselectone`
// });
// uni.setStorageSync('tel', data.result.tel);
// }
// getjigou()
// })
2025-05-28 17:36:42 +08:00
2025-06-20 17:32:20 +08:00
// }
// const jigouArray = ref([]);
// const getjigou = () => {
// const url = `${base_url}/sys/sysDepart/queryInstitutionsList`;
// fetch(url)
// .then(res => res.json())
// .then(data => {
// jigouArray.value = [...data]
// console.log("机构打印", jigouArray.value)
// })
// }
// const secondArray = ref([]);
// const jigouClick = (element) => {
// const url = `${element.serverUrl}/h5Api/nuBaseInfo/list`;
// fetch(url)
// .then(res => res.json())
// .then(data => {
// secondArray.value = [...data.result]
// })
// uni.setStorage({
// key: 'serverUrl',
// data: {
// url: element.serverUrl,
// }
// });
// const urlpost = `${base_url}/h5Api/nuBizAdvisoryInfo/editNuBizAdvisoryInfo`;
// const payload = {
// openId: ceshi.openid,
// serverUrl: element.serverUrl
// };
// console.log("???/", payload)
// fetch(urlpost, {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json'
// },
// body: JSON.stringify(payload)
// })
// .then(res => res.json())
// .then(data => {
// // secondArray.value = [...data.result];
// console.log("???", data)
// })
// .catch(err => {
// console.error('请求失败:', err);
// });
// }
const superLogin = () => {
uni.login({
provider: 'weixin',
success(res) {
getOpenid(res.code).then(res => {
let openid = res.data.openid
uni.setStorageSync("openid", openid)
getMessage(openid).then(res => {
// uni.navigateTo({
// url: `/pages/login/phonebumber`
// });
if(!res.result.tel){
uni.redirectTo({
url: `/pages/login/index`
});
}else{
// uni.setStorageSync('tel', res.result.tel);
// uni.setStorageSync('token', res.result.token);
// uni.setStorageSync('serverUrl', res.result.serverUrl);
// uni.redirectTo({
// url: `/pages/login/threeselectone`
// });
if(uni.getStorageSync('special')){
uni.setStorageSync('tel', res.result.tel);
uni.setStorageSync('token', res.result.token);
uni.setStorageSync('serverUrl', res.result.serverUrl);
uni.redirectTo({
url: `/pages/login/special`
});
}else{
uni.setStorageSync('tel', res.result.tel);
uni.setStorageSync('token', res.result.token);
uni.setStorageSync('serverUrl', res.result.serverUrl);
uni.redirectTo({
url: `/pages/login/threeselectone`
});
}
}
})
})
},
fail(err) {
console.error('获取 code 失败:', err);
2025-05-28 17:36:42 +08:00
}
});
}
2025-06-20 17:32:20 +08:00
onLoad((options) => {
superLogin();
if(options.type){
uni.setStorageSync('special', true);
}else{
uni.setStorageSync('special', false);
2025-05-28 17:36:42 +08:00
}
2025-06-20 17:32:20 +08:00
// const href = window.location.href;
// const queryString = href.split('?')[1]?.split('#')[0]; // 提取 ? 和 # 之间的参数
// const query = {};
2025-05-28 17:36:42 +08:00
2025-06-20 17:32:20 +08:00
// if (queryString) {
// queryString.split('&').forEach(pair => {
// const [key, value] = pair.split('=');
// query[key] = decodeURIComponent(value);
// });
// }
2025-05-28 17:36:42 +08:00
2025-06-20 17:32:20 +08:00
// console.log('解析到的 query 参数:', query);
// if (query.code) {
// getOpenId(query.code)
// // 调用你的方法,比如 fetchUserInfo(query.code)
// }
2025-05-28 17:36:42 +08:00
});
</script>
2025-06-03 17:29:22 +08:00
<style scoped lang="scss">
2025-05-28 17:36:42 +08:00
.callback-container {
padding: 24px;
}
.avatar {
width: 80px;
height: 80px;
border-radius: 40px;
margin-top: 12px;
}
2025-06-03 17:29:22 +08:00
.login-container {
display: flex;
flex-direction: column;
min-height: 100vh;
width: 100%;
background-color: rgb(239, 241, 252);
position: relative;
2025-06-09 17:33:50 +08:00
justify-content: center;
align-items: center;
2025-06-03 17:29:22 +08:00
}
.array-father {
width: 33%;
position: relative;
}
.botton-view {
position: fixed;
bottom: 0;
left: 0;
height: 200rpx;
width: 100%;
// background-color: greenyellow;
display: flex;
justify-content: space-between;
font-weight: 500;
.bottom-button {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.bottom-button-target {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
color: rgb(42, 133, 235);
}
.blue-heng {
height: 6rpx;
width: 150rpx;
background-color: rgb(42, 133, 235);
position: absolute;
bottom: 55rpx;
left: 50%;
/* 左边缘到父容器左边的距离占父宽度 50% */
transform: translateX(-50%);
}
}
2025-06-09 17:33:50 +08:00
.imge{
width: 240rpx;
height: 240rpx;
margin-bottom: 50rpx;
}
.font{
font-weight: 600;
font-size: 35rpx;
// margin-bottom: 100rpx;
}
2025-05-28 17:36:42 +08:00
</style>