更新:登录功能

This commit is contained in:
2025-11-04 12:37:04 +08:00
commit a21fb92916
897 changed files with 51500 additions and 0 deletions

41
hooks/useUpload.ts Normal file
View File

@@ -0,0 +1,41 @@
// hooks/useUpload.ts
import { ref } from 'vue'
import { getAuthToken } from '@/utils/auth'
export function useUpload(uploadUrl: string) {
const progress = ref(0)
const uploading = ref(false)
const upload = (filePath: string) => {
uploading.value = true
return new Promise((resolve, reject) => {
const uploadTask = uni.uploadFile({
url: uploadUrl,
filePath,
name: 'file',
header: {
Authorization: `Bearer ${getAuthToken()}`,
},
success: (res) => {
try {
const data = JSON.parse(res.data)
if (data.code === 200) resolve(data.data)
else reject(data)
} catch (e) {
reject(e)
}
},
fail: reject,
complete: () => {
uploading.value = false
},
})
uploadTask.onProgressUpdate((res) => {
progress.value = res.progress
})
})
}
return { progress, uploading, upload }
}