设备接口列表对接

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 { /deep/ .uni-forms-item:last-of-type {
margin-bottom: 0 !important; margin-bottom: 0 !important;
} }
position: relative;
} }
.status-point-success { .status-point-success {

View File

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

View File

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

View File

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

View File

@@ -34,9 +34,10 @@ export default {
align-items: center; align-items: center;
position: absolute; position: absolute;
left: 50%; left: 50%;
top: 50%; top: 0%;
transform: translate(-50%, -50%); transform: translate(-50%, 0);
} }
.empty-text { .empty-text {
margin-top: 30rpx; margin-top: 30rpx;
font-size: 28rpx; font-size: 28rpx;
@@ -45,6 +46,7 @@ export default {
color: #666; color: #666;
line-height: 32rpx; line-height: 32rpx;
} }
.empty-img { .empty-img {
width: 244rpx; width: 244rpx;
height: 320rpx; height: 320rpx;

View File

@@ -32,17 +32,32 @@
</picker> </picker>
</view> </view>
<view class="content device" :style="{ minHeight: minHeight }"> <view class="content device" :style="{ minHeight: minHeight }">
<uni-card :title="item.name" :sub-title="item.project" :extra="item.type" padding="0" <uni-card :title="item.equipmentName" :sub-title="item.projectName" :extra="item.projectType" padding="0"
v-for="(item, index) in deviceListFilter" :key="index" @click="jump(item)" thumbnail="/static/device.png"> v-for="(item, index) in deviceListFilter" :key="index" @click="jump(item)" thumbnail="/static/device.png">
<!-- <text>{{ item.project }} {{ item.type }}</text> --> <!-- <text>{{ item.project }} {{ item.type }}</text> -->
</uni-card> </uni-card>
<uni-load-more status="nomore"></uni-load-more> <Cn-empty v-if="store.empty || deviceListFilter.length == 0"></Cn-empty>
<uni-load-more v-if="deviceListFilter && deviceListFilter.length > 0" :status="store.status"></uni-load-more>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
export default { export default {
data () { props: {
store: {
type: Object,
default: {}
},
projectList: {
type: Array,
default: []
},
projectType: {
type: Array,
default: []
},
},
data() {
return { return {
loading: false, loading: false,
select: { select: {
@@ -51,101 +66,29 @@ export default {
projectType: '', projectType: '',
projectTypeIndex: 0 projectTypeIndex: 0
}, },
projectType: [
{
text: '全部类型',
value: 0
},
{
text: '监测',
value: 1
},
{
text: '用能',
value: 2
},
{
text: '环境',
value: 3
},
{
text: '安防',
value: 4
},
{
text: '其他',
value: 5
}
],
projectList: [
{
text: '全部项目',
value: 1
},
{
text: 'XXX项目1',
value: 1
},
{
text: 'XXX项目2',
value: 1
},
{
text: 'XXX项目3',
value: 1
},
],
navHeight: 0, navHeight: 0,
minHeight: '', minHeight: ''
deviceList: [
{
name: '设备APF-1',
des: '设备描述1',
type: '监测',
project: 'XXX项目1',
},
{
name: '设备APF-2',
des: '设备描述1',
type: '监测',
project: 'XXX项目1',
},
{
name: '设备APF-3',
des: '设备描述2',
type: '用能',
project: 'XXX项目2'
},
{
name: '设备DVR-1',
des: '设备描述3',
type: '监测',
project: 'XXX项目3'
}
]
} }
}, },
computed: { computed: {
deviceListFilter () { deviceListFilter() {
return this.deviceList.filter(item => { return this.store.data.filter(item => {
if (this.select.projectName) { if (this.select.projectName && this.select.projectType) {
return item.project === this.select.projectName return item.project === this.select.projectName && item.type === this.select.projectType
} else if (this.select.projectType) { } else
return item.type === this.select.projectType if (this.select.projectName) {
} else { return item.projectId === this.projectList[this.select.projectNameIndex].id
return true } else if (this.select.projectType) {
} return item.projectType === this.projectType[this.select.projectTypeIndex].id
} else {
return true
}
}) })
} }
}, },
methods: { methods: {
submitFeedBack () { uni.navigateTo({ url: '/pages/home/feedback' }) }, submitFeedBack() { uni.navigateTo({ url: '/pages/home/feedback' }) },
projectTypeChange (e) { projectTypeChange(e) {
// 重置name
this.select.projectName = ''
this.select.projectNameIndex = 0
this.select.projectTypeIndex = e.detail.value this.select.projectTypeIndex = e.detail.value
if (e.detail.value === 0) { if (e.detail.value === 0) {
this.select.projectType = '' this.select.projectType = ''
@@ -155,12 +98,8 @@ export default {
}, },
projectNameChange (e) { projectNameChange(e) {
console.log(e); console.log(e);
// 重置type
this.select.projectType = ''
this.select.projectTypeIndex = 0
this.select.projectNameIndex = e.detail.value this.select.projectNameIndex = e.detail.value
if (e.detail.value === 0) { if (e.detail.value === 0) {
this.select.projectName = '' this.select.projectName = ''
@@ -168,7 +107,7 @@ export default {
} }
this.select.projectName = this.projectList[e.detail.value].text this.select.projectName = this.projectList[e.detail.value].text
}, },
registerDevice () { registerDevice() {
uni.showModal({ uni.showModal({
title: '提示', title: '提示',
content: '请选择设备类型', content: '请选择设备类型',
@@ -188,15 +127,15 @@ export default {
} }
}) })
}, },
registerGateway () { registerGateway() {
uni.navigateTo({ uni.navigateTo({
url: '/pages/gateway/new' url: '/pages/gateway/new'
}) })
}, },
navMenuClick (index) { navMenuClick(index) {
this.navMenuActive = index this.navMenuActive = index
}, },
jump (item) { jump(item) {
if (item.name.indexOf('APF') > -1) { if (item.name.indexOf('APF') > -1) {
uni.navigateTo({ uni.navigateTo({
url: '/pages/device/APF/detail' url: '/pages/device/APF/detail'
@@ -208,7 +147,7 @@ export default {
} }
}, },
}, },
mounted () { mounted() {
setTimeout(() => { setTimeout(() => {
// 获取nav高度 // 获取nav高度
uni.createSelectorQuery().select('.nav').boundingClientRect((rect) => { uni.createSelectorQuery().select('.nav').boundingClientRect((rect) => {

View File

@@ -3,15 +3,15 @@
<view slot="body"> <view slot="body">
<view class="index"> <view class="index">
<!-- 运维 --> <!-- 运维 -->
<YunWei v-if="userInfo.role == 1" /> <YunWei v-if="userInfo.role == 1" :store="store" :projectList="projectList" :projectType="projectType" />
<!-- 专职 --> <!-- 专职 -->
<ZhuanZhi v-if="userInfo.role == 2" /> <ZhuanZhi v-if="userInfo.role == 2" :store="store" :projectList="projectList" :projectType="projectType" />
<!-- 工程 --> <!-- 工程 -->
<GongCheng v-if="userInfo.role == 3" /> <GongCheng v-if="userInfo.role == 3" :store="store" :projectList="projectList" :projectType="projectType" />
<!-- 主用户 --> <!-- 主用户 -->
<ZhuYongHu v-if="userInfo.role == 4" /> <ZhuYongHu v-if="userInfo.role == 4" :store="store" :projectList="projectList" :projectType="projectType" />
<!-- 子用户 --> <!-- 子用户 -->
<ZiYongHu v-if="userInfo.role == 5" /> <ZiYongHu v-if="userInfo.role == 5" :store="store" :projectList="projectList" :projectType="projectType" />
<YouKe v-if="userInfo.role == 6"> </YouKe> <YouKe v-if="userInfo.role == 6"> </YouKe>
<uni-fab ref="fab" direction="vertical" horizontal="right" vertical="bottom" :content="content" <uni-fab ref="fab" direction="vertical" horizontal="right" vertical="bottom" :content="content"
@trigger="trigger" /> @trigger="trigger" />
@@ -26,7 +26,10 @@ import ZhuYongHu from "./comp/indexZhuYongHu.vue";
import ZiYongHu from "./comp/indexZiYongHu.vue"; import ZiYongHu from "./comp/indexZiYongHu.vue";
import ZhuanZhi from "./comp/indexZhuanZhi.vue"; import ZhuanZhi from "./comp/indexZhuanZhi.vue";
import YouKe from "./comp/indexYouKe.vue"; import YouKe from "./comp/indexYouKe.vue";
import list from '../../common/js/list'
import { getProjectList } from '../../common/api/project'
export default { export default {
mixins: [list],
components: { components: {
YunWei, YunWei,
GongCheng, GongCheng,
@@ -35,16 +38,43 @@ export default {
ZhuanZhi, ZhuanZhi,
YouKe YouKe
}, },
data () { data() {
return { return {
loading: false, loading: true,
userInfo: { userInfo: {
role: 4 role: 4
} },
projectList: [],
projectType: [
{
text: '全部类型',
value: 0
},
{
text: '监测',
value: 1
},
{
text: '用能',
value: 2
},
{
text: '环境',
value: 3
},
{
text: '安防',
value: 4
},
{
text: '其他',
value: 5
}
],
} }
}, },
computed: { computed: {
content () { content() {
let arr = [1, 3, 4] let arr = [1, 3, 4]
let content = [{ let content = [{
iconPath: '/static/mine3.png', iconPath: '/static/mine3.png',
@@ -70,7 +100,7 @@ export default {
} }
}, },
methods: { methods: {
send () { send() {
uni.createPushMessage({ uni.createPushMessage({
title: '灿能', title: '灿能',
content: '灿能推送', content: '灿能推送',
@@ -83,7 +113,7 @@ export default {
}) })
}, },
trigger (e) { trigger(e) {
if (e.index === 500) { if (e.index === 500) {
uni.navigateTo({ uni.navigateTo({
url: '/pages/device/new' url: '/pages/device/new'
@@ -138,12 +168,38 @@ export default {
this.$util.toast(roleName + '角色切换成功') this.$util.toast(roleName + '角色切换成功')
} }
this.$refs.fab.close() this.$refs.fab.close()
},
init() {
this.store = this.DataSource('/EquipmentDelivery/queryEquipmentByProject')
this.store.reload()
this.store.firstCallBack = () => {
this.loading = false
console.log(this.store);
}
this.getProjectList()
},
getProjectList() {
getProjectList({
currentPage: 1,
pageSize: 9999
}).then(res => {
console.log(res)
this.projectList = [{
text: '全部项目',
value: ''
}, ...res.data.records.map(item => {
return {
text: item.name,
value: item.id
}
})]
})
} }
}, },
onLoad (options) { onLoad(options) {
this.loading = false this.init()
}, },
onShow () { onShow() {
this.userInfo = uni.getStorageSync(this.$cacheKey.userInfo) this.userInfo = uni.getStorageSync(this.$cacheKey.userInfo)
if (!this.userInfo) { if (!this.userInfo) {
this.userInfo = { this.userInfo = {