userinfo.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <!-- <view class="container">
  3. <uni-list>
  4. <uni-list-item title="个人资料" @click="navTo('/pages/set/userinfo')" ></uni-list-item>
  5. <uni-list-item title="修改密码" @click="navTo('/pages/set/password')" ></uni-list-item>
  6. <uni-list-item title="实名认证" @click="navTo('/pages/set/phone')" ></uni-list-item>
  7. <uni-list-item title="收货地址" @click="navTo('/pages/set/address')" ></uni-list-item>
  8. </uni-list>
  9. <uni-list class="margin-t-20">
  10. <uni-list-item title="消息推送" :switch-checked='true' :show-switch="true" :show-arrow="false" switch-color='#5dbc7c' @switchChange='switchChange'>
  11. </uni-list-item>
  12. </uni-list>
  13. <uni-list class="margin-t-20">
  14. <uni-list-item title="清除缓存" ></uni-list-item>
  15. <uni-list-item title="检查更新" >
  16. <template slot="right">
  17. 当前版本 1.0.3
  18. </template>
  19. </uni-list-item>
  20. </uni-list>
  21. <view class="list-cell log-out-btn" @click="toLogout">
  22. <text class="cell-tit">退出登录</text>
  23. </view>
  24. </view> -->
  25. <view class="container">
  26. <view class="row b-b flex jg">
  27. <text class="tit">头像</text>
  28. <image :src="userInfo.avatar" @click.stop="imgsub"></image>
  29. </view>
  30. <view class="row b-b flex">
  31. <text class="tit">昵称</text>
  32. <input class="input" v-model="userInfo.nickname" type="text" placeholder-class="placeholder" />
  33. </view>
  34. <view class="row b-b flex">
  35. <text class="tit">邀请码</text>
  36. <input class="input" v-model="userInfo.uid" type="text" disabled="true" placeholder-class="placeholder" style="color: #999;" />
  37. </view>
  38. <view class="row b-b flex" v-if="userInfo.account || userInfo.phone">
  39. <text class="tit">用户账号</text>
  40. <input class="input" v-model="userInfo.account || userInfo.phone" type="number" disabled="true" placeholder-class="placeholder" style="color: #999;"/>
  41. </view>
  42. <view class="submit-box" >
  43. <view class="submit" @click="edit">确认修改</view>
  44. <view class="submit1" @click="toLogout">退出登录</view>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import uniList from '@/components/uni-list/uni-list.vue';
  50. import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
  51. import { mapState, mapMutations } from 'vuex';
  52. import { logout } from '@/api/set.js';
  53. import {
  54. uploads,edit,upload
  55. } from '@/api/user.js';
  56. export default {
  57. components: {
  58. uniList,
  59. uniListItem
  60. },
  61. data() {
  62. return {
  63. userInfo:{},
  64. pics:[],
  65. };
  66. },
  67. onLoad() {
  68. this.userInfo = uni.getStorageSync('userInfo') || '';
  69. console.log(this.userInfo)
  70. },
  71. methods: {
  72. ...mapMutations('user',['logout']),
  73. //退出登录
  74. toLogout() {
  75. let obj = this;
  76. uni.showModal({
  77. content: '确定要退出登录么',
  78. success: e => {
  79. if (e.confirm) {
  80. logout({}).then(e => {
  81. obj.logout();
  82. uni.navigateTo({
  83. url:'/pages/public/login'
  84. })
  85. })
  86. .catch(e => {
  87. console.log(e);
  88. });
  89. }
  90. }
  91. });
  92. },
  93. imgsub() {
  94. let obj = this
  95. upload({
  96. filename: ''
  97. }).then(res => {
  98. console.log(res[0].url)
  99. obj.userInfo.avatar = res[0].url
  100. });
  101. },
  102. edit() {
  103. const that = this;
  104. uni.showLoading({
  105. title: '提交中...',
  106. mask:true
  107. })
  108. if(this.userInfo.nickname == '') {
  109. return this.$api.msg('昵称不能为空!')
  110. }
  111. edit({
  112. avatar: this.userInfo.avatar,
  113. nickname: this.userInfo.nickname
  114. }).then( e =>{
  115. uni.hideLoading()
  116. that.$api.msg('修改成功');
  117. setTimeout(()=> {
  118. uni.switchTab({
  119. url:'/pages/user/user'
  120. });
  121. }, 1000);
  122. }).catch(e =>{
  123. console.log(e);
  124. that.$api.msg('修改失败');
  125. })
  126. }
  127. }
  128. };
  129. </script>
  130. <style lang='scss'>
  131. /* page{
  132. background: $page-color-base;
  133. }
  134. .list-cell{
  135. display:flex;
  136. align-items:baseline;
  137. padding: 20rpx $page-row-spacing;
  138. line-height:60rpx;
  139. position:relative;
  140. background: #fff;
  141. justify-content: center;
  142. &.log-out-btn{
  143. margin-top: 40rpx;
  144. .cell-tit{
  145. color: $uni-color-primary;
  146. text-align: center;
  147. margin-right: 0;
  148. }
  149. }
  150. .cell-tit{
  151. flex: 1;
  152. font-size: $font-base + 2rpx;
  153. color: $font-color-dark;
  154. margin-right:10rpx;
  155. }
  156. .cell-tip{
  157. font-size: $font-base;
  158. color: $font-color-light;
  159. }
  160. switch{
  161. transform: translateX(16rpx) scale(.84);
  162. }
  163. } */
  164. page {
  165. background-color: #f3f3f3;
  166. min-height: 100%;
  167. .container{
  168. height: 100%;
  169. }
  170. }
  171. .row {
  172. background-color: #fff;
  173. padding: 42rpx 25rpx;
  174. font-size: 30rpx;
  175. color: #333333;
  176. image{
  177. width: 80rpx;
  178. height: 80rpx;
  179. border-radius: 50%;
  180. }
  181. .input {
  182. text-align: right;
  183. color: #333333;
  184. }
  185. }
  186. .submit-box{
  187. padding-top: 157rpx;
  188. .submit{
  189. margin: 40rpx auto;
  190. width: 560rpx;
  191. background-color: #6EAB4E;
  192. color: #FFFFFF;
  193. text-align: center;
  194. padding:26rpx 0rpx;
  195. border-radius: 50rpx;
  196. }
  197. .submit1{
  198. margin: 40rpx auto;
  199. width: 560rpx;
  200. border: 1px solid #6EAB4E;
  201. background-color: #FFFFFF;
  202. color: #6EAB4E;
  203. text-align: center;
  204. padding:26rpx 0rpx;
  205. border-radius: 50rpx;
  206. }
  207. }
  208. .jg {
  209. margin-bottom: 20rpx;
  210. }
  211. </style>