UserSelection.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <view class="container">
  3. <!-- 用户部分 -->
  4. <view class="button-group">
  5. <image :src="imagePath2" mode="aspectFit" class="icon"></image>
  6. <up-button type="success" shape="circle" class="button" @click="handleBtn(1)">用户</up-button>
  7. </view>
  8. <!-- 志愿者部分 -->
  9. <view class="button-group">
  10. <image :src="imagePath1" mode="aspectFit" class="icon"></image>
  11. <up-button type="success" shape="circle" class="button" @click="handleBtn(2)">志愿者</up-button>
  12. </view>
  13. </view>
  14. </template>
  15. <script setup>
  16. import {
  17. userOrWorker
  18. } from '@/api/login';
  19. import store from "@/store"
  20. const imagePath1 = '/static/志愿者.png';
  21. const imagePath2 = '/static/用户.png';
  22. function handleBtn(userType = 0) { // 默认值 0
  23. const params = {
  24. userType: userType // 使用传入的 userType
  25. };
  26. // 把 userType 存入本地存储
  27. uni.setStorageSync('userType', userType);
  28. userOrWorker(params)
  29. .then(res => {
  30. // 重新拉取用户信息,储存本地
  31. store.dispatch('GetInfo').then(() => {
  32. uni.reLaunch({
  33. url: '/pages/index'
  34. });
  35. })
  36. })
  37. .catch(err => {
  38. console.error('设置失败:', err);
  39. });
  40. }
  41. </script>
  42. <style scoped>
  43. /* 外层容器 - 垂直排列两个按钮组 */
  44. .container {
  45. display: flex;
  46. flex-direction: column;
  47. align-items: center;
  48. justify-content: center;
  49. height: 100vh;
  50. /* 可根据需要调整高度 */
  51. }
  52. /* 每个按钮组(图片+按钮)垂直排列 */
  53. .button-group {
  54. display: flex;
  55. flex-direction: column;
  56. align-items: center;
  57. margin-bottom: 40rpx;
  58. /* 组与组之间的间距 */
  59. }
  60. /* 图标样式 */
  61. .icon {
  62. width: 100rpx;
  63. height: 100rpx;
  64. margin-bottom: 20rpx;
  65. /* 图片和按钮之间的间距 */
  66. }
  67. /* 按钮样式 (可根据需要调整) */
  68. .button {
  69. /* 如果uView按钮需要额外样式可以在这里添加 */
  70. }
  71. </style>