user-info.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view class="user-info-page">
  3. <!-- 头像区域 -->
  4. <view class="avatar-section">
  5. <view class="avatar-wrap">
  6. <text>头像:</text>
  7. <u-avatar :size="50" :src="userInfo.avatar"></u-avatar>
  8. <u-button type="success" style="width:200rpx" size="small" @click="handleEditAvatar">去修改</u-button>
  9. </view>
  10. </view>
  11. <!-- 基本信息区域 -->
  12. <view class="info-section">
  13. <view class="section-title">基本信息</view>
  14. <view class="info-card">
  15. <u-cell-group :border="false">
  16. <u-cell title="姓名" :value="userInfo.nickName || '无'" />
  17. <u-cell title="性别" :value="userInfo.sex == 0 ? '男' : userInfo.sex == 1 ? '女' : '未知' || '无'" />
  18. <u-cell title="生日" :value="userInfo.birthday || '无'" />
  19. <u-cell title="学历" :value="userInfo.education || '无'" />
  20. <u-cell title="毕业学校" :value="userInfo.school || '无'" :border="false" />
  21. </u-cell-group>
  22. </view>
  23. </view>
  24. <!-- 账号信息区域 -->
  25. <view class="info-section">
  26. <view class="section-title">用户账号</view>
  27. <view class="info-card">
  28. <u-cell-group :border="false">
  29. <u-cell title="账号" :value="userInfo.userName" />
  30. <u-cell title="创建日期" :value="userInfo.createTime" />
  31. <u-cell title="最近登录" :value="userInfo.loginDate || '--'" :border="false" />
  32. </u-cell-group>
  33. </view>
  34. </view>
  35. <!-- 员工资料区域 -->
  36. <view class="info-section">
  37. <view class="section-title">员工资料</view>
  38. <view class="info-card">
  39. <u-cell-group :border="false">
  40. <u-cell title="公司" :value="userInfo.company || '无'" />
  41. <u-cell title="员工编号" :value="userInfo.employeeId || '无'" />
  42. <u-cell title="职位" :value="userInfo.position || '无'" :border="false" />
  43. </u-cell-group>
  44. </view>
  45. </view>
  46. <!-- 联系方式区域 -->
  47. <view class="info-section">
  48. <view class="section-title">联系方式</view>
  49. <view class="info-card">
  50. <u-cell-group :border="false">
  51. <u-cell title="电话" :value="userInfo.phonenumber" />
  52. <u-cell title="邮箱" :value="userInfo.email || '无'" />
  53. <u-cell title="住址" :value="userInfo.address || '无'" :border="false" />
  54. </u-cell-group>
  55. </view>
  56. </view>
  57. </view>
  58. </template>
  59. <script setup>
  60. import {
  61. ref
  62. } from 'vue'
  63. import baseUrl from '@/config/request.js';
  64. const userInfo = ref({
  65. avatar: '/static/images/avatar.jpg',
  66. name: '无',
  67. gender: '无',
  68. birthday: '无',
  69. education: '无',
  70. school: '无',
  71. username: '用户账号',
  72. account: 'fxt',
  73. createTime: '2024-06-12 12:00:00',
  74. lastLogin: '',
  75. company: '无',
  76. employeeId: '无',
  77. position: '无',
  78. phone: '18888888888',
  79. email: '无',
  80. address: '无'
  81. })
  82. //获取用户信息
  83. function getUserInfo() {
  84. uni.$u.http.get('/app/appUser/getUserInfoById').then(res => {
  85. if (res.code == 200) {
  86. userInfo.value = res.data
  87. }
  88. })
  89. }
  90. getUserInfo()
  91. //设置头像 /app/appUser/setAvatar 入参 avatarfile
  92. function setAvatar(avatarfile) {
  93. uni.$u.http.post('/app/appUser/setAvatar?avatarfile='+avatarfile).then(res => {
  94. if (res.code == 200) {
  95. userInfo.value.avatar = avatarfile
  96. uni.showToast({
  97. title: '头像设置成功',
  98. icon: 'success'
  99. })
  100. }
  101. })
  102. }
  103. const handleEditAvatar = () => {
  104. const token = uni.getStorageSync('token')
  105. uni.chooseImage({
  106. count: 1,
  107. success: (res) => {
  108. const filePath = res.tempFilePaths[0]
  109. uni.uploadFile({
  110. url: `${baseUrl}/common/upload`,
  111. filePath: filePath,
  112. name: 'file',
  113. header: {
  114. "Authorization": token
  115. },
  116. success: (uploadRes) => {
  117. const data = JSON.parse(uploadRes.data)
  118. if (data.code === 200) {
  119. setAvatar(data.url)
  120. } else {
  121. uni.showToast({
  122. title: '上传失败',
  123. icon: 'none'
  124. })
  125. }
  126. },
  127. fail: () => {
  128. uni.showToast({
  129. title: '上传失败',
  130. icon: 'none'
  131. })
  132. }
  133. })
  134. }
  135. })
  136. }
  137. </script>
  138. <style>
  139. page {
  140. background: #F5F6FA;
  141. }
  142. </style>
  143. <style lang="scss" scoped>
  144. .user-info-page {
  145. padding: 20rpx;
  146. box-sizing: border-box;
  147. .avatar-section {
  148. background: #FFFFFF;
  149. border-radius: 16rpx;
  150. padding: 40rpx;
  151. margin-bottom: 20rpx;
  152. .avatar-wrap {
  153. display: flex;
  154. align-items: center;
  155. gap: 30rpx;
  156. }
  157. }
  158. .info-section {
  159. margin-bottom: 20rpx;
  160. .section-title {
  161. font-size: 28rpx;
  162. color: #666;
  163. padding: 20rpx 10rpx;
  164. font-weight: 500;
  165. }
  166. .info-card {
  167. background: #FFFFFF;
  168. border-radius: 16rpx;
  169. overflow: hidden;
  170. }
  171. }
  172. }
  173. </style>