接口对接

This commit is contained in:
仲么了
2023-03-30 09:04:07 +08:00
parent 3f966d4024
commit 0325347e06
15 changed files with 226 additions and 61 deletions

30
App.vue
View File

@@ -1,7 +1,37 @@
<script> <script>
import encrypt from './common/js/aes.js' import encrypt from './common/js/aes.js'
import {
MQTT_IP,
MQTT_OPTIONS
} from './common/js/mqtt.js';
import mqtt from 'mqtt/dist/mqtt.js'
export default { export default {
methods: {
connect () {
MQTT_OPTIONS.clientId = uni.getStorageSync('cidAES')
var that = this
let client = mqtt.connect('ws://' + MQTT_IP, MQTT_OPTIONS)
client.on('connect', function () {
console.log('连接成功')
client.subscribe(that.topic, function (err) {
if (!err) {
console.log('订阅成功')
}
})
}).on('reconnect', function (error) {
console.log(error);
console.log('正在重连...', that.topic)
}).on('error', function (error) {
console.log('连接失败...', error)
}).on('end', function () {
console.log('连接断开')
}).on('message', function (topic, message) {
console.log('接收推送信息:', message.toString())
})
}
},
onLaunch: function () { onLaunch: function () {
// this.connect()
let cidAES = uni.getStorageSync('cidAES') || 'nnvmhMk8626D8QHhJefm+W9rTAJWuBPRxcnRm4+9bWXdSLRIyTnTruoYfLxGK3Oy' let cidAES = uni.getStorageSync('cidAES') || 'nnvmhMk8626D8QHhJefm+W9rTAJWuBPRxcnRm4+9bWXdSLRIyTnTruoYfLxGK3Oy'
uni.setStorageSync('cidAES', cidAES); uni.setStorageSync('cidAES', cidAES);
if (!cidAES) { if (!cidAES) {

22
common/api/project.js Normal file
View File

@@ -0,0 +1,22 @@
import request from '../js/request'
import config from '../js/config'
export function addAppProject (params, files) {
return uni.uploadFile({
url: config.domain + '/project/addAppProject', //仅为示例,非真实的接口地址
files: files,
header: {
"Authorization": "12",
},
formData: params,
});
}
export function getProjectList (params) {
return request({
url: '/project/queryProject',
method: 'post',
data: params,
})
}

View File

@@ -1,7 +1,7 @@
const debug = true // true 是连地服务端本地false 是连接线上 const debug = true // true 是连地服务端本地false 是连接线上
const development = { const development = {
domain: 'http://pqmcc.com:8040', domain: 'http://192.168.1.114:10210',
devCode: "2aaecd0b124df819eda75e639a1f91fd", devCode: "2aaecd0b124df819eda75e639a1f91fd",
key: "f81804778c89c779" key: "f81804778c89c779"
} }

View File

@@ -23,17 +23,18 @@ export default {
status: "more", status: "more",
empty: false, empty: false,
total: 0, total: 0,
header: {}, header: {
"Content-Type": "application/json;charset=UTF-8",
},
params: { params: {
pages: 1, currentPage: 1,
step: 20, pageSize: 20,
entity: {},
}, },
reload () { reload () {
this.data = []; this.data = [];
this.status = "loading"; this.status = "loading";
this.empty = false; this.empty = false;
this.params.pages = 1; this.params.currentPage = 1;
this.next(); this.next();
}, },
callBack: null, callBack: null,
@@ -42,47 +43,33 @@ export default {
next () { next () {
me.$request({ me.$request({
url: url, url: url,
data: Object.assign( data: this.params,
{
// page: {
// current: this.params.pages,
// orders: [],
// size: this.params.step,
// total: 0,
// },
offset: this.params.pages,
limit: this.params.step,
current: this.params.pages,
pageSize: this.params.step,
},
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?.result?.records || []; let resultData = res.rows || res.data?.list || res.data?.records || [];
if (this.params.pages == 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.step) { } else if (resultData.length < this.params.pageSize) {
this.status = "noMore"; 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.step) { if (resultData.length < this.params.pageSize) {
this.status = "noMore"; this.status = "noMore";
} }
} }
if (this.params.pages == 1) { if (this.params.currentPage == 1) {
this.firstCallBack && this.firstCallBack(); this.firstCallBack && this.firstCallBack();
} }
this.loadedCallback && this.loadedCallback(); this.loadedCallback && this.loadedCallback();
this.params.pages++; this.params.currentPage++;
this.total = res.total; this.total = res.total;
this.loading = false; this.loading = false;
}); });

11
common/js/mqtt.js Normal file
View File

@@ -0,0 +1,11 @@
export const MQTT_IP = '60.204.148.71:9001'//mqtt地址端口, 使用emqx时一定要加mqtt
const MQTT_USERNAME = 'test'//mqtt用户名
const MQTT_PASSWORD = 'test'//密码
export const MQTT_OPTIONS = {
connectTimeout: 5000,
clientId: '',
username: MQTT_USERNAME,
password: MQTT_PASSWORD,
clean: false
}

View File

@@ -24,14 +24,16 @@ export default (options = {}) => {
}, },
header: { header: {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Authorization":"12",
...options.header ...options.header
}, },
method: options.method || 'GET', method: options.method || 'GET',
success: async (res) => { success: async (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) { if (res.data.resultCode !== 10000 && res.data.code !== 'A0000' ) {
errHandler(res.data) errHandler(res.data)
reject(res.data) reject(res.data)
} else { } else {

View File

@@ -0,0 +1,52 @@
<template>
<view class="empty" :style="{ paddingTop: paddingTop + 'rpx' }">
<image :src="img" mode="aspectFill" class="empty-img"></image>
<view class="empty-text">{{ msg }}</view>
</view>
</template>
<script>
export default {
props: {
msg: {
type: String,
default: '暂无数据',
},
img: {
type: String,
default: '/static/empty.png',
},
paddingTop: {
type: Number,
default: 70,
},
},
data() {
return {}
},
}
</script>
<style>
.empty {
display: flex;
flex-direction: column;
align-items: center;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.empty-text {
margin-top: 30rpx;
font-size: 28rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #666;
line-height: 32rpx;
}
.empty-img {
width: 244rpx;
height: 320rpx;
}
</style>

View File

@@ -132,7 +132,7 @@
"/api" : { "/api" : {
"https" : true, "https" : true,
// "target" : "https://china.indpecker.com", // "target" : "https://china.indpecker.com",
"target" : "http://pqmcc.com:8040", "target" : "http://192.168.1.114:10210",
"changOrigin" : true, "changOrigin" : true,
"pathRewrite" : { "pathRewrite" : {
"/api" : "" "/api" : ""

View File

@@ -1,5 +1,6 @@
{ {
"dependencies": { "dependencies": {
"html2canvas": "^1.4.1" "html2canvas": "^1.4.1",
"mqtt": "3.0.0"
} }
} }

View File

@@ -421,7 +421,7 @@
"list": [ "list": [
{ {
"name": "login", //模式名称 "name": "login", //模式名称
"path": "pages/device/APF/detail", //启动页面,必选 "path": "pages/project/new", //启动页面,必选
"query": "" //启动参数在页面的onLoad函数里面得到。 "query": "" //启动参数在页面的onLoad函数里面得到。
} }
] ]

View File

@@ -35,6 +35,10 @@
</uni-list-item> </uni-list-item>
</uni-list> </uni-list>
</view> </view>
<view style="padding: 0 20rpx" v-show="navMenuActive == 2">
<image class="gplot gplot-box" mode="aspectFill" src="/static/test2.pic.png"
v-for="(item, key) in 3" :key="key" />
</view>
<uni-load-more status="nomore"></uni-load-more> <uni-load-more status="nomore"></uni-load-more>
</view> </view>
<uni-fab ref="fab" direction="vertical" horizontal="right" vertical="bottom" :content="content" <uni-fab ref="fab" direction="vertical" horizontal="right" vertical="bottom" :content="content"
@@ -53,9 +57,11 @@ export default {
loading: false, loading: false,
project: '', project: '',
navMenuList: [{ navMenuList: [{
text: '设备列表' text: '设备'
}, { }, {
text: '子用户列表' text: '子用户'
}, {
text: '拓扑图'
}], }],
content: [], content: [],
navHeight: 0, navHeight: 0,
@@ -168,4 +174,10 @@ export default {
border-radius: 10rpx; border-radius: 10rpx;
} }
} }
.gplot {
position: relative;
width: 100%;
border: 8rpx solid #ccc;
}
</style> </style>

View File

@@ -4,7 +4,8 @@
<uni-nav-bar dark :fixed="true" status-bar left-icon="left" :rightIcon="userInfo.role == '2' ? '' : 'plusempty'" <uni-nav-bar dark :fixed="true" status-bar left-icon="left" :rightIcon="userInfo.role == '2' ? '' : 'plusempty'"
background-color="#fff" color="#111" title="项目管理" @clickLeft="back" @clickRight="add" /> background-color="#fff" color="#111" title="项目管理" @clickLeft="back" @clickRight="add" />
<view class="message"> <view class="message">
<uni-card title="XXX项目1" extra="用能" @click="jump('XXX项目1')"> <uni-card :title="item.name" :extra="item.projectType" @click="jump('XXX项目1')"
v-for="(item, index) in store.data" :key="index">
<view class="term-list-bottom"> <view class="term-list-bottom">
<view class="term-list-bottom-item"> <view class="term-list-bottom-item">
<view>设备个数</view> <view>设备个数</view>
@@ -16,25 +17,16 @@
</view> </view>
</view> </view>
</uni-card> </uni-card>
<uni-card title="XXX项目2" extra="监测" @click="jump('XXX项目2')"> <Cn-empty v-if="store.empty"></Cn-empty>
<view class="term-list-bottom"> <uni-load-more v-if="store.data && store.data.length > 0" :status="store.status"></uni-load-more>
<view class="term-list-bottom-item">
<view>设备个数</view>
<view>3</view>
</view>
<view class="term-list-bottom-item">
<view>用户个数</view>
<view>1</view>
</view>
</view>
</uni-card>
<uni-load-more status="nomore"></uni-load-more>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
import list from '../../common/js/list'
export default { export default {
mixins: [list],
data () { data () {
return { return {
loading: false, loading: false,
@@ -43,7 +35,8 @@ export default {
}, },
methods: { methods: {
init () { init () {
this.userInfo = uni.getStorageSync('userInfo') this.store = this.DataSource('/project/queryProject')
this.store.reload()
}, },
back () { back () {
uni.navigateBack() uni.navigateBack()

View File

@@ -8,20 +8,22 @@
<uni-easyinput type="number" v-model="formData.name" placeholder="请输入项目名称" /> <uni-easyinput type="number" v-model="formData.name" placeholder="请输入项目名称" />
</uni-forms-item> </uni-forms-item>
<uni-forms-item label="项目类别"> <uni-forms-item label="项目类别">
<uni-data-select v-model="formData.type" :localdata="TypeRange"></uni-data-select> <uni-data-select v-model="formData.projectType" :localdata="TypeRange"></uni-data-select>
</uni-forms-item> </uni-forms-item>
<uni-forms-item label="区域"> <uni-forms-item label="区域">
<view style="display:flex;"> <view style="display:flex;">
<uni-easyinput :clearable="false" type="textarea" autoHeight v-model="formData.address" <uni-easyinput :clearable="false" type="textarea" autoHeight v-model="formData.area"
placeholder="请输入区域信息" /> placeholder="请输入区域信息" />
<uni-icons type="location" color="#007aff" size="26" class="ml20" <uni-icons type="location" color="#007aff" size="26" class="ml20"
@click="chooseLocation"></uni-icons> @click="chooseLocation"></uni-icons>
</view> </view>
</uni-forms-item> </uni-forms-item>
<uni-forms-item label="描述"> <uni-forms-item label="描述">
<uni-easyinput type="textarea" autoHeight v-model="formData.name" placeholder="请输入项目描述" /> <uni-easyinput type="textarea" autoHeight v-model="formData.description"
placeholder="请输入项目描述" />
</uni-forms-item> </uni-forms-item>
<uni-file-picker title="请上传拓扑图" :sourceType="['album']"></uni-file-picker> <uni-file-picker v-model="formData.files" title="请上传拓扑图" :sourceType="['album']"
@select="select"></uni-file-picker>
</uni-forms> </uni-forms>
</view> </view>
<view class="btn-wrap"> <view class="btn-wrap">
@@ -32,14 +34,20 @@
</Cn-page> </Cn-page>
</template> </template>
<script> <script>
import { addAppProject } from '../../common/api/project'
export default { export default {
data () { data () {
return { return {
loading: false, loading: false,
formData: { formData: {
area: "",
files: [],
description: '',
projectType: '1',
name: '', name: '',
gplot: '', userId: '123456',
type:'' lat: '2',
lng: '3'
}, },
TypeRange: [ TypeRange: [
{ {
@@ -53,8 +61,22 @@ export default {
] ]
} }
}, },
onLoad () {
uni.getLocation({
type: 'wgs84',
success: function (res) {
console.log(res);
console.log('当前位置的经度:' + res.longitude);
console.log('当前位置的纬度:' + res.latitude);
}
});
},
methods: { methods: {
select (e) {
console.log(e);
},
chooseLocation () { chooseLocation () {
uni.chooseLocation({ uni.chooseLocation({
success: function (res) { success: function (res) {
this.address = res.name this.address = res.name
@@ -65,11 +87,44 @@ export default {
} }
}); });
}, },
submit () { async submit () {
this.$util.toast('项目创建成功') if (!this.formData.name) {
setTimeout(() => { this.$util.toast('请输入项目名称')
uni.navigateBack({ delta: 1 }) return
}, 1500); }
if (!this.formData.projectType) {
this.$util.toast('请选择项目类别')
return
}
if (!this.formData.area) {
this.$util.toast('请输入区域信息')
return
}
if (!this.formData.description) {
this.$util.toast('请输入项目描述')
return
}
if (!this.formData.files.length) {
this.$util.toast('请上传拓扑图')
return
}
let arr = []
for (let i = 0; i < this.formData.files.length; i++) {
let item = this.formData.files[i]
arr.push({
name: 'files',
url: item.url
})
}
let data = JSON.parse(JSON.stringify(this.formData))
delete data.files
addAppProject(data, arr).then(res => {
console.log(res)
this.$util.toast('项目创建成功')
// setTimeout(() => {
// uni.navigateBack({ delta: 1 })
// }, 1500);
})
} }
} }
} }

2
pnpm-lock.yaml generated
View File

@@ -2,7 +2,7 @@ lockfileVersion: 5.4
specifiers: specifiers:
html2canvas: ^1.4.1 html2canvas: ^1.4.1
mqtt: ^3.0.0 mqtt: 3.0.0
dependencies: dependencies:
html2canvas: 1.4.1 html2canvas: 1.4.1

BIN
static/empty.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB