set.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <view class="set">
  3. <view class="set_ul">
  4. <view class="set_li flex">
  5. <view class="set_li_name">头像</view>
  6. <view class="set_li_img flexs" @click="uploadHead">
  7. <image :src="info.avatar" mode="aspectFill" class="head"></image>
  8. <image src="/static/image/publice/jinruer@2x.png" mode=""></image>
  9. </view>
  10. </view>
  11. <view class="set_li flex">
  12. <view class="set_li_name">昵称</view>
  13. <view class="set_li_ipt">
  14. <input type="text" @input="changeName" :value="info.nickname" />
  15. </view>
  16. </view>
  17. </view>
  18. <button class="set_btn" hover-class="hover-view" @click="quitLogin">退出登录</button>
  19. </view>
  20. </template>
  21. <script>
  22. import $DB from '../../http/debounce.js'
  23. export default {
  24. data() {
  25. return {
  26. info:{},//
  27. };
  28. },
  29. methods:{
  30. //退出登录
  31. quitLogin () {
  32. uni.showModal({
  33. content: '是否退出登录?',
  34. success: (res) => {
  35. if (res.confirm) {
  36. uni.removeStorageSync('token')
  37. uni.redirectTo({url:'/pages/login/login'})
  38. }
  39. }
  40. });
  41. },
  42. //修改名字
  43. changeName:$DB(function(e){
  44. if (!e.detail.value) return
  45. this.$api.changeInfo({nickname:e.detail.value}).then(res=>{
  46. if (res.code === 1) {
  47. }
  48. })
  49. }),
  50. //修改头像
  51. uploadHead () {
  52. uni.chooseImage({
  53. count: 1, //默认9
  54. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  55. sourceType: ['album','camera'], //从相册选择
  56. success: (res)=> {
  57. this.$api.upload_image({path:res.tempFilePaths[0]}).then(res=>{
  58. this.$api.changeInfo({avatar_url:res.url}).then(res=>{
  59. if (res.code === 1) {
  60. uni.showToast({title:res.msg})
  61. this.getSet()
  62. }
  63. })
  64. })
  65. }
  66. });
  67. },
  68. //获取设置信息
  69. getSet () {
  70. this.$api.getSettingInfo().then(res=>{
  71. if (res.code === 1) {
  72. this.info = res.data
  73. }
  74. })
  75. }
  76. },
  77. onShow() {
  78. this.getSet()
  79. }
  80. }
  81. </script>
  82. <style lang="scss">
  83. .set {
  84. min-height: calc(100vh - 44px);
  85. position: relative;
  86. }
  87. .set_li {
  88. padding: 30rpx;
  89. background: #FFFFFF;
  90. margin-top: 2rpx;
  91. &:first-child {
  92. padding: 15rpx 30rpx;
  93. }
  94. .set_li_name {
  95. font-size: 28rpx;
  96. }
  97. .set_li_img {
  98. image {
  99. width: 22rpx;
  100. height: 22rpx;
  101. }
  102. .head {
  103. width: 70rpx;
  104. height: 70rpx;
  105. flex-shrink: 0;
  106. margin-right: 20rpx;
  107. border-radius: 50%;
  108. }
  109. }
  110. .set_li_ipt {
  111. color: #999999;
  112. font-size: 26rpx;
  113. input {
  114. font-size: 26rpx;
  115. text-align: right;
  116. }
  117. }
  118. }
  119. .set_btn {
  120. color: #333333;
  121. height: 98rpx;
  122. bottom: 42rpx;
  123. left: 50%;
  124. width: 690rpx;
  125. position: absolute;
  126. transform: translateX(-50%);
  127. font-size: 30rpx;
  128. background: #FFFFFF;
  129. box-shadow: 0rpx 0rpx 16rpx 0rpx rgba(102, 102, 102, 0.2);
  130. border-radius: 10rpx;
  131. }
  132. </style>