set.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <view class="container">
  3. <view class="row b-b flex">
  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" type="number" disabled="true" placeholder-class="placeholder" />
  18. </view>
  19. <view class="submit-box flex" >
  20. <view class="submit" @click="edit">确认修改</view>
  21. <view class="submit" @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 {
  31. uploads,edit
  32. } from '@/api/user.js';
  33. export default {
  34. components: {
  35. uniList,
  36. uniListItem
  37. },
  38. data() {
  39. return {
  40. // nickName:'李淡淡',
  41. // id:'HFBNXISN',
  42. // account:'13745262356',
  43. userInfo:'',
  44. };
  45. },
  46. onLoad() {
  47. this.userInfo = uni.getStorageSync('userInfo') || '';
  48. },
  49. methods: {
  50. ...mapMutations('user',['logout']),
  51. //退出登录
  52. toLogout() {
  53. let obj = this;
  54. uni.showModal({
  55. content: '确定要退出登录么',
  56. success: e => {
  57. if (e.confirm) {
  58. logout({}).then(e => {
  59. obj.logout();
  60. uni.navigateTo({
  61. url:'/pages/public/login'
  62. })
  63. })
  64. .catch(e => {
  65. console.log(e);
  66. });
  67. }
  68. }
  69. });
  70. },
  71. imgsub() {
  72. console.log('上传头像')
  73. uploads({
  74. filename: ''
  75. }).then(data => {
  76. console.log("data",data);
  77. this.userInfo.avatar = data[0].url;
  78. })
  79. },
  80. edit() {
  81. const that = this;
  82. edit({
  83. avatar: this.userInfo.avatar,
  84. nickname: this.userInfo.nickname
  85. }).then( e =>{
  86. that.$api.msg('修改成功');
  87. setTimeout(()=> {
  88. uni.switchTab({
  89. url:'/pages/user/user'
  90. });
  91. }, 1000);
  92. }).catch(e =>{
  93. console.log(e);
  94. that.$api.msg('修改失败');
  95. })
  96. }
  97. }
  98. };
  99. </script>
  100. <style lang="scss">
  101. page {
  102. min-height: 100%;
  103. .container{
  104. height: 100%;
  105. }
  106. }
  107. .row {
  108. padding: 42rpx 25rpx;
  109. font-size: 30rpx;
  110. color: #333333;
  111. image{
  112. width: 80rpx;
  113. height: 80rpx;
  114. border-radius: 50%;
  115. }
  116. .input {
  117. text-align: right;
  118. color: #333333;
  119. }
  120. }
  121. .submit-box{
  122. padding-top: 157rpx;
  123. .submit{
  124. margin: 40rpx;
  125. width: 50%;
  126. background-color: #5771DF;
  127. color: #FFFFFF;
  128. text-align: center;
  129. padding:26rpx 0rpx;
  130. border-radius: 50rpx;
  131. }
  132. }
  133. </style>