page3.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <template>
  2. <view class="content">
  3. <!-- 背景图片 -->
  4. <image class="bg-image" src="http://115.190.125.125:9000/static-images/login-bg.png" mode="aspectFill"></image>
  5. <!-- 顶部标题区域 -->
  6. <view class="header-section">
  7. <!-- <view class="app-logo">🪶🪶</view> -->
  8. <image class="app-logo" src="http://115.190.125.125:9000/static-images/logo.png" mode="widthFix"></image>
  9. <!-- <view class="app-name">青鸾之恋</view> -->
  10. <view class="app-slogan">真诚相遇 · 携手一生</view>
  11. </view>
  12. <!-- 登录框 -->
  13. <view class="login-box">
  14. <!-- 微信一键登录 -->
  15. <button class="wechat-login-btn" @click="login_zheshow">
  16. <image class="wechat-icon" src="http://115.190.125.125:9000/static-images/wechat-icon.png" mode="aspectFit"></image>
  17. <text>微信一键登录</text>
  18. </button>
  19. </view>
  20. <!-- 底部提示 -->
  21. <view class="footer-tip">
  22. <text class="tip-icon">💗</text>
  23. <text class="tip-text">遇见对的人,不再孤单</text>
  24. </view>
  25. <btnlogin :zheshow='zheshow'/>
  26. </view>
  27. </template>
  28. <script>
  29. import btnlogin from '@/components/butlogin';
  30. import api from '@/utils/api.js'
  31. import userAuth from '@/utils/userAuth.js'
  32. export default {
  33. components: {
  34. btnlogin
  35. },
  36. data() {
  37. return {
  38. zheshow: false, // 控制弹窗显示隐藏
  39. redirectUrl: '' // 登录成功后跳转地址(可选)
  40. }
  41. },
  42. onLoad(options) {
  43. // 处理跳转参数
  44. this.redirectUrl = options && options.redirect ? decodeURIComponent(options.redirect) : ''
  45. },
  46. methods: {
  47. login_zheshow() {
  48. this.zheshow = !this.zheshow
  49. },
  50. loset(Logon_Credentials) {
  51. // 获取微信登录code
  52. uni.login({
  53. provider: 'weixin',
  54. success: async (loginRes) => {
  55. // ✅ 获取手机号code
  56. const phoneCode = (Logon_Credentials && Logon_Credentials.code && String(Logon_Credentials.code).trim())
  57. ? String(Logon_Credentials.code).trim()
  58. : null;
  59. // ✅ 一次性调用微信登录接口,无需用户提供头像和昵称
  60. const loginParams = {
  61. code: loginRes.code,
  62. phoneCode: phoneCode
  63. };
  64. uni.showLoading({title: '登录中...'})
  65. try {
  66. const wechatLoginResult = await api.auth.wechatLogin(loginParams);
  67. const token = wechatLoginResult?.token || wechatLoginResult?.data?.token
  68. const user = wechatLoginResult?.user || wechatLoginResult?.data?.user
  69. if (!token || !user) {
  70. throw new Error('微信登录返回数据异常')
  71. }
  72. uni.setStorageSync("userId", user.userId);
  73. // ✅ 保存登录信息(后端已返回完整信息,直接保存)
  74. userAuth.saveLoginInfo(token, user)
  75. uni.hideLoading()
  76. uni.showToast({title: '登录成功', icon: 'success'})
  77. // ✅ 初始化 TIM 和 WebSocket
  78. // 延迟一下,确保全局方法已挂载
  79. await new Promise(resolve => setTimeout(resolve, 200))
  80. try {
  81. const app = getApp()
  82. if (app && app.globalData && app.globalData.initGlobalTIM) {
  83. await app.globalData.initGlobalTIM()
  84. } else {
  85. console.warn('⚠️ 全局 initGlobalTIM 方法不存在,尝试直接导入')
  86. // 如果全局方法不存在,直接导入 tim-manager
  87. const timManager = require('@/utils/tim-manager.js').default
  88. const timPresenceManager = require('@/utils/tim-presence-manager.js').default
  89. // 初始化 TIM
  90. if (!timManager.isLogin) {
  91. const SDKAppID = 1600109674
  92. if (!timManager.tim) {
  93. timManager.init(SDKAppID)
  94. }
  95. const res = await uni.request({
  96. url: `https://api.zhongruanke.cn/api/im/getUserSig?userId=${user.userId}`,
  97. method: 'GET'
  98. })
  99. if (res[1].data.code === 200) {
  100. const userSig = res[1].data.data.userSig
  101. await timManager.login(String(user.userId), userSig)
  102. // 初始化 WebSocket
  103. await timPresenceManager.init(String(user.userId))
  104. }
  105. }
  106. }
  107. } catch (error) {
  108. console.error('❌ 初始化 TIM 失败:', error)
  109. }
  110. // ✅ 跳转首页
  111. setTimeout(() => {
  112. const target = this.redirectUrl || '/pages/index/index'
  113. uni.reLaunch({url: target})
  114. }, 500)
  115. } catch (error) {
  116. console.error('❌ 微信登录失败:', error)
  117. uni.hideLoading()
  118. uni.showToast({
  119. title: error?.message || '登录失败,请重试',
  120. icon: 'none',
  121. duration: 2000
  122. })
  123. }
  124. },
  125. fail: (err) => {
  126. console.error('获取微信code失败:', err)
  127. uni.showToast({title: '微信登录失败', icon: 'none'})
  128. }
  129. })
  130. }
  131. }
  132. }
  133. </script>
  134. <style lang="scss" scoped>
  135. .content {
  136. padding: 40rpx;
  137. min-height: 100vh;
  138. position: relative;
  139. overflow: hidden;
  140. .bg-image {
  141. position: fixed;
  142. top: 0;
  143. left: 0;
  144. width: 100%;
  145. height: 100%;
  146. z-index: 0;
  147. pointer-events: none;
  148. }
  149. // 添加装饰性元素
  150. &::before {
  151. content: '❤️';
  152. position: absolute;
  153. top: 100rpx;
  154. right: 60rpx;
  155. font-size: 60rpx;
  156. opacity: 0.2;
  157. animation: heartbeat 2s infinite;
  158. }
  159. &::after {
  160. content: '💕';
  161. position: absolute;
  162. bottom: 200rpx;
  163. left: 40rpx;
  164. font-size: 50rpx;
  165. opacity: 0.2;
  166. animation: heartbeat 2s infinite 0.5s;
  167. }
  168. }
  169. @keyframes heartbeat {
  170. 0%, 100% {
  171. transform: scale(1);
  172. }
  173. 50% {
  174. transform: scale(1.1);
  175. }
  176. }
  177. .header-section {
  178. text-align: center;
  179. margin-bottom: 60rpx;
  180. position: relative;
  181. z-index: 1;
  182. .app-logo {
  183. font-size: 120rpx;
  184. margin-bottom: 20rpx;
  185. // animation: heartbeat 1s infinite;
  186. }
  187. .app-name {
  188. font-size: 48rpx;
  189. font-weight: bold;
  190. background: linear-gradient(135deg, #ff6b9d 0%, #ff8fab 100%);
  191. -webkit-background-clip: text;
  192. -webkit-text-fill-color: transparent;
  193. margin-bottom: 15rpx;
  194. }
  195. .app-slogan {
  196. font-size: 26rpx;
  197. color: #333333;
  198. opacity: 0.8;
  199. }
  200. }
  201. .login-box {
  202. background: rgba(211, 127, 140, 0);
  203. border-radius: 30rpx;
  204. padding: 80rpx 40rpx;
  205. margin-bottom: 30rpx;
  206. box-shadow: 0 8rpx 24rpx rgba(255, 107, 157, 0.15);
  207. border: 2rpx solid rgba(255, 107, 157, 0.1);
  208. display: flex;
  209. justify-content: center;
  210. align-items: center;
  211. position: relative;
  212. z-index: 1;
  213. // .wechat-login-btn {
  214. // width: 100%;
  215. // height: 90rpx;
  216. // background: #FFFFFF;
  217. // color: #ff6b9d;
  218. // border-radius: 50rpx;
  219. // font-size: 30rpx;
  220. // font-weight: bold;
  221. // display: flex;
  222. // align-items: center;
  223. // justify-content: center;
  224. // border: 2rpx solid #ff6b9d;
  225. // box-shadow: 0 8rpx 20rpx rgba(255, 107, 157, 0.2);
  226. // .wechat-icon {
  227. // width: 40rpx;
  228. // height: 40rpx;
  229. // margin-right: 10rpx;
  230. // }
  231. // &:active {
  232. // opacity: 0.9;
  233. // transform: translateY(2rpx);
  234. // }
  235. // }
  236. .wechat-login-btn {
  237. width: 100%;
  238. height: 96rpx;
  239. // 渐变背景+光泽叠加
  240. background: linear-gradient(90deg, #9d40e9 0%, #5a35f7 100%),
  241. radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.15), transparent 50%);
  242. background-blend-mode: overlay;
  243. color: #ffffff;
  244. border-radius: 60rpx;
  245. font-size: 32rpx;
  246. font-weight: bold;
  247. display: flex;
  248. align-items: center;
  249. justify-content: center;
  250. border: none;
  251. // 多层光影:外层投影+内高光+内阴影
  252. box-shadow: 0 6rpx 16rpx rgba(90, 53, 247, 0.4),
  253. 0 3rpx 8rpx rgba(90, 53, 247, 0.2),
  254. inset 0 2rpx 3rpx rgba(255, 255, 255, 0.25),
  255. inset 0 -2rpx 3rpx rgba(0, 0, 0, 0.15);
  256. transition: all 0.2s ease; // 动画过渡,更自然
  257. }
  258. .wechat-login-btn:active {
  259. transform: translateY(2rpx);
  260. box-shadow: 0 3rpx 8rpx rgba(90, 53, 247, 0.3),
  261. 0 1rpx 4rpx rgba(90, 53, 247, 0.2),
  262. inset 0 1rpx 2rpx rgba(255, 255, 255, 0.15),
  263. inset 0 -2rpx 3rpx rgba(0, 0, 0, 0.2);
  264. }
  265. .wechat-icon {
  266. width: 45rpx;
  267. height: 45rpx;
  268. margin-right: 15rpx;
  269. filter: drop-shadow(0 1rpx 2rpx rgba(0, 0, 0, 0.1)); // 给图标加轻微阴影,更立体
  270. }
  271. }
  272. .footer-tip {
  273. text-align: center;
  274. margin-top: 60rpx;
  275. padding: 30rpx;
  276. position: relative;
  277. z-index: 1;
  278. .tip-icon {
  279. font-size: 50rpx;
  280. display: block;
  281. margin-bottom: 15rpx;
  282. animation: heartbeat 2s infinite;
  283. }
  284. .tip-text {
  285. font-size: 26rpx;
  286. color: #333333;
  287. font-weight: 500;
  288. letter-spacing: 2rpx;
  289. }
  290. }
  291. button {
  292. &::after {
  293. border: none;
  294. }
  295. }
  296. </style>