userinfo.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <view class="content">
  3. <view class="row1">
  4. <text class="tit">头像</text>
  5. <view class="background-img" @click.stop="imgsub"><image class="background-img" :src="userInfo.avatar" mode="aspectFill"></image></view>
  6. </view>
  7. <view class="row">
  8. <text class="tit">昵称</text>
  9. <input class="input" type="text" v-model="userInfo.nickname" placeholder-class="placeholder" />
  10. </view>
  11. <view class="row">
  12. <text class="tit">ID</text>
  13. <input class="input" type="text" disabled="true" v-model="userInfo.id" placeholder-class="placeholder" />
  14. </view>
  15. <view class="row">
  16. <text class="tit">账户</text>
  17. <input class="input" type="text" disabled="true" v-model="userInfo.username" placeholder-class="placeholder" />
  18. </view>
  19. <view class="add-btn" @click="confirm">提交</view>
  20. <view class="out" @click="toLogout">退出登录</view>
  21. </view>
  22. </template>
  23. <script>
  24. import { mapState,mapMutations } from 'vuex';
  25. import { uploads } from '@/api/user.js';
  26. import {userEdit,logout} from '@/api/set.js';
  27. export default{
  28. data(){
  29. return{
  30. }
  31. },
  32. onLoad() {
  33. console.log(this.userInfo)
  34. },
  35. computed: {
  36. ...mapState('user',['userInfo'])
  37. },
  38. methods: {
  39. ...mapMutations('user',['logout']),
  40. imgsub() {
  41. console.log('上传头像')
  42. uploads({
  43. filename: ''
  44. }).then(res => {
  45. // console.log("data",data);
  46. // this.userInfo.avatar = data.fullurl;
  47. console.log(res,'++++++++++++++++')
  48. this.userInfo.avatar = res[0].fullurl;
  49. })
  50. },
  51. confirm() {
  52. userEdit({ avatar: this.userInfo.avatar ,nickname: this.userInfo.nickname})
  53. .then(e => {
  54. this.$api.msg('修改成功');
  55. setTimeout(()=> {
  56. uni.switchTab({
  57. url:'/pages/user/user'
  58. });
  59. }, 1000);
  60. console.log(e);
  61. })
  62. .catch(e => {
  63. console.log(e);
  64. });
  65. },
  66. toLogout(){
  67. let obj = this;
  68. uni.showModal({
  69. content: '确定要退出登录么',
  70. success: (e)=>{
  71. if(e.confirm){
  72. // logout({}).then((e) => {
  73. // uni.navigateBack();
  74. // }).catch((e) => {
  75. // console.log(e);
  76. // })
  77. uni.navigateBack();
  78. obj.logout();
  79. }
  80. }
  81. });
  82. },
  83. }
  84. }
  85. </script>
  86. <style lang="scss">
  87. .row1 {
  88. display: flex;
  89. align-items: center;
  90. justify-content: space-between;
  91. position: relative;
  92. padding: 0 30upx;
  93. height: 110upx;
  94. background: #000;
  95. margin-bottom: 20upx;
  96. .tit {
  97. flex-shrink: 0;
  98. width: 120upx;
  99. font-size: $font-lg;
  100. color: #fff;
  101. }
  102. .background-img {
  103. width: 80rpx;
  104. height: 80rpx;
  105. border-radius: 50%;
  106. background: #f2f2f2;
  107. }
  108. }
  109. .row {
  110. display: flex;
  111. align-items: center;
  112. padding: 0 30upx;
  113. height: 110upx;
  114. background: #000;
  115. .tit {
  116. flex-shrink: 0;
  117. width: 120upx;
  118. font-size: $font-lg;
  119. color: #fff;
  120. }
  121. .input {
  122. flex: 1;
  123. text-align: right;
  124. font-size: $font-base;
  125. color: #fff;
  126. }
  127. }
  128. .add-btn {
  129. display: flex;
  130. align-items: center;
  131. justify-content: center;
  132. margin: 158rpx auto 30rpx;
  133. width: 560rpx;
  134. height: 80rpx;
  135. background: linear-gradient(-74deg, #CE9C6D, #FFECD6);
  136. border-radius: 40px;
  137. color: #FFFFFF;
  138. }
  139. .out {
  140. display: flex;
  141. align-items: center;
  142. justify-content: center;
  143. margin: 0 auto 30rpx;
  144. width: 560rpx;
  145. height: 80rpx;
  146. border: 1px solid #FFECD6;
  147. background: #FFFFFF;
  148. border-radius: 40px;
  149. color: #CE9C6D;
  150. }
  151. </style>