page3.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <view class="content">
  3. <!-- 背景图片 -->
  4. <image class="bg-image" src="/static/login-bg.png" mode="aspectFill"></image>
  5. <!-- 顶部标题区域 -->
  6. <view class="header-section">
  7. <!-- <view class="app-logo">🪶🪶</view> -->
  8. <image class="app-logo" src="/static/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="/static/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. console.log('=== 开始微信登录流程 ===')
  52. console.log('用户登录信息:', 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. console.log('微信登录code:', loginRes.code)
  62. console.log('手机号code:', phoneCode || '未提供')
  63. // ✅ 一次性调用微信登录接口,无需用户提供头像和昵称
  64. const loginParams = {
  65. code: loginRes.code,
  66. phoneCode: phoneCode
  67. };
  68. uni.showLoading({title: '登录中...'})
  69. try {
  70. const wechatLoginResult = await api.auth.wechatLogin(loginParams);
  71. const token = wechatLoginResult?.token || wechatLoginResult?.data?.token
  72. const user = wechatLoginResult?.user || wechatLoginResult?.data?.user
  73. if (!token || !user) {
  74. throw new Error('微信登录返回数据异常')
  75. }
  76. console.log('✅ 微信登录成功,用户ID:', user.userId)
  77. console.log('✅ 微信登录成功')
  78. console.log('用户ID:', user.userId)
  79. console.log('昵称:', user.nickname)
  80. console.log('头像:', user.avatarUrl ? '已设置' : '未设置')
  81. console.log('手机号:', user.phone || '未设置')
  82. uni.setStorageSync("userId", user.userId);
  83. // ✅ 保存登录信息(后端已返回完整信息,直接保存)
  84. userAuth.saveLoginInfo(token, user)
  85. uni.hideLoading()
  86. uni.showToast({title: '登录成功', icon: 'success'})
  87. // ✅ 跳转首页
  88. setTimeout(() => {
  89. const target = this.redirectUrl || '/pages/index/index'
  90. uni.reLaunch({url: target})
  91. }, 500)
  92. } catch (error) {
  93. console.error('❌ 微信登录失败:', error)
  94. uni.hideLoading()
  95. uni.showToast({
  96. title: error?.message || '登录失败,请重试',
  97. icon: 'none',
  98. duration: 2000
  99. })
  100. }
  101. },
  102. fail: (err) => {
  103. console.error('获取微信code失败:', err)
  104. uni.showToast({title: '微信登录失败', icon: 'none'})
  105. }
  106. })
  107. }
  108. }
  109. }
  110. </script>
  111. <style lang="scss" scoped>
  112. .content {
  113. padding: 40rpx;
  114. min-height: 100vh;
  115. position: relative;
  116. overflow: hidden;
  117. .bg-image {
  118. position: fixed;
  119. top: 0;
  120. left: 0;
  121. width: 100%;
  122. height: 100%;
  123. z-index: 0;
  124. pointer-events: none;
  125. }
  126. // 添加装饰性元素
  127. &::before {
  128. content: '❤️';
  129. position: absolute;
  130. top: 100rpx;
  131. right: 60rpx;
  132. font-size: 60rpx;
  133. opacity: 0.2;
  134. animation: heartbeat 2s infinite;
  135. }
  136. &::after {
  137. content: '💕';
  138. position: absolute;
  139. bottom: 200rpx;
  140. left: 40rpx;
  141. font-size: 50rpx;
  142. opacity: 0.2;
  143. animation: heartbeat 2s infinite 0.5s;
  144. }
  145. }
  146. @keyframes heartbeat {
  147. 0%, 100% {
  148. transform: scale(1);
  149. }
  150. 50% {
  151. transform: scale(1.1);
  152. }
  153. }
  154. .header-section {
  155. text-align: center;
  156. margin-bottom: 60rpx;
  157. position: relative;
  158. z-index: 1;
  159. .app-logo {
  160. font-size: 120rpx;
  161. margin-bottom: 20rpx;
  162. // animation: heartbeat 1s infinite;
  163. }
  164. .app-name {
  165. font-size: 48rpx;
  166. font-weight: bold;
  167. background: linear-gradient(135deg, #ff6b9d 0%, #ff8fab 100%);
  168. -webkit-background-clip: text;
  169. -webkit-text-fill-color: transparent;
  170. margin-bottom: 15rpx;
  171. }
  172. .app-slogan {
  173. font-size: 26rpx;
  174. color: #333333;
  175. opacity: 0.8;
  176. }
  177. }
  178. .login-box {
  179. background: rgba(211, 127, 140, 0);
  180. border-radius: 30rpx;
  181. padding: 80rpx 40rpx;
  182. margin-bottom: 30rpx;
  183. box-shadow: 0 8rpx 24rpx rgba(255, 107, 157, 0.15);
  184. border: 2rpx solid rgba(255, 107, 157, 0.1);
  185. display: flex;
  186. justify-content: center;
  187. align-items: center;
  188. position: relative;
  189. z-index: 1;
  190. // .wechat-login-btn {
  191. // width: 100%;
  192. // height: 90rpx;
  193. // background: #FFFFFF;
  194. // color: #ff6b9d;
  195. // border-radius: 50rpx;
  196. // font-size: 30rpx;
  197. // font-weight: bold;
  198. // display: flex;
  199. // align-items: center;
  200. // justify-content: center;
  201. // border: 2rpx solid #ff6b9d;
  202. // box-shadow: 0 8rpx 20rpx rgba(255, 107, 157, 0.2);
  203. // .wechat-icon {
  204. // width: 40rpx;
  205. // height: 40rpx;
  206. // margin-right: 10rpx;
  207. // }
  208. // &:active {
  209. // opacity: 0.9;
  210. // transform: translateY(2rpx);
  211. // }
  212. // }
  213. .wechat-login-btn {
  214. width: 100%;
  215. height: 96rpx;
  216. // 渐变背景+光泽叠加
  217. background: linear-gradient(90deg, #9d40e9 0%, #5a35f7 100%),
  218. radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.15), transparent 50%);
  219. background-blend-mode: overlay;
  220. color: #ffffff;
  221. border-radius: 60rpx;
  222. font-size: 32rpx;
  223. font-weight: bold;
  224. display: flex;
  225. align-items: center;
  226. justify-content: center;
  227. border: none;
  228. // 多层光影:外层投影+内高光+内阴影
  229. box-shadow: 0 6rpx 16rpx rgba(90, 53, 247, 0.4),
  230. 0 3rpx 8rpx rgba(90, 53, 247, 0.2),
  231. inset 0 2rpx 3rpx rgba(255, 255, 255, 0.25),
  232. inset 0 -2rpx 3rpx rgba(0, 0, 0, 0.15);
  233. transition: all 0.2s ease; // 动画过渡,更自然
  234. }
  235. .wechat-login-btn:active {
  236. transform: translateY(2rpx);
  237. box-shadow: 0 3rpx 8rpx rgba(90, 53, 247, 0.3),
  238. 0 1rpx 4rpx rgba(90, 53, 247, 0.2),
  239. inset 0 1rpx 2rpx rgba(255, 255, 255, 0.15),
  240. inset 0 -2rpx 3rpx rgba(0, 0, 0, 0.2);
  241. }
  242. .wechat-icon {
  243. width: 45rpx;
  244. height: 45rpx;
  245. margin-right: 15rpx;
  246. filter: drop-shadow(0 1rpx 2rpx rgba(0, 0, 0, 0.1)); // 给图标加轻微阴影,更立体
  247. }
  248. }
  249. .footer-tip {
  250. text-align: center;
  251. margin-top: 60rpx;
  252. padding: 30rpx;
  253. position: relative;
  254. z-index: 1;
  255. .tip-icon {
  256. font-size: 50rpx;
  257. display: block;
  258. margin-bottom: 15rpx;
  259. animation: heartbeat 2s infinite;
  260. }
  261. .tip-text {
  262. font-size: 26rpx;
  263. color: #333333;
  264. font-weight: 500;
  265. letter-spacing: 2rpx;
  266. }
  267. }
  268. button {
  269. &::after {
  270. border: none;
  271. }
  272. }
  273. </style>