UserSelection.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <view class="container">
  3. <view class="select-title">欢迎使用</view>
  4. <view class="select-text">请选择您的身份开始使用</view>
  5. <view class="select-box">
  6. <view v-for="item in list" :key="item.key" class="select-item" :style="{ background: item.bgcColor }" @click="handleBtn(item.key)">
  7. <view class="select-img">
  8. <img :src="item.icon" alt="" style="width: 48px;height: 48px;">
  9. </view>
  10. <view class="select-text-box">
  11. <view class="select-lable">{{ item.label }}</view>
  12. <view class="select-box-text">{{ item.text }}</view>
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <script setup>
  19. import {
  20. userOrWorker
  21. } from '@/api/login';
  22. import store from "@/store"
  23. const list = [
  24. {
  25. label: '我是用户',
  26. text: '寻找并预约服务',
  27. icon: '/static/img/user.png',
  28. key: 1,
  29. bgcColor: 'linear-gradient(135deg, rgba(45, 58, 78, 1) 0%, rgba(61, 74, 94, 1) 100%), rgba(0, 0, 0, 0)'
  30. },
  31. {
  32. label: '我是志愿者',
  33. text: '提供专业服务',
  34. icon: '/static/img/admin.png',
  35. key: 2,
  36. bgcColor: 'linear-gradient(135deg, rgba(16, 185, 129, 1) 0%, rgba(32, 201, 145, 1) 100%), rgba(0, 0, 0, 0)'
  37. }
  38. ]
  39. function handleBtn(userType = 0) { // 默认值 0
  40. const params = {
  41. userType: userType // 使用传入的 userType
  42. };
  43. // 把 userType 存入本地存储
  44. uni.setStorageSync('userType', userType);
  45. userOrWorker(params)
  46. .then(res => {
  47. // 重新拉取用户信息,储存本地
  48. store.dispatch('GetInfo').then(() => {
  49. uni.reLaunch({
  50. url: '/pages/index'
  51. });
  52. })
  53. })
  54. .catch(err => {
  55. console.error('设置失败:', err);
  56. });
  57. }
  58. </script>
  59. <style scoped lang="scss">
  60. .container {
  61. padding: 28px 24px;
  62. display: flex;
  63. flex-direction: column;
  64. align-items: center;
  65. .select-title {
  66. font-size: 30px;
  67. font-weight: 400;
  68. line-height: 36px;
  69. color: rgba(45, 58, 78, 1);
  70. margin-bottom: 14px;
  71. }
  72. .select-text {
  73. font-size: 16px;
  74. font-weight: 400;
  75. line-height: 24px;
  76. color: rgba(75, 85, 99, 1);
  77. margin-bottom: 50px;
  78. }
  79. .select-box {
  80. width: 100%;
  81. .select-item {
  82. padding: 24px;
  83. display: flex;
  84. align-items: center;
  85. border-radius: 16px;
  86. margin-bottom: 24px;
  87. .select-img {
  88. margin-right: 24px;
  89. }
  90. .select-text-box {
  91. .select-lable {
  92. font-size: 20px;
  93. font-weight: 400;
  94. line-height: 28px;
  95. color: #fff;
  96. margin-bottom: 8px;
  97. }
  98. .select-box-text {
  99. font-size: 16px;
  100. font-weight: 400;
  101. line-height: 24px;
  102. color: #fff;
  103. }
  104. }
  105. }
  106. }
  107. }
  108. </style>