云链智安app
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

index.vue 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <view class="container">
  3. <view class="account_number">
  4. <image @click="chooseImage" class="account_to" :src="user.user.avatar" mode=""></image>
  5. </view>
  6. <view class="toptabbar">
  7. <view class="toptabbar_">
  8. <view class="toptabbar_box">
  9. <view class="toptabbar_left">
  10. 名称
  11. </view>
  12. <view class="toptabbar_right">
  13. {{user.user.loginName||''}}
  14. </view>
  15. </view>
  16. <view class="toptabbar_box">
  17. <view class="toptabbar_left">
  18. 角色
  19. </view>
  20. <view class="toptabbar_right">
  21. {{user.user.roles[0].roleName||''}}
  22. </view>
  23. </view>
  24. <view class="toptabbar_box">
  25. <view class="toptabbar_left">
  26. 公司
  27. </view>
  28. <view class="toptabbar_right">
  29. {{user.user.dept.deptName||''}}
  30. </view>
  31. </view>
  32. <view class="toptabbar_box">
  33. <view class="toptabbar_left">
  34. 创建时间
  35. </view>
  36. <view class="toptabbar_right">
  37. {{user.user.createTime||''}}
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <!-- -->
  45. <script>
  46. import request from '@/utils/request';
  47. export default {
  48. data() {
  49. return {
  50. user:[],
  51. }
  52. },
  53. onLoad() {
  54. this.getuserinfo()
  55. },
  56. methods: {
  57. async getuserinfo() {
  58. try {
  59. const response = await request({
  60. url: '/platform/user/selectaccountNumber',
  61. method: 'post',
  62. header: {
  63. 'Content-Type': 'application/x-www-form-urlencoded'
  64. },
  65. });
  66. this.user = response.data
  67. } catch (error) {
  68. console.error('登录失败:', error);
  69. }
  70. },
  71. // 选择图片
  72. chooseImage() {
  73. uni.chooseImage({
  74. count: 1,
  75. sizeType: ['original', 'compressed'],
  76. sourceType: ['album', 'camera'],
  77. success: (res) => {
  78. const tempFilePaths = res.tempFilePaths;
  79. // 使用 uni.uploadFile 方式上传
  80. this.uploadFile(tempFilePaths[0]);
  81. },
  82. fail: (err) => {
  83. console.error('选择图片失败:', err);
  84. uni.showToast({
  85. title: '选择图片失败',
  86. icon: 'none'
  87. });
  88. }
  89. });
  90. },
  91. // 使用 uni.uploadFile 上传
  92. async uploadFile(filePath) {
  93. uni.showLoading({
  94. title: '上传中...'
  95. });
  96. try {
  97. const response = await new Promise((resolve, reject) => {
  98. uni.uploadFile({
  99. url: 'https://esos-iot.bjdexn.cn/platform/shu/upload/webPost', // 如 '/platform/shu/upload/webPost'
  100. filePath: filePath,
  101. name: 'file', // 后端接收的字段名
  102. formData: {},
  103. success: resolve,
  104. fail: reject
  105. });
  106. });
  107. const res = JSON.parse(response.data);
  108. await this.updateAvatar(res.data.url);
  109. uni.hideLoading();
  110. uni.showToast({
  111. title: '上传成功',
  112. icon: 'success'
  113. });
  114. } catch (error) {
  115. console.error('上传失败:', error);
  116. uni.hideLoading();
  117. uni.showToast({
  118. title: '上传失败',
  119. icon: 'none'
  120. });
  121. }
  122. },
  123. // 更新头像URL
  124. async updateAvatar(url) {
  125. try {
  126. const response = await request({
  127. url: '/platform/user/profile/update',
  128. method: 'post',
  129. header: {
  130. 'Content-Type': 'application/x-www-form-urlencoded'
  131. },
  132. data:{avatar:url},
  133. });
  134. this.getuserinfo();
  135. // 更新本地用户信息等操作
  136. } catch (error) {
  137. console.error('头像更新失败:', error);
  138. throw error;
  139. }
  140. }
  141. }
  142. }
  143. </script>
  144. <style scoped>
  145. .uni-page{
  146. width: 100%;
  147. height: 100%;
  148. }
  149. .container {
  150. height: 100%;
  151. /* background: linear-gradient(to bottom, #007545 -40%, #f0f5f5 40%, #f0f5f5 100%); */
  152. background-color: #f5f5f5;
  153. box-sizing: border-box;
  154. }
  155. .account_number{
  156. width: 100%;
  157. padding: 20rpx;
  158. display: flex;
  159. justify-content: center;
  160. box-sizing: border-box;
  161. }
  162. .account_to{
  163. width: 200rpx;
  164. height: 200rpx;
  165. border-radius: 100rpx;
  166. }
  167. .toptabbar {
  168. width: 100%;
  169. padding: 10rpx 40rpx;
  170. box-sizing: border-box;
  171. }
  172. .toptabbar_{
  173. border-radius: 10rpx;
  174. overflow: hidden;
  175. padding:0rpx 20rpx 20rpx 20rpx;
  176. background-color: #ffffff;
  177. }
  178. .toptabbar_box{
  179. width: 100%;
  180. height: 120rpx;
  181. display: flex;
  182. align-items: center;
  183. justify-content: space-between;
  184. border-bottom: 1rpx #f5f5f5 solid;
  185. }
  186. .toptabbar_left{
  187. font-size: 28rpx;
  188. }
  189. </style>