fix: 后端接口对接,问题修复。
This commit is contained in:
@@ -51,7 +51,7 @@ const API_PATHS = {
|
|||||||
// 塘口列表模式1
|
// 塘口列表模式1
|
||||||
POND_LIST: {
|
POND_LIST: {
|
||||||
v1: '/fishery/pond/list',
|
v1: '/fishery/pond/list',
|
||||||
v2: '/fishery/pond/list',
|
v2: '/fishery/pond/list_mode1',
|
||||||
},
|
},
|
||||||
// 塘口列表模式2
|
// 塘口列表模式2
|
||||||
POND_LIST_MODE2: {
|
POND_LIST_MODE2: {
|
||||||
@@ -79,27 +79,22 @@ const API_PATHS = {
|
|||||||
POND: {
|
POND: {
|
||||||
// 新增塘口
|
// 新增塘口
|
||||||
ADD: {
|
ADD: {
|
||||||
v1: '/fishery/pond',
|
|
||||||
v2: '/fishery/pond',
|
v2: '/fishery/pond',
|
||||||
},
|
},
|
||||||
// 修改塘口
|
// 修改塘口
|
||||||
UPDATE: {
|
UPDATE: {
|
||||||
v1: '/api/pond/update',
|
|
||||||
v2: '/fishery/pond',
|
v2: '/fishery/pond',
|
||||||
},
|
},
|
||||||
// 删除塘口
|
// 删除塘口
|
||||||
DELETE: {
|
DELETE: {
|
||||||
v1: '/api/pond/delete',
|
|
||||||
v2: '/fishery/pond',
|
v2: '/fishery/pond',
|
||||||
},
|
},
|
||||||
// 鱼类列表
|
// 鱼类列表
|
||||||
FISH_LIST: {
|
FISH_LIST: {
|
||||||
v1: '/fishery/fish/list',
|
|
||||||
v2: '/fishery/fish/list',
|
v2: '/fishery/fish/list',
|
||||||
},
|
},
|
||||||
// 塘口基本数据
|
// 塘口基本数据
|
||||||
BASE_INFO: {
|
BASE_INFO: {
|
||||||
v1: '/api/pond/base_info',
|
|
||||||
v2: '/fishery/pond',
|
v2: '/fishery/pond',
|
||||||
},
|
},
|
||||||
// 塘口下设备信息
|
// 塘口下设备信息
|
||||||
@@ -124,7 +119,7 @@ const API_PATHS = {
|
|||||||
// 设备列表
|
// 设备列表
|
||||||
LIST_ALL: {
|
LIST_ALL: {
|
||||||
v1: '/api/device/list_all_device',
|
v1: '/api/device/list_all_device',
|
||||||
v2: '/fishery/device/list',
|
v2: '/fishery/device/list_all_device',
|
||||||
},
|
},
|
||||||
// 设备详情
|
// 设备详情
|
||||||
INFO: {
|
INFO: {
|
||||||
@@ -168,7 +163,6 @@ const API_PATHS = {
|
|||||||
},
|
},
|
||||||
// 检测设备是否在线
|
// 检测设备是否在线
|
||||||
CHECK_STATUS: {
|
CHECK_STATUS: {
|
||||||
v1: '/api/device/check_device_status',
|
|
||||||
v2: '/iot/device/status',
|
v2: '/iot/device/status',
|
||||||
},
|
},
|
||||||
// 盐度设置
|
// 盐度设置
|
||||||
@@ -183,7 +177,6 @@ const API_PATHS = {
|
|||||||
},
|
},
|
||||||
// 添加水质检测仪
|
// 添加水质检测仪
|
||||||
ADD_DETECTOR: {
|
ADD_DETECTOR: {
|
||||||
v1: '/api/device/add_device_detector',
|
|
||||||
v2: '/iot/device/add_device_detector',
|
v2: '/iot/device/add_device_detector',
|
||||||
},
|
},
|
||||||
// 设置溶解氧/水温告警
|
// 设置溶解氧/水温告警
|
||||||
@@ -209,7 +202,7 @@ const API_PATHS = {
|
|||||||
// 添加控制一体机
|
// 添加控制一体机
|
||||||
ADD_CONTROLLER: {
|
ADD_CONTROLLER: {
|
||||||
v1: '/api/device/add_device_controller',
|
v1: '/api/device/add_device_controller',
|
||||||
v2: '/fishery/device/controller',
|
v2: '/iot/device/add_device_controller',
|
||||||
},
|
},
|
||||||
// 启停溶解氧
|
// 启停溶解氧
|
||||||
SET_OXY_OPEN: {
|
SET_OXY_OPEN: {
|
||||||
@@ -329,17 +322,14 @@ const API_PATHS = {
|
|||||||
MESSAGE: {
|
MESSAGE: {
|
||||||
// 充值记录
|
// 充值记录
|
||||||
PAY: {
|
PAY: {
|
||||||
v1: '/api/message/page_pay',
|
|
||||||
v2: '/fishery/payOrder/list',
|
v2: '/fishery/payOrder/list',
|
||||||
},
|
},
|
||||||
// 报警记录
|
// 报警记录
|
||||||
WARN: {
|
WARN: {
|
||||||
v1: '/api/message/page_warn',
|
|
||||||
v2: '/fishery/messageWarn/list',
|
v2: '/fishery/messageWarn/list',
|
||||||
},
|
},
|
||||||
// 开关记录
|
// 开关记录
|
||||||
SWITCH: {
|
SWITCH: {
|
||||||
v1: '/api/message/page_op_record',
|
|
||||||
v2: '/fishery/messageOpRecord/list',
|
v2: '/fishery/messageOpRecord/list',
|
||||||
},
|
},
|
||||||
// 已读一条消息
|
// 已读一条消息
|
||||||
|
|||||||
@@ -4,14 +4,12 @@ import Taro from '@tarojs/taro';
|
|||||||
|
|
||||||
// 塘口模式1
|
// 塘口模式1
|
||||||
export function getPond1() {
|
export function getPond1() {
|
||||||
// 从本地存储获取手机号
|
const userId = Taro.getStorageSync("UserId");
|
||||||
const userKeyword = Taro.getStorageSync('Phone');
|
return httpService.get(API.HOME.POND_LIST(), {
|
||||||
const queryParams = {
|
|
||||||
params: {
|
params: {
|
||||||
userKeyword: userKeyword || undefined
|
rootUserId: userId || undefined
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
return httpService.get(API.HOME.POND_LIST(), { params: queryParams });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 塘口模式2
|
// 塘口模式2
|
||||||
|
|||||||
@@ -23,5 +23,6 @@ export function pondBaseInfo(data){
|
|||||||
}
|
}
|
||||||
// 塘口下设备信息
|
// 塘口下设备信息
|
||||||
export function pondDeviceInfo(data){
|
export function pondDeviceInfo(data){
|
||||||
return httpService.post(API.POND.DEVICE_INFO(), {data})
|
// 后端接口:GET /devices/{pondId},使用路径参数
|
||||||
|
return httpService.get(API.POND.DEVICE_INFO() + '/' + data.id)
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@
|
|||||||
正常</nut-tag
|
正常</nut-tag
|
||||||
>
|
>
|
||||||
<nut-tag class="tagErr font_28 m_r_15" v-else-if="item.status == 2">
|
<nut-tag class="tagErr font_28 m_r_15" v-else-if="item.status == 2">
|
||||||
{{ item.warnCodeInfo.warnDescription }}</nut-tag
|
{{ item.warnCodeInfo?.warnDescription }}</nut-tag
|
||||||
>
|
>
|
||||||
<nut-tag
|
<nut-tag
|
||||||
class="font_28 m_r_15"
|
class="font_28 m_r_15"
|
||||||
@@ -116,7 +116,7 @@
|
|||||||
:class="
|
:class="
|
||||||
!item.up
|
!item.up
|
||||||
? ''
|
? ''
|
||||||
: alarmJudgeCode(item.warnCodeInfo.warnCode, 7)
|
: alarmJudgeCode(item.warnCodeInfo?.warnCode, 7)
|
||||||
? 'c_E22323'
|
? 'c_E22323'
|
||||||
: ''
|
: ''
|
||||||
"
|
"
|
||||||
@@ -143,8 +143,8 @@
|
|||||||
:class="
|
:class="
|
||||||
!item.up
|
!item.up
|
||||||
? ''
|
? ''
|
||||||
: alarmJudgeCode(item.warnCodeInfo.warnCode, 9) ||
|
: alarmJudgeCode(item.warnCodeInfo?.warnCode, 9) ||
|
||||||
alarmJudgeCode(item.warnCodeInfo.warnCode, 8)
|
alarmJudgeCode(item.warnCodeInfo?.warnCode, 8)
|
||||||
? 'c_E22323'
|
? 'c_E22323'
|
||||||
: ''
|
: ''
|
||||||
"
|
"
|
||||||
@@ -169,7 +169,7 @@
|
|||||||
:class="
|
:class="
|
||||||
!item.up
|
!item.up
|
||||||
? ''
|
? ''
|
||||||
: alarmJudgeCode(item.warnCodeInfo.warnCode, 10)
|
: alarmJudgeCode(item.warnCodeInfo?.warnCode, 10)
|
||||||
? 'c_E22323'
|
? 'c_E22323'
|
||||||
: ''
|
: ''
|
||||||
"
|
"
|
||||||
@@ -803,7 +803,10 @@ function getDeviceList() {
|
|||||||
}
|
}
|
||||||
// 查询塘口下设备列表
|
// 查询塘口下设备列表
|
||||||
pondDeviceInfo({ id }).then((res: any) => {
|
pondDeviceInfo({ id }).then((res: any) => {
|
||||||
if (res.statusCode == 200) {
|
console.log('塘口设备接口返回:', res);
|
||||||
|
if (res.code == 200) {
|
||||||
|
console.log('检测仪列表:', res.data.listDetector);
|
||||||
|
console.log('控制器列表:', res.data.listController);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (
|
if (
|
||||||
res.data &&
|
res.data &&
|
||||||
@@ -827,9 +830,9 @@ function getDeviceList() {
|
|||||||
oxyIds.push(item.id);
|
oxyIds.push(item.id);
|
||||||
let num = 3;
|
let num = 3;
|
||||||
const devCount = Number(item.deviceCount) + Number(item.switchCount);
|
const devCount = Number(item.deviceCount) + Number(item.switchCount);
|
||||||
const msg = item.warnCodeInfo.warnDescription;
|
const msg = item.warnCodeInfo?.warnDescription || '';
|
||||||
const showPh = !alarmJudgeCode(item.warnCodeInfo.warnCode, 1);
|
const showPh = !alarmJudgeCode(item.warnCodeInfo?.warnCode, 1);
|
||||||
const showSa = !alarmJudgeCode(item.warnCodeInfo.warnCode, 2);
|
const showSa = !alarmJudgeCode(item.warnCodeInfo?.warnCode, 2);
|
||||||
if (msg) {
|
if (msg) {
|
||||||
item.isPh = showPh;
|
item.isPh = showPh;
|
||||||
item.isSa = showSa;
|
item.isSa = showSa;
|
||||||
@@ -847,10 +850,10 @@ function getDeviceList() {
|
|||||||
item.num = num;
|
item.num = num;
|
||||||
item.status = Number(item.deviceCount) == 0 ? 0 : msg ? 2 : 1;
|
item.status = Number(item.deviceCount) == 0 ? 0 : msg ? 2 : 1;
|
||||||
// 判断设备是否离线,异常、断电 0 6 15
|
// 判断设备是否离线,异常、断电 0 6 15
|
||||||
const code0 = alarmJudgeCode(item.warnCodeInfo.warnCode, 0);
|
const code0 = alarmJudgeCode(item.warnCodeInfo?.warnCode, 0);
|
||||||
const code6 = alarmJudgeCode(item.warnCodeInfo.warnCode, 6);
|
const code6 = alarmJudgeCode(item.warnCodeInfo?.warnCode, 6);
|
||||||
const code11 = alarmJudgeCode(item.warnCodeInfo.warnCode, 15);
|
const code11 = alarmJudgeCode(item.warnCodeInfo?.warnCode, 15);
|
||||||
const code17 = alarmJudgeCode(item.warnCodeInfo.warnCode, 17);
|
const code17 = alarmJudgeCode(item.warnCodeInfo?.warnCode, 17);
|
||||||
item.up = true;
|
item.up = true;
|
||||||
if (code0 || code6 || code11 || code17) {
|
if (code0 || code6 || code11 || code17) {
|
||||||
item.up = false;
|
item.up = false;
|
||||||
@@ -860,6 +863,7 @@ function getDeviceList() {
|
|||||||
keepNightOpen.value = res.data.keepNightOpen;
|
keepNightOpen.value = res.data.keepNightOpen;
|
||||||
doList.value = res.data.listDetector;
|
doList.value = res.data.listDetector;
|
||||||
controlList.value = res.data.listController;
|
controlList.value = res.data.listController;
|
||||||
|
console.log('赋值后 controlList:', controlList.value);
|
||||||
if (res.data.listDetector && res.data.listDetector.length > 0) {
|
if (res.data.listDetector && res.data.listDetector.length > 0) {
|
||||||
firstDoId.value = res.data.listDetector[0].id
|
firstDoId.value = res.data.listDetector[0].id
|
||||||
? res.data.listDetector[0].id
|
? res.data.listDetector[0].id
|
||||||
@@ -935,7 +939,7 @@ function selectCharts(e) {
|
|||||||
}
|
}
|
||||||
getDeviceHistory();
|
getDeviceHistory();
|
||||||
pondDeviceInfo({ id }).then((res: any) => {
|
pondDeviceInfo({ id }).then((res: any) => {
|
||||||
if (res.statusCode == 200) {
|
if (res.code == 200) {
|
||||||
const oxyIds = [];
|
const oxyIds = [];
|
||||||
// setTimeout(() => {
|
// setTimeout(() => {
|
||||||
// showTour.value = res.data.length == 0 ? true : false;
|
// showTour.value = res.data.length == 0 ? true : false;
|
||||||
@@ -949,9 +953,9 @@ function selectCharts(e) {
|
|||||||
res.data.listDetector.forEach((item: any) => {
|
res.data.listDetector.forEach((item: any) => {
|
||||||
oxyIds.push(item.id);
|
oxyIds.push(item.id);
|
||||||
let num = 3;
|
let num = 3;
|
||||||
const msg = item.warnCodeInfo.warnDescription;
|
const msg = item.warnCodeInfo?.warnDescription || '';
|
||||||
const showPh = !alarmJudgeCode(item.warnCodeInfo.warnCode, 1);
|
const showPh = !alarmJudgeCode(item.warnCodeInfo?.warnCode, 1);
|
||||||
const showSa = !alarmJudgeCode(item.warnCodeInfo.warnCode, 2);
|
const showSa = !alarmJudgeCode(item.warnCodeInfo?.warnCode, 2);
|
||||||
if (msg) {
|
if (msg) {
|
||||||
item.isPh = showPh;
|
item.isPh = showPh;
|
||||||
item.isSa = showSa;
|
item.isSa = showSa;
|
||||||
@@ -974,10 +978,10 @@ function selectCharts(e) {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// 判断设备是否离线,异常、断电 0 6 11
|
// 判断设备是否离线,异常、断电 0 6 11
|
||||||
const code0 = alarmJudgeCode(item.warnCodeInfo.warnCode, 0);
|
const code0 = alarmJudgeCode(item.warnCodeInfo?.warnCode, 0);
|
||||||
const code6 = alarmJudgeCode(item.warnCodeInfo.warnCode, 6);
|
const code6 = alarmJudgeCode(item.warnCodeInfo?.warnCode, 6);
|
||||||
const code11 = alarmJudgeCode(item.warnCodeInfo.warnCode, 15);
|
const code11 = alarmJudgeCode(item.warnCodeInfo?.warnCode, 15);
|
||||||
const code17 = alarmJudgeCode(item.warnCodeInfo.warnCode, 17);
|
const code17 = alarmJudgeCode(item.warnCodeInfo?.warnCode, 17);
|
||||||
item.up = true;
|
item.up = true;
|
||||||
if (code0 || code6 || code11 || code17) {
|
if (code0 || code6 || code11 || code17) {
|
||||||
item.up = false;
|
item.up = false;
|
||||||
@@ -1812,6 +1816,7 @@ function setParamsCtr(id) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
function switchRes(list, index, type) {
|
function switchRes(list, index, type) {
|
||||||
|
console.log('switchRes 调用:', { list, index, type });
|
||||||
if (list.length > 0) {
|
if (list.length > 0) {
|
||||||
const info = list.filter((res) => res.index == index);
|
const info = list.filter((res) => res.index == index);
|
||||||
if (type == "img") {
|
if (type == "img") {
|
||||||
|
|||||||
@@ -480,7 +480,8 @@ function getDeviceList() {
|
|||||||
}
|
}
|
||||||
// 设备列表
|
// 设备列表
|
||||||
function getDevicesList() {
|
function getDevicesList() {
|
||||||
allDeviceList({ type: 1 }).then((res: any) => {
|
const userId = Taro.getStorageSync("UserId");
|
||||||
|
allDeviceList({ type: 1,rootUserId:userId }).then((res: any) => {
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
res.data.forEach((r: any) => {
|
res.data.forEach((r: any) => {
|
||||||
r.open = true;
|
r.open = true;
|
||||||
|
|||||||
@@ -386,7 +386,31 @@ definePageConfig({
|
|||||||
const instance = Taro.getCurrentInstance();
|
const instance = Taro.getCurrentInstance();
|
||||||
const r = instance.router.params.params;
|
const r = instance.router.params.params;
|
||||||
const page = instance.router.params.page;
|
const page = instance.router.params.page;
|
||||||
const params = r ? JSON.parse(r) : undefined;
|
|
||||||
|
console.log('URL参数原始值', r);
|
||||||
|
let params: any = undefined;
|
||||||
|
try {
|
||||||
|
if (r) {
|
||||||
|
// URL解码后再解析JSON
|
||||||
|
const decodedParams = decodeURIComponent(r);
|
||||||
|
console.log('URL解码后', decodedParams);
|
||||||
|
params = JSON.parse(decodedParams);
|
||||||
|
console.log('解析后的参数', params);
|
||||||
|
} else {
|
||||||
|
console.error('未获取到params参数');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('参数解析失败', e, '原始参数:', r);
|
||||||
|
// 参数解析失败,显示提示后返回
|
||||||
|
Taro.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: '参数错误,请重新进入',
|
||||||
|
showCancel: false,
|
||||||
|
success: () => {
|
||||||
|
Taro.navigateBack();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
const check = `https://www.yuceyun.cn/wechat/check.png`;
|
const check = `https://www.yuceyun.cn/wechat/check.png`;
|
||||||
const check_a = `https://www.yuceyun.cn/wechat/check_a.png`;
|
const check_a = `https://www.yuceyun.cn/wechat/check_a.png`;
|
||||||
const r_v = `https://www.yuceyun.cn/wechat/r_v.png`;
|
const r_v = `https://www.yuceyun.cn/wechat/r_v.png`;
|
||||||
@@ -434,14 +458,22 @@ const waterType = ref<number>(1);
|
|||||||
/** ----------------metod start------------------ */
|
/** ----------------metod start------------------ */
|
||||||
// 监测设备在线状态
|
// 监测设备在线状态
|
||||||
function getCheckDevice() {
|
function getCheckDevice() {
|
||||||
|
if (!params) {
|
||||||
|
console.error('params参数为空');
|
||||||
|
state.show = true;
|
||||||
|
state.msg = '参数错误';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
devicetype: params.devType,
|
devicetype: params.devType,
|
||||||
serialnum: params.devNum,
|
serialnum: params.devNum,
|
||||||
};
|
};
|
||||||
|
console.log('检查设备状态', data);
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
checkDeviceStatus(data)
|
checkDeviceStatus(data)
|
||||||
.then((res: any) => {
|
.then((res: any) => {
|
||||||
if (res.statusCode == 200) {
|
if (res.code == 200) {
|
||||||
status.value = res.data;
|
status.value = res.data;
|
||||||
if (status.value == 0) {
|
if (status.value == 0) {
|
||||||
state.show = true;
|
state.show = true;
|
||||||
@@ -454,6 +486,9 @@ function getCheckDevice() {
|
|||||||
} else if (status.value == 8) {
|
} else if (status.value == 8) {
|
||||||
state.show = true;
|
state.show = true;
|
||||||
state.msg = "设备禁用";
|
state.msg = "设备禁用";
|
||||||
|
} else {
|
||||||
|
state.show = true;
|
||||||
|
state.msg = "设备异常";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -462,6 +497,12 @@ function getCheckDevice() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
function next() {
|
function next() {
|
||||||
|
if (!params) {
|
||||||
|
state.show = true;
|
||||||
|
state.msg = '参数错误';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const num = current.value;
|
const num = current.value;
|
||||||
if (num == 4) {
|
if (num == 4) {
|
||||||
// 验证参数,发起添加设备请求
|
// 验证参数,发起添加设备请求
|
||||||
@@ -502,8 +543,9 @@ function next() {
|
|||||||
listPutPondPartId: listPutPondPartId.value,
|
listPutPondPartId: listPutPondPartId.value,
|
||||||
isOxygenUsed:isHave.value==1?true:false
|
isOxygenUsed:isHave.value==1?true:false
|
||||||
};
|
};
|
||||||
|
console.log('添加设备数据', data);
|
||||||
addDeviceController(data).then((res) => {
|
addDeviceController(data).then((res) => {
|
||||||
if (res.statusCode == 200) {
|
if (res.code == 200) {
|
||||||
Taro.redirectTo({
|
Taro.redirectTo({
|
||||||
url: "/my/addDevSuccess?name=添加测控一体机&page=" + page,
|
url: "/my/addDevSuccess?name=添加测控一体机&page=" + page,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -766,7 +766,7 @@ Taro.useUnload(() => {
|
|||||||
// 查询公告
|
// 查询公告
|
||||||
function getNotice(openType = 0) {
|
function getNotice(openType = 0) {
|
||||||
noticeList().then((res) => {
|
noticeList().then((res) => {
|
||||||
if (res.statusCode == 200) {
|
if (res.code == 200) {
|
||||||
const nList: any = [];
|
const nList: any = [];
|
||||||
noticeRows.value = res.data.sort(sortByField("priority", false));
|
noticeRows.value = res.data.sort(sortByField("priority", false));
|
||||||
if (noticeRows.value.length > 0) {
|
if (noticeRows.value.length > 0) {
|
||||||
@@ -860,9 +860,10 @@ function getWarnMsg() {
|
|||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
});
|
});
|
||||||
msgWarn(warnParams.value).then((res: any) => {
|
const userId = Taro.getStorageSync("UserId");
|
||||||
if (res.statusCode == 200) {
|
msgWarn({ ...warnParams.value, userId }).then((res: any) => {
|
||||||
const unReadCount = Number(res.data.unReadCount);
|
if (res.code == 200) {
|
||||||
|
const unReadCount = res.rows ? res.rows.filter(item => !item.isRead).length : 0;
|
||||||
if (unReadCount) {
|
if (unReadCount) {
|
||||||
Taro.setTabBarBadge({
|
Taro.setTabBarBadge({
|
||||||
index: 1, // tabBar的位置,从0开始计数
|
index: 1, // tabBar的位置,从0开始计数
|
||||||
@@ -921,10 +922,11 @@ function changeMode() {
|
|||||||
}
|
}
|
||||||
// 塘口模式1
|
// 塘口模式1
|
||||||
function pond1() {
|
function pond1() {
|
||||||
|
const userId = Taro.getStorageSync("UserId");
|
||||||
getPond1().then((res: any) => {
|
getPond1().then((res: any) => {
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
const pondIds = [];
|
const pondIds = [];
|
||||||
const rows = res.rows || [];
|
const rows = res.data || [];
|
||||||
rows.forEach((item: any) => {
|
rows.forEach((item: any) => {
|
||||||
pondIds.push(item.id);
|
pondIds.push(item.id);
|
||||||
let num = 3;
|
let num = 3;
|
||||||
@@ -988,9 +990,10 @@ function addDevice() {
|
|||||||
}
|
}
|
||||||
// 加载设备列表
|
// 加载设备列表
|
||||||
function loadDeviceList() {
|
function loadDeviceList() {
|
||||||
|
const userId = Taro.getStorageSync("UserId");
|
||||||
const pondId = mode.value == 1 ? selPond.value : selPond_2.value;
|
const pondId = mode.value == 1 ? selPond.value : selPond_2.value;
|
||||||
allDeviceList({ type: 1 }).then((res) => {
|
allDeviceList({ type: 1 ,rootUserId:userId}).then((res) => {
|
||||||
if (res.statusCode == 200) {
|
if (res.code == 200) {
|
||||||
if (res.data.length > 0) {
|
if (res.data.length > 0) {
|
||||||
res.data.forEach((r) => {
|
res.data.forEach((r) => {
|
||||||
r.disabled = false;
|
r.disabled = false;
|
||||||
@@ -1093,7 +1096,7 @@ function onconfirm(list) {
|
|||||||
};
|
};
|
||||||
bandDeviceToPond(data)
|
bandDeviceToPond(data)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.statusCode == 200) {
|
if (res.code == 200) {
|
||||||
state.show = true;
|
state.show = true;
|
||||||
state.msg = "操作成功";
|
state.msg = "操作成功";
|
||||||
pond2();
|
pond2();
|
||||||
@@ -1129,7 +1132,7 @@ function goScan() {
|
|||||||
success: (res) => {
|
success: (res) => {
|
||||||
const result = res.result;
|
const result = res.result;
|
||||||
deviceScan({ qrcode: result }).then((v) => {
|
deviceScan({ qrcode: result }).then((v) => {
|
||||||
if (v.statusCode == 200) {
|
if (v.code == 200) {
|
||||||
params.devType = String(v.data.deviceType);
|
params.devType = String(v.data.deviceType);
|
||||||
params.devNum = v.data.serialNum;
|
params.devNum = v.data.serialNum;
|
||||||
|
|
||||||
@@ -1195,7 +1198,7 @@ function toLogin() {
|
|||||||
// 查询设备到期
|
// 查询设备到期
|
||||||
function getDeviceDead() {
|
function getDeviceDead() {
|
||||||
deviceDead().then((res) => {
|
deviceDead().then((res) => {
|
||||||
if (res.statusCode == 200) {
|
if (res.code == 200) {
|
||||||
deadList.value = res.data;
|
deadList.value = res.data;
|
||||||
// if(res.data.length>0){
|
// if(res.data.length>0){
|
||||||
// Taro.showModal({
|
// Taro.showModal({
|
||||||
|
|||||||
186
src/utils/api-helper.ts
Normal file
186
src/utils/api-helper.ts
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
/**
|
||||||
|
* API辅助工具
|
||||||
|
* 提供统一的参数处理和响应适配
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建请求URL
|
||||||
|
* 根据新接口规范,不再需要拼接rootuserid参数
|
||||||
|
* @param url 基础URL
|
||||||
|
* @param params 查询参数对象(可选)
|
||||||
|
* @returns 完整的URL
|
||||||
|
*/
|
||||||
|
export function buildUrl(url: string, params?: Record<string, any>): string {
|
||||||
|
// 新版Java接口不需要拼接rootuserid
|
||||||
|
// 认证信息通过header传递
|
||||||
|
if (!params || Object.keys(params).length === 0) {
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
|
||||||
|
const queryString = Object.entries(params)
|
||||||
|
.filter(([_, value]) => value !== undefined && value !== null)
|
||||||
|
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
|
||||||
|
.join('&')
|
||||||
|
|
||||||
|
return queryString ? `${url}?${queryString}` : url
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 响应数据适配器
|
||||||
|
* 处理C#和Java后端返回格式的差异
|
||||||
|
*/
|
||||||
|
export class ResponseAdapter {
|
||||||
|
/**
|
||||||
|
* 适配响应数据
|
||||||
|
* @param response 原始响应数据
|
||||||
|
* @returns 标准化后的响应数据
|
||||||
|
*/
|
||||||
|
static adapt(response: any): any {
|
||||||
|
if (!response) return response
|
||||||
|
|
||||||
|
// 如果已经是标准格式,直接返回
|
||||||
|
if (this.isStandardFormat(response)) {
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理可能的格式差异
|
||||||
|
// Java后端可能使用 code 而不是 statusCode
|
||||||
|
if (response.code !== undefined && response.statusCode === undefined) {
|
||||||
|
response.statusCode = response.code
|
||||||
|
}
|
||||||
|
|
||||||
|
// Java后端可能使用 message 而不是 errors
|
||||||
|
if (response.message !== undefined && response.errors === undefined) {
|
||||||
|
response.errors = response.message
|
||||||
|
}
|
||||||
|
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查是否为标准格式
|
||||||
|
* @param response 响应数据
|
||||||
|
* @returns 是否为标准格式
|
||||||
|
*/
|
||||||
|
private static isStandardFormat(response: any): boolean {
|
||||||
|
return response.statusCode !== undefined && response.data !== undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断响应是否成功
|
||||||
|
* @param response 响应数据
|
||||||
|
* @returns 是否成功
|
||||||
|
*/
|
||||||
|
static isSuccess(response: any): boolean {
|
||||||
|
const adapted = this.adapt(response)
|
||||||
|
return adapted.statusCode === 200 || adapted.code === 200
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取响应数据
|
||||||
|
* @param response 响应数据
|
||||||
|
* @returns 数据内容
|
||||||
|
*/
|
||||||
|
static getData(response: any): any {
|
||||||
|
const adapted = this.adapt(response)
|
||||||
|
return adapted.data
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取错误信息
|
||||||
|
* @param response 响应数据
|
||||||
|
* @returns 错误信息
|
||||||
|
*/
|
||||||
|
static getError(response: any): string {
|
||||||
|
const adapted = this.adapt(response)
|
||||||
|
return adapted.errors || adapted.message || '系统异常'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求参数构建器
|
||||||
|
* 简化API调用时的参数构建
|
||||||
|
*/
|
||||||
|
export class ParamsBuilder {
|
||||||
|
private params: Record<string, any> = {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加参数
|
||||||
|
* @param key 参数名
|
||||||
|
* @param value 参数值
|
||||||
|
* @returns this
|
||||||
|
*/
|
||||||
|
add(key: string, value: any): this {
|
||||||
|
if (value !== undefined && value !== null) {
|
||||||
|
this.params[key] = value
|
||||||
|
}
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量添加参数
|
||||||
|
* @param params 参数对象
|
||||||
|
* @returns this
|
||||||
|
*/
|
||||||
|
addAll(params: Record<string, any>): this {
|
||||||
|
Object.entries(params).forEach(([key, value]) => {
|
||||||
|
this.add(key, value)
|
||||||
|
})
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建最终参数对象
|
||||||
|
* @returns 参数对象
|
||||||
|
*/
|
||||||
|
build(): Record<string, any> {
|
||||||
|
return { ...this.params }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API路径生成器
|
||||||
|
* 用于处理RESTful风格的路径参数
|
||||||
|
*/
|
||||||
|
export class PathBuilder {
|
||||||
|
private path: string
|
||||||
|
|
||||||
|
constructor(basePath: string) {
|
||||||
|
this.path = basePath
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加路径段
|
||||||
|
* @param segment 路径段
|
||||||
|
* @returns this
|
||||||
|
*/
|
||||||
|
append(segment: string | number): this {
|
||||||
|
this.path = `${this.path}/${segment}`
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加多个路径段
|
||||||
|
* @param segments 路径段数组
|
||||||
|
* @returns this
|
||||||
|
*/
|
||||||
|
appendAll(...segments: (string | number)[]): this {
|
||||||
|
segments.forEach(segment => this.append(segment))
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建最终路径
|
||||||
|
* @returns 路径字符串
|
||||||
|
*/
|
||||||
|
build(): string {
|
||||||
|
return this.path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
buildUrl,
|
||||||
|
ResponseAdapter,
|
||||||
|
ParamsBuilder,
|
||||||
|
PathBuilder,
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user