花开物业版本1.0
This commit is contained in:
141
huakai-app/pageSubPack/api/api.js
Normal file
141
huakai-app/pageSubPack/api/api.js
Normal file
@@ -0,0 +1,141 @@
|
||||
import request,{get,post,upload} from "./request.js"
|
||||
|
||||
|
||||
// =======账号密码登录========
|
||||
export const getLoginPassword = (data) =>{
|
||||
return post('/api/resident/auth/loginByPassword',data)
|
||||
}
|
||||
// 注册新用户获取验证码
|
||||
export const getSendCode = (data) =>{
|
||||
return post('/api/resident/auth/sendSmsCode',data)
|
||||
}
|
||||
// 注册新用户
|
||||
export const getRegisterUser = (data) =>{
|
||||
return post('/api/resident/auth/register',data)
|
||||
}
|
||||
// 短信验证码登录
|
||||
export const getLoginBySms = (data) =>{
|
||||
return post('/api/resident/auth/loginBySms',data)
|
||||
}
|
||||
// 忘记密码接口
|
||||
export const getResetPassword = (data) =>{
|
||||
return post('/api/resident/auth/resetPassword',data)
|
||||
}
|
||||
// =========首页=======
|
||||
// 获取bannar图
|
||||
export const getBannarList = (data) =>{
|
||||
return get('/resident/banner',data)
|
||||
}
|
||||
// 首页最新公告
|
||||
export const getNoticeLatest = () =>{
|
||||
return get('/api/resident/notice/latest')
|
||||
}
|
||||
|
||||
// 查询已认证的小区
|
||||
export const getVillageList = (data) =>{
|
||||
return get('/api/resident/village/myList', data)
|
||||
}
|
||||
// 获取当前小区
|
||||
export const getCurrentVillage = () =>{
|
||||
return get('/api/resident/village/current')
|
||||
}
|
||||
// 切换小区
|
||||
export const getVillageSwitch = (data)=>{
|
||||
return post('/api/resident/village/switch',data)
|
||||
}
|
||||
// 首页最新活动列表
|
||||
export const getActivitylatest = () =>{
|
||||
return get('/api/resident/activity/latest')
|
||||
}
|
||||
|
||||
// ========公告列表======
|
||||
// 获取公告列表
|
||||
export const getNoticeList = (data) =>{
|
||||
return get('/api/resident/notice/list',data)
|
||||
}
|
||||
// 获取公告详情
|
||||
export const getNoticeDetails = (noticeId) =>{
|
||||
return get(`/api/resident/notice/${noticeId}`)
|
||||
}
|
||||
// =========键开门===============
|
||||
// 查询门禁列表
|
||||
export const getAccessDevices = (data) =>{
|
||||
return get("/api/resident/access/devices",data)
|
||||
}
|
||||
// 确认开门
|
||||
export const getAccessOpen = (data) =>{
|
||||
return post("/api/resident/access/open",data)
|
||||
}
|
||||
// ==========活动列表===========
|
||||
// 获取活动列表
|
||||
export const getActivityList = (data) =>{
|
||||
return get("/api/resident/activity/list",data)
|
||||
}
|
||||
// 获取活动列表详情
|
||||
export const getActivityDetails = (id) =>{
|
||||
return get(`/api/resident/activity/${id}`)
|
||||
}
|
||||
// 确认报名
|
||||
export const confirmResident = (id) =>{
|
||||
return post(`/api/resident/activity/${id}/apply`)
|
||||
}
|
||||
// 取消报名
|
||||
export const cancelActivity = (id) =>{
|
||||
return post(`/api/resident/activity/${id}/cancel`)
|
||||
}
|
||||
// =========我的活动========
|
||||
export const getMyActivityList = (data) =>{
|
||||
return get("/api/resident/activity/my",data)
|
||||
}
|
||||
// ===========活动实况============
|
||||
// 活动实况列表
|
||||
export const getActivityLive = (id) =>{
|
||||
return get(`/api/resident/activity/${id}/live`)
|
||||
}
|
||||
// 添加实况
|
||||
export const addActivityLive = (id, data) =>{
|
||||
return post(`/api/resident/activity/${id}/live`, data)
|
||||
}
|
||||
// 签到
|
||||
export const signinActivityLive = (id, data) =>{
|
||||
return post(`/api/resident/activity/${id}/signin`, data)
|
||||
}
|
||||
// ==============在线报修========
|
||||
// 添加报修工单
|
||||
export const addQueryRepair = (data) =>{
|
||||
return post("/repairOrder/addRepair",data)
|
||||
}
|
||||
// 获取公共维修项目列表
|
||||
export const getRepairProjectList = (data) =>{
|
||||
return get("/repairOrder/list",data)
|
||||
}
|
||||
// 获取报修列表
|
||||
export const getQueryRepair = (data) =>{
|
||||
return get("/repairOrder/queryRepair",data)
|
||||
}
|
||||
// 获取房屋列表
|
||||
export const getHouseList = (data) =>{
|
||||
return get('/api/resident/my/house/list',data)
|
||||
}
|
||||
// 报修详情
|
||||
export const getRepairDetail = (data) =>{
|
||||
return get('/repairOrder/queryRepairDetail',data)
|
||||
}
|
||||
// =========访客邀请===========
|
||||
// 获取访客列表
|
||||
export const getVisitorList = (data) =>{
|
||||
return get('/api/visitor/list',data)
|
||||
}
|
||||
// 获取详情信息
|
||||
export const getVisitorDetail = (id) =>{
|
||||
return get(`/api/visitor/${id}`)
|
||||
}
|
||||
// 新增访客
|
||||
export const addVisitorData = (data) =>{
|
||||
return post("/api/visitor", data)
|
||||
}
|
||||
|
||||
// 上传单张图片
|
||||
export const uploadFile = (filePath) => {
|
||||
return upload(filePath,'/api/resident/file/uploadImage');
|
||||
}
|
||||
225
huakai-app/pageSubPack/api/apiSub.js
Normal file
225
huakai-app/pageSubPack/api/apiSub.js
Normal file
@@ -0,0 +1,225 @@
|
||||
import request, {
|
||||
get,
|
||||
post,
|
||||
deleteMethod,
|
||||
putMethod
|
||||
} from "./request.js"
|
||||
|
||||
// 字典
|
||||
export const getSystemDictData = (data) => {
|
||||
return get('/system/dict/data/list', data)
|
||||
}
|
||||
|
||||
// =======公告列表========
|
||||
export const getResidentNoticeList = (data) => {
|
||||
return get('/api/resident/notice/list', data)
|
||||
}
|
||||
// 我的房屋列表
|
||||
export const getMyHouseList = (data) => {
|
||||
return get('/api/resident/my/house/list', data)
|
||||
}
|
||||
// 提交房屋注册认证申请
|
||||
export const myHouseApply = (data) => {
|
||||
return post('/api/resident/my/house/apply', data)
|
||||
}
|
||||
// 查询小区列表
|
||||
export const getVillageList = (data) => {
|
||||
return get('/api/resident/village/list', data)
|
||||
} // 查询楼栋列表
|
||||
export const getHouseBuildings = (data) => {
|
||||
return get('/api/resident/house/buildings', data)
|
||||
}
|
||||
// 查询单元列表
|
||||
export const getHouseUnits = (data) => {
|
||||
return get('/api/resident/house/units', data)
|
||||
}
|
||||
// 查询楼层列表
|
||||
export const getHouseFloors = (data) => {
|
||||
return get('/api/resident/house/floors', data)
|
||||
}
|
||||
// 查询户号列表
|
||||
export const getHouseHouses = (data) => {
|
||||
return get('/api/resident/house/houses', data)
|
||||
}
|
||||
// 房屋绑定手机获取验证码
|
||||
export const getHouseAuthSendSmsCode = (data) => {
|
||||
return post('/api/resident/auth/sendSmsCode', data)
|
||||
}
|
||||
// 房屋详情
|
||||
export const getMyHouseDetail = (data) => {
|
||||
return get(`/api/resident/my/house/${data.id}`, data)
|
||||
}
|
||||
// 删除房屋
|
||||
export const deleteMyHouse = (data) => {
|
||||
return deleteMethod(`/api/resident/my/house/${data.id}`, data)
|
||||
}
|
||||
// 设置默认房屋
|
||||
export const setMyHouseDefault = (data) => {
|
||||
return post(`/api/resident/my/house/default`, data)
|
||||
}
|
||||
// 获取当前用户登录信息
|
||||
export const getUserProfile = (data) => {
|
||||
return get(`/api/resident/user/profile`, data)
|
||||
}
|
||||
// 发送新手机号验证码
|
||||
export const getAuthSendSmsCode = (data) => {
|
||||
return post(`/api/resident/auth/sendSmsCode`, data)
|
||||
}
|
||||
// 更改手机号
|
||||
export const getUserChangePhone = (data) => {
|
||||
return post(`/api/resident/user/changePhone`, data)
|
||||
}
|
||||
// 获取消息通知开关
|
||||
export const getUserNotify = (data) => {
|
||||
return get(`/api/resident/user/notify`, data)
|
||||
}
|
||||
// 更新消息通知开关
|
||||
export const changeUserNotify = (data) => {
|
||||
return post(`/api/resident/user/notify`, data)
|
||||
} // 修改密码(需登录)
|
||||
export const authChangePassword = (data) => {
|
||||
return post(`/api/resident/auth/changePassword`, data)
|
||||
} // 退出登录
|
||||
export const authLogout = (data) => {
|
||||
return post(`/api/resident/auth/logout`, data)
|
||||
}
|
||||
// 编辑房屋
|
||||
export const upDateMyHouse = (data) => {
|
||||
return putMethod(`/api/resident/my/house/${data.id}`, data)
|
||||
|
||||
}
|
||||
|
||||
// =========问卷调查=========
|
||||
// 问卷列表
|
||||
export const getQuestionnaireList = (data) => {
|
||||
return get('/api/resident/questionnaire/list',data)
|
||||
}
|
||||
// 问卷详情
|
||||
export const getQuestionnaireDetail = (data) => {
|
||||
return get('/api/resident/questionnaire/myAnswers',data)
|
||||
}
|
||||
// 提交问卷
|
||||
export const submitQuestionnair = (id,data) => {
|
||||
return post(`/api/resident/questionnaire/${id}/submit`, data)
|
||||
}
|
||||
// =====投诉意见=======
|
||||
// 获取投诉类型
|
||||
export const getComplainType = () => {
|
||||
return get('/complain/getComplainType')
|
||||
}
|
||||
// 获取投诉列表
|
||||
export const getComplainList = (data) => {
|
||||
return get('/complain/getComplainList',data)
|
||||
}
|
||||
// 提交投诉建议
|
||||
export const addComplain = (data) => {
|
||||
return post('/complain/add',data)
|
||||
}
|
||||
// 投诉详情
|
||||
export const getComplainDetail = (data) => {
|
||||
return get('/complain/detail',data)
|
||||
}
|
||||
// 联系物业
|
||||
export const getManagePhoneData = (data) => {
|
||||
return get('/api/manage/banner/getManagePhone',data)
|
||||
}
|
||||
|
||||
// 修改身份证照片
|
||||
export const uploadFileUploadImage = (data) => {
|
||||
return post(`/api/resident/file/uploadImage`, data)
|
||||
}
|
||||
|
||||
// 水电表
|
||||
export const getTopUpSelectByResident = (data) => {
|
||||
console.log(data);
|
||||
return get(`/api/topUp/selectByResident/${data.residentUserId}`, data)
|
||||
}
|
||||
// 绑定设备
|
||||
export const getTopUpBindDevice = (data) => {
|
||||
return post(`/api/topUp/bindDevice/${data.deviceCode}/${data.residentUserId}/${data.openid}/${data.deviceType}`,
|
||||
data)
|
||||
}
|
||||
// 充值调用
|
||||
// /${data.rechargeAmount}/${data.type}/${data.deviceCode}
|
||||
export const getTopUp = (data) => {
|
||||
return post(`/api/topUp`, data)
|
||||
}
|
||||
export const getopenIdByCode = (data) => {
|
||||
return get(`/api/topUp/getOpenIdByCode?code=${data.code}`, data)
|
||||
}
|
||||
|
||||
// 微信支付调用
|
||||
export const getToWxPay = (data) => {
|
||||
return post(`/api/topUp/wxPay/${data.orderId}/${data.openid}`, data)
|
||||
}
|
||||
// 缴费记录查询
|
||||
export const getTopupRecordWithStat = (data) => {
|
||||
return get(
|
||||
`/api/topUp/topupRecordWithStat?residentUserId=${data.residentUserId}&pageNum=${data.pageNum}&pageSize=${data.pageSize}`,
|
||||
data)
|
||||
}
|
||||
export const postInsertOpenId = (data) => {
|
||||
return post(`/api/resident/auth/insertOpenId`, data)
|
||||
}
|
||||
export const postSubscribeAuth = (data) => {
|
||||
return post(`/api/wx/subscribeAuth/auth`, 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)
|
||||
}
|
||||
104
huakai-app/pageSubPack/api/request.js
Normal file
104
huakai-app/pageSubPack/api/request.js
Normal file
@@ -0,0 +1,104 @@
|
||||
let baseUrl = '';
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
baseUrl = 'https://wuyeapi.bugtc.com'; // 开发环境
|
||||
} else {
|
||||
baseUrl = 'https://wuyeapi.bugtc.com'; // 生产环境
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示接口错误提示(自动处理长消息截断问题)
|
||||
* @param {string|Object} msg - 错误消息或含 msg 字段的错误对象
|
||||
*/
|
||||
export function showApiError(msg) {
|
||||
const message = typeof msg === 'string' ? msg : (msg.msg || msg.message || '请求失败');
|
||||
uni.showToast({ title: message || '请求失败', icon: 'error', duration: 2000 });
|
||||
}
|
||||
|
||||
export default function request(url, data = {}, method = "GET") {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.showLoading({
|
||||
title: '请求中...',
|
||||
mask: true
|
||||
});
|
||||
|
||||
uni.request({
|
||||
url: baseUrl + url,
|
||||
data: data,
|
||||
method: method,
|
||||
header: {
|
||||
"Authorization": "Bearer " + (uni.getStorageSync("token") || ''),
|
||||
"clientid": "resident",
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
success: (res) => {
|
||||
uni.hideLoading();
|
||||
|
||||
// HTTP 失败
|
||||
if (res.statusCode !== 200) {
|
||||
reject({ msg: `请求异常 ${res.statusCode}`, code: res.statusCode });
|
||||
return;
|
||||
}
|
||||
|
||||
const resData = res.data || {};
|
||||
|
||||
// token 过期
|
||||
if (resData.code === 401) {
|
||||
uni.showToast({ title: '登录过期,请重新登录', icon: 'none' });
|
||||
uni.clearStorageSync('token');
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: '/pageSubPack/loginSub/pwd-login' });
|
||||
}, 1500);
|
||||
reject({ msg: '登录过期', code: 401 });
|
||||
return;
|
||||
}
|
||||
|
||||
// 成功
|
||||
if (resData.code === 200) {
|
||||
resolve(resData);
|
||||
}
|
||||
// 业务失败(code === 500 统一 showToast 展示完整 msg)
|
||||
else {
|
||||
if (resData.code === 500 && resData.msg) {
|
||||
uni.showToast({ title: resData.msg, icon: 'error', duration: 2500 });
|
||||
}
|
||||
reject({ msg: resData.msg || '请求失败', code: resData.code, data: resData });
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
uni.hideLoading();
|
||||
reject({ msg: '网络异常', code: -1, raw: err });
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export const get = (url, data = {}) => request(url, data, 'GET');
|
||||
export const post = (url, data) => request(url, data, 'POST');
|
||||
export const deleteMethod = (url, data) => request(url, data, 'DELETE');
|
||||
export const putMethod = (url, data) => request(url, data, 'PUT');
|
||||
|
||||
// 上传
|
||||
export const upload = (filePath, url) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.uploadFile({
|
||||
url: baseUrl + url,
|
||||
filePath: filePath,
|
||||
name: 'file',
|
||||
header: {
|
||||
"Authorization": "Bearer " + (uni.getStorageSync("token") || ''),
|
||||
"clientid": "resident"
|
||||
},
|
||||
success: (res) => {
|
||||
try {
|
||||
const data = JSON.parse(res.data);
|
||||
resolve(data.data || ''); // 直接返回图片地址
|
||||
} catch (e) {
|
||||
resolve('');
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
190
huakai-app/pageSubPack/api/useImageUpload.js
Normal file
190
huakai-app/pageSubPack/api/useImageUpload.js
Normal file
@@ -0,0 +1,190 @@
|
||||
// 服务器地址(与 request.js 保持一致)
|
||||
const baseUrl = 'http://192.168.0.239:8080';
|
||||
|
||||
/**
|
||||
* 图片上传 Hook
|
||||
* 支持 uniapp 和微信小程序
|
||||
* 解决编辑回显后重新上传的问题
|
||||
*/
|
||||
|
||||
import { reactive } from 'vue'
|
||||
|
||||
/**
|
||||
* @param {Object} options 配置
|
||||
* @param {string} options.uploadUrl - 上传接口地址
|
||||
* @param {string} options.fileKey - 上传文件的字段名,默认 'file'
|
||||
* @returns {Object}
|
||||
*/
|
||||
export function useImageUpload(options = {}) {
|
||||
const {
|
||||
uploadUrl = '/api/resident/file/uploadImage',
|
||||
fileKey = 'file'
|
||||
} = options
|
||||
|
||||
// 使用 reactive 对象存储所有状态
|
||||
const state = reactive({
|
||||
// 当前显示的图片(前端展示用,支持 base64/blob URL/网络URL)
|
||||
previewUrl: '',
|
||||
// 服务器返回的 URL(提交时使用)
|
||||
serverUrl: '',
|
||||
// 临时的文件路径(重新上传时用)
|
||||
tempFilePath: null,
|
||||
// 上传状态
|
||||
uploading: false
|
||||
})
|
||||
|
||||
/**
|
||||
* 设置回显图片(编辑时从后端获取)
|
||||
* @param {string} url - 后端返回的图片URL
|
||||
*/
|
||||
const setPreviewUrl = (url) => {
|
||||
if (url) {
|
||||
// 确保 url 是字符串
|
||||
const urlStr = typeof url === 'string' ? url : (url?.url || String(url))
|
||||
state.previewUrl = urlStr
|
||||
state.serverUrl = urlStr
|
||||
state.tempFilePath = null // 重置临时文件,表示没有重新上传
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择图片并预览(不上传)
|
||||
* @returns {Promise<string>} 返回临时文件路径
|
||||
*/
|
||||
const chooseImage = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.chooseImage({
|
||||
count: 1,
|
||||
sizeType: ['compressed'],
|
||||
sourceType: ['camera', 'album'],
|
||||
success: (res) => {
|
||||
const path = res.tempFilePaths?.[0]
|
||||
if (!path) {
|
||||
reject(new Error('选择图片失败'))
|
||||
return
|
||||
}
|
||||
// 确保 path 是字符串
|
||||
const pathStr = typeof path === 'string' ? path : String(path)
|
||||
// 设置预览
|
||||
state.previewUrl = pathStr
|
||||
// 记录临时文件路径
|
||||
state.tempFilePath = pathStr
|
||||
// 置空服务器URL,等实际上传后再获取
|
||||
state.serverUrl = ''
|
||||
resolve(pathStr)
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图片到服务器
|
||||
* @returns {Promise<Object>} 返回 { url: string }
|
||||
*/
|
||||
const uploadImage = () => {
|
||||
// 如果没有新选择临时文件,直接返回已有的服务器URL
|
||||
if (!state.tempFilePath) {
|
||||
return Promise.resolve({ url: state.serverUrl })
|
||||
}
|
||||
|
||||
// 如果已经有服务器URL且没有重新选择,也直接返回
|
||||
if (state.serverUrl && !state.tempFilePath) {
|
||||
return Promise.resolve({ url: state.serverUrl })
|
||||
}
|
||||
|
||||
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: filePath,
|
||||
name: fileKey,
|
||||
header: {
|
||||
'Authorization': 'Bearer ' + (uni.getStorageSync('token') || ''),
|
||||
'clientid': 'resident'
|
||||
},
|
||||
success: (res) => {
|
||||
try {
|
||||
const data = JSON.parse(res.data)
|
||||
if (data.code === 200 && data.data) {
|
||||
// 更新服务器URL(确保存的是字符串)
|
||||
const url = typeof data.data === 'string' ? data.data : (data.data?.url || '')
|
||||
state.serverUrl = url
|
||||
// 清空临时文件
|
||||
state.tempFilePath = null
|
||||
resolve({ url })
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: data.msg || '上传失败',
|
||||
icon: 'none'
|
||||
})
|
||||
reject(new Error(data.msg || '上传失败'))
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({
|
||||
title: '上传失败',
|
||||
icon: 'none'
|
||||
})
|
||||
reject(e)
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
uni.showToast({
|
||||
title: err.message || '上传失败',
|
||||
icon: 'none'
|
||||
})
|
||||
reject(err)
|
||||
},
|
||||
complete: () => {
|
||||
state.uploading = false
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最终可提交的URL
|
||||
* 如果有新上传的图片,先上传再返回URL
|
||||
* 如果没有新上传,直接返回已有的服务器URL
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
const getSubmitUrl = async () => {
|
||||
// 如果重新选择了新图片,先上传
|
||||
if (state.tempFilePath) {
|
||||
return await uploadImage()
|
||||
}
|
||||
// 否则返回已有的服务器URL
|
||||
return { url: state.serverUrl }
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置状态
|
||||
*/
|
||||
const reset = () => {
|
||||
state.previewUrl = ''
|
||||
state.serverUrl = ''
|
||||
state.tempFilePath = null
|
||||
state.uploading = false
|
||||
}
|
||||
|
||||
// 返回 reactive state 和方法
|
||||
// state 作为 reactive 对象,在模板中通过 idCardFrontUpload.state.previewUrl 访问
|
||||
return {
|
||||
state,
|
||||
setPreviewUrl,
|
||||
chooseImage,
|
||||
uploadImage,
|
||||
getSubmitUrl,
|
||||
reset
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user