page3.vue 9.3 KB

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