Files
2026-10-14 09:28:49 +08:00

409 lines
12 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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)
}
// RZbank
/**
* 归一化 billId/billIds:单个 id 用 billId,多个用 billIds,统一转为 billIds 数组
*/
function normalizeBillParams(obj) {
if (!obj) return
// 先解码再拆分为数组
if (typeof obj.billIds === 'string') {
const decoded = decodeURIComponent(obj.billIds)
obj.billIds = decoded.includes(',') ?
decoded.split(',').map(v => v.trim()).filter(Boolean) : [decoded]
}
// billId 存在且 billIds 不存在时,包装为数组
if (obj.billId && !obj.billIds) {
const decoded = decodeURIComponent(
typeof obj.billId === 'string' ? obj.billId : String(obj.billId)
)
obj.billIds = decoded.includes(',') ?
decoded.split(',').map(v => v.trim()).filter(Boolean) : [decoded]
delete obj.billId
}
}
/**
* 从启动参数中获取 App 传入的全部数据(支付参数 + token + userId)
*/
export function captureAppLaunchData(onShowOptions) {
let data = null
let queryData = null
const tryGetData = (options, label) => {
if (!options) return null
console.log(label, JSON.stringify(options))
// 保存 path query 参数(供接口调用)
if (options.query && Object.keys(options.query).length > 0) {
queryData = options.query
console.log(label + ' path query 参数:', JSON.stringify(queryData))
}
// 优先从 query 获取
if (options.query && Object.keys(options.query).length > 0) {
return options.query
}
// referrerInfo.extraData:可能是对象也可能是查询字符串
const extraData = options?.referrerInfo?.extraData
if (extraData) {
if (typeof extraData === 'string') {
console.log(label + ' extraData 是查询字符串,解析中...')
return parseQueryString(extraData)
}
return extraData
}
return null
}
// 冷启动
try {
data = tryGetData(wx.getLaunchOptionsSync?.() || {}, '冷启动')
} catch (e) {
console.error('getLaunchOptionsSync 失败:', e)
}
// 热启动
if (!data) {
data = tryGetData(onShowOptions, '热启动')
}
if (data && (data.payAmount || data.acct || data.custId || data.billId || data.billIds)) {
// 归一化 billId/billIds:单个 id 用 billId,多个用 billIds,统一转为 billIds 数组
normalizeBillParams(data)
// 恢复登录态
if (data.token) {
uni.setStorageSync('token', data.token)
console.log('已恢复 token')
}
if (data.userId) {
uni.setStorageSync('userId', data.userId)
console.log('已恢复 userId')
}
uni.setStorageSync(STORAGE_KEY, data)
console.log('已存储 App 支付数据:', JSON.stringify(data))
}
// 归一化 queryData 中的 billId/billIds
normalizeBillParams(queryData)
// 单独保存参数供接口使用(优先 queryData,fallback 到 data,即 extraData 来源)
const queryParams = queryData || data
if (queryParams) {
uni.setStorageSync(APP_QUERY_KEY, queryParams)
console.log('已存储 App 接口参数:', JSON.stringify(queryParams))
}
return data
}
// 获取日照银行小程序拉起参数
export const getBankMiniProgramParams = (data) => {
return post('/api/pay/yidang/create', data)
}
/**
* 支付返回结果
* 日照银行支付小程序完成支付后,通过 navigateBackMiniProgram 携带 extraData 返回,
* 本小程序在 App.onShow 中通过 referrerInfo.extraData 接收(场景值 1038)。
* 这里只负责捕获/读取/清除原始返回数据,成功/失败判定见 resolvePaymentResult。
*/
const PAYMENT_RESULT_KEY = 'payment_return_result'
/**
* 捕获支付返回结果(在 App.onShow 中调用)
* 注意:App 冷/热启动进入时 extraData 是支付参数(payAmount/billIds 等),
* 并非支付返回,需跳过,避免覆盖真实结果。
*/
export function capturePaymentResult(onShowOptions) {
console.log(onShowOptions)
if (!onShowOptions) return
const extraData = onShowOptions?.referrerInfo?.extraData
if (!extraData) return
// 含支付参数字段说明是 App 跳转进入(冷/热启动),不是支付返回,跳过
if (typeof extraData === 'object' && (extraData.payAmount || extraData.billId || extraData.billIds || extraData
.acct || extraData.custId)) {
return
}
let parsed = extraData
if (typeof extraData === 'string') {
try {
parsed = JSON.parse(extraData)
} catch (e) {
parsed = parseQueryString(extraData)
}
}
console.log('捕获到支付返回结果:', JSON.stringify(parsed))
uni.setStorageSync(PAYMENT_RESULT_KEY, parsed)
}
/** 读取支付返回结果(读取后建议调用 clearPaymentReturnResult 清除) */
export function getPaymentReturnResult() {
try {
return uni.getStorageSync(PAYMENT_RESULT_KEY) || null
} catch (e) {
return null
}
}
/** 清除支付返回结果 */
export function clearPaymentReturnResult() {
uni.removeStorageSync(PAYMENT_RESULT_KEY)
}
// 失败/成功信号值(大小写不敏感),字段名与取值以日照银行实际返回为准,如不一致只需调整下方映射
const FAIL_SIGNALS = ['fail', 'failed', 'cancel', 'cancelled', 'error', 'closed', 'notpay', 'payerror', '2', 'false',
'no', '01'
]
const SUCCESS_SIGNALS = ['success', 'ok', 'paid', 'finish', 'finished', '1', '0000', '0', '200', 'true', 'yes', '00']
const RESULT_FIELDS = ['payResult', 'result', 'status', 'payStatus', 'tradeState', 'returnCode', 'code', 'errCode',
'orderState'
]
/**
* 判定日照银行返回的支付结果:'success' | 'fail' | null(无法判定)
*/
export function resolvePaymentResult(data) {
console.log("日照银行返回数据:", data)
if (!data || typeof data !== 'object') return null
// 布尔字段优先
if (typeof data.success === 'boolean') return data.success ? 'success' : 'fail'
if (typeof data.isSuccess === 'boolean') return data.isSuccess ? 'success' : 'fail'
for (const key of RESULT_FIELDS) {
const v = data[key]
if (v === undefined || v === null || v === '') continue
const s = String(v).trim().toLowerCase()
if (FAIL_SIGNALS.includes(s)) return 'fail'
if (SUCCESS_SIGNALS.includes(s)) return 'success'
}
return null
}