UserSelection.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. const imagePath1 = '/static/志愿者.png';
  20. const imagePath2 = '/static/用户.png';
  21. function handleBtn(userType = 0) { // 默认值 0
  22. const params = {
  23. userType: userType // 使用传入的 userType
  24. };
  25. // 把 userType 存入本地存储
  26. uni.setStorageSync('userType', userType);
  27. userOrWorker(params)
  28. .then(res => {
  29. console.log(res, '用户类型设置成功');
  30. })
  31. .catch(err => {
  32. console.error('设置失败:', err);
  33. });
  34. // uni.redirectTo({
  35. // url: '/pages//index'
  36. // });
  37. uni.reLaunch({
  38. url: '/pages/index'
  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>