You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

208 lines
5.0 KiB

8 months ago
  1. <template>
  2. <view class="setting">
  3. <mNavbar title="设置" :leftClick="leftClick"></mNavbar>
  4. <van-cell-group>
  5. <van-cell @click="fileUploads" title="头像" style="display: flex;align-items: center;" is-link>
  6. <template #value>
  7. <image style="width: 118rpx;height: 118rpx;border-radius: 50%;" :src="userInfo.headImage"></image>
  8. </template>
  9. </van-cell>
  10. <van-cell title="昵称" :value="userInfo.nickName" @click="showBottom = true" is-link></van-cell>
  11. <van-cell title="性别" :value="userInfo.sex || '暂无'" @click="changeGenderShow = true" is-link></van-cell>
  12. </van-cell-group>
  13. <van-cell-group style="margin-top: 10rpx;">
  14. <!-- <van-cell title="手机号" :value="userInfo.phone || '未绑定'" @click="toPhoneDetail" is-link></van-cell> -->
  15. <van-cell title="用户协议" @click="keyValue = 'protocol';configPopupShow = true" is-link></van-cell>
  16. <van-cell title="隐私政策" @click="keyValue = 'policy';configPopupShow = true" is-link></van-cell>
  17. <van-cell title="关于我们" @click="keyValue = 'we';configPopupShow = true" is-link></van-cell>
  18. </van-cell-group>
  19. <configPopup :keyValue="keyValue" :show="configPopupShow" :list="config" @close="configPopupShow = false" />
  20. <van-popup v-model:show="showBottom" round position="bottom" @close="showBottom = false">
  21. <view style="padding: 20rpx;">
  22. <view style="text-align: center;font-size: 35rpx;">修改昵称</view>
  23. <view class="item-line flex">
  24. <view class="before"></view>
  25. <view class="label">用户昵称</view>
  26. <input v-model="userInfo.nickName" placeholder="请输入昵称" />
  27. </view>
  28. <view @click="editNickName" class="button-submit">立即修改</view>
  29. </view>
  30. </van-popup>
  31. <van-action-sheet v-model:show="changeGenderShow" :actions="actions" @select="selectGender" />
  32. </view>
  33. </template>
  34. <script>
  35. import mNavbar from '@/components/base/m-navbar.vue'
  36. import configPopup from '@/components/configPopup'
  37. import OSS from "ali-oss"
  38. import { v4 as uuidv4 } from 'uuid';
  39. export default {
  40. components: { mNavbar, configPopup },
  41. data() {
  42. return {
  43. userInfo: {},
  44. configPopupShow: false,
  45. keyValue: '',
  46. config: [],
  47. showBottom: false,
  48. changeGenderShow: false,
  49. actions: [
  50. { name: '男' },
  51. {name: '女'},
  52. {name: '未知'}
  53. ]
  54. }
  55. },
  56. onShow() {
  57. this.getUserInfo()
  58. this.getConfig()
  59. },
  60. methods: {
  61. //返回个人中心
  62. leftClick() {
  63. uni.switchTab({
  64. url: '/pages/index/center'
  65. })
  66. },
  67. //获取用户信息
  68. getUserInfo() {
  69. this.$api('getUserInfo', {}, res => {
  70. if (res.code == 200) {
  71. this.userInfo = res.result;
  72. }
  73. })
  74. },
  75. //获取配置
  76. getConfig() {
  77. this.$api('getConfig', {}, res => {
  78. if (res.code == 200) {
  79. this.config = res.result
  80. }
  81. })
  82. },
  83. //选择性别
  84. selectGender(val) {
  85. this.userInfo.sex = val.name;
  86. this.editNickName();
  87. this.changeGenderShow = false;
  88. },
  89. //修改用户信息
  90. editNickName() {
  91. let data = {
  92. nickName: this.userInfo.nickName,
  93. sex : this.userInfo.sex,
  94. headImage : this.userInfo.headImage,
  95. id: this.userInfo.id
  96. }
  97. this.$api('editUserInfo', data , res => {
  98. if (res.code == 200) {
  99. this.showBottom = false;
  100. uni.showToast({
  101. title : '修改成功',
  102. icon : 'none'
  103. })
  104. this.getUserInfo();
  105. }
  106. })
  107. },
  108. //上传文件
  109. fileUploads() {
  110. uni.chooseImage({
  111. count: 1, // 默认9,设置为1表示单选
  112. sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
  113. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  114. success: (res) => {
  115. let resultPromise = [];
  116. this.uploadFileToOSS(res.tempFiles[0]).then(imgPath => {
  117. this.userInfo.headImage = imgPath;
  118. this.editNickName();
  119. })
  120. }
  121. });
  122. }
  123. }
  124. }
  125. </script>
  126. <style scoped lang="scss">
  127. .setting {
  128. background-color: #f3f3f3;
  129. min-height: calc(100vh);
  130. .item-line {
  131. height: 60rpx;
  132. line-height: 60rpx;
  133. font-size: 28rpx;
  134. font-family: PingFang SC, PingFang SC-Bold;
  135. font-weight: 700;
  136. text-align: left;
  137. color: #333333;
  138. margin-top: 40rpx;
  139. }
  140. .item-line .before {
  141. width: 8rpx;
  142. height: 30rpx;
  143. background: #4fd3bc;
  144. border-radius: 4rpx;
  145. margin: 15rpx 12rpx 15rpx 0;
  146. }
  147. .item-line .label {
  148. width: 152rpx;
  149. height: 60rpx;
  150. }
  151. .item-line input {
  152. width: 456rpx;
  153. height: 60rpx;
  154. line-height: 60rpx;
  155. background: #f5f5f5;
  156. border-radius: 12rpx;
  157. font-size: 24rpx;
  158. font-family: PingFang SC, PingFang SC-Medium;
  159. font-weight: 500;
  160. text-align: left;
  161. color: #939393;
  162. padding: 0 20rpx;
  163. }
  164. .button-submit {
  165. width: 596rpx;
  166. height: 90rpx;
  167. line-height: 90rpx;
  168. background: linear-gradient(180deg, #6fdfbe, #5ac796);
  169. border-radius: 46rpx;
  170. margin: 40rpx auto;
  171. font-size: 28rpx;
  172. font-family: PingFang SC, PingFang SC-Regular;
  173. font-weight: 400;
  174. text-align: center;
  175. color: #ffffff;
  176. }
  177. }
  178. </style>