information.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <view class="common_page" :style="{'height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title="个人资料" bgColor="#FFFFFF"></cus-header>
  4. <view class="form" v-if="userInfo">
  5. <view class="avatar">
  6. <view class="title">头像</view>
  7. <view class="imgbox">
  8. <up-upload
  9. :fileList="fileList"
  10. @afterRead="afterRead"
  11. @delete="deletePic"
  12. multiple
  13. :maxCount="1"
  14. width="122rpx"
  15. height="122rpx"
  16. >
  17. <image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/09/29/b04d6b0e-0d30-4043-a2b1-d639e15e2aac.png"
  18. mode="widthFix" style="width: 122rpx;height: 122rpx;"></image>
  19. </up-upload>
  20. </view>
  21. </view>
  22. <view class="item adfacjb">
  23. <view class="left">用户名</view>
  24. <view class="right">
  25. <up-input v-model="userInfo.realName" border="none" placeholder="请输入用户名"></up-input>
  26. </view>
  27. </view>
  28. <!-- <view class="item adfacjb">
  29. <view class="left">手机号码</view>
  30. <view class="right">
  31. <up-input v-model="userInfo.phone" border="none" placeholder="请输入手机号码"></up-input>
  32. </view>
  33. </view> -->
  34. <view class="item adfacjb">
  35. <view class="left">家庭公益名称</view>
  36. <view class="right">
  37. <up-input v-model="userInfo.welfareName" border="none" placeholder="请输入家庭公益名称"></up-input>
  38. </view>
  39. </view>
  40. <view class="item adfacjb">
  41. <view class="left">家庭公益口号</view>
  42. <view class="right">
  43. <up-input v-model="userInfo.welfareSlogan" border="none" placeholder="请输入家庭公益口号"></up-input>
  44. </view>
  45. </view>
  46. </view>
  47. <view class="btn" @click="save">保存</view>
  48. </view>
  49. </template>
  50. <script setup name="">
  51. import { BaseApi } from '../common/api/baseApi';
  52. import CusHeader from '@/components/CusHeader/index.vue'
  53. import { ref, onMounted, getCurrentInstance } from 'vue'
  54. const { proxy } = getCurrentInstance()
  55. const fileList = ref([])
  56. const userInfo = ref(null)
  57. const save = () => {
  58. if(!userInfo.value?.avatarPath) return proxy.$showToast('请上传用户头像')
  59. if(!userInfo.value?.realName) return proxy.$showToast('请输入用户名')
  60. // if(!proxy.$reg.mobile(userInfo.value.phone)) return proxy.$showToast('请输入正确的手机号')
  61. if(!userInfo.value?.welfareName) return proxy.$showToast('请输入家庭公益名称')
  62. if(!userInfo.value?.welfareSlogan) return proxy.$showToast('请输入家庭公益口号')
  63. }
  64. const deletePic = (event) => {
  65. fileList.value.splice(event.index, 1);
  66. };
  67. // 新增图片
  68. const afterRead = async (event) => {
  69. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  70. let lists = [].concat(event.file);
  71. let fileListLen = fileList.value.length;
  72. lists.map((item) => {
  73. fileList.value.push({
  74. ...item,
  75. status: 'uploading',
  76. message: '上传中',
  77. });
  78. });
  79. for (let i = 0; i < lists.length; i++) {
  80. const result = await uploadFilePromise(lists[i].url);
  81. let item = fileList.value[fileListLen];
  82. fileList.value.splice(fileListLen, 1, {
  83. ...item,
  84. status: 'success',
  85. message: '',
  86. url: result,
  87. });
  88. fileListLen++;
  89. }
  90. };
  91. const uploadFilePromise = (url) => {
  92. return new Promise((resolve, reject) => {
  93. let a = uni.uploadFile({
  94. url: BaseApi+'/uploadFile', // 仅为示例,非真实的接口地址
  95. filePath: url,
  96. name: 'file',
  97. formData: {
  98. user: 'test',
  99. },
  100. success: (res) => {
  101. setTimeout(() => {
  102. resolve(res.data.data);
  103. }, 1000);
  104. },
  105. });
  106. });
  107. };
  108. const getUserInfo = () => {
  109. try{
  110. proxy.$api.get(`/wx/${JSON.parse(uni.getStorageSync('userInfo')).id}`).then(({data:res})=>{
  111. if(res.code!==0) return this.$showToast(res.msg)
  112. userInfo.value = res.data;
  113. if(userInfo.value?.avatarPath) fileList.value = [{name:'',url:userInfo.value?.avatarPath}];
  114. })
  115. }catch(e){
  116. userInfo.value = null
  117. }
  118. }
  119. onMounted(()=>{
  120. getUserInfo()
  121. })
  122. </script>
  123. <style scoped lang="scss">
  124. ::v-deep .u-input__content input{
  125. font-family: PingFangSC, PingFang SC;
  126. font-weight: 400;
  127. font-size: 30rpx !important;
  128. color: #252525 !important;
  129. line-height: 42rpx !important;
  130. text-align: right !important;
  131. }
  132. .common_page{
  133. .form{
  134. background: #FFFFFF;
  135. border-radius: 24rpx;
  136. padding: 14rpx 22rpx 0;
  137. margin-top: 20rpx;
  138. .avatar{
  139. .title{
  140. font-family: PingFang-SC, PingFang-SC;
  141. font-weight: bold;
  142. font-size: 30rpx;
  143. color: #252525;
  144. line-height: 42rpx;
  145. }
  146. .imgbox{
  147. padding: 34rpx 0 47rpx;
  148. }
  149. border-bottom: 1rpx solid #E6E6E6;
  150. }
  151. .item{
  152. height: 110rpx;
  153. box-shadow: inset 0rpx -1rpx 0rpx 0rpx #E6E6E6;
  154. .left{
  155. width: 200rpx;
  156. font-family: PingFang-SC, PingFang-SC;
  157. font-weight: bold;
  158. font-size: 30rpx;
  159. color: #252525;
  160. line-height: 42rpx;
  161. padding-right: 20rpx;
  162. box-sizing: border-box;
  163. }
  164. .right{
  165. width: calc(100% - 200rpx);
  166. }
  167. }
  168. }
  169. .btn{
  170. width: calc(100% - 80rpx);
  171. height: 90rpx;
  172. background: #B7F358;
  173. border-radius: 45rpx;
  174. font-family: PingFang-SC, PingFang-SC;
  175. font-weight: bold;
  176. font-size: 32rpx;
  177. color: #151B29;
  178. line-height: 90rpx;
  179. text-align: center;
  180. letter-spacing: 2rpx;
  181. position: fixed;
  182. left: 40rpx;
  183. bottom: 64rpx;
  184. }
  185. }
  186. </style>