1
0

info.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <view class="main pdt0">
  3. <view class="form">
  4. <view class="form_group">
  5. <view class="lable re" style="margin-top: 19px">头像</view>
  6. <image :src="user.avatar ? ip + user.avatar : '../../static/head.png'" class="head" @click="choice()"></image>
  7. </view>
  8. <view class="form_group">
  9. <view class="lable re">姓名</view>
  10. <input v-model="user.nickName" placeholder="请输入姓名" />
  11. </view>
  12. <view class="form_group">
  13. <view class="lable">科室</view>
  14. <view class="desc">{{ user.dept.deptName }}</view>
  15. </view>
  16. <view class="form_group">
  17. <view class="lable">角色</view>
  18. <view class="desc" v-if="user.roles.length > 0">{{ user.roles[0].roleName }}</view>
  19. </view>
  20. <view class="form_group">
  21. <view class="lable re">个人介绍</view>
  22. </view>
  23. <leditor ref="editor" v-model="user.introduce"></leditor>
  24. </view>
  25. <button class="btn" @click="save()">
  26. <text class="icon">&#xe653;</text>
  27. <text>确认修改</text>
  28. </button>
  29. </view>
  30. </template>
  31. <script>
  32. export default {
  33. data() {
  34. return {
  35. ip: this.http.ip,
  36. user: this.getUser()
  37. };
  38. },
  39. onLoad() {
  40. setTimeout(() => {
  41. this.$refs.editor.setContents();
  42. }, 300);
  43. // 监听从裁剪页发布的事件,获得裁剪结果
  44. uni.$on('uAvatarCropper', (path) => {
  45. uni.showLoading({ title: '正在上传...', mask: true });
  46. // 上传到服务端
  47. uni.uploadFile({
  48. url: this.ip + '/system/user/profile/avatar',
  49. filePath: path,
  50. name: 'avatarfile',
  51. header: { Authorization: this.getUser().token },
  52. contentType: 'application/x-www-form-urlencoded',
  53. success: (res) => {
  54. let r = JSON.parse(res.data);
  55. if (r.code === 200) {
  56. uni.showToast({ title: '更新成功' });
  57. this.user.avatar = r.imgUrl;
  58. let user = this.getUser();
  59. user.avatar = this.user.avatar;
  60. uni.setStorageSync('user', user);
  61. this.$forceUpdate();
  62. } else {
  63. uni.hideLoading();
  64. uni.showModal({ content: r.msg, showCancel: false });
  65. }
  66. }
  67. });
  68. });
  69. },
  70. methods: {
  71. choice() {
  72. uni.navigateTo({
  73. url: '/components/u-avatar-cropper/u-avatar-cropper?destWidth=100&rectWidth=140&fileType=jpg'
  74. });
  75. },
  76. save() {
  77. let rule = [
  78. { name: 'avatar', checkType: 'notnull', errorMsg: '请上传头像' },
  79. { name: 'nickName', checkType: 'notnull', errorMsg: '请输入姓名' },
  80. { name: 'introduce', checkType: 'editor', errorMsg: '请输入个人介绍' }
  81. ];
  82. if (!this.verify.check(this.user, rule)) {
  83. uni.showModal({ content: this.verify.error, showCancel: false });
  84. return false;
  85. }
  86. this.http.request({
  87. url: '/system/user/editInfo',
  88. data: { nickName: this.user.nickName, introduce: this.user.introduce },
  89. method: 'POST',
  90. success: (res) => {
  91. let user = this.getUser();
  92. user.nickName = this.user.nickName;
  93. user.introduce = this.user.introduce;
  94. uni.setStorageSync('user', user);
  95. uni.showToast({ title: '编辑成功' });
  96. }
  97. });
  98. }
  99. }
  100. };
  101. </script>
  102. <style lang="scss">
  103. .form {
  104. .head {
  105. width: 40px;
  106. height: 60px;
  107. border-radius: 3px;
  108. float: right;
  109. }
  110. input {
  111. padding: 4px 0px 0px 3px;
  112. }
  113. }
  114. </style>