information.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. <image class="imgbox-avatar" :src="userInfo.avatarPath||defaultAvatar" @click="changeAvatar"></image>
  9. </view>
  10. </view>
  11. <view class="item adfacjb">
  12. <view class="left">用户名</view>
  13. <view class="right">
  14. <up-input v-model="userInfo.realName" border="none" placeholder="请输入用户名"></up-input>
  15. </view>
  16. </view>
  17. <!-- <view class="item adfacjb">
  18. <view class="left">手机号码</view>
  19. <view class="right">
  20. <up-input v-model="userInfo.phone" border="none" placeholder="请输入手机号码"></up-input>
  21. </view>
  22. </view> -->
  23. <view class="item adfacjb">
  24. <view class="left">家庭公益名称</view>
  25. <view class="right">
  26. <up-input v-model="userInfo.welfareName" border="none" placeholder="请输入家庭公益名称"></up-input>
  27. </view>
  28. </view>
  29. <view class="item adfacjb">
  30. <view class="left">家庭公益口号</view>
  31. <view class="right">
  32. <up-input v-model="userInfo.welfareSlogan" border="none" placeholder="请输入家庭公益口号"></up-input>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="btn" @click="save">保存</view>
  37. <qf-image-cropper :width="500" :height="500" :radius="30" @crop="handleCrop" ref="qicRef" v-if="qicShow"></qf-image-cropper>
  38. </view>
  39. </template>
  40. <script setup name="">
  41. import { BaseApi2 } from '../common/api/baseApi';
  42. import CusHeader from '@/components/CusHeader/index.vue'
  43. import { ref, onMounted, getCurrentInstance, nextTick } from 'vue'
  44. const { proxy } = getCurrentInstance()
  45. const defaultAvatar = ref('https://oss.familydaf.cn/sxsnfile/20251218/3821654e080945998d464f3c3aa64122.png')
  46. const userInfo = ref({
  47. avatarPath:''
  48. })
  49. const qicShow = ref(false)
  50. const save = () => {
  51. if(!userInfo.value?.avatarPath) return proxy.$showToast('请上传用户头像')
  52. if(!userInfo.value?.realName) return proxy.$showToast('请输入用户名')
  53. // if(!proxy.$reg.mobile(userInfo.value.phone)) return proxy.$showToast('请输入正确的手机号')
  54. if(!userInfo.value?.welfareName) return proxy.$showToast('请输入家庭公益名称')
  55. if(!userInfo.value?.welfareSlogan) return proxy.$showToast('请输入家庭公益口号')
  56. userInfo.value.id = uni.getStorageSync('userInfo')&&JSON.parse(uni.getStorageSync('userInfo')).id;
  57. proxy.$api.put('/wx/update',userInfo.value).then(({data:res})=>{
  58. if(res.code!==0) return proxy.$showToast(res.msg)
  59. proxy.$showToast('保存成功')
  60. setTimeout(()=>{
  61. uni.reLaunch({
  62. url:'/pages/my'
  63. })
  64. },1000)
  65. })
  66. }
  67. const changeAvatar = () => {
  68. uni.showActionSheet({
  69. itemList: ['从手机相册选择'],
  70. success: (res) => {
  71. if (res.tapIndex === 0) { // 从手机相册选择
  72. chooseLocalImage();
  73. }
  74. }
  75. });
  76. }
  77. // 从本地选择图片并显示
  78. const chooseLocalImage = () => {
  79. uni.chooseImage({
  80. count: 1, // 只能选择一张
  81. sizeType: ['compressed'], // 压缩图片
  82. sourceType: ['album', 'camera'], // 可以从相册或相机选择
  83. success: (res) => {
  84. const tempFilePaths = res.tempFilePaths;
  85. if (tempFilePaths && tempFilePaths.length > 0) {
  86. qicShow.value = true;
  87. nextTick(()=>{
  88. proxy.$refs.qicRef.initImage(tempFilePaths[0],true)
  89. })
  90. }
  91. },
  92. fail: (err) => {
  93. console.error('选择图片失败', err);
  94. }
  95. });
  96. }
  97. const handleCrop = async (e) => {
  98. const result = await uploadFilePromise(e.tempFilePath);
  99. userInfo.value.avatarPath = result||'';
  100. qicShow.value = false;
  101. }
  102. const uploadFilePromise = (url) => {
  103. return new Promise((resolve, reject) => {
  104. let a = uni.uploadFile({
  105. url: BaseApi2+'/sys/oss/upload',
  106. filePath: url,
  107. name: 'file',
  108. success: (res) => {
  109. setTimeout(() => {
  110. let data = JSON.parse(res.data)
  111. if(data&&data.code===0){
  112. resolve(data.data);
  113. }else proxy.$showToast(data?.msg)
  114. }, 1000);
  115. },
  116. fail: err =>{
  117. resolve('');
  118. }
  119. });
  120. });
  121. };
  122. const getUserInfo = () => {
  123. try{
  124. proxy.$api.get(`/wx/${JSON.parse(uni.getStorageSync('userInfo')).id}`).then(({data:res})=>{
  125. if(res.code!==0) return proxy.$showToast(res.msg)
  126. userInfo.value = res.data;
  127. })
  128. }catch(e){
  129. userInfo.value = null
  130. }
  131. }
  132. onMounted(()=>{
  133. getUserInfo()
  134. })
  135. </script>
  136. <style scoped lang="scss">
  137. ::v-deep .u-input__content input{
  138. font-family: PingFangSC, PingFang SC;
  139. font-weight: 400;
  140. font-size: 30rpx !important;
  141. color: #252525 !important;
  142. line-height: 42rpx !important;
  143. text-align: right !important;
  144. }
  145. .common_page{
  146. .form{
  147. background: #FFFFFF;
  148. border-radius: 24rpx;
  149. padding: 14rpx 22rpx 0;
  150. margin-top: 20rpx;
  151. .avatar{
  152. .title{
  153. font-family: PingFang-SC, PingFang-SC;
  154. font-weight: bold;
  155. font-size: 30rpx;
  156. color: #252525;
  157. line-height: 42rpx;
  158. }
  159. .imgbox{
  160. width: 122rpx;
  161. height: 122rpx;
  162. margin: 34rpx 0 47rpx;
  163. &-avatar{
  164. width: 100%;
  165. height: 100%;
  166. border-radius: 50%;
  167. }
  168. }
  169. border-bottom: 1rpx solid #E6E6E6;
  170. }
  171. .item{
  172. height: 110rpx;
  173. box-shadow: inset 0rpx -1rpx 0rpx 0rpx #E6E6E6;
  174. .left{
  175. width: 200rpx;
  176. font-family: PingFang-SC, PingFang-SC;
  177. font-weight: bold;
  178. font-size: 30rpx;
  179. color: #252525;
  180. line-height: 42rpx;
  181. padding-right: 20rpx;
  182. box-sizing: border-box;
  183. }
  184. .right{
  185. width: calc(100% - 200rpx);
  186. }
  187. }
  188. }
  189. .btn{
  190. width: calc(100% - 80rpx);
  191. height: 90rpx;
  192. background: #B7F358;
  193. border-radius: 45rpx;
  194. font-family: PingFang-SC, PingFang-SC;
  195. font-weight: bold;
  196. font-size: 32rpx;
  197. color: #151B29;
  198. line-height: 90rpx;
  199. text-align: center;
  200. letter-spacing: 2rpx;
  201. position: fixed;
  202. left: 40rpx;
  203. bottom: 64rpx;
  204. }
  205. }
  206. </style>