帧视界壹通告,付费看视频的微信小程序
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.

244 lines
5.2 KiB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
  1. <template>
  2. <view class='updateUserInfo'>
  3. <!--顶部导航栏-->
  4. <navbar leftClick @leftClick="$utils.navigateBack" title="修改个人信息" />
  5. <!--主页面-->
  6. <view class="frame">
  7. <view class="headImage">
  8. <view style="" class="key">头像</view>
  9. <view style="" class="value" @click="chooseAndUpdateUserImage">
  10. <image :src='form.headImage' style="width: 100%;height: 100%"></image>
  11. <!-- <uv-upload :fileList="fileList" :maxCount="1" multiple width="150rpx" height="150rpx"
  12. :deletable="false" :previewFullImage="false" @afterRead="afterRead" ></uv-upload> -->
  13. </view>
  14. </view>
  15. <view class="item">
  16. <view class="label">昵称</view>
  17. <view class="value">
  18. <uv-input v-model="form.nickName" placeholder="昵称" border="bottom" clearable></uv-input>
  19. </view>
  20. </view>
  21. <view class="item" @click="sexChange">
  22. <view class="label">性别</view>
  23. <view>{{form.sex}}</view>
  24. </view>
  25. <view class="item">
  26. <view class="label">联系方式</view>
  27. <view class="value">
  28. <uv-input v-model="form.phone" placeholder="联系方式" border="bottom" clearable></uv-input>
  29. </view>
  30. </view>
  31. </view>
  32. <!-- ActionSheet 操作菜单 -->
  33. <uv-action-sheet ref="actionSheet" :actions="sexList" title="性别" @select="select" @close="close">
  34. </uv-action-sheet>
  35. <!--确认修改个人信息按钮-->
  36. <button @click="confirmEditUserInfo" class="bottomBtn">
  37. 确认修改
  38. </button>
  39. </view>
  40. </template>
  41. <script>
  42. import '../../common.css'; // 引入公共 CSS 文件
  43. import {
  44. mapState
  45. } from 'vuex'
  46. export default {
  47. computed: {
  48. ...mapState(['userInfo']),
  49. },
  50. data() {
  51. return {
  52. form: {
  53. sex: '',
  54. nickName: '1',
  55. phone: '',
  56. headImage: '',
  57. },
  58. // itemUserImage: userInfo.headImage,
  59. fileList: [],
  60. sexList: [{
  61. name: '男',
  62. value: 1
  63. },
  64. {
  65. name: '女',
  66. value: 0
  67. },
  68. ],
  69. }
  70. },
  71. mounted() {
  72. this.form = this.userInfo
  73. if (this.userInfo.sex == '' || this.userInfo.sex == null) {
  74. this.userInfo.sex = '未知'
  75. }
  76. console.log(this.userInfo.headImage, "this.userInfo.headImage");
  77. // this.fileList.push({
  78. // url: this.userInfo.headImage
  79. // })
  80. },
  81. methods: {
  82. // 确认修改个人信息
  83. confirmEditUserInfo() {
  84. this.$api('infoUpdateInfo', this.form, res => {
  85. if (res.code == 200) {
  86. // 修改VueX中的信息,是否有密码啥的
  87. uni.showToast({
  88. title: '修改成功',
  89. icon: 'success'
  90. })
  91. setTimeout(() => {
  92. uni.navigateTo({
  93. url: '/pages/index/index'
  94. })
  95. }, 300)
  96. }
  97. })
  98. },
  99. // 打开图片选择器并更新头像
  100. chooseAndUpdateUserImage() {
  101. const self = this;
  102. uni.chooseImage({
  103. count: 1, // 限制选择一张图片
  104. sizeType: ['original', 'compressed'], // 可选择原图或压缩图
  105. sourceType: ['album', 'camera'], // 可以从相册或相机选择
  106. success: (res) => {
  107. // 获取选择的图片临时路径
  108. const tempFilePath = res.tempFilePaths[0];
  109. console.log(tempFilePath, "Selected Image");
  110. // 调用上传方法
  111. self.updateUserImage(tempFilePath);
  112. },
  113. fail: (err) => {
  114. console.error("Failed to select image:", err);
  115. }
  116. });
  117. },
  118. // 修改头像
  119. updateUserImage(filePath) {
  120. const self = this;
  121. console.log(filePath, "Selected Image Path");
  122. // 调用上传方法
  123. self.$Oss.ossUpload(filePath).then(url => {
  124. // 将上传后的图片URL设置到头像中
  125. self.form.headImage = url;
  126. console.log("Uploaded Image URL:", url);
  127. }).catch(err => {
  128. console.error("Failed to upload image:", err);
  129. });
  130. },
  131. deleteImage(e) {
  132. this.fileList.splice(e.index, 1)
  133. },
  134. afterRead(e) {
  135. let self = this
  136. e.file.forEach(file => {
  137. self.$Oss.ossUpload(file.url).then(url => {
  138. self.fileList.push({
  139. url
  140. })
  141. })
  142. })
  143. },
  144. sexChange() {
  145. this.$refs.actionSheet.open() //打开ActionSheet 操作菜单
  146. },
  147. // ActionSheet 操作菜单选中
  148. select(e) {
  149. console.log('选中该项:', e);
  150. this.form.sex = e.name
  151. this.$refs.actionSheet.close() //关闭操作菜单
  152. },
  153. // ActionSheet 操作菜单关闭
  154. close() {
  155. this.$refs.actionSheet.close() //关闭操作菜单
  156. },
  157. }
  158. }
  159. </script>
  160. <style lang="scss" scoped>
  161. * {
  162. box-sizing: border-box;
  163. margin: 0;
  164. padding: 0;
  165. }
  166. .updateUserInfo {
  167. .frame {
  168. padding: 28rpx 28rpx 0 28rpx;
  169. .headImage {
  170. display: flex;
  171. // width: 100vw;
  172. padding: 20rpx;
  173. .key {
  174. width: 70%;
  175. height: 150rpx;
  176. display: flex;
  177. align-items: center;
  178. }
  179. .value {
  180. border-radius: 50%;
  181. border: 1px solid red;
  182. overflow: hidden;
  183. width: 30%;
  184. }
  185. }
  186. .item {
  187. display: flex;
  188. justify-content: space-between;
  189. // border-bottom: 1px solid #c9c9c9;
  190. margin-top: 20rpx;
  191. padding: 20rpx;
  192. .label {
  193. width: 50%;
  194. }
  195. .value {
  196. width: 50%;
  197. text-align: right;
  198. }
  199. }
  200. }
  201. }
  202. /deep/ .input__content {
  203. /deep/.uv-input__content__field-wrapper {
  204. border: 1px solid red;
  205. input {
  206. text-align: right;
  207. }
  208. }
  209. }
  210. /deep/ .uv-input__content__field-wrapper__field {
  211. text-align: right;
  212. }
  213. </style>