page3.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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. <<<<<<< HEAD
  51. loset(Logon_Credentials){
  52. console.log('=== 开始微信登录流程 ===')
  53. console.log('用户输入信息:', Logon_Credentials)
  54. // 获取微信登录code
  55. uni.login({
  56. provider: 'weixin',
  57. success: async (loginRes) => {
  58. const loginParams = {
  59. code: loginRes.code.trim(), // 必需:微信登录code
  60. nickname: Logon_Credentials.nickname?.trim() || '', // 可选:用户昵称(从Logon_Credentials获取)
  61. avatarUrl: Logon_Credentials.active?.trim() || '', // 可选:用户头像(注意:后端字段是avatarUrl,前端若存的是active,需对应)
  62. phoneCode: Logon_Credentials.code?.trim() || '' // 可选:手机号授权code(从Logon_Credentials获取)
  63. };
  64. uni.showLoading({ title: '登录中...' })
  65. try {
  66. // 1. 微信授权登录
  67. // const wechatLoginResult = await api.auth.wechatLogin(loginParams)
  68. // ✅ 获取手机号code
  69. const phoneCode = (Logon_Credentials && Logon_Credentials.code && String(Logon_Credentials.code).trim())
  70. ? String(Logon_Credentials.code).trim()
  71. : null;
  72. console.log('微信登录code:', loginRes.code)
  73. console.log('用户昵称:', Logon_Credentials.nickname)
  74. console.log('用户头像:', Logon_Credentials.active ? '已提供' : '未提供')
  75. console.log('手机号code:', phoneCode || '未提供')
  76. // ✅ 一次性调用微信登录接口,传入所有信息
  77. const wechatLoginResult = await api.auth.wechatLogin({
  78. code: loginRes.code,
  79. nickname: Logon_Credentials.nickname || '微信用户',
  80. avatarUrl: Logon_Credentials.active || null,
  81. phoneCode: phoneCode
  82. });
  83. const token = wechatLoginResult?.token || wechatLoginResult?.data?.token
  84. const user = wechatLoginResult?.user || wechatLoginResult?.data?.user
  85. if (!token || !user) {
  86. throw new Error('微信登录返回数据异常')
  87. }
  88. console.log('✅ 微信登录成功,用户ID:', user.userId)
  89. uni.setStorageSync("userId", user.userId);
  90. // 2. 获取手机号
  91. // const phoneCode = (Logon_Credentials && Logon_Credentials.code && String(Logon_Credentials.code).trim()) ? String(Logon_Credentials.code).trim() : 'mock_dev_code'
  92. console.log('📱 使用phoneCode:', phoneCode)
  93. console.log('✅ 微信登录成功')
  94. console.log('用户ID:', user.userId)
  95. console.log('昵称:', user.nickname)
  96. console.log('头像:', user.avatarUrl ? '已设置' : '未设置')
  97. console.log('手机号:', user.phone || '未设置')
  98. // ✅ 保存登录信息(后端已返回完整信息,直接保存)
  99. userAuth.saveLoginInfo(token, user)
  100. uni.hideLoading()
  101. uni.showToast({ title: '登录成功', icon: 'success' })
  102. // ✅ 跳转首页
  103. setTimeout(() => {
  104. const target = this.redirectUrl || '/pages/index/index'
  105. uni.reLaunch({ url: target })
  106. }, 500)
  107. } catch (error) {
  108. console.error('❌ 微信登录失败:', error)
  109. uni.hideLoading()
  110. uni.showToast({
  111. title: error?.message || '登录失败,请重试',
  112. icon: 'none',
  113. duration: 2000
  114. })
  115. =======
  116. loset(Logon_Credentials){
  117. console.log(Logon_Credentials,'登录信息')
  118. // 获取微信登录code
  119. uni.login({
  120. provider: 'weixin',
  121. success: async (loginRes) => {
  122. uni.showLoading({ title: '登录中...' })
  123. try {
  124. // 1. 微信授权登录
  125. const wechatLoginResult = await api.auth.wechatLogin(loginRes.code)
  126. const token = wechatLoginResult?.token || wechatLoginResult?.data?.token
  127. const user = wechatLoginResult?.user || wechatLoginResult?.data?.user
  128. if (!token || !user) {
  129. throw new Error('微信登录返回数据异常')
  130. }
  131. console.log('✅ 微信登录成功,用户ID:', user.userId)
  132. // 2. 获取手机号
  133. const phoneCode = (Logon_Credentials && Logon_Credentials.code && String(Logon_Credentials.code).trim()) ? String(Logon_Credentials.code).trim() : 'mock_dev_code'
  134. console.log('📱 使用phoneCode:', phoneCode)
  135. try {
  136. const phoneResult = await api.auth.wechatPhone(phoneCode)
  137. const phone = phoneResult?.phone || phoneResult?.data?.phone
  138. if (phone) {
  139. console.log('✅ 成功获取手机号')
  140. user.phone = phone
  141. } else {
  142. console.warn('⚠️ 手机号为空,使用默认值(开发环境)')
  143. // 开发环境:如果后端返回了mock手机号,也可能在user对象中
  144. user.phone = user.phone || '13800138000'
  145. }
  146. } catch (phoneError) {
  147. console.error('❌ 获取手机号接口失败:', phoneError)
  148. // 开发环境容错:继续登录,使用默认手机号
  149. user.phone = user.phone || '13800138000'
  150. console.warn('⚠️ 使用默认手机号继续登录(开发环境)')
  151. }
  152. // 3. 更新用户信息(昵称和头像)
  153. user.nickname = Logon_Credentials.nickname || user.nickname
  154. user.avatar = Logon_Credentials.active || user.avatar
  155. console.log('💾 保存用户信息:', { userId: user.userId, phone: user.phone, nickname: user.nickname })
  156. // 4. 如果用户输入了昵称或头像,更新到后端
  157. if (Logon_Credentials.nickname || Logon_Credentials.active) {
  158. try {
  159. await api.user.updateInfo({
  160. userId: user.userId,
  161. nickname: user.nickname,
  162. avatarUrl: user.avatar
  163. })
  164. console.log('✅ 用户信息已更新到后端')
  165. } catch (updateError) {
  166. console.warn('⚠️ 更新用户信息失败:', updateError)
  167. // 不影响登录流程,继续
  168. }
  169. }
  170. // 5. 保存登录信息
  171. userAuth.saveLoginInfo(token, user)
  172. uni.hideLoading()
  173. uni.showToast({ title: '登录成功', icon: 'success' })
  174. // 5. 跳转首页
  175. setTimeout(() => {
  176. const target = this.redirectUrl || '/pages/index/index'
  177. uni.reLaunch({ url: target })
  178. }, 500)
  179. } catch (error) {
  180. console.error('❌ 微信登录失败:', error)
  181. uni.hideLoading()
  182. uni.showToast({
  183. title: error?.message || '登录失败,请重试',
  184. icon: 'none',
  185. duration: 2000
  186. })
  187. }
  188. },
  189. fail: (err) => {
  190. console.error('获取微信code失败:', err)
  191. uni.showToast({ title: '微信登录失败', icon: 'none' })
  192. >>>>>>> yh
  193. }
  194. })
  195. }
  196. }
  197. }
  198. </script>
  199. <style lang="scss" scoped>
  200. .content {
  201. padding: 40rpx;
  202. min-height: 100vh;
  203. position: relative;
  204. overflow: hidden;
  205. .bg-image {
  206. position: fixed;
  207. top: 0;
  208. left: 0;
  209. width: 100%;
  210. height: 100%;
  211. z-index: 0;
  212. pointer-events: none;
  213. }
  214. // 添加装饰性元素
  215. &::before {
  216. content: '❤️';
  217. position: absolute;
  218. top: 100rpx;
  219. right: 60rpx;
  220. font-size: 60rpx;
  221. opacity: 0.2;
  222. animation: heartbeat 2s infinite;
  223. }
  224. &::after {
  225. content: '💕';
  226. position: absolute;
  227. bottom: 200rpx;
  228. left: 40rpx;
  229. font-size: 50rpx;
  230. opacity: 0.2;
  231. animation: heartbeat 2s infinite 0.5s;
  232. }
  233. }
  234. @keyframes heartbeat {
  235. 0%, 100% {
  236. transform: scale(1);
  237. }
  238. 50% {
  239. transform: scale(1.1);
  240. }
  241. }
  242. .header-section {
  243. text-align: center;
  244. margin-bottom: 60rpx;
  245. position: relative;
  246. z-index: 1;
  247. .app-logo {
  248. font-size: 120rpx;
  249. margin-bottom: 20rpx;
  250. // animation: heartbeat 1s infinite;
  251. }
  252. .app-name {
  253. font-size: 48rpx;
  254. font-weight: bold;
  255. background: linear-gradient(135deg, #ff6b9d 0%, #ff8fab 100%);
  256. -webkit-background-clip: text;
  257. -webkit-text-fill-color: transparent;
  258. margin-bottom: 15rpx;
  259. }
  260. .app-slogan {
  261. font-size: 26rpx;
  262. color: #333333;
  263. opacity: 0.8;
  264. }
  265. }
  266. .login-box {
  267. background: rgba(211, 127, 140, 0);
  268. border-radius: 30rpx;
  269. padding: 80rpx 40rpx;
  270. margin-bottom: 30rpx;
  271. box-shadow: 0 8rpx 24rpx rgba(255, 107, 157, 0.15);
  272. border: 2rpx solid rgba(255, 107, 157, 0.1);
  273. display: flex;
  274. justify-content: center;
  275. align-items: center;
  276. position: relative;
  277. z-index: 1;
  278. // .wechat-login-btn {
  279. // width: 100%;
  280. // height: 90rpx;
  281. // background: #FFFFFF;
  282. // color: #ff6b9d;
  283. // border-radius: 50rpx;
  284. // font-size: 30rpx;
  285. // font-weight: bold;
  286. // display: flex;
  287. // align-items: center;
  288. // justify-content: center;
  289. // border: 2rpx solid #ff6b9d;
  290. // box-shadow: 0 8rpx 20rpx rgba(255, 107, 157, 0.2);
  291. // .wechat-icon {
  292. // width: 40rpx;
  293. // height: 40rpx;
  294. // margin-right: 10rpx;
  295. // }
  296. // &:active {
  297. // opacity: 0.9;
  298. // transform: translateY(2rpx);
  299. // }
  300. // }
  301. .wechat-login-btn {
  302. width: 100%;
  303. height: 96rpx;
  304. // 渐变背景+光泽叠加
  305. background: linear-gradient(90deg, #9d40e9 0%, #5a35f7 100%),
  306. radial-gradient(circle at 30% 30%, rgba(255,255,255,0.15), transparent 50%);
  307. background-blend-mode: overlay;
  308. color: #ffffff;
  309. border-radius: 60rpx;
  310. font-size: 32rpx;
  311. font-weight: bold;
  312. display: flex;
  313. align-items: center;
  314. justify-content: center;
  315. border: none;
  316. // 多层光影:外层投影+内高光+内阴影
  317. box-shadow:
  318. 0 6rpx 16rpx rgba(90, 53, 247, 0.4),
  319. 0 3rpx 8rpx rgba(90, 53, 247, 0.2),
  320. inset 0 2rpx 3rpx rgba(255, 255, 255, 0.25),
  321. inset 0 -2rpx 3rpx rgba(0, 0, 0, 0.15);
  322. transition: all 0.2s ease; // 动画过渡,更自然
  323. }
  324. .wechat-login-btn:active {
  325. transform: translateY(2rpx);
  326. box-shadow:
  327. 0 3rpx 8rpx rgba(90, 53, 247, 0.3),
  328. 0 1rpx 4rpx rgba(90, 53, 247, 0.2),
  329. inset 0 1rpx 2rpx rgba(255, 255, 255, 0.15),
  330. inset 0 -2rpx 3rpx rgba(0, 0, 0, 0.2);
  331. }
  332. .wechat-icon {
  333. width: 45rpx;
  334. height: 45rpx;
  335. margin-right: 15rpx;
  336. filter: drop-shadow(0 1rpx 2rpx rgba(0,0,0,0.1)); // 给图标加轻微阴影,更立体
  337. }
  338. }
  339. .footer-tip {
  340. text-align: center;
  341. margin-top: 60rpx;
  342. padding: 30rpx;
  343. position: relative;
  344. z-index: 1;
  345. .tip-icon {
  346. font-size: 50rpx;
  347. display: block;
  348. margin-bottom: 15rpx;
  349. animation: heartbeat 2s infinite;
  350. }
  351. .tip-text {
  352. font-size: 26rpx;
  353. color: #333333;
  354. font-weight: 500;
  355. letter-spacing: 2rpx;
  356. }
  357. }
  358. button {
  359. &::after {
  360. border: none;
  361. }
  362. }
  363. </style>