userinfo.vue 3.7 KB

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