1
0
forked from dyf/APP

常规小优化

This commit is contained in:
liub
2026-04-22 08:29:06 +08:00
parent 01ff9c7a05
commit 1f88de4710
22 changed files with 1682 additions and 392 deletions

View File

@ -24,7 +24,7 @@
{{Statu.boundRemark}}
</view>
</view>
<view class="btnLink" @click="Link()">
<view class="btnLink" @click="Bind()">
绑定
</view>
@ -71,7 +71,10 @@
"communicationMode": "",
"imei": ""
},
serverDevice: null
serverDevice: null,
groupid:null,
typeList:[],
uploadStatu:null
}
},
computed: {
@ -86,7 +89,6 @@
}
},
deviceStatu: function() {
debugger;
if (!this.device.name && !this.device.macAddress) {
return "";
}
@ -127,7 +129,8 @@
console.log("返回取消订阅");
clearInterval(inteval);
ble.removeAllCallback(pagePath);
clearTimeout(this.Statu.timeInteval);
this.uploadStatu=null;
if(!this.Statu.isBind && these.device.deviceId){
ble.disconnectDevice(these.device.deviceId).catch(ex=>{
console.error("无法断开蓝牙连接");
@ -137,6 +140,8 @@
onLoad(option) {
these = this;
this.groupid=new Date().getTime()+"";
ble = bleTool.getBleTool();
ble.addStateBreakCallback(res => {
@ -258,6 +263,108 @@
},
methods: {
getDevList() {
return new Promise((resolve,reject)=>{
let arr = [
];
request({
url: '/app/xinghan/device/typeAll',
method: 'get'
}).then(res => {
if (res && res.code == 200) {
console.log("获取到类型", res.data);
arr = res.data;
this.typeList = arr;
resolve(arr);
return;
}
reject();
}).catch(ex => {
console.error("获取设备类型列表失败",ex);
reject();
})
});
},
uploadItem() {
if(this.uploadStatu!==null){
console.error("执行过上传,不再执行");
return;
}
this.uploadStatu="start";
console.log("开始上传设备");
let type=this.device.name.toLowerCase();
if(type.indexOf("bjq6155-")>-1){//6155特别处理
type="xh6155"
}
if(type.indexOf("bjq6155-")>-1){//6155特别处理
type="xh6155"
}
if(type.indexOf("bjq6075-")>-1){//6075j特别处理
bype='bjq6075j';
}
type=type.replace(/-/g,'');
let upload=()=>{
let f=this.typeList.find((v,i)=>{
if(type.indexOf(v.typeName.replace(/-/g,'').toLowerCase())>-1){
return true;
}
});
if(!f){
this.uploadStatu="type is valid";
console.error("找不到此类型名称",type);
console.error("tpelist=",this.typeList);
return;
}
let json = {
"deviceType": f.id,
"deviceName": this.device.name,
"deviceMac": this.device.macAddress,
"bluetoothName": this.device.name,
"deviceImei":this.device.imei?this.device.imei:'',
"remark": "com.chxhyc.cn auto upload"
}
request({
url: '/app/xinghan/device/add',
method: 'post',
data: json
}).then(res => {
if (res && res.code == 200) {
this.uploadStatu="success";
console.log("上传成功",res);
} else {
this.uploadStatu="upload error";
console.error("上传失败,",res);
}
}).catch(ex => {
this.uploadStatu="upload error";
console.error("上传失败,",ex);
});
}
let exec = () => {
if(this.typeList.length==0){
this.getDevList().then(results=>{
upload();
}).catch(ex=>{
this.uploadStatu="get types error";
console.error("获取类型失败,",ex);
});
}else{
upload();
}
}
setTimeout(exec, 10)
},
reLinkdevice() {
ble.LinkBlue(these.device.deviceId).then(res => {
updateLoading(these, {
@ -320,6 +427,7 @@
clearInterval(inteval);
} else {
deviceInvalid();
this.uploadItem();
}
} else {
this.serverDevice =null;
@ -337,7 +445,7 @@
}, 500);
},
Link() {
Bind() {
// 调用绑定设备接口
// let f = ble.data.LinkedList.find((v) => {

View File

@ -727,7 +727,7 @@
});
let index = 1;
let total = 5;
let total = 1;
let linkCallback = (res) => {
console.log("连接成功", these.device);

View File

@ -45,12 +45,17 @@
</view>
<view class="tab">
<view class="center tabItem" @click="Status.tabIndex=0" :class="{'active':Status.tabIndex==0}">未入库(<text class="mathIcon">{{UnJoin.length}}</text>)</view>
<view class="center tabItem" @click="Status.tabIndex=1" :class="{'active':Status.tabIndex==1}">已入库(<text class="mathIcon">{{joined.length}}</text>)</view>
<view class="center tabItem" @click="Status.tabIndex=2" :class="{'active':Status.tabIndex==2}">全部(<text class="mathIcon">{{SearchEquips.length}}</text>)</view>
</view>
</view>
<view class="mainContent">
<view class="p100">
<view class="list searchList">
<view class="item" v-on:click="Link(item,index)" v-for="item, index in SearchEquips"
<view class="item" v-on:click="Link(item,index)" v-for="item, index in list"
v-show="!item['linkStatu']"
:class="{'displayNone':item.name.toLowerCase().indexOf(search.toLowerCase())===-1}">
<view class="leftImg ">
@ -152,7 +157,8 @@
title: '添加设备',
showBack: true,
height: 90
}
},
tabIndex:0
},
search: '',
groupid: '',
@ -168,12 +174,35 @@
}
},
computed: {
list(){
if(this.Status.tabIndex==0){
return this.UnJoin;
}
if(this.Status.tabIndex==1){
return this.joined;
}
return this.SearchEquips;
},
SearchEquips: function() {
let f = this.EquipMents.filter(v => {
return v.name.toLowerCase().indexOf(this.search.toLowerCase()) > -1
});
return f;
}
},
joined(){
let f=this.EquipMents.filter(v => {
return v.name.toLowerCase().indexOf(this.search.toLowerCase()) > -1 && v.isUpload;
});
return f;
},
UnJoin(){
let f=this.EquipMents.filter(v => {
return v.name.toLowerCase().indexOf(this.search.toLowerCase()) > -1 && !v.isUpload;
});
return f;
},
},
onHide: function() {
ble.StopSearch();
@ -427,7 +456,7 @@
if (!f) {
arr[i].remark = '正在校验...';
these.EquipMents.push(arr[i]);
these.EquipMents.unshift(arr[i]);
these.getDevice(arr[i]);
@ -482,18 +511,19 @@
ble.addStateBreakCallback(() => {
MsgError('蓝牙不可用','确定',these);
MsgError('蓝牙不可用','',these);
these.EquipMents=[];
these.EquipMents.filter((v, i) => {
these.$set(these.EquipMents[i], 'link', false);
});
}, pagePath);
ble.addStateRecoveryCallback(() => {
these.ReSearch();
MsgSuccess('蓝牙恢复可用','',these,()=>{
MsgSuccess('蓝牙恢复可用','确定',these,()=>{
MsgClear(these);
})
});
},
pagePath);
@ -553,11 +583,10 @@
// #ifdef APP|APP-PLUS
setTimeout(()=>{
debugger;
MsgInfo("如需要在PC上查看此数据,请复制链接后通过微信发送到PC,在PC端打开然后点右上角扫码授权","复制链接",these,true,()=>{
console.log("执行复制");
console.log("开始访问剪切板");
uni.setClipboardData({
data:'https://static-mp-5b7c35fc-f6fe-4100-a2e1-3669e4d4bfc9.next.bspapp.com/AppTools/views/index.html',
success(){
@ -565,25 +594,19 @@
title:'已复制链接'
});
// #ifdef APP
plus.runtime.openURL('weixin://', (err) => {
MsgError("打开微信失败,请手动打开微信,发送至'文件传输助手'");
});
// #endif
// #ifndef APP
MsgInfo("已复制链接,请打开浏览器查看","",these);
setTimeout(()=>{
MsgClear(these);
},1200)
// #endif
},
fail(ex){
console.error("无法复制",ex)
fail(ex) {
console.error("ex=",ex);
}
});
});
},500);
// #endif
},
onShow: function() {
@ -812,6 +835,7 @@
let json = getUrlParams(res.result);
if (!json.key) {
MsgError('无效的二维码','',these);
return;
@ -892,11 +916,11 @@
ble.disconnectDevice().finally(dis => {
ble.StopSearch().finally(res => {
setTimeout(()=>{
this.EquipMents = [];
this.EquipMents = [];
this.PairEquip = [];
ble.StartSearch().then(result => {
setTimeout(()=>{
ble.StartSearch().then(result => {
}).catch(err => {
console.error("err=", err);
@ -904,7 +928,7 @@
}).finally(()=>{
hideLoading(these);
});
},200);
},600)
}).catch(ex => {
console.error("ex=", ex);
@ -993,7 +1017,7 @@
});
let index = 1;
let total = 5;
let total = 1;
let linkCallback = (res) => {
let c = these.PairEquip.find(function(v) {
@ -1029,14 +1053,11 @@
return false;
});
ble.StopSearch();
resolve(res);
}).catch((ex) => {
if (index == total) {
console.log("连接了N次都没连上");
updateLoading(this, {
text: ex.msg
});
reject(ex);
return;
}
@ -1058,8 +1079,8 @@
these.sendEquipToMq();
}).catch(ex => {
console.log("ex=", ex)
MsgError("连接失败:" + ex.msg,'',these);
MsgError("连接失败"+ex.code + ex.msg,'',these);
hideLoading(these);
});
}
@ -1076,6 +1097,22 @@
</script>
<style>
.tabItem.active{
border-bottom:2rpx solid #BBE600;
color:#BBE600;
}
.mathIcon{
color: #BBE600;
}
.tab{
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-content: center;
justify-content: space-evenly;
height: 60rpx;
font-size: 28rpx;
}
.noLink {
text-align: center;
width: 100%;
@ -1228,12 +1265,7 @@
min-height: 120rpx;
}
.searchList {
width: 100%;
height: calc(100% - 186rpx);
overflow-y: scroll;
margin-top: 120rpx;
}
.list .item {
width: 100%;
@ -1447,7 +1479,7 @@
.topStatric {
width: 100%;
box-sizing: border-box;
padding: 30rpx;
padding:0rpx 30rpx;
position: fixed;
top: 0rpx;
z-index: 99;
@ -1463,9 +1495,15 @@
.mainContent {
margin-top: 160rpx;
margin-top: 280rpx;
}
.searchList {
width: 100%;
height: calc(100% - 186rpx);
overflow-y: scroll;
margin-top: 90rpx;
}
/* #endif */
@ -1476,9 +1514,15 @@
}
.topStatric {
top: 90rpx
top: 130rpx
}
.searchList {
width: 100%;
height: calc(100% - 186rpx);
overflow-y: scroll;
margin-top: 150rpx;
}
/* #endif */

View File

@ -27,10 +27,11 @@
<mescroll-uni class="device-list" @init="mescrollInit" @down="downCallback" @up="upCallback" :up="upOption"
:down="downOption" :fixed="false" :style="{ height: mescrollHeight + 'px' }">
<view v-if="deviceList.length>0">
<uni-swipe-action ref="swipeAction" >
<uni-swipe-action ref="swipeAction">
<block v-for="(item, index) in deviceList" :key="index" :ref="'swipeItem_' + index">
<uni-swipe-action-item :right-options="Options" :show="item.showOption"
@click="handleSwipeClick($event, item, index)" class="device-card"
:class="item.active?'active':''"
:style="{ border: item.communicationMode==0 && item.onlineStatus==1 && item.alarmStatus==1 ? '1px solid rgba(224, 52, 52, 1)' : 'none' }">
<view @click.stop="handleFile(item,index)">
<view class="device-header">
@ -62,7 +63,8 @@
</view>
</view>
</view>
<image @click.stop="swipeToggle(item,index)" src="/static/images/common/cires.png" class="circle" mode="aspectFit"></image>
<image @click.stop="swipeToggle(item,index)" src="/static/images/common/cires.png"
class="circle" mode="aspectFit"></image>
</uni-swipe-action-item>
</block>
</uni-swipe-action>
@ -136,8 +138,8 @@
</view>
<!-- 蒙板用于点击任意位置关闭悬浮的菜单 -->
<view class="mask" v-show="showTooltip||showshare" @click.stop="closePopMenu"></view>
<MsgBox ref="msgPop" />
</view>
</template>
@ -242,8 +244,8 @@
isLock: false,
empty: {
tip: '暂无数据',
hideScroll: false,
icon: '/static/images/common/empty.png'
hideScroll: false,
icon: '/static/images/common/empty.png'
},
textNoMore: '没有更多数据了'
},
@ -315,7 +317,7 @@
},
bleBreak(res) {
// console.error("蓝牙断开连接", res);
console.error("蓝牙断开连接", res);
if (res.deviceId) {
this.updateBleStatu(res.deviceId);
}
@ -698,37 +700,44 @@
}
})
},
swipeToggle(item,index){
if(!item.showOption || item.showOption=='none'){
this.$set(this.deviceList[index],'showOption','right');
swipeToggle(item, index) {
if (!item.showOption || item.showOption == 'none') {
this.$set(this.deviceList[index], 'showOption', 'right');
return;
}
this.$set(this.deviceList[index],'showOption','none');
this.$set(this.deviceList[index], 'showOption', 'none');
},
// 列表跳转
handleFile(item,index) {
if(item.showOption=='right'){
this.$set(this.deviceList[index],'showOption','none');
handleFile(item, index) {
if (item.showOption == 'right') {
this.$set(this.deviceList[index], 'showOption', 'none');
return;
}
let url = item.detailPageUrl;
uni.navigateTo({
url: url,
events: {
ack: function(data) {}
},
success: (res) => {
// 页面跳转成功后的回调函数
res.eventChannel.emit('detailData', {
data: item,
deviceType: this.tabs[this.activeTab].id || '',
apiType: 'listA' //标识,根据这个参数,区分普通详情,分享跳转详情,查不一样的权限信息
});
},
fail(ex) {
console.log("ex=", ex);
}
})
this.$set(this.deviceList[index], 'active', true);
setTimeout(() => {
this.$set(this.deviceList[index], 'active', false);
let url = item.detailPageUrl;
uni.navigateTo({
url: url,
events: {
ack: function(data) {}
},
success: (res) => {
// 页面跳转成功后的回调函数
res.eventChannel.emit('detailData', {
data: item,
deviceType: this.tabs[this.activeTab].id || '',
apiType: 'listA' //标识,根据这个参数,区分普通详情,分享跳转详情,查不一样的权限信息
});
},
fail(ex) {
console.log("ex=", ex);
}
});
}, 100);
},
updateDeviceStatus(data) {
@ -768,7 +777,6 @@
}
},
onLoad() {
// console.error("首页加载");
this.getTab()
this.downCallback();
@ -785,7 +793,7 @@
this.downCallback();
});
ble = bleTool.getBleTool();
console.log("this=",this);
console.log("this=", this);
recei = BleReceive.getBleReceive(this);
//蓝牙连接成功的回调
ble.addRecoveryCallback((res) => {
@ -795,7 +803,7 @@
//蓝牙断开连接的回调
ble.addDisposeCallback((res) => {
// console.log("蓝牙断开连接的回调");
console.log("蓝牙断开连接的回调");
this.bleBreak(res);
}, pagePath);
@ -813,8 +821,8 @@
//接收到消息的回调
ble.addReceiveCallback((receive, device, path, recArr) => {
// console.error("首页收到消息了");
let json=recei.ReceiveData(receive, device, path, recArr);
// console.error("首页收到消息了");
let json = recei.ReceiveData(receive, device, path, recArr);
// console.error("消息内容",json);
this.updateBleStatu();
}, pagePath);
@ -888,22 +896,23 @@
text-align: center;
/* 文字居中 */
/* 设置最小宽度 */
position: relative;
}
.tab-item.active {
color: #bbe600;
height: 60rpx;
font-weight: bold;
}
.tab-item.active::before{
.tab-item.active::before {
content: "";
background-color: #bbe600;
background-color: #bbe600;
position: absolute;
top: 90%;
left:35%;
left: 35%;
width: 30%;
height: 6rpx;
border-radius: 6rpx;
@ -957,6 +966,9 @@
box-sizing: border-box;
position: relative;
}
.device-card.active{
background-color: #2a2a2a !important;
}
.device-header {
@ -1160,23 +1172,24 @@
}
.cancelBtn{
.cancelBtn {
text-align: center;
width: 170rpx !important;
background-color: #00000000;
}
.agreement-popupC .cancelBtn{
border:1rpx solid #E03434;
color:#E03434;
.agreement-popupC .cancelBtn {
border: 1rpx solid #E03434;
color: #E03434;
}
.agreement-popupD .cancelBtn{
.agreement-popupD .cancelBtn {
border: 1rpx solid rgba(255, 255, 255, 0.6);
color:rgba(255, 255, 255, 0.6);
color: rgba(255, 255, 255, 0.6);
}
.agreement-popupD {
width: 75%;
background-color: rgb(42, 42, 42);

280
pages/common/map/index.nvue Normal file
View File

@ -0,0 +1,280 @@
<template>
<view class="container">
<map class="map" :latitude="latitude" :longitude="longitude" :markers="covers" @markertap="onMarkerTap"
:scale="16"></map>
<!-- 加载提示 -->
<view v-if="loading" class="loading-mask">
<view class="loading-content">加载中...</view>
</view>
</view>
</template>
<script>
import Common from "@/utils/Common.js";
export default {
data() {
return {
latitude: 39.909,
longitude: 116.39742,
covers: [],
loading: true,
markerData: [],
clickMarker: {
"deviceId": "",
"deviceName": "",
"deviceImei": "",
"deviceMac": "",
"communicationMode": null,
"devicePic": "",
"typeName": "",
"bluetoothName": "",
"deviceStatus": 1,
"personnelInfo": null,
"sendMsg": null,
"mainLightMode": null,
"laserLightMode": "",
"batteryPercentage": "",
"chargeState": "0",
"batteryRemainingTime": "0",
"onlineStatus": 0,
"longitude": "",
"latitude": "",
"address": "",
"alarmStatus": null,
"lightBrightness": null
},
Status: {
BottomMenu: {
show: false,
showHeader: true,
menuItems: [{
text: '高德地图',
value: 'amap',
icon: ''
},
{
text: '百度地图',
value: 'baidumap',
icon: ''
}
],
activeIndex: -1,
bgColor: '#2a2a2a',
itemBgColor: '#3a3a3a',
textColor: '#ffffffde',
textAlign: 'flex-start',
title: '选择导航',
showDivider: false,
dividerColor: '#00000000',
dividerThickness: '0rpx',
dividerMargin: '10rpx',
itemHeight: '80rpx',
type: '',
showBtn: false,
btnBgColor: "#bbe600",
btnText: "确定",
btnTextColor: "#232323de",
showMask: true,
maskBgColor: '#00000066',
showClose: false
}
}
}
},
onLoad() {
const eventChannel = this.getOpenerEventChannel();
eventChannel.on('Map', (receivedData) => {
console.log("地图页收到数据",receivedData);
this.loading = true;
this.covers = [];
const dataContent = receivedData.data;
if (Array.isArray(dataContent)) {
const validDevices = dataContent.filter(device =>
device.latitude && device.longitude &&
device.latitude !== '' && device.longitude !== ''
);
this.markerData = validDevices;
if (validDevices.length > 0) {
this.processMultipleMarkers(validDevices);
} else {
console.log('无有效经纬度');
this.loading = false;
}
} else if (typeof dataContent === 'object' && dataContent !== null) {
if (this.validateMarker(dataContent)) {
this.markerData = [dataContent];
this.processSingleMarker(dataContent);
} else {
console.log('经纬度无效');
this.loading = false;
}
}
});
},
methods: {
showAction() {
let gd=plus.runtime.isApplicationExist({
pname: 'com.autonavi.minimap', // 安卓高德包名
action: 'iosamap://' // iOS高德 Scheme
});
let bd= plus.runtime.isApplicationExist({
pname: 'com.baidu.BaiduMap', // 安卓百度包名
action: 'baidumap://' // iOS百度 Scheme
});
let list=[];
let gdStr='高德地图';
let bdStr='百度地图';
console.log("gd=",gd);
console.log("bd=",bd);
list=[gdStr,bdStr];
uni.showActionSheet({
title: '选择地图',
itemList:list ,
success: (res)=> {
let mapType = 'amap';
if (res.tapIndex == 1) {
mapType = 'baiduMap';
if(!bd){
uni.showToast({
icon:"error",
title:'未安装'+bdStr
});
return;
}
}
if(res.tapIndex==0 && !gd) {
uni.showToast({
icon:"error",
title:'未安装'+gdStr
})
return;
}
let marker = this.clickMarker;
Common.MapNavi(marker.longitude, marker.latitude, marker.address, mapType).catch(
ex => {
uni.showToast({
icon: "error",
title: '无法打开地图'
});
});
},
})
},
navigatMap(e) {
console.log("点位被点击,", e);
},
processSingleMarker(marker) {
const lat = parseFloat(marker.latitude);
const lng = parseFloat(marker.longitude);
this.latitude = lat;
this.longitude = lng;
this.covers = [{
id: marker.id+"",
latitude: lat,
longitude: lng,
iconPath: '/static/images/common/mapLocation.png',
width: 30,
height: 50,
anchor: {
x: 0.5,
y: 0.5
},
callout: {
content: marker.deviceName
}
}];
console.log("covers=",this.covers);
this.loading = false;
},
processMultipleMarkers(markers) {
const first = markers[0];
this.latitude = parseFloat(first.latitude);
this.longitude = parseFloat(first.longitude);
this.covers = markers.map((marker, index) => ({
id: marker.id+"",
latitude: parseFloat(marker.latitude),
longitude: parseFloat(marker.longitude),
iconPath: '/static/images/common/mapLocation.png',
width: 30,
height: 50,
anchor: {
x: 0.5,
y: 0.5
},
callout: {
content: marker.deviceName
}
}));
this.loading = false;
},
validateMarker(marker) {
const lat = parseFloat(marker.latitude);
const lng = parseFloat(marker.longitude);
return !isNaN(lat) && !isNaN(lng);
},
onMarkerTap(e) {
console.log('点击了标记', e);
let marker = this.markerData.find(item => {
return item.id == e.detail.markerId
});
console.log('点击了标记', marker);
if (marker) {
this.clickMarker = marker;
this.showAction();
}
}
}
}
</script>
<style>
/* nvue 全屏必须这样写 */
.container {
flex: 1;
box-sizing: border-box;
}
.map {
width: 750rpx;
flex: 1;
}
.loading-mask {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
justify-content: center;
align-items: center;
z-index: 999;
}
.loading-content {
color: #fff;
font-size: 28rpx;
padding: 20rpx 30rpx;
background-color: rgba(0, 0, 0, 0.7);
border-radius: 8rpx;
}
</style>

View File

@ -79,16 +79,17 @@ export default {
this.latitude = lat;
this.longitude = lng;
// 创建标记点
console.log("devicePic=",marker)
this.covers = [{
id: marker.deviceImei, // 适配deviceId字段
latitude: lat,
longitude: lng,
iconPath: marker.devicePic || '/static/images/common/mapLocation.png',
width: 40,
height: 40,
iconPath: '/static/images/common/mapLocation.png',
width: 60,
height: 60,
anchor: {x: 0.5, y: 0.5}, // 锚点在中心
callout: {
content: `ID: ${marker.deviceImei}`
content: `${marker.deviceName}`
}
}];
@ -102,17 +103,18 @@ export default {
this.latitude = parseFloat(firstMarker.latitude);
this.longitude = parseFloat(firstMarker.longitude);
console.log("devicePic=",marker.devicePic)
// 转换所有有效标记点
this.covers = markers.map((marker, index) => ({
id: marker.deviceId || marker.id || marker.deviceImei || index + 1,
latitude: parseFloat(marker.latitude),
longitude: parseFloat(marker.longitude),
iconPath: marker.devicePic || '/static/images/common/device.png',
width: 40,
height: 40,
iconPath: '/static/images/common/mapLocation.png',
width: 60,
height: 60,
anchor: {x: 0.5, y: 0.5},
callout: {
content: `ID: ${marker.deviceImei}`,
content: `${marker.deviceName}`,
}
}));

View File

@ -20,7 +20,7 @@
<!-- 编辑弹窗 -->
<MsgBox ref="editPop">
<view>
修改紧急联系人
编辑紧急联系人
</view>
<view class="w60">

View File

@ -151,7 +151,9 @@
uni.reLaunch({
url: '/pages/common/login/index'
});
})
});
},
// 退出登录