information.vue 6.4 KB

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