set.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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">ID</text>
  13. <input class="input" v-model="userInfo.uid" type="text" disabled="true" placeholder-class="placeholder" />
  14. </view>
  15. <view class="row b-b flex">
  16. <text class="tit">用户账号</text>
  17. <input class="input" v-model="userInfo.account || userInfo.phone" type="number" disabled="true" placeholder-class="placeholder" />
  18. </view>
  19. <view class="submit-box ">
  20. <view class="submit" @click="edit">确认修改</view>
  21. <view class="submit submit1" @click="toLogout">退出登录</view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import uniList from '@/components/uni-list/uni-list.vue';
  27. import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
  28. import { mapState, mapMutations } from 'vuex';
  29. import { logout } from '@/api/set.js';
  30. import { uploads, edit, upload } 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({})
  56. .then(e => {
  57. obj.logout();
  58. uni.switchTab({
  59. url: '/pages/index/index'
  60. });
  61. })
  62. .catch(e => {
  63. console.log(e);
  64. });
  65. }
  66. }
  67. });
  68. },
  69. imgsub() {
  70. let obj = this;
  71. upload({
  72. filename: ''
  73. }).then(res => {
  74. console.log(res, '上传图片');
  75. console.log(res[0].url);
  76. obj.userInfo.avatar = res[0].url;
  77. });
  78. },
  79. edit() {
  80. const that = this;
  81. uni.showLoading({
  82. title: '提交中...',
  83. mask: true
  84. });
  85. edit({
  86. avatar: this.userInfo.avatar,
  87. nickname: this.userInfo.nickname
  88. })
  89. .then(e => {
  90. uni.hideLoading();
  91. that.$api.msg('修改成功');
  92. setTimeout(() => {
  93. uni.switchTab({
  94. url: '/pages/user/user'
  95. });
  96. }, 1000);
  97. })
  98. .catch(e => {
  99. console.log(e);
  100. that.$api.msg('修改失败');
  101. });
  102. }
  103. }
  104. };
  105. </script>
  106. <style lang="scss">
  107. page {
  108. background-color: #f3f3f3;
  109. min-height: 100%;
  110. .container {
  111. height: 100%;
  112. }
  113. }
  114. .row {
  115. background-color: #fff;
  116. padding: 42rpx 25rpx;
  117. font-size: 30rpx;
  118. color: #333333;
  119. image {
  120. width: 80rpx;
  121. height: 80rpx;
  122. border-radius: 50%;
  123. }
  124. .input {
  125. text-align: right;
  126. color: #333333;
  127. }
  128. }
  129. .submit-box {
  130. padding-top: 157rpx;
  131. .submit {
  132. margin: 40rpx auto;
  133. width: 560rpx;
  134. background-color: #ee2f72;
  135. color: #ffffff;
  136. text-align: center;
  137. padding: 26rpx 0rpx;
  138. border-radius: 50rpx;
  139. }
  140. .submit1 {
  141. background-color: #ffffff;
  142. color: #ee2f72;
  143. border: 1px solid #ee2f72;
  144. }
  145. }
  146. .jg {
  147. margin-bottom: 20rpx;
  148. }
  149. .out {
  150. display: flex;
  151. align-items: center;
  152. justify-content: center;
  153. margin: 0 auto 30rpx;
  154. width: 560rpx;
  155. height: 80rpx;
  156. border: 1px solid #58bab0;
  157. background: #ffffff;
  158. border-radius: 40px;
  159. color: #58bab0;
  160. }
  161. </style>