set.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. }).catch(e =>{
  88. console.log(e);
  89. that.$api.msg('修改失败');
  90. })
  91. }
  92. }
  93. };
  94. </script>
  95. <style lang="scss">
  96. page {
  97. min-height: 100%;
  98. .container{
  99. height: 100%;
  100. }
  101. }
  102. .row {
  103. padding: 42rpx 25rpx;
  104. font-size: 30rpx;
  105. color: #333333;
  106. image{
  107. width: 80rpx;
  108. height: 80rpx;
  109. border-radius: 50%;
  110. }
  111. .input {
  112. text-align: right;
  113. color: #333333;
  114. }
  115. }
  116. .submit-box{
  117. padding-top: 157rpx;
  118. .submit{
  119. margin: 40rpx;
  120. width: 50%;
  121. background-color: #5771DF;
  122. color: #FFFFFF;
  123. text-align: center;
  124. padding:26rpx 0rpx;
  125. border-radius: 50rpx;
  126. }
  127. }
  128. </style>