information.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. userInfo.value.avatarPath = fileList.value[0]?.url||''
  59. if(!userInfo.value?.avatarPath) return proxy.$showToast('请上传用户头像')
  60. if(!userInfo.value?.realName) return proxy.$showToast('请输入用户名')
  61. // if(!proxy.$reg.mobile(userInfo.value.phone)) return proxy.$showToast('请输入正确的手机号')
  62. if(!userInfo.value?.welfareName) return proxy.$showToast('请输入家庭公益名称')
  63. if(!userInfo.value?.welfareSlogan) return proxy.$showToast('请输入家庭公益口号')
  64. userInfo.value.id = uni.getStorageSync('userInfo')&&JSON.parse(uni.getStorageSync('userInfo')).id;
  65. proxy.$api.put('/wx/update',userInfo.value).then(({data:res})=>{
  66. if(res.code!==0) return proxy.$showToast(res.msg)
  67. proxy.$showToast('保存成功')
  68. setTimeout(()=>{
  69. uni.reLaunch({
  70. url:'/pages/my'
  71. })
  72. },1000)
  73. })
  74. }
  75. const deletePic = (event) => {
  76. fileList.value.splice(event.index, 1);
  77. userInfo.value.avatarPath = '';
  78. };
  79. // 新增图片
  80. const afterRead = async (event) => {
  81. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  82. let lists = [].concat(event.file);
  83. let fileListLen = fileList.value.length;
  84. lists.map((item) => {
  85. fileList.value.push({
  86. ...item,
  87. status: 'uploading',
  88. message: '上传中',
  89. });
  90. });
  91. for (let i = 0; i < lists.length; i++) {
  92. const result = await uploadFilePromise(lists[i].url);
  93. if(result){
  94. let item = fileList.value[fileListLen];
  95. fileList.value.splice(fileListLen, 1, {
  96. ...item,
  97. status: 'success',
  98. message: '',
  99. url: result,
  100. });
  101. }
  102. fileListLen++;
  103. }
  104. };
  105. const uploadFilePromise = (url) => {
  106. return new Promise((resolve, reject) => {
  107. let a = uni.uploadFile({
  108. url: BaseApi+'/uploadFile',
  109. filePath: url,
  110. name: 'file',
  111. success: (res) => {
  112. setTimeout(() => {
  113. let data = JSON.parse(res.data)
  114. if(data&&data.code===0){
  115. resolve(data.data);
  116. }else proxy.$showToast(data?.msg)
  117. }, 1000);
  118. },
  119. fail: err =>{
  120. resolve('');
  121. }
  122. });
  123. });
  124. };
  125. const getUserInfo = () => {
  126. try{
  127. proxy.$api.get(`/wx/${JSON.parse(uni.getStorageSync('userInfo')).id}`).then(({data:res})=>{
  128. if(res.code!==0) return proxy.$showToast(res.msg)
  129. userInfo.value = res.data;
  130. if(userInfo.value?.avatarPath) fileList.value = [{name:'',url:userInfo.value?.avatarPath}];
  131. })
  132. }catch(e){
  133. userInfo.value = null
  134. }
  135. }
  136. onMounted(()=>{
  137. getUserInfo()
  138. })
  139. </script>
  140. <style scoped lang="scss">
  141. ::v-deep .u-input__content input{
  142. font-family: PingFangSC, PingFang SC;
  143. font-weight: 400;
  144. font-size: 30rpx !important;
  145. color: #252525 !important;
  146. line-height: 42rpx !important;
  147. text-align: right !important;
  148. }
  149. .common_page{
  150. .form{
  151. background: #FFFFFF;
  152. border-radius: 24rpx;
  153. padding: 14rpx 22rpx 0;
  154. margin-top: 20rpx;
  155. .avatar{
  156. .title{
  157. font-family: PingFang-SC, PingFang-SC;
  158. font-weight: bold;
  159. font-size: 30rpx;
  160. color: #252525;
  161. line-height: 42rpx;
  162. }
  163. .imgbox{
  164. padding: 34rpx 0 47rpx;
  165. }
  166. border-bottom: 1rpx solid #E6E6E6;
  167. }
  168. .item{
  169. height: 110rpx;
  170. box-shadow: inset 0rpx -1rpx 0rpx 0rpx #E6E6E6;
  171. .left{
  172. width: 200rpx;
  173. font-family: PingFang-SC, PingFang-SC;
  174. font-weight: bold;
  175. font-size: 30rpx;
  176. color: #252525;
  177. line-height: 42rpx;
  178. padding-right: 20rpx;
  179. box-sizing: border-box;
  180. }
  181. .right{
  182. width: calc(100% - 200rpx);
  183. }
  184. }
  185. }
  186. .btn{
  187. width: calc(100% - 80rpx);
  188. height: 90rpx;
  189. background: #B7F358;
  190. border-radius: 45rpx;
  191. font-family: PingFang-SC, PingFang-SC;
  192. font-weight: bold;
  193. font-size: 32rpx;
  194. color: #151B29;
  195. line-height: 90rpx;
  196. text-align: center;
  197. letter-spacing: 2rpx;
  198. position: fixed;
  199. left: 40rpx;
  200. bottom: 64rpx;
  201. }
  202. }
  203. </style>