set.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <view class="container">
  3. <!-- #ifdef MP-WEIXIN -->
  4. <view class="row b-b flex jg">
  5. <text class="tit">头像</text>
  6. <image :src="userInfo.avatar" @click.stop="imgsub"></image>
  7. </view>
  8. <!-- <view class="row b-b flex jg">
  9. <text class="tit">头像</text>
  10. <button type="primary" open-type="chooseAvatar" @chooseavatar="onChooseAvatar" plain="true" style="border: none;position: relative;">
  11. <image :src="userInfo.avatar" @click="imgsub"></image>
  12. </button>
  13. </view> -->
  14. <view class="row b-b flex">
  15. <text class="tit">昵称</text>
  16. <input class="input" v-model="userInfo.nickname" type="nickname" @blur="test" placeholder-class="placeholder" />
  17. </view>
  18. <!-- #endif -->
  19. <!-- #ifndef MP-WEIXIN -->
  20. <view class="row b-b flex jg">
  21. <text class="tit">头像</text>
  22. <image :src="userInfo.avatar" @click.stop="imgsub"></image>
  23. </view>
  24. <view class="row b-b flex">
  25. <text class="tit">昵称</text>
  26. <input class="input" v-model="userInfo.nickname" type="text" placeholder-class="placeholder" />
  27. </view>
  28. <!-- #endif -->
  29. <view class="row b-b flex">
  30. <text class="tit">ID</text>
  31. <input class="input" v-model="userInfo.uid" type="text" disabled="true" placeholder-class="placeholder" />
  32. </view>
  33. <view class="submit-box ">
  34. <view class="submit" @click="edit">确认修改</view>
  35. <view class="submit submit1" @click="toLogout">退出登录</view>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import uniList from '@/components/uni-list/uni-list.vue';
  41. import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
  42. import { mapState, mapMutations } from 'vuex';
  43. import { logout } from '@/api/set.js';
  44. import { uploads, edit, upload } from '@/api/user.js';
  45. export default {
  46. components: {
  47. uniList,
  48. uniListItem
  49. },
  50. data() {
  51. return {
  52. userInfo: {},
  53. pics: []
  54. };
  55. },
  56. // onUnload() {
  57. // if (this.userInfo.nickname == '微信用户') {
  58. // logout({})
  59. // .then(e => {
  60. // obj.logout();
  61. // })
  62. // .catch(e => {
  63. // console.log(e);
  64. // });
  65. // }
  66. // console.log('222');
  67. // },
  68. onLoad() {
  69. this.userInfo = uni.getStorageSync('userInfo') || '';
  70. console.log(this.userInfo);
  71. },
  72. methods: {
  73. ...mapMutations('user', ['logout']),
  74. //退出登录
  75. toLogout() {
  76. let obj = this;
  77. uni.showModal({
  78. content: '确定要退出登录么',
  79. success: e => {
  80. if (e.confirm) {
  81. logout({})
  82. .then(e => {
  83. obj.logout();
  84. uni.switchTab({
  85. url: '/pages/index/index'
  86. });
  87. })
  88. .catch(e => {
  89. console.log(e);
  90. });
  91. }
  92. }
  93. });
  94. },
  95. imgsub() {
  96. let obj = this;
  97. upload({
  98. filename: ''
  99. }).then(res => {
  100. console.log(res, '上传图片');
  101. console.log(res[0].url);
  102. obj.userInfo.avatar = res[0].url;
  103. });
  104. },
  105. test(e) {
  106. console.log(e.detail, '123456');
  107. },
  108. onChooseAvatar(e) {
  109. this.userInfo.avatar = e.detail.avatarUrl;
  110. },
  111. edit() {
  112. const that = this;
  113. uni.showLoading({
  114. title: '提交中...',
  115. mask: true
  116. });
  117. edit({
  118. avatar: this.userInfo.avatar,
  119. nickname: this.userInfo.nickname
  120. })
  121. .then(e => {
  122. uni.hideLoading();
  123. that.$api.msg('修改成功');
  124. setTimeout(() => {
  125. uni.switchTab({
  126. url: '/pages/user/user'
  127. });
  128. }, 1000);
  129. })
  130. .catch(e => {
  131. console.log(e);
  132. that.$api.msg('修改失败');
  133. });
  134. }
  135. }
  136. };
  137. </script>
  138. <style lang="scss">
  139. page {
  140. background-color: #f3f3f3;
  141. min-height: 100%;
  142. .container {
  143. height: 100%;
  144. }
  145. }
  146. .row {
  147. background-color: #fff;
  148. padding: 42rpx 25rpx;
  149. font-size: 30rpx;
  150. color: #333333;
  151. button {
  152. width: 80rpx;
  153. height: 80rpx;
  154. margin: 0;
  155. padding: 0;
  156. border-radius: 50%;
  157. }
  158. image {
  159. width: 80rpx;
  160. height: 80rpx;
  161. border-radius: 50%;
  162. }
  163. .input {
  164. text-align: right;
  165. color: #333333;
  166. }
  167. }
  168. .submit-box {
  169. padding-top: 157rpx;
  170. .submit {
  171. margin: 40rpx auto;
  172. width: 560rpx;
  173. background-color: #ee2f72;
  174. color: #ffffff;
  175. text-align: center;
  176. padding: 26rpx 0rpx;
  177. border-radius: 50rpx;
  178. }
  179. .submit1 {
  180. background-color: #ffffff;
  181. color: #ee2f72;
  182. border: 1px solid #ee2f72;
  183. }
  184. }
  185. .jg {
  186. margin-bottom: 20rpx;
  187. }
  188. .out {
  189. display: flex;
  190. align-items: center;
  191. justify-content: center;
  192. margin: 0 auto 30rpx;
  193. width: 560rpx;
  194. height: 80rpx;
  195. border: 1px solid #58bab0;
  196. background: #ffffff;
  197. border-radius: 40px;
  198. color: #58bab0;
  199. }
  200. </style>