information.vue 8.2 KB

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