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