userinfo.vue 3.5 KB

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