switch.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view class="container">
  3. <!-- 背景图片区域 -->
  4. <img class="img_bg" src="../../static/images/center-bg.png" />
  5. <!-- 身份列表区域 -->
  6. <view class="list">
  7. <!-- 每一个身份区域 -->
  8. <view class="list_item" v-for="item in listData" :key="item.id" @click="handleChange(item)">
  9. <!-- 头像 -->
  10. <img class="item_img" mode="aspectFill" :src="item.headImage || '/static/images/header.png'" />
  11. <!-- 姓名 -->
  12. <view class="item_name">{{ item.name }}</view>
  13. <!-- 身份类别 -->
  14. <view v-if="item.identityId === 1" class="item_type parents">家长</view>
  15. <view v-if="item.identityId === 2" class="item_type student">学生</view>
  16. <view v-if="item.identityId === 3" class="item_type teacher">老师</view>
  17. <!-- 是否设置成默认身份 -->
  18. <!-- <view class="item_default" @click="handleClick(item)">
  19. <radio style="transform: scale(0.5)" :checked="item.isCheck"></radio>
  20. 设置默认身份
  21. </view> -->
  22. <!-- 是否选中 -->
  23. <!-- <uni-icons v-if="item.id === currentId" class="item_check" type="checkmarkempty" size="30" color="#00BAAD"></uni-icons> -->
  24. <div v-if="item.id === currentId" class="item_check">当前身份</div>
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script setup>
  30. import { onLoad } from '@dcloudio/uni-app'
  31. import { ref } from 'vue'
  32. onLoad((options) => {
  33. let info = JSON.parse(decodeURIComponent(options.info))
  34. // console.log(info)
  35. uni.setStorageSync('token', info.token)
  36. currentId.value = uni.getStorageSync('userInfo').id || ''
  37. listData.value = info.user
  38. })
  39. // 用户身份列表
  40. const listData = ref([])
  41. // 当前展示身份id
  42. const currentId = ref()
  43. // 点击是否设置默认身份按钮回调
  44. // const handleClick = (item) => {
  45. // listData.value.forEach((ele) => {
  46. // ele.isCheck = false
  47. // })
  48. // item.isCheck = true
  49. // }
  50. // 点击每一个身份时的回调
  51. const handleChange = (item) => {
  52. // console.log(item)
  53. uni.setStorageSync('userhead', item.userhead)
  54. uni.setStorageSync('userInfo', item)
  55. uni.reLaunch({
  56. url: '/pages/home/home'
  57. })
  58. }
  59. </script>
  60. <style lang="scss" scoped>
  61. .container {
  62. min-height: 100vh;
  63. background-color: #f1f6fe;
  64. .img_bg {
  65. position: absolute;
  66. top: -70rpx;
  67. right: 0;
  68. width: 589rpx;
  69. height: 320rpx;
  70. pointer-events: none;
  71. }
  72. .list {
  73. z-index: 1;
  74. position: relative;
  75. padding: 58rpx 20rpx;
  76. .list_item {
  77. position: relative;
  78. display: flex;
  79. box-sizing: border-box;
  80. padding: 30rpx 22rpx;
  81. margin-bottom: 30rpx;
  82. width: 710rpx;
  83. height: 177rpx;
  84. border-radius: 8rpx;
  85. background-color: #fff;
  86. .item_img {
  87. width: 60rpx;
  88. height: 60rpx;
  89. border-radius: 50%;
  90. object-fit: cover;
  91. }
  92. .item_name {
  93. margin: 10rpx 16rpx 0 23rpx;
  94. height: 30rpx;
  95. font-size: 28rpx;
  96. }
  97. .item_type {
  98. margin-top: 15rpx;
  99. padding: 0 20rpx;
  100. height: 30rpx;
  101. font-size: 20rpx;
  102. color: #fff;
  103. border-radius: 28rpx;
  104. }
  105. .teacher {
  106. background-color: #00baad;
  107. }
  108. .parents {
  109. background-color: #0061ff;
  110. }
  111. .student {
  112. background-color: orange;
  113. }
  114. .item_default {
  115. position: absolute;
  116. top: 118rpx;
  117. left: 22rpx;
  118. font-size: 16rpx;
  119. color: #a6a6a6;
  120. }
  121. .item_check {
  122. position: absolute;
  123. top: 50%;
  124. right: 48rpx;
  125. transform: translateY(-50%);
  126. color: #00baad;
  127. }
  128. }
  129. }
  130. }
  131. </style>