user-info.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <view class="page-container">
  3. <u-nav-bar title="个人信息" color="#333" bg="white"></u-nav-bar>
  4. <view class="main-content">
  5. <u-panel>
  6. <u-des-row label="头像" border forward @click="editAvatar">
  7. <view slot="value" class="u-flex" style="justify-content: flex-end;">
  8. <image :style="{background: form.avatar?'':'#9FA5BA'}" :src="form.avatar" class="avatar"
  9. mode="aspectFill"></image>
  10. </view>
  11. </u-des-row>
  12. <u-des-row label="姓名" :value="form.studentName" border />
  13. <u-des-row label="性别" :value="form.genderName || '--'" border />
  14. <u-des-row label="专业群名称" :value="form.majorName || '--'" border />
  15. <u-des-row label="学号" :value="form.studentNO || '--'" border />
  16. <!-- <u-des-row label="年级" :value="form.test" border />s -->
  17. <u-des-row label="班级" :value="form.gradeName || '--'" border />
  18. <u-des-row label="电子邮箱" :value="form.test" border @click="editEmail">
  19. <view slot="value" class="u-flex" style="justify-content: flex-end;">
  20. {{form.studentEmail}}
  21. <view class="u-right-icon">
  22. <image style="width:24rpx;height:24rpx;" src="/static/edit.png" />
  23. </view>
  24. </view>
  25. </u-des-row>
  26. <u-des-row label="手机" eye>
  27. <view slot="value" slot-scope="{isOpen}">{{isOpen ? userInfo.mobileNo : hideCode(userInfo.mobileNo, 3,4) }}</view>
  28. </u-des-row>
  29. </u-panel>
  30. <!-- <button type="primary" class="button" @click="onSumbit">立即修改</button> -->
  31. </view>
  32. <u-drawer-input :visible.sync="visible" :config="inputConfig" @sumbit="setEmail" @cancel="visible=false" />
  33. </view>
  34. </template>
  35. <script>
  36. import {
  37. mapState
  38. } from 'vuex'
  39. import {
  40. hideCode
  41. } from '@/common'
  42. export default {
  43. data() {
  44. return {
  45. genderNameOptions: [{
  46. label: '男',
  47. vlaue: '男'
  48. }, {
  49. label: '女',
  50. value: '女'
  51. }],
  52. form: {
  53. avatar: '',
  54. genderName: '',
  55. studentEmail: '',
  56. },
  57. inputConfig: {},
  58. visible: false // 抽屉
  59. }
  60. },
  61. computed: {
  62. ...mapState({
  63. userInfo: state => state.user.userInfo,
  64. })
  65. },
  66. watch: {
  67. userInfo: {
  68. handler(xy) {
  69. this.init()
  70. },
  71. deep: true,
  72. immediate: true
  73. },
  74. },
  75. methods: {
  76. hideCode,
  77. async init() {
  78. Object.assign(this.form, this.userInfo || {})
  79. },
  80. editAvatar() {
  81. const that = this
  82. uni.chooseImage({
  83. count: 1, //默认9
  84. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  85. sourceType: ['album', 'camera'], //从相册选择
  86. success(res) {
  87. const filePath = res.tempFilePaths[0]
  88. console.log(111, res)
  89. uni.uploadFile({
  90. url: `/shunt/upload`,
  91. filePath: filePath,
  92. // fileType: 'image',
  93. name: 'file',
  94. header: {
  95. token: uni.getStorageSync('TOKEN')
  96. },
  97. formData: {
  98. // file: res.tempFiles[0],
  99. fileType: 'AVATAR',
  100. },
  101. success(uploadFileRes) {
  102. const data = JSON.parse(uploadFileRes.data)
  103. const filePath = data.data.filePath
  104. that.setAvatar(filePath)
  105. }
  106. });
  107. }
  108. });
  109. },
  110. setAvatar(avatar) {
  111. this.setUserInfo('/shunt/set-avatar', {
  112. avatar
  113. })
  114. },
  115. editEmail() {
  116. this.inputConfig = {
  117. title: '电子邮箱',
  118. value: this.form.studentEmail,
  119. placeholder: '请输入电子邮箱',
  120. rule: [{
  121. name: "value",
  122. checkType: "email",
  123. errorMsg: "请输入正确的邮箱"
  124. }]
  125. }
  126. this.visible = true
  127. },
  128. setEmail(email) {
  129. this.setUserInfo('/shunt/set-email', {
  130. email
  131. })
  132. },
  133. async setUserInfo(url, data) {
  134. try {
  135. uni.showLoading()
  136. await this.$ajax.post(url, data)
  137. await this.$store.dispatch('user/updateUserInfo')
  138. uni.showToast({
  139. title: '修改成功',
  140. icon: "success"
  141. });
  142. this.visible = false
  143. } catch (e) {
  144. console.log('setUserInfo', e)
  145. //TODO handle the exception
  146. } finally {
  147. uni.hideLoading()
  148. }
  149. },
  150. },
  151. }
  152. </script>
  153. <style lang="scss" scoped>
  154. .page-container {
  155. .main-content {
  156. padding: 32rpx 32rpx 32rpx 32rpx; // 188
  157. .avatar {
  158. width: 81rpx;
  159. height: 81rpx;
  160. // background: #9FA5BA;
  161. border-radius: 100%;
  162. //border: 1rpx solid #9FA5BA;
  163. }
  164. .button {
  165. background: linear-gradient(90deg, #36ACFC 0%, #078EF7 100%);
  166. border-radius: 45rpx;
  167. font-size: 32rpx;
  168. font-weight: 400;
  169. color: #FFFFFF;
  170. padding: 28rpx;
  171. margin-top: 80rpx;
  172. }
  173. }
  174. }
  175. </style>