| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- <template>
- <view class="content">
- <!-- 背景图片 http://115.190.125.125:9000/static-images/login-bg.png-->
- <image class="bg-image" src="https://api.zhongruanke.cn/minio/static-images/login-bg.png" mode="aspectFill"></image>
- <!-- 顶部标题区域 -->
- <view class="header-section">
- <!-- <view class="app-logo">🪶🪶</view> -->
- <!-- http://115.190.125.125:9000/static-images/logo.png -->
- <image class="app-logo" src="https://api.zhongruanke.cn/minio/static-images/logo.png" mode="widthFix"></image>
- <!-- <view class="app-name">青鸾之恋</view> -->
- <view class="app-slogan">真诚相遇 · 携手一生</view>
- </view>
- <!-- 登录框 -->
- <view class="login-box">
- <!-- 微信一键登录 -->
- <button class="wechat-login-btn" @click="login_zheshow">
- <!-- http://115.190.125.125:9000/static-images/wechat-icon.png -->
- <image class="wechat-icon" src="https://api.zhongruanke.cn/minio/static-images/wechat-icon.png" mode="aspectFit"></image>
- <text>微信一键登录</text>
- </button>
- </view>
- <!-- 底部提示 -->
- <view class="footer-tip">
- <text class="tip-icon">💗</text>
- <text class="tip-text">遇见对的人,不再孤单</text>
- </view>
- <btnlogin :zheshow='zheshow'/>
- </view>
- </template>
- <script>
- import btnlogin from '@/components/butlogin';
- import api from '@/utils/api.js'
- import userAuth from '@/utils/userAuth.js'
- export default {
- components: {
- btnlogin
- },
- data() {
- return {
- zheshow: false, // 控制弹窗显示隐藏
- redirectUrl: '' // 登录成功后跳转地址(可选)
- }
- },
- onLoad(options) {
- // 处理跳转参数
- this.redirectUrl = options && options.redirect ? decodeURIComponent(options.redirect) : ''
- },
- methods: {
- login_zheshow() {
- this.zheshow = !this.zheshow
- },
- loset(Logon_Credentials) {
-
- // 获取微信登录code
- uni.login({
- provider: 'weixin',
- success: async (loginRes) => {
- // ✅ 获取手机号code
- const phoneCode = (Logon_Credentials && Logon_Credentials.code && String(Logon_Credentials.code).trim())
- ? String(Logon_Credentials.code).trim()
- : null;
- // ✅ 一次性调用微信登录接口,无需用户提供头像和昵称
- const loginParams = {
- code: loginRes.code,
- phoneCode: phoneCode
- };
-
- uni.showLoading({title: '登录中...'})
- try {
- const wechatLoginResult = await api.auth.wechatLogin(loginParams);
- const token = wechatLoginResult?.token || wechatLoginResult?.data?.token
- const user = wechatLoginResult?.user || wechatLoginResult?.data?.user
- if (!token || !user) {
- throw new Error('微信登录返回数据异常')
- }
-
- uni.setStorageSync("userId", user.userId);
- // ✅ 保存登录信息(后端已返回完整信息,直接保存)
- userAuth.saveLoginInfo(token, user)
- uni.hideLoading()
- uni.showToast({title: '登录成功', icon: 'success'})
- // ✅ 初始化 TIM 和 WebSocket
-
-
- // 延迟一下,确保全局方法已挂载
- await new Promise(resolve => setTimeout(resolve, 200))
-
- try {
- const app = getApp()
- if (app && app.globalData && app.globalData.initGlobalTIM) {
- await app.globalData.initGlobalTIM()
-
- } else {
- console.warn('⚠️ 全局 initGlobalTIM 方法不存在,尝试直接导入')
- // 如果全局方法不存在,直接导入 tim-manager
- const timManager = require('@/utils/tim-manager.js').default
- const timPresenceManager = require('@/utils/tim-presence-manager.js').default
-
- // 初始化 TIM
- if (!timManager.isLogin) {
- const SDKAppID = 1600109674
- if (!timManager.tim) {
- timManager.init(SDKAppID)
-
- }
-
- const res = await uni.request({
- url: `https://api.zhongruanke.cn/api/im/getUserSig?userId=${user.userId}`,
- method: 'GET'
- })
-
- if (res[1].data.code === 200) {
- const userSig = res[1].data.data.userSig
- await timManager.login(String(user.userId), userSig)
-
-
- // 初始化 WebSocket
- await timPresenceManager.init(String(user.userId))
-
- }
- }
- }
- } catch (error) {
- console.error('❌ 初始化 TIM 失败:', error)
- }
- // ✅ 跳转首页
- setTimeout(() => {
- const target = this.redirectUrl || '/pages/index/index'
- uni.reLaunch({url: target})
- }, 500)
- } catch (error) {
- console.error('❌ 微信登录失败:', error)
- uni.hideLoading()
- uni.showToast({
- title: error?.message || '登录失败,请重试',
- icon: 'none',
- duration: 2000
- })
- }
- },
- fail: (err) => {
- console.error('获取微信code失败:', err)
- uni.showToast({title: '微信登录失败', icon: 'none'})
- }
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .content {
- padding: 40rpx;
- min-height: 100vh;
- position: relative;
- overflow: hidden;
- .bg-image {
- position: fixed;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- z-index: 0;
- pointer-events: none;
- }
- // 添加装饰性元素
- &::before {
- content: '❤️';
- position: absolute;
- top: 100rpx;
- right: 60rpx;
- font-size: 60rpx;
- opacity: 0.2;
- animation: heartbeat 2s infinite;
- }
- &::after {
- content: '💕';
- position: absolute;
- bottom: 200rpx;
- left: 40rpx;
- font-size: 50rpx;
- opacity: 0.2;
- animation: heartbeat 2s infinite 0.5s;
- }
- }
- @keyframes heartbeat {
- 0%, 100% {
- transform: scale(1);
- }
- 50% {
- transform: scale(1.1);
- }
- }
- .header-section {
- text-align: center;
- margin-bottom: 60rpx;
- position: relative;
- z-index: 1;
- .app-logo {
- font-size: 120rpx;
- margin-bottom: 20rpx;
- // animation: heartbeat 1s infinite;
- }
- .app-name {
- font-size: 48rpx;
- font-weight: bold;
- background: linear-gradient(135deg, #ff6b9d 0%, #ff8fab 100%);
- -webkit-background-clip: text;
- -webkit-text-fill-color: transparent;
- margin-bottom: 15rpx;
- }
- .app-slogan {
- font-size: 26rpx;
- color: #333333;
- opacity: 0.8;
- }
- }
- .login-box {
- background: rgba(211, 127, 140, 0);
- border-radius: 30rpx;
- padding: 80rpx 40rpx;
- margin-bottom: 30rpx;
- box-shadow: 0 8rpx 24rpx rgba(255, 107, 157, 0.15);
- border: 2rpx solid rgba(255, 107, 157, 0.1);
- display: flex;
- justify-content: center;
- align-items: center;
- position: relative;
- z-index: 1;
- // .wechat-login-btn {
- // width: 100%;
- // height: 90rpx;
- // background: #FFFFFF;
- // color: #ff6b9d;
- // border-radius: 50rpx;
- // font-size: 30rpx;
- // font-weight: bold;
- // display: flex;
- // align-items: center;
- // justify-content: center;
- // border: 2rpx solid #ff6b9d;
- // box-shadow: 0 8rpx 20rpx rgba(255, 107, 157, 0.2);
- // .wechat-icon {
- // width: 40rpx;
- // height: 40rpx;
- // margin-right: 10rpx;
- // }
- // &:active {
- // opacity: 0.9;
- // transform: translateY(2rpx);
- // }
- // }
- .wechat-login-btn {
- width: 100%;
- height: 96rpx;
- // 渐变背景+光泽叠加
- background: linear-gradient(90deg, #9d40e9 0%, #5a35f7 100%),
- radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.15), transparent 50%);
- background-blend-mode: overlay;
- color: #ffffff;
- border-radius: 60rpx;
- font-size: 32rpx;
- font-weight: bold;
- display: flex;
- align-items: center;
- justify-content: center;
- border: none;
- // 多层光影:外层投影+内高光+内阴影
- box-shadow: 0 6rpx 16rpx rgba(90, 53, 247, 0.4),
- 0 3rpx 8rpx rgba(90, 53, 247, 0.2),
- inset 0 2rpx 3rpx rgba(255, 255, 255, 0.25),
- inset 0 -2rpx 3rpx rgba(0, 0, 0, 0.15);
- transition: all 0.2s ease; // 动画过渡,更自然
- }
- .wechat-login-btn:active {
- transform: translateY(2rpx);
- box-shadow: 0 3rpx 8rpx rgba(90, 53, 247, 0.3),
- 0 1rpx 4rpx rgba(90, 53, 247, 0.2),
- inset 0 1rpx 2rpx rgba(255, 255, 255, 0.15),
- inset 0 -2rpx 3rpx rgba(0, 0, 0, 0.2);
- }
- .wechat-icon {
- width: 45rpx;
- height: 45rpx;
- margin-right: 15rpx;
- filter: drop-shadow(0 1rpx 2rpx rgba(0, 0, 0, 0.1)); // 给图标加轻微阴影,更立体
- }
- }
- .footer-tip {
- text-align: center;
- margin-top: 60rpx;
- padding: 30rpx;
- position: relative;
- z-index: 1;
- .tip-icon {
- font-size: 50rpx;
- display: block;
- margin-bottom: 15rpx;
- animation: heartbeat 2s infinite;
- }
- .tip-text {
- font-size: 26rpx;
- color: #333333;
- font-weight: 500;
- letter-spacing: 2rpx;
- }
- }
- button {
- &::after {
- border: none;
- }
- }
- </style>
|