设备接口列表对接

This commit is contained in:
仲么了
2023-04-04 08:47:19 +08:00
parent 0325347e06
commit feb7d7b6ed
8 changed files with 184 additions and 169 deletions

10
common/api/device.js Normal file
View File

@@ -0,0 +1,10 @@
import request from '../js/request';
import config from '../js/config';
export function getDeviceList(params) {
return request({
url: '/EquipmentDelivery/queryEquipmentByProject',
method: 'post',
data: params,
});
}

View File

@@ -234,6 +234,7 @@ page {
/deep/ .uni-forms-item:last-of-type {
margin-bottom: 0 !important;
}
position: relative;
}
.status-point-success {

View File

@@ -1,38 +1,38 @@
export default {
onPullDownRefresh () {
onPullDownRefresh() {
this.store && this.store.reload();
this.store.loadedCallback = () => {
uni.stopPullDownRefresh();
};
},
onReachBottom () {
if (this.store.status != "noMore") {
onReachBottom() {
if (this.store.status != 'noMore') {
this.store.next && this.store.next();
}
},
data () {
data() {
return {
store: {},
};
},
methods: {
DataSource (url) {
DataSource(url) {
var me = this;
return {
data: [],
status: "more",
status: 'more',
empty: false,
total: 0,
header: {
"Content-Type": "application/json;charset=UTF-8",
'Content-Type': 'application/json;charset=UTF-8',
},
params: {
currentPage: 1,
pageSize: 20,
},
reload () {
reload() {
this.data = [];
this.status = "loading";
this.status = 'loading';
this.empty = false;
this.params.currentPage = 1;
this.next();
@@ -40,28 +40,31 @@ export default {
callBack: null,
firstCallBack: null,
loadedCallback: null,
next () {
next() {
me.$request({
url: url,
data: this.params,
header: this.header,
method: "POST",
method: 'POST',
}).then((res) => {
console.warn(res);
let resultData = res.rows || res.data?.list || res.data?.records || [];
let resultData =
res.data?.list || res.data?.records || [];
if (this.params.currentPage == 1) {
this.data = resultData;
if (resultData.length == 0 || resultData == 0) {
this.empty = true;
} else if (resultData.length < this.params.pageSize) {
this.status = "noMore";
} else if (
resultData.length < this.params.pageSize
) {
this.status = 'noMore';
} else if (res.total == resultData.length) {
this.status = "noMore";
this.status = 'noMore';
}
} else {
this.data.push(...resultData);
if (resultData.length < this.params.pageSize) {
this.status = "noMore";
this.status = 'noMore';
}
}

View File

@@ -1,80 +1,86 @@
import config from "./config";
let arr = []
import config from './config';
let arr = [];
export default (options = {}) => {
if (options.data == undefined) {
options.data = {}
options.data = {};
}
// 防止接口重复点击
if (arr.indexOf(options.url) === -1) {
arr.push(options.url)
arr.push(options.url);
} else {
return new Promise((resolve, reject) => {
reject({
code: -1,
msg: '请勿重复提交'
})
})
msg: '请勿重复提交',
});
});
}
return new Promise((reslove, reject) => {
uni.request({
url: options.url.indexOf('http') === -1 ? config.domain + options.url : options.url,
url:
options.url.indexOf('http') === -1
? config.domain + options.url
: options.url,
data: {
...options.data,
},
header: {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Authorization":"12",
...options.header
'Content-Type': 'application/json;charset=UTF-8',
// "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
Authorization: '12',
...options.header,
},
method: options.method || 'GET',
success: async (res) => {
console.log(res);
if (arr.indexOf(options.url) > -1) {
arr.splice(arr.indexOf(options.url), 1)
arr.splice(arr.indexOf(options.url), 1);
}
if (res.data.resultCode !== 10000 && res.data.code !== 'A0000' ) {
errHandler(res.data)
reject(res.data)
if (
res.data.resultCode !== 10000 &&
res.data.code !== 'A0000'
) {
errHandler(res.data);
reject(res.data);
} else {
reslove(res.data)
reslove(res.data);
}
},
fail: (err) => {
if (arr.indexOf(options.url) > -1) {
arr.splice(arr.indexOf(options.url), 1)
arr.splice(arr.indexOf(options.url), 1);
}
reject(err)
reject(err);
uni.showToast({
icon: 'none',
title: '网络异常,请稍后再试',
})
});
uni.reLaunch({
url: '/pages/user/login',
});
},
})
})
}
});
});
};
/**
* 错误处理
* @param {Number} code 错误码
*/
function errHandler (res) {
function errHandler(res) {
switch (res.resultCode) {
case '401':
// #ifdef MP
uni.removeStorageSync('Cookie');
uni.clearStorageSync();
// #endif
uni.reLaunch({ url: '/pages/user/login' })
break
uni.reLaunch({ url: '/pages/user/login' });
break;
default:
uni.showToast({
title: res.msg || '服务端未知错误',
duration: 2000,
icon: 'none'
icon: 'none',
});
break;
}

View File

@@ -1,20 +1,18 @@
export default {
data () {
return {
};
data() {
return {};
},
// #ifdef MP
onShareAppMessage (res) {
onShareAppMessage(res) {
return {
title: "荣创科技",
path: "/pages/index/index",
title: '荣创科技',
path: '/pages/index/index',
};
},
onShareTimeline () {
onShareTimeline() {
return {
title: "荣创科技",
path: "/pages/index/index",
title: '荣创科技',
path: '/pages/index/index',
};
},
// #endif