userinfo.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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" v-model="userInfo.avatar" :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.uid" 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.account" 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 { upload } from '@/api/order.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. upload({
  43. filename: ''
  44. }).then(data => {
  45. console.log("data",data);
  46. this.userInfo.avatar = data[0].url;
  47. })
  48. },
  49. confirm() {
  50. userEdit({ avatar: this.userInfo.avatar ,nickname: this.userInfo.nickname})
  51. .then(e => {
  52. this.$api.msg('修改成功');
  53. setTimeout(()=> {
  54. uni.switchTab({
  55. url:'/pages/user/user'
  56. });
  57. }, 1000);
  58. console.log(e);
  59. })
  60. .catch(e => {
  61. console.log(e);
  62. });
  63. },
  64. toLogout(){
  65. let obj = this;
  66. uni.showModal({
  67. content: '确定要退出登录么',
  68. success: (e)=>{
  69. if(e.confirm){
  70. logout({}).then((e) => {
  71. uni.navigateBack();
  72. }).catch((e) => {
  73. console.log(e);
  74. })
  75. obj.logout();
  76. }
  77. }
  78. });
  79. },
  80. }
  81. }
  82. </script>
  83. <style lang="scss">
  84. .row1 {
  85. display: flex;
  86. align-items: center;
  87. justify-content: space-between;
  88. position: relative;
  89. padding: 0 30upx;
  90. height: 110upx;
  91. background: #fff;
  92. margin-bottom: 20upx;
  93. .tit {
  94. flex-shrink: 0;
  95. width: 120upx;
  96. font-size: $font-lg;
  97. color: $font-color-dark;
  98. }
  99. .background-img {
  100. width: 80rpx;
  101. height: 80rpx;
  102. border-radius: 50%;
  103. background: #f2f2f2;
  104. }
  105. }
  106. .row {
  107. display: flex;
  108. align-items: center;
  109. padding: 0 30upx;
  110. height: 110upx;
  111. background: #fff;
  112. .tit {
  113. flex-shrink: 0;
  114. width: 120upx;
  115. font-size: $font-lg;
  116. color: $font-color-dark;
  117. }
  118. .input {
  119. flex: 1;
  120. text-align: right;
  121. font-size: $font-base;
  122. color: $color-gray;
  123. }
  124. }
  125. .add-btn {
  126. display: flex;
  127. align-items: center;
  128. justify-content: center;
  129. margin: 158rpx auto 30rpx;
  130. width: 560rpx;
  131. height: 80rpx;
  132. background: #52C696;
  133. border-radius: 40px;
  134. color: #FFFFFF;
  135. }
  136. .out {
  137. display: flex;
  138. align-items: center;
  139. justify-content: center;
  140. margin: 0 auto 30rpx;
  141. width: 560rpx;
  142. height: 80rpx;
  143. border: 1px solid #52C696;
  144. background: #FFFFFF;
  145. border-radius: 40px;
  146. color: #52C696;
  147. }
  148. </style>