userinfo.vue 3.5 KB

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