userinfo.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view class="container">
  3. <view class="row b-b flex jg">
  4. <text class="tit">头像</text>
  5. <image :src="userInfo.avatar" @click.stop="imgsub"></image>
  6. </view>
  7. <view class="row b-b flex">
  8. <text class="tit">昵称</text>
  9. <input class="input" v-model="userInfo.nickname" type="text" placeholder-class="placeholder" />
  10. </view>
  11. <view class="row b-b flex">
  12. <text class="tit">邀请码</text>
  13. <input class="input" v-model="userInfo.uid" type="text" disabled="true" placeholder-class="placeholder" style="color: #999;" />
  14. </view>
  15. <view class="submit-box flex" >
  16. <view class="submit" @click="edit">确认修改</view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. import uniList from '@/components/uni-list/uni-list.vue';
  22. import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
  23. import { mapState, mapMutations } from 'vuex';
  24. import { logout } from '@/api/set.js';
  25. import {
  26. uploads,edit,upload
  27. } from '@/api/user.js';
  28. export default {
  29. components: {
  30. uniList,
  31. uniListItem
  32. },
  33. data() {
  34. return {
  35. userInfo:{},
  36. pics:[],
  37. };
  38. },
  39. onLoad() {
  40. this.userInfo = uni.getStorageSync('userInfo') || '';
  41. console.log(this.userInfo)
  42. },
  43. methods: {
  44. ...mapMutations('user',['logout']),
  45. //退出登录
  46. toLogout() {
  47. let obj = this;
  48. uni.showModal({
  49. content: '确定要退出登录么',
  50. success: e => {
  51. if (e.confirm) {
  52. logout({}).then(e => {
  53. obj.logout();
  54. uni.navigateTo({
  55. url:'/pages/public/login'
  56. })
  57. })
  58. .catch(e => {
  59. console.log(e);
  60. });
  61. }
  62. }
  63. });
  64. },
  65. imgsub() {
  66. let obj = this
  67. upload({
  68. filename: ''
  69. }).then(res => {
  70. console.log(res[0].url)
  71. obj.userInfo.avatar = res[0].url
  72. });
  73. },
  74. edit() {
  75. const that = this;
  76. uni.showLoading({
  77. title: '提交中...',
  78. mask:true
  79. })
  80. edit({
  81. avatar: this.userInfo.avatar,
  82. nickname: this.userInfo.nickname
  83. }).then( e =>{
  84. uni.hideLoading()
  85. that.$api.msg('修改成功');
  86. setTimeout(()=> {
  87. uni.switchTab({
  88. url:'/pages/user/user'
  89. });
  90. }, 1000);
  91. }).catch(e =>{
  92. console.log(e);
  93. that.$api.msg('修改失败');
  94. })
  95. }
  96. }
  97. };
  98. </script>
  99. <style lang='scss'>
  100. /* page{
  101. background: $page-color-base;
  102. }
  103. .list-cell{
  104. display:flex;
  105. align-items:baseline;
  106. padding: 20rpx $page-row-spacing;
  107. line-height:60rpx;
  108. position:relative;
  109. background: #fff;
  110. justify-content: center;
  111. &.log-out-btn{
  112. margin-top: 40rpx;
  113. .cell-tit{
  114. color: $uni-color-primary;
  115. text-align: center;
  116. margin-right: 0;
  117. }
  118. }
  119. .cell-tit{
  120. flex: 1;
  121. font-size: $font-base + 2rpx;
  122. color: $font-color-dark;
  123. margin-right:10rpx;
  124. }
  125. .cell-tip{
  126. font-size: $font-base;
  127. color: $font-color-light;
  128. }
  129. switch{
  130. transform: translateX(16rpx) scale(.84);
  131. }
  132. } */
  133. page {
  134. background-color: #f3f3f3;
  135. min-height: 100%;
  136. .container{
  137. height: 100%;
  138. }
  139. }
  140. .row {
  141. background-color: #fff;
  142. padding: 42rpx 25rpx;
  143. font-size: 30rpx;
  144. color: #333333;
  145. image{
  146. width: 80rpx;
  147. height: 80rpx;
  148. border-radius: 50%;
  149. }
  150. .input {
  151. text-align: right;
  152. color: #333333;
  153. }
  154. }
  155. .submit-box{
  156. padding-top: 157rpx;
  157. .submit{
  158. margin: 40rpx auto;
  159. width: 560rpx;
  160. background-color: $base-color;
  161. color: #FFFFFF;
  162. text-align: center;
  163. padding:26rpx 0rpx;
  164. border-radius: 50rpx;
  165. }
  166. }
  167. .jg {
  168. margin-bottom: 20rpx;
  169. }
  170. </style>