index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <page
  3. :title="type == 1 ? '完善资料' : '编辑资料'"
  4. ref="pageRef"
  5. nav-color="#fff"
  6. custom-class="paddingB25"
  7. >
  8. <view >
  9. <view >
  10. <div
  11. class="avatar-wrapper btn-clear"
  12. @click="onChooseAvatar"
  13. >
  14. <view class="avatarView">
  15. <image
  16. v-if="(user && user.avatar) || ossurl.common.noavatar"
  17. class="avatar"
  18. :src="user.avatar"
  19. ></image>
  20. <image v-else class="avatar" :src="ossurl.common.noavatar"></image>
  21. <image class="avatarEdit" :src="ossurl.mine.editIcon" />
  22. </view>
  23. </div>
  24. <view
  25. class="flex-align-between padding15 cell"
  26. @click="showEdit('编辑昵称', 'nickname')"
  27. >
  28. <view class="font5">昵称:</view>
  29. <view class="flex-align">
  30. <view class="marginR5">
  31. {{ (user && user.nickname) || '请输入' }}
  32. </view>
  33. <view class="cuIcon-right"></view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </page>
  39. </template>
  40. <script>
  41. import resource from '@/utils/resource'
  42. import ossurl from '@/utils/ossurl'
  43. import loginInfo from './login_info'
  44. export default {
  45. components: { loginInfo },
  46. data() {
  47. return {
  48. resource,
  49. ossurl,
  50. type: 0
  51. }
  52. },
  53. computed: {
  54. user() {
  55. if (!this.$store.getters.token) return null
  56. return this.$store.getters.user
  57. },
  58. supportHigher() {
  59. let systemInfo = this.$store.state.systemInfo
  60. if (!systemInfo) return false
  61. return this.$common.compareVersion(systemInfo.SDKVersion, '2.21.2') >= 0
  62. }
  63. },
  64. onLoad(option) {
  65. this.type = option.type || 0
  66. },
  67. methods: {
  68. onChooseAvatar() {
  69. let self = this
  70. uni.chooseImage({
  71. count: 1,
  72. sourceType:['album'],
  73. success: (chooseImageRes) => {
  74. console.log(chooseImageRes)
  75. const tempFilePaths = chooseImageRes.tempFilePaths;
  76. uni.uploadFile({
  77. url: self.$service.base.apis.UPLOAD, //仅为示例,非真实的接口地址
  78. filePath: tempFilePaths[0],
  79. name: 'file',
  80. header: {
  81. Authentication: self.$store.getters.token
  82. },
  83. formData: {
  84. appId: 'supermart',
  85. folder: 'avatar'
  86. },
  87. success: (res) => {
  88. console.log(res)
  89. if (res.statusCode == 200) {
  90. const result = JSON.parse(res.data)
  91. if (result.code == 0) {
  92. self.updateAvatar(result.data.url || resource.defaultAvatar)
  93. }
  94. }
  95. },
  96. error: (res) => {
  97. self.$message.error('上传图片失败')
  98. }
  99. })
  100. },
  101. error: (res) => {
  102. self.$message.error('选择图片失败')
  103. }
  104. });
  105. },
  106. async updateAvatar(url) {
  107. const res = await this.$service.user.updateAvatar(url)
  108. this.$service.user.info()
  109. },
  110. showEdit(title, key) {
  111. this.$router.push('user_edit', {
  112. title,
  113. key,
  114. value: (this.user && this.user[key]) || ''
  115. })
  116. },
  117. getUserProfile(e) {
  118. wx.getUserProfile({
  119. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  120. success: (res) => {
  121. this.getUserinfo({ detail: res })
  122. }
  123. })
  124. },
  125. async getUserinfo(e) {
  126. if (!e.detail || !e.detail.encryptedData) return
  127. const encryptedData = e.detail.encryptedData
  128. const signature = e.detail.signature
  129. const iv = e.detail.iv
  130. const rawData = e.detail.rawData
  131. const res = await this.$service.user.complete(encryptedData, iv, signature, rawData)
  132. if (res) {
  133. this.initUser()
  134. if (this.type == 1) {
  135. this.$router.back()
  136. }
  137. }
  138. },
  139. async initUser() {
  140. this.$service.user.info()
  141. }
  142. }
  143. }
  144. </script>
  145. <style lang="scss"></style>
  146. <style lang="scss" scoped>
  147. .bg {
  148. position: fixed;
  149. z-index: -1;
  150. left: 0;
  151. right: 0;
  152. top: 0;
  153. width: 100%;
  154. height: 100%;
  155. opacity: 0.3;
  156. }
  157. .cell {
  158. border-top: 1px solid rgba($color: #fff, $alpha: 0.3);
  159. border-bottom: 1px solid rgba($color: #fff, $alpha: 0.3);
  160. }
  161. .btn {
  162. height: 100rpx;
  163. line-height: 100rpx;
  164. background: linear-gradient(270deg, #d070ff 0%, #8b3dff 100%);
  165. border-radius: 50rpx;
  166. color: #fff;
  167. font-size: 32rpx;
  168. text-align: center;
  169. }
  170. .avatar-wrapper{
  171. text-align: center;
  172. }
  173. .avatarView {
  174. position: relative;
  175. display: inline-block;
  176. margin-top: 40px;
  177. margin-bottom: 40px;
  178. .avatar {
  179. width: 148rpx;
  180. height: 148rpx;
  181. border-radius: 50%;
  182. border: 8rpx solid #ffe996;
  183. }
  184. .avatarEdit {
  185. position: absolute;
  186. bottom: 0;
  187. right: 0;
  188. width: 48rpx;
  189. height: 48rpx;
  190. z-index: 10;
  191. }
  192. }
  193. </style>