userinfo.vue 5.0 KB

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