Просмотр исходного кода

feat: 用户信息更新接口及图标更换

liangan 2 недель назад
Родитель
Сommit
a47f784879
40 измененных файлов с 105 добавлено и 30 удалено
  1. 1 1
      env/.env
  2. 1 1
      src/api/login.ts
  3. 1 1
      src/pages/mine/mine.vue
  4. 99 24
      src/pages/mine/myProfile.vue
  5. 2 2
      src/pages/wallet/withdraw.vue
  6. BIN
      src/static/app/icons/1024x1024.png
  7. BIN
      src/static/app/icons/120x120.png
  8. BIN
      src/static/app/icons/144x144.png
  9. BIN
      src/static/app/icons/152x152.png
  10. BIN
      src/static/app/icons/167x167.png
  11. BIN
      src/static/app/icons/180x180.png
  12. BIN
      src/static/app/icons/192x192.png
  13. BIN
      src/static/app/icons/20x20.png
  14. BIN
      src/static/app/icons/29x29.png
  15. BIN
      src/static/app/icons/40x40.png
  16. BIN
      src/static/app/icons/58x58.png
  17. BIN
      src/static/app/icons/60x60.png
  18. BIN
      src/static/app/icons/72x72.png
  19. BIN
      src/static/app/icons/76x76.png
  20. BIN
      src/static/app/icons/80x80.png
  21. BIN
      src/static/app/icons/87x87.png
  22. BIN
      src/static/app/icons/96x96.png
  23. 1 1
      src/store/user.ts
  24. BIN
      unpackage/res/icons/1024x1024.png
  25. BIN
      unpackage/res/icons/120x120.png
  26. BIN
      unpackage/res/icons/144x144.png
  27. BIN
      unpackage/res/icons/152x152.png
  28. BIN
      unpackage/res/icons/167x167.png
  29. BIN
      unpackage/res/icons/180x180.png
  30. BIN
      unpackage/res/icons/192x192.png
  31. BIN
      unpackage/res/icons/20x20.png
  32. BIN
      unpackage/res/icons/29x29.png
  33. BIN
      unpackage/res/icons/40x40.png
  34. BIN
      unpackage/res/icons/58x58.png
  35. BIN
      unpackage/res/icons/60x60.png
  36. BIN
      unpackage/res/icons/72x72.png
  37. BIN
      unpackage/res/icons/76x76.png
  38. BIN
      unpackage/res/icons/80x80.png
  39. BIN
      unpackage/res/icons/87x87.png
  40. BIN
      unpackage/res/icons/96x96.png

+ 1 - 1
env/.env

@@ -14,7 +14,7 @@ VITE_SERVER_BASEURL = 'http://124.222.152.234:8101'
 # 第二个请求地址
 VITE_API_SECONDARY_URL = 'https://ukw0y1.laf.run'
 
-VITE_UPLOAD_BASEURL = 'https://ukw0y1.laf.run/upload'
+VITE_UPLOAD_BASEURL = 'http://124.222.152.234:8101/operating/file/upload'
 
 # 有些同学可能需要在微信小程序里面根据 develop、trial、release 分别设置上传地址,参考代码如下。
 # 下面的变量如果没有设置,会默认使用 VITE_SERVER_BASEURL or VITE_UPLOAD_BASEURL

+ 1 - 1
src/api/login.ts

@@ -42,7 +42,7 @@ export function logout() {
  * 修改用户信息
  */
 export function updateInfo(data: any) {
-  return http.post('/user/updateInfo', data)
+  return http.post('/cif/api/user/updateUser', data)
 }
 
 /**

+ 1 - 1
src/pages/mine/mine.vue

@@ -66,7 +66,7 @@ onShow(() => {
         width="96rpx"
         height="96rpx"
         round
-        :src="isLoggedIn && userInfo?.avatar ? userInfo.avatar : '/static/images/default-avatar.png'"
+        :src="isLoggedIn ? userInfo?.headPic : '/static/images/default-avatar.png'"
       />
       <!-- 已登录 -->
       <view v-if="isLoggedIn" class="ml-24rpx text-32rpx font-bold">

+ 99 - 24
src/pages/mine/myProfile.vue

@@ -13,49 +13,124 @@
 // eslint-disable-next-line unused-imports/no-unused-imports
 import { onPageScroll, onReachBottom } from '@dcloudio/uni-app'
 import useZPaging from 'z-paging/components/z-paging/js/hooks/useZPaging.js'
+import { updateInfo } from '@/api/login'
+import { useUserStore } from '@/store'
+import { getEnvBaseUploadUrl } from '@/utils'
+import { toast } from '@/utils/toast'
 
 defineOptions({
   name: 'MyProfile', // 我的资料
 })
+
+const userStore = useUserStore()
+const userInfo = computed(() => {
+  return getUserInfoHook()
+})
+
 // z-paging
 const paging = ref(null)
 // 类似mixins,如果是页面滚动务必要写这一行,并传入当前ref绑定的paging,注意此处是paging,而非paging.value
 useZPaging(paging)
-// 搜索结果
-const dataList = ref([])
-function queryList(pageNo, pageSize) {
-  // 此处请求仅为演示,请替换为自己项目中的请求
-  setTimeout(() => {
-    dataList.value = [
-      { title: '123' },
-      { title: '123' },
-      { title: '123' },
-      { title: '12345' },
-    ]
-    paging.value.complete(dataList.value)
-  }, 1000)
+
+const uploading = ref(false)
+
+// 更新头像
+async function updateAvatar() {
+  try {
+    // 使用 uni.chooseMedia 选择图片
+    const res: any = await new Promise((resolve, reject) => {
+      uni.chooseMedia({
+        count: 1,
+        mediaType: ['image'],
+        sourceType: ['album', 'camera'],
+        success: resolve,
+        fail: reject,
+      })
+    })
+
+    if (!res.tempFiles || res.tempFiles.length === 0) {
+      return
+    }
+
+    const tempFile = res.tempFiles[0]
+    const tempFilePath = tempFile.tempFilePath
+
+    // 检查文件大小(限制为5MB)
+    const maxSize = 5 * 1024 * 1024
+    if (tempFile.size > maxSize) {
+      toast.error('Image size cannot exceed 5MB')
+      return
+    }
+
+    uploading.value = true
+    await uni.showLoading({
+      title: 'Uploading...',
+      mask: true,
+    })
+
+    // 上传图片
+    const uploadRes: any = await new Promise((resolve, reject) => {
+      uni.uploadFile({
+        url: `${getEnvBaseUploadUrl()}`,
+        filePath: tempFilePath,
+        name: 'file',
+        success: resolve,
+        fail: reject,
+      })
+    })
+    console.log('uploadRes', uploadRes)
+    // 解析上传结果
+    const uploadData = JSON.parse(uploadRes.data)
+    if (uploadData.code !== 200) {
+      throw new Error(uploadData.message || 'Upload failed')
+    }
+
+    const avatarUrl = uploadData.data.url
+    // 调用更新用户信息接口
+    await updateInfo({
+      headPic: avatarUrl,
+    })
+    // 更新本地用户信息
+    const newUserInfo = { ...userInfo.value, headPic: avatarUrl }
+    userStore.setUserInfo(newUserInfo)
+
+    uni.hideLoading()
+    toast.success('Avatar updated successfully')
+  }
+  catch (error: any) {
+    uni.hideLoading()
+    console.error('Update avatar failed:', error)
+    toast.error(error.message || 'Failed to update avatar')
+  }
+  finally {
+    uploading.value = false
+  }
 }
 </script>
 
 <template>
-  <z-paging ref="paging" refresher-only use-page-scroll @query="queryList">
+  <z-paging ref="paging" refresher-only use-page-scroll>
     <view class="py-20rpx">
       <wd-cell-group custom-class="mb-20rpx" border>
         <wd-cell title="Avatar" center>
-          <view class="flex items-center justify-end">
-            <wd-img width="64rpx" height="64rpx" custom-class="mr-18rpx" round src="/static/images/avatar.jpg" />
-            <wd-icon name="arrow-right" size="36rpx" />
+          <view class="flex items-center justify-end" @click="updateAvatar">
+            <view class="relative flex items-center justify-center">
+              <wd-img width="64rpx" height="64rpx" round :src="userInfo.headPic" />
+              <view v-if="uploading" class="absolute inset-0 flex items-center justify-center rounded-full bg-black bg-opacity-50">
+                <wd-loading size="20rpx" color="#fff" />
+              </view>
+            </view>
+            <wd-icon name="arrow-right" custom-class="ml-10rpx" size="36rpx" />
           </view>
         </wd-cell>
-        <wd-cell title="User ID" value="123456" />
-        <wd-cell title="User Name" value="Aamir Khan" />
-        <wd-cell title="Full Name" value="Aamir Khan" />
-        <wd-cell title="Mobile Number" value="88017123456789" />
+        <wd-cell title="User ID" :value="userInfo.userId" />
+        <wd-cell title="User Name" :value="userInfo.name" />
+        <wd-cell title="Mobile Number" :value="userInfo.phoneNo" />
       </wd-cell-group>
       <wd-cell-group custom-class="mb-20rpx" border>
-        <wd-cell title="Bank Name" value="Aamir Khan" />
-        <wd-cell title="Bank Account Name" value="Aamir Khan" />
-        <wd-cell title="Bank Account No." value="88017123456789" />
+        <wd-cell title="Bank Name" :value="userInfo.bank" />
+        <wd-cell title="Bank Account Name" :value="userInfo.bankAccountName" />
+        <wd-cell title="Bank Account No." :value="userInfo.bankAccount" />
       </wd-cell-group>
     </view>
   </z-paging>

+ 2 - 2
src/pages/wallet/withdraw.vue

@@ -11,7 +11,7 @@
 <script lang="ts" setup>
 import { withdrawAdd } from '@/api/wallet'
 import { formatNumber } from '@/utils'
-import { getPageParams, toPage } from '@/utils/page'
+import { getPageParams, goBack, toPage } from '@/utils/page'
 import { toast } from '@/utils/toast'
 
 defineOptions({
@@ -64,7 +64,7 @@ onLoad((options) => {
       title="Withdraw"
     >
       <template #left>
-        <wd-icon name="thin-arrow-left" size="32rpx" />
+        <wd-icon name="thin-arrow-left" size="32rpx" @click="goBack" />
       </template>
       <template #right>
         <text class="text-28rpx" @click="toPage('/pages/wallet/withdrawRecord', { type: queryParams.type })">

BIN
src/static/app/icons/1024x1024.png


BIN
src/static/app/icons/120x120.png


BIN
src/static/app/icons/144x144.png


BIN
src/static/app/icons/152x152.png


BIN
src/static/app/icons/167x167.png


BIN
src/static/app/icons/180x180.png


BIN
src/static/app/icons/192x192.png


BIN
src/static/app/icons/20x20.png


BIN
src/static/app/icons/29x29.png


BIN
src/static/app/icons/40x40.png


BIN
src/static/app/icons/58x58.png


BIN
src/static/app/icons/60x60.png


BIN
src/static/app/icons/72x72.png


BIN
src/static/app/icons/76x76.png


BIN
src/static/app/icons/80x80.png


BIN
src/static/app/icons/87x87.png


BIN
src/static/app/icons/96x96.png


+ 1 - 1
src/store/user.ts

@@ -6,7 +6,7 @@ import { toast } from '@/utils/toast'
 
 // 初始化状态
 const userInfoState: any = {
-  avatar: '/static/images/default-avatar.png',
+  headPic: '/static/images/default-avatar.png',
 }
 
 export const useUserStore = defineStore(

BIN
unpackage/res/icons/1024x1024.png


BIN
unpackage/res/icons/120x120.png


BIN
unpackage/res/icons/144x144.png


BIN
unpackage/res/icons/152x152.png


BIN
unpackage/res/icons/167x167.png


BIN
unpackage/res/icons/180x180.png


BIN
unpackage/res/icons/192x192.png


BIN
unpackage/res/icons/20x20.png


BIN
unpackage/res/icons/29x29.png


BIN
unpackage/res/icons/40x40.png


BIN
unpackage/res/icons/58x58.png


BIN
unpackage/res/icons/60x60.png


BIN
unpackage/res/icons/72x72.png


BIN
unpackage/res/icons/76x76.png


BIN
unpackage/res/icons/80x80.png


BIN
unpackage/res/icons/87x87.png


BIN
unpackage/res/icons/96x96.png