userinfo.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <view class="content">
  3. <view class="row1">
  4. <text class="tit">头像</text>
  5. <view class="background-img" @click="upload"><image class="background-img" v-model="avatar" :src="avatar" mode="aspectFill"></image></view>
  6. </view>
  7. <view class="row">
  8. <text class="tit">昵称</text>
  9. <input class="input" type="button" v-model="name" placeholder-class="placeholder" />
  10. </view>
  11. <view class="row">
  12. <text class="tit">邀请码</text>
  13. <input class="input" disabled type="text" v-model="uid" placeholder-class="placeholder" />
  14. </view>
  15. <view class="row">
  16. <text class="tit">账号</text>
  17. <input class="input" disabled type="text" v-model="phone" placeholder-class="placeholder" />
  18. </view>
  19. <button class="add-btn" @click="confirm">修改</button>
  20. <button class="loginout" @click="loginout">退出登录</button>
  21. </view>
  22. </template>
  23. <script>
  24. import { mapState,mapMutations } from 'vuex';
  25. import { userEdit,upload,logout } from '@/api/set.js';
  26. export default {
  27. data() {
  28. return {
  29. name: '', // 昵称
  30. uid: '',
  31. phone:'',
  32. avatar: '',
  33. };
  34. },
  35. computed: {
  36. ...mapState('user',['userInfo']),
  37. startDate() {
  38. console.log('start');
  39. },
  40. endDate() {
  41. console.log('end');
  42. }
  43. },
  44. onShow(option) {
  45. // 获取生日日期
  46. console.log(this.userInfo);
  47. this.name = this.userInfo.nickname + '';
  48. this.uid = this.userInfo.uid || '';
  49. this.avatar = this.userInfo.avatar || '';
  50. this.phone = this.userInfo.phone || '';
  51. },
  52. methods: {
  53. ...mapMutations('user', ['logout']),
  54. // 上传头像
  55. upload() {
  56. console.log("111111")
  57. upload({
  58. filename: ''
  59. }).then(data => {
  60. this.avatar = data[0].url;
  61. console.log(this.avatar, 'tup')
  62. setTimeout(() => {
  63. uni.hideLoading()
  64. }, 500)
  65. });
  66. },
  67. switchChange(e) {
  68. this.addressData.default = e.value;
  69. },
  70. confirm() {
  71. userEdit({
  72. nickname: this.name,
  73. avatar: this.avatar,
  74. }).then(e => {
  75. this.$api.msg('修改成功');
  76. setTimeout(() => {
  77. uni.switchTab({
  78. url: '/pages/user/user'
  79. });
  80. }, 1000);
  81. console.log(e);
  82. })
  83. .catch(e => {
  84. console.log(e);
  85. });
  86. },
  87. loginout() {
  88. let obj = this;
  89. uni.showModal({
  90. content: '确定要退出登录么',
  91. success: e => {
  92. if (e.confirm) {
  93. logout({}).then()
  94. uni.navigateBack();
  95. obj.logout();
  96. }
  97. }
  98. });
  99. }
  100. }
  101. };
  102. </script>
  103. <style lang="scss">
  104. page {
  105. background: $page-color-base;
  106. }
  107. .row1 {
  108. display: flex;
  109. align-items: center;
  110. justify-content: space-between;
  111. position: relative;
  112. padding: 0 30upx;
  113. height: 110upx;
  114. background: #fff;
  115. margin-bottom: 20upx;
  116. .tit {
  117. flex-shrink: 0;
  118. width: 120upx;
  119. font-size: $font-lg;
  120. color: $font-color-dark;
  121. }
  122. .background-img {
  123. width: 80rpx;
  124. height: 80rpx;
  125. border-radius: 50%;
  126. background: #f2f2f2;
  127. }
  128. }
  129. .row {
  130. display: flex;
  131. align-items: center;
  132. justify-content: space-between;
  133. position: relative;
  134. padding: 0 30upx;
  135. height: 110upx;
  136. background: #fff;
  137. .tit {
  138. flex-shrink: 0;
  139. width: 120upx;
  140. font-size: $font-lg;
  141. color: $font-color-dark;
  142. }
  143. .tit1 {
  144. flex-shrink: 0;
  145. width: 150upx;
  146. font-size: $font-lg;
  147. color: $font-color-dark;
  148. }
  149. .input {
  150. text-align: right;
  151. flex: 1;
  152. font-size: $font-base;
  153. color: $color-gray;
  154. }
  155. .iconlocation {
  156. font-size: 36upx;
  157. color: $font-color-light;
  158. }
  159. }
  160. .add-btn {
  161. display: flex;
  162. align-items: center;
  163. justify-content: center;
  164. width: 560upx;
  165. height: 80upx;
  166. margin: 60upx auto;
  167. font-size: $font-lg;
  168. color: #fff;
  169. background: $base-color;
  170. border-radius: 40upx;
  171. }
  172. .loginout {
  173. display: flex;
  174. align-items: center;
  175. justify-content: center;
  176. width: 560upx;
  177. height: 80upx;
  178. margin: 60upx auto;
  179. font-size: $font-lg;
  180. color: $base-color;
  181. background: #FFFFFF;
  182. border: 1px solid $base-color;
  183. border-radius: 40upx;
  184. }
  185. </style>