login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <template>
  2. <view class="login-container">
  3. <!-- Logo 区 -->
  4. <view class="logo-section">
  5. <image class="logo" src="/static/logo.png" mode="aspectFit" @error="handleImageError"></image>
  6. <text class="app-name">浠艾福</text>
  7. <text class="slogan">Care Family · 家庭健康成长俱乐部</text>
  8. </view>
  9. <!-- 平台简介 -->
  10. <view class="intro-section">
  11. <view class="intro-card">
  12. <view class="intro-title">🌏 给全家的一站式幸福提案</view>
  13. <view class="intro-desc">
  14. 围绕<span class="highlight">身、心、智、行、富</span>五个维度,用科技、智慧与温情,为您定制全生命周期解决方案。
  15. </view>
  16. <view class="dimension-tags">
  17. <view class="dim-tag dim-body">身 · 主动健康</view>
  18. <view class="dim-tag dim-mind">心 · 情绪丰盈</view>
  19. <view class="dim-tag dim-wisdom">智 · 赋能未来</view>
  20. <view class="dim-tag dim-action">行 · 知行合一</view>
  21. <view class="dim-tag dim-wealth">富 · 物质精神</view>
  22. </view>
  23. <view class="intro-powered">亿图腾科技出品</view>
  24. </view>
  25. </view>
  26. <!-- 微信一键登录 -->
  27. <view class="login-form">
  28. <view class="wechat-section">
  29. <button
  30. class="wechat-btn"
  31. :loading="loading"
  32. @click="handleWechatLogin"
  33. >
  34. <text class="wechat-icon">微信</text>
  35. <text>一键登录</text>
  36. </button>
  37. </view>
  38. <view class="agreement">
  39. <checkbox-group @change="onAgreementChange">
  40. <label>
  41. <checkbox value="agree" :checked="agreed" />
  42. <text class="agreement-text">我已阅读并同意</text>
  43. </label>
  44. </checkbox-group>
  45. <text class="link" @click="showAgreement">《用户协议》</text>
  46. <text class="agreement-text">和</text>
  47. <text class="link" @click="showPrivacy">《隐私政策》</text>
  48. </view>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import { wechatLogin, checkTeamInviteStatus, joinTeamByInvite } from '../../utils/api.js'
  54. export default {
  55. data() {
  56. return {
  57. loading: false,
  58. agreed: false,
  59. nickname: '',
  60. avatar: '',
  61. redirectUrl: ''
  62. }
  63. },
  64. onLoad(options) {
  65. // 处理邀请码
  66. if (options.inviteCode) {
  67. uni.setStorageSync('inviteCode', options.inviteCode)
  68. uni.setStorageSync('inviteType', options.inviteType || 'family')
  69. }
  70. // 存储登录后跳转地址
  71. if (options.redirect) {
  72. this.redirectUrl = decodeURIComponent(options.redirect)
  73. }
  74. },
  75. methods: {
  76. handleImageError(e) {
  77. console.log('Logo 加载失败,使用默认显示')
  78. },
  79. onAgreementChange(e) {
  80. this.agreed = e.detail.value.length > 0
  81. },
  82. showAgreement() {
  83. uni.navigateTo({
  84. url: '/pages/policy/agreement'
  85. })
  86. },
  87. showPrivacy() {
  88. uni.navigateTo({
  89. url: '/pages/policy/privacy'
  90. })
  91. },
  92. handleWechatLogin() {
  93. if (!this.agreed) {
  94. uni.showToast({ title: '请先同意用户协议', icon: 'none' })
  95. return
  96. }
  97. this.loading = true
  98. var self = this
  99. uni.login({
  100. provider: 'weixin',
  101. success: function(loginRes) {
  102. wechatLogin(loginRes.code, {
  103. nickname: self.nickname || '用户',
  104. avatar: self.avatar || ''
  105. }).then(function(res) {
  106. // 保存 token 和用户信息
  107. uni.setStorageSync('token', res.data.token)
  108. uni.setStorageSync('userId', res.data.userId)
  109. uni.setStorageSync('role', res.data.role)
  110. uni.setStorageSync('familyId', res.data.familyId)
  111. uni.setStorageSync('currentRole', res.data.role)
  112. uni.setStorageSync('isSwitchedChild', false)
  113. uni.setStorageSync('isSwitchedTeacher', false)
  114. // 保存 openid,用于后续自动登录
  115. if (res.data.openid) {
  116. uni.setStorageSync('openid', res.data.openid)
  117. }
  118. uni.setStorageSync('userInfo', {
  119. nickname: res.data.nickname,
  120. userId: res.data.userId
  121. })
  122. // 存储成长规划师审核状态
  123. if (res.data.teacherStatus) {
  124. uni.setStorageSync('teacherStatus', res.data.teacherStatus)
  125. }
  126. if (res.data.teacherRejectReason) {
  127. uni.setStorageSync('teacherRejectReason', res.data.teacherRejectReason)
  128. }
  129. uni.showToast({ title: '登录成功', icon: 'success' })
  130. // 根据角色跳转到对应首页,或进入信息编辑页面
  131. setTimeout(function() {
  132. if (res.data.needsRoleSelect) {
  133. uni.redirectTo({
  134. url: '/pages/user-edit/user-edit?token=' + res.data.token + '&userId=' + res.data.userId + '&needsRoleSelect=true'
  135. })
  136. } else {
  137. self.handlePostLoginRouting()
  138. }
  139. }, 1000)
  140. }).catch(function(e) {
  141. uni.showToast({ title: e.message || '登录失败', icon: 'none' })
  142. self.loading = false
  143. })
  144. },
  145. fail: function() {
  146. uni.showToast({ title: '微信登录失败', icon: 'none' })
  147. self.loading = false
  148. }
  149. })
  150. },
  151. handlePostLoginRouting() {
  152. const inviteCode = uni.getStorageSync('inviteCode')
  153. const inviteType = uni.getStorageSync('inviteType')
  154. if (inviteCode && inviteType === 'team') {
  155. this.handleTeamInviteFlow(inviteCode)
  156. } else {
  157. this.navigateToHome()
  158. }
  159. },
  160. async handleTeamInviteFlow(inviteCode) {
  161. try {
  162. const res = await checkTeamInviteStatus(inviteCode)
  163. const status = res.data.status
  164. if (status === 'not_planner') {
  165. uni.redirectTo({ url: `/pages/guide/register/index?inviteCode=${inviteCode}` })
  166. } else if (status === 'not_in_team') {
  167. uni.showModal({
  168. title: '加入团队',
  169. content: '是否加入该规划师团队?',
  170. success: async (confirmRes) => {
  171. if (confirmRes.confirm) {
  172. try {
  173. await joinTeamByInvite(inviteCode)
  174. uni.showToast({ title: '加入成功', icon: 'success' })
  175. uni.removeStorageSync('inviteCode')
  176. uni.removeStorageSync('inviteType')
  177. this.navigateToHome()
  178. } catch (e) {
  179. uni.showToast({ title: e.message || '加入失败', icon: 'none' })
  180. }
  181. } else {
  182. this.navigateToHome()
  183. }
  184. }
  185. })
  186. } else if (status === 'already_in_team') {
  187. uni.showModal({
  188. title: '加入新团队',
  189. content: '您已在其他团队中,离开当前团队并加入新团队?',
  190. success: async (confirmRes) => {
  191. if (confirmRes.confirm) {
  192. try {
  193. await joinTeamByInvite(inviteCode)
  194. uni.showToast({ title: '加入成功', icon: 'success' })
  195. uni.removeStorageSync('inviteCode')
  196. uni.removeStorageSync('inviteType')
  197. this.navigateToHome()
  198. } catch (e) {
  199. uni.showToast({ title: e.message || '加入失败', icon: 'none' })
  200. }
  201. } else {
  202. this.navigateToHome()
  203. }
  204. }
  205. })
  206. } else {
  207. this.navigateToHome()
  208. }
  209. } catch (e) {
  210. uni.showToast({ title: e.message || '处理邀请失败', icon: 'none' })
  211. this.navigateToHome()
  212. }
  213. },
  214. navigateToHome() {
  215. if (this.redirectUrl) {
  216. const redirect = this.redirectUrl
  217. this.redirectUrl = ''
  218. uni.reLaunch({ url: redirect })
  219. } else {
  220. uni.reLaunch({ url: '/pages/index/index' })
  221. }
  222. }
  223. }
  224. }
  225. </script>
  226. <style scoped>
  227. .login-container {
  228. min-height: 100vh;
  229. background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
  230. padding: 60rpx 40rpx;
  231. }
  232. /* ===== Logo 区 ===== */
  233. .logo-section {
  234. text-align: center;
  235. margin-bottom: 48rpx;
  236. }
  237. .logo {
  238. width: 160rpx;
  239. height: 160rpx;
  240. border-radius: 80rpx;
  241. background: #fff;
  242. }
  243. .app-name {
  244. display: block;
  245. font-size: 52rpx;
  246. font-weight: bold;
  247. color: #fff;
  248. margin-top: 20rpx;
  249. }
  250. .slogan {
  251. display: block;
  252. font-size: 26rpx;
  253. color: rgba(255, 255, 255, 0.8);
  254. margin-top: 10rpx;
  255. }
  256. /* ===== 平台简介卡片 ===== */
  257. .intro-section {
  258. margin-bottom: 48rpx;
  259. }
  260. .intro-card {
  261. background: rgba(255, 255, 255, 0.15);
  262. border: 1rpx solid rgba(255, 255, 255, 0.3);
  263. border-radius: 20rpx;
  264. padding: 32rpx 28rpx;
  265. backdrop-filter: blur(10px);
  266. }
  267. .intro-title {
  268. font-size: 30rpx;
  269. font-weight: bold;
  270. color: #fff;
  271. text-align: center;
  272. margin-bottom: 16rpx;
  273. }
  274. .intro-desc {
  275. font-size: 24rpx;
  276. color: rgba(255, 255, 255, 0.9);
  277. line-height: 1.7;
  278. text-align: center;
  279. margin-bottom: 24rpx;
  280. }
  281. .intro-desc .highlight {
  282. color: #FFD700;
  283. font-weight: 600;
  284. }
  285. .dimension-tags {
  286. display: flex;
  287. flex-wrap: wrap;
  288. justify-content: center;
  289. gap: 12rpx;
  290. margin-bottom: 20rpx;
  291. }
  292. .dim-tag {
  293. font-size: 22rpx;
  294. padding: 8rpx 16rpx;
  295. border-radius: 30rpx;
  296. background: rgba(255, 255, 255, 0.2);
  297. color: #fff;
  298. font-weight: 500;
  299. }
  300. .dim-body { background: rgba(91, 155, 213, 0.4); }
  301. .dim-mind { background: rgba(236, 72, 153, 0.4); }
  302. .dim-wisdom { background: rgba(139, 92, 246, 0.4); }
  303. .dim-action { background: rgba(16, 185, 129, 0.4); }
  304. .dim-wealth { background: rgba(245, 158, 11, 0.4); }
  305. .intro-powered {
  306. text-align: center;
  307. font-size: 20rpx;
  308. color: rgba(255, 255, 255, 0.6);
  309. }
  310. /* ===== 登录表单 ===== */
  311. .login-form {
  312. background: #fff;
  313. border-radius: 20rpx;
  314. padding: 40rpx;
  315. }
  316. .wechat-section {
  317. margin-bottom: 32rpx;
  318. }
  319. .wechat-btn {
  320. display: flex;
  321. align-items: center;
  322. justify-content: center;
  323. gap: 10rpx;
  324. width: 100%;
  325. height: 88rpx;
  326. background: #07c160;
  327. color: #fff;
  328. border-radius: 44rpx;
  329. font-size: 32rpx;
  330. }
  331. .wechat-icon {
  332. font-size: 36rpx;
  333. }
  334. .agreement {
  335. margin-top: 16rpx;
  336. text-align: center;
  337. font-size: 24rpx;
  338. }
  339. .agreement-text {
  340. color: #666;
  341. }
  342. .link {
  343. color: #667eea;
  344. }
  345. .agreement-text.link {
  346. text-decoration: underline;
  347. }
  348. </style>