我的车位,我的车辆
This commit is contained in:
@@ -5,6 +5,10 @@ import request, {
|
||||
putMethod
|
||||
} from "./request.js"
|
||||
|
||||
// 字典
|
||||
export const getSystemDictData = (data) => {
|
||||
return get('/system/dict/data/list', data)
|
||||
}
|
||||
|
||||
// =======公告列表========
|
||||
export const getResidentNoticeList = (data) => {
|
||||
@@ -87,4 +91,62 @@ export const upDateMyHouse = (data) => {
|
||||
// 修改身份证照片
|
||||
export const uploadFileUploadImage = (data) => {
|
||||
return post(`/api/resident/file/uploadImage`, data)
|
||||
}
|
||||
}
|
||||
// 添加车辆
|
||||
export const postCar = (data) => {
|
||||
return post(`/api/resident/car`, data)
|
||||
}
|
||||
// 修改车辆
|
||||
export const putCar = (data) => {
|
||||
return putMethod(`/api/resident/car`, data)
|
||||
}
|
||||
|
||||
// 获取车辆列表
|
||||
export const getMyCarList = (data) => {
|
||||
return get(`/api/resident/car/myList`, data)
|
||||
}
|
||||
// 获取车位列表
|
||||
export const getCarList = (data) => {
|
||||
return get(`/api/resident/car/list`, data)
|
||||
}
|
||||
// 获取车辆详细信息
|
||||
export const getCarDetail = (data) => {
|
||||
return get(`/api/resident/car/${data.id}`, data)
|
||||
}
|
||||
// 删除车辆信息
|
||||
export const deleteCar = (data) => {
|
||||
return deleteMethod(`/api/resident/car/${data.carId}`, data)
|
||||
}
|
||||
// 获取用户车位绑定列表
|
||||
export const getUserParkingSpaceList = (data) => {
|
||||
return get(`/api/resident/car/parking/list`, data)
|
||||
}
|
||||
|
||||
// 获取区域列表
|
||||
export const getResidentCarAreaManageAreaListByVillageId = (data) => {
|
||||
return get(`/ResidentCarAreaManage/areaListByVillageId`, data)
|
||||
}
|
||||
// 根据区域id获得车位列表
|
||||
export const getResidentCarAreaManageParkingListByAreaId = (data) => {
|
||||
return get(`/ResidentCarAreaManage/parkingListByAreaId`, data)
|
||||
}
|
||||
// 绑定车位
|
||||
export const postCarBind = (data) => {
|
||||
return post(`/api/resident/car/bind`, data)
|
||||
}
|
||||
// 获取用户下车位绑定信息
|
||||
// export const getCarList = (data) => {
|
||||
// return get(`/api/resident/car/list`, data)
|
||||
// }
|
||||
// 删除车位
|
||||
export const deleteParking = (data) => {
|
||||
return deleteMethod(`/ResidentCarAreaManage/parking/${data.parkingId}`, data)
|
||||
}
|
||||
// 车位详情
|
||||
export const getParkingDetail = (data) => {
|
||||
return get(`/api/resident/car/parking/detail/${data.id}`, data)
|
||||
}
|
||||
// 解绑车辆
|
||||
export const rebindCar = (data) => {
|
||||
return post(`/ResidentCarAreaManage/rebind`, data)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// 服务器地址(与 request.js 保持一致)
|
||||
const baseUrl = 'http://192.168.0.224:8080';
|
||||
const baseUrl = 'http://192.168.0.239:8080';
|
||||
|
||||
/**
|
||||
* 图片上传 Hook
|
||||
@@ -7,7 +7,7 @@ const baseUrl = 'http://192.168.0.224:8080';
|
||||
* 解决编辑回显后重新上传的问题
|
||||
*/
|
||||
|
||||
import { ref } from 'vue'
|
||||
import { reactive } from 'vue'
|
||||
|
||||
/**
|
||||
* @param {Object} options 配置
|
||||
@@ -21,14 +21,17 @@ export function useImageUpload(options = {}) {
|
||||
fileKey = 'file'
|
||||
} = options
|
||||
|
||||
// 当前显示的图片(前端展示用,支持 base64/blob URL/网络URL)
|
||||
const previewUrl = ref('')
|
||||
// 服务器返回的 URL(提交时使用)
|
||||
const serverUrl = ref('')
|
||||
// 临时的文件路径(重新上传时用)
|
||||
const tempFilePath = ref(null)
|
||||
// 上传状态
|
||||
const uploading = ref(false)
|
||||
// 使用 reactive 对象存储所有状态
|
||||
const state = reactive({
|
||||
// 当前显示的图片(前端展示用,支持 base64/blob URL/网络URL)
|
||||
previewUrl: '',
|
||||
// 服务器返回的 URL(提交时使用)
|
||||
serverUrl: '',
|
||||
// 临时的文件路径(重新上传时用)
|
||||
tempFilePath: null,
|
||||
// 上传状态
|
||||
uploading: false
|
||||
})
|
||||
|
||||
/**
|
||||
* 设置回显图片(编辑时从后端获取)
|
||||
@@ -36,9 +39,11 @@ export function useImageUpload(options = {}) {
|
||||
*/
|
||||
const setPreviewUrl = (url) => {
|
||||
if (url) {
|
||||
previewUrl.value = url
|
||||
serverUrl.value = url
|
||||
tempFilePath.value = null // 重置临时文件,表示没有重新上传
|
||||
// 确保 url 是字符串
|
||||
const urlStr = typeof url === 'string' ? url : (url?.url || String(url))
|
||||
state.previewUrl = urlStr
|
||||
state.serverUrl = urlStr
|
||||
state.tempFilePath = null // 重置临时文件,表示没有重新上传
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,14 +58,20 @@ export function useImageUpload(options = {}) {
|
||||
sizeType: ['compressed'],
|
||||
sourceType: ['camera', 'album'],
|
||||
success: (res) => {
|
||||
const path = res.tempFilePaths[0]
|
||||
const path = res.tempFilePaths?.[0]
|
||||
if (!path) {
|
||||
reject(new Error('选择图片失败'))
|
||||
return
|
||||
}
|
||||
// 确保 path 是字符串
|
||||
const pathStr = typeof path === 'string' ? path : String(path)
|
||||
// 设置预览
|
||||
previewUrl.value = path
|
||||
state.previewUrl = pathStr
|
||||
// 记录临时文件路径
|
||||
tempFilePath.value = path
|
||||
state.tempFilePath = pathStr
|
||||
// 置空服务器URL,等实际上传后再获取
|
||||
serverUrl.value = ''
|
||||
resolve(path)
|
||||
state.serverUrl = ''
|
||||
resolve(pathStr)
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(err)
|
||||
@@ -71,25 +82,32 @@ export function useImageUpload(options = {}) {
|
||||
|
||||
/**
|
||||
* 上传图片到服务器
|
||||
* @returns {Promise<string>} 返回服务器上的URL
|
||||
* @returns {Promise<Object>} 返回 { url: string }
|
||||
*/
|
||||
const uploadImage = () => {
|
||||
// 如果没有新选择临时文件,直接返回已有的服务器URL
|
||||
if (!tempFilePath.value) {
|
||||
return Promise.resolve(serverUrl.value)
|
||||
if (!state.tempFilePath) {
|
||||
return Promise.resolve({ url: state.serverUrl })
|
||||
}
|
||||
|
||||
// 如果已经有服务器URL且没有重新选择,也直接返回
|
||||
if (serverUrl.value && !tempFilePath.value) {
|
||||
return Promise.resolve(serverUrl.value)
|
||||
if (state.serverUrl && !state.tempFilePath) {
|
||||
return Promise.resolve({ url: state.serverUrl })
|
||||
}
|
||||
|
||||
uploading.value = true
|
||||
state.uploading = true
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
// 确保 filePath 是字符串
|
||||
const filePath = state.tempFilePath
|
||||
if (!filePath || typeof filePath !== 'string') {
|
||||
state.uploading = false
|
||||
reject(new Error('文件路径无效'))
|
||||
return
|
||||
}
|
||||
uni.uploadFile({
|
||||
url: baseUrl + uploadUrl,
|
||||
filePath: tempFilePath.value,
|
||||
filePath: filePath,
|
||||
name: fileKey,
|
||||
header: {
|
||||
'Authorization': 'Bearer ' + (uni.getStorageSync('token') || ''),
|
||||
@@ -101,10 +119,10 @@ export function useImageUpload(options = {}) {
|
||||
if (data.code === 200 && data.data) {
|
||||
// 更新服务器URL(确保存的是字符串)
|
||||
const url = typeof data.data === 'string' ? data.data : (data.data?.url || '')
|
||||
serverUrl.value = url
|
||||
state.serverUrl = url
|
||||
// 清空临时文件
|
||||
tempFilePath.value = null
|
||||
resolve(url)
|
||||
state.tempFilePath = null
|
||||
resolve({ url })
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: data.msg || '上传失败',
|
||||
@@ -128,7 +146,7 @@ export function useImageUpload(options = {}) {
|
||||
reject(err)
|
||||
},
|
||||
complete: () => {
|
||||
uploading.value = false
|
||||
state.uploading = false
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -138,36 +156,35 @@ export function useImageUpload(options = {}) {
|
||||
* 获取最终可提交的URL
|
||||
* 如果有新上传的图片,先上传再返回URL
|
||||
* 如果没有新上传,直接返回已有的服务器URL
|
||||
* @returns {Promise<string>}
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
const getSubmitUrl = async () => {
|
||||
// 如果重新选择了新图片,先上传
|
||||
if (tempFilePath.value) {
|
||||
if (state.tempFilePath) {
|
||||
return await uploadImage()
|
||||
}
|
||||
// 否则返回已有的服务器URL
|
||||
return serverUrl.value
|
||||
return { url: state.serverUrl }
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置状态
|
||||
*/
|
||||
const reset = () => {
|
||||
previewUrl.value = ''
|
||||
serverUrl.value = ''
|
||||
tempFilePath.value = null
|
||||
uploading.value = false
|
||||
state.previewUrl = ''
|
||||
state.serverUrl = ''
|
||||
state.tempFilePath = null
|
||||
state.uploading = false
|
||||
}
|
||||
|
||||
// 返回 reactive state 和方法
|
||||
// state 作为 reactive 对象,在模板中通过 idCardFrontUpload.state.previewUrl 访问
|
||||
return {
|
||||
previewUrl, // 前端展示用
|
||||
serverUrl, // 提交时使用的URL
|
||||
tempFilePath, // 临时文件路径
|
||||
uploading, // 上传中状态
|
||||
setPreviewUrl, // 设置回显图片(编辑时用)
|
||||
chooseImage, // 选择图片(预览用,不上传)
|
||||
uploadImage, // 上传到服务器
|
||||
getSubmitUrl, // 获取最终可提交的URL(自动处理上传)
|
||||
reset // 重置
|
||||
state,
|
||||
setPreviewUrl,
|
||||
chooseImage,
|
||||
uploadImage,
|
||||
getSubmitUrl,
|
||||
reset
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user