UserSelection.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.reLaunch({
  35. url: '/pages/index'
  36. });
  37. }
  38. </script>
  39. <style scoped>
  40. /* 外层容器 - 垂直排列两个按钮组 */
  41. .container {
  42. display: flex;
  43. flex-direction: column;
  44. align-items: center;
  45. justify-content: center;
  46. height: 100vh;
  47. /* 可根据需要调整高度 */
  48. }
  49. /* 每个按钮组(图片+按钮)垂直排列 */
  50. .button-group {
  51. display: flex;
  52. flex-direction: column;
  53. align-items: center;
  54. margin-bottom: 40rpx;
  55. /* 组与组之间的间距 */
  56. }
  57. /* 图标样式 */
  58. .icon {
  59. width: 100rpx;
  60. height: 100rpx;
  61. margin-bottom: 20rpx;
  62. /* 图片和按钮之间的间距 */
  63. }
  64. /* 按钮样式 (可根据需要调整) */
  65. .button {
  66. /* 如果uView按钮需要额外样式可以在这里添加 */
  67. }
  68. </style>