This commit is contained in:
Iruka 2024-09-25 18:47:15 +08:00
parent fdecc67075
commit baeb93e976
10 changed files with 245 additions and 186 deletions

View File

@ -1,13 +1,15 @@
<script>
import land from "@/utils/land.js"
import mqttUtil from "@/utils/mqttUtil.js"
export default {
data() {
return {
land: new land(), //
mqtt: null,
mqttObj: {
topics: []
}
},
}
},
globalData: {},
@ -25,6 +27,7 @@
uni.$on("mqtt-subscribes", topics => {
this.mqttSubscribes();
});
},
onShow: function() {
console.log('App Show')

17
api/index.js Normal file
View File

@ -0,0 +1,17 @@
import request from "@/utils/request"
// 查询用户所属公司列表
export function deptTreeSelectByRole() {
return request({
url: "/system/user/deptTreeByRole",
method: "get"
})
}
//查询管理员地块列表
export function getManagerGroundList(userID) {
return request({
url: "/landManager/select/" + userID,
method: "get"
})
}

View File

@ -7,12 +7,13 @@
<view class="iconfont icon-qiye icon"></view>
</template>
<template v-slot:title>
{{item.name}}
{{item.label}}
</template>
<template v-slot:right-icon>
<u-badge numberType="overflow" type="primary" max="999" :value="item.children.length" />
<u-badge numberType="overflow" type="primary" max="999" :showZero="true"
:value="item.children.length" />
</template>
<view class="u-collapse-content" v-if="item.isShow">
<view class="u-collapse-content" v-if="item.id == selectCId">
<u-list>
<u-list-item v-for="item2 in item.children">
<u-cell @click="select(item2)">
@ -20,10 +21,11 @@
<view class="iconfont icon-ditu icon"></view>
</template>
<template v-slot:title>
{{item2.name}}
{{item2.name}}
</template>
<template v-slot:right-icon>
<u-badge numberType="overflow" type="success" max="999" :value="item2.valueNum" />
<u-badge numberType="overflow" type="success" max="999" :showZero="true"
:value="item2.valueNum" />
</template>
</u-cell>
</u-list-item>
@ -36,73 +38,49 @@
</template>
<script>
import store from "@/store"
import {
deptTreeSelectByRole,
getManagerGroundList,
} from "@/api/index.js"
export default {
name: 'custom-select-land',
emits: ["select"],
props: {
// selectItem: {
// type: Object,
// default: null,
// required: true
// }
},
props: {},
watch: {},
data() {
return {
user: store.state.user.user,
show: false,
showValue: null,
list: [],
list: getApp().land.list,
selectCId: getApp().land.selectCId,
selectItem: getApp().land.selectItem,
}
},
created() {
this.getLandData();
const that = this;
getApp().land.getList(that.user.userId);
that.list = getApp().land.list;
that.selectCId = getApp().land.selectCId;
that.selectItem = getApp().land.selectItem;
},
methods: {
getLandData() {
if (!this.list.length) {
let arr = [];
for (var i = 0; i < 20; i++) {
let obj = {
id: i,
name: "公司" + i,
isShow: false,
children: []
}
for (var j = 0; j < 50; j++) {
obj.children.push({
id: j,
name: "地块" + j,
})
}
arr.push(obj);
}
this.list = arr;
}
return this.list;
},
open() {
console.log("open:", this.list);
if (this.list.length > 0) {
this.show = true;
} else {
uni.showToast({
title: "无数据",
icon: 'none'
})
this.$toast("无数据");
}
// console.error("selectItem:", this.selectItem)
},
close() {
const that = this;
that.show = false;
that.list.forEach((item, index) => {
if (index == that.showValue) {
item.isShow = true;
} else {
item.isShow = false;
}
})
this.show = false;
},
select(item) {
this.selectItem = item;
getApp().land.setStorage(2, item);
this.$emit("select", item);
this.close();
},
@ -111,7 +89,7 @@
},
openItem(e) {
this.showValue = e;
this.list[e].isShow = true;
this.selectCId = this.list[e].id;
this.$nextTick(() => {
this.$refs.refCollapse.init();
})

14
main.js
View File

@ -44,16 +44,22 @@ import {
createSSRApp
} from 'vue'
import uviewPlus from "@/uni_modules/uview-plus"
import directive from "@/directive"
import directive from "@/directive"
import * as commonUtils from "@/utils/common.js"
import constant from "@/utils/constant.js"
export function createApp() {
const app = createSSRApp(App)
app.use(uviewPlus)
app.use(directive)
app.config.globalProperties.$toast = commonUtils.toast;
app.config.globalProperties.$showConfirm = commonUtils.showConfirm;
app.config.globalProperties.$constant = constant;
// #ifndef MP
// 处理 wx.connectSocket promisify 兼容问题,强制返回 SocketTask
uni.connectSocket = (function (connectSocket) {
return function (options) {
options.success = options.success || function () {}
uni.connectSocket = (function(connectSocket) {
return function(options) {
options.success = options.success || function() {}
return connectSocket.call(this, options)
}
})(uni.connectSocket)

View File

@ -1,5 +1,13 @@
<template>
<view>横向列表页面111222(o)33</view>
<button @click="openLand">选择地块</button>
<!-- 弹窗 -->
<view>
<!-- 地块选择 -->
<custom-select-land ref="refLand" @select=""></custom-select-land>
<!-- 角度 -->
<custom-angle-slider ref="refAngleSlider" mode="bottom" @close="" @confirm="angleSliderConfirm" />
</view>
</template>
<script>

View File

@ -1,17 +1,18 @@
<template>
<!-- 顶部导航栏 -->
<uni-nav-bar :statusBar="true" :fixed="true" backgroundColor="#39ac4f" :border="false" color="#fff">
<block v-slot:left>
<view @click="openLand">地块</view>
</block>
<view>西安设备测试</view>
<view>田间</view>
<block v-slot:right>
<view class="fixed">
<view align="right" class="iconfont icon-liebiao icon" @click="toList"></view>
<view align="right" class="iconfont icon-scan icon" @click="toQRCode"></view>
<view align="right" class="icon iconfont icon-liebiao" @click="toList"></view>
<view align="right" class="icon iconfont icon-scan" @click="toQRCode"></view>
</view>
</block>
</uni-nav-bar>
<custom-select-land ref="refLand" :data="landList" @select=""></custom-select-land>
<!-- 内容 -->
<view class="content">
<!-- 顶部搜索框 -->
<view class="header-section">
@ -240,7 +241,7 @@
</view>
<view class="control">
<u-row>
<u-col span="3" style=" align-items: flex-end;" @click="showAnglePopupel">
<u-col span="3" style=" align-items: flex-end;" @click="angleSliderShow">
<view class="buttons">
<view class="btn fixed active">
<text></text>
@ -380,8 +381,10 @@
<!-- 弹窗 -->
<view>
<!-- 地块选择 -->
<custom-select-land ref="refLand" @select=""></custom-select-land>
<!-- 角度 -->
<angle-progress-bar ref="angleBarRef" mode="bottom" @close="" @confirm="swiperConfirm" />
<custom-angle-slider ref="refAngleSlider" mode="bottom" @close="" @confirm="angleSliderConfirm" />
</view>
</template>
@ -429,14 +432,14 @@
})
},
toQRCode() {},
showAnglePopupel() {
this.$refs.angleBarRef.show("1-1", "①开", 10, {
angleSliderShow() {
this.$refs.refAngleSlider.show("1-1", "①开", 10, {
// item: e.row,
// index: e.index,
});
},
swiperConfirm(e) {
console.error("swiperConfirm:", e);
angleSliderConfirm(e) {
console.error("angleSliderConfirm:", e);
},
},
}
@ -800,117 +803,4 @@
.battery-level-0 {
width: 0%;
}
/* 弹出进度条 */
// .dialog-container {
// min-width: 300px;
// .dialog-title {
// position: relative;
// text-align: center;
// height: 34px;
// line-height: 34px;
// border-bottom: 1px solid #ddd;
// &>uni-view {
// display: inline-block;
// font-weight: bold;
// font-size: 16px;
// }
// &>uni-view:nth-child(2) {
// font-size: 14px;
// color: #5bc724;
// margin-left: 10px;
// }
// .close-btn {
// position: absolute;
// top: 50%;
// right: 10px;
// transform: translateY(-50%);
// }
// }
// movable-area {
// height: 30rpx;
// width: 210px;
// margin: auto;
// border-radius: 5px;
// background-color: #D8D8D8;
// overflow: hidden;
// }
// movable-view {
// display: flex;
// align-items: center;
// justify-content: center;
// width: 10px;
// height: 100%;
// background-color: #15d99b;
// color: #fff;
// text-align: center;
// }
// ::v-deep .uni-slider-handle-wrapper {
// height: 30px !important;
// }
// ::v-deep .uni-slider-thumb {
// width: 24px !important;
// height: 24px !important;
// box-shadow: 0 0 0px 4px #74ffd4 !important;
// margin-top: -12px !important;
// }
// ::v-deep uni-slider {
// margin: 10px 18px 0 18px !important;
// }
// ::v-deep uni-slider .uni-slider-tap-area {
// padding: 0 !important;
// }
// .dialog-body {
// .grid {
// margin: 20px;
// display: grid;
// grid-template-columns: 0.5fr 2fr 0.5fr;
// .grid-time:first-child,
// .grid-time:last-child {
// display: grid;
// justify-items: end;
// align-items: end;
// &>uni-view {
// width: 35px;
// height: 30px;
// background-color: #eaecf0;
// text-align: center;
// font-size: 30px;
// line-height: 26px;
// color: #564556;
// }
// }
// .grid-time:last-child {
// justify-items: left;
// }
// }
// .buttons {
// margin: 40px 10px 10px;
// display: flex;
// justify-content: center;
// }
// }
// }
</style>

View File

@ -1,10 +1,12 @@
import user from '@/store/modules/user'
import getters from './getters'
import { createStore } from "vuex";
import {
createStore
} from "vuex";
const store = createStore({
modules: {
user
},
getters
modules: {
user
},
getters
});
export default store;

View File

@ -4,9 +4,11 @@ const constant = {
roles: 'vuex_roles',
permissions: 'vuex_permissions',
company: "vuex_company",
user: "vuex_user",
username: "username",
password: "password",
rememberPassword: "rememberPassword",
user: "vuex_user"
lands: "custom_lands",
landItem: "custom_landItem",
}
export default constant

151
utils/land.js Normal file
View File

@ -0,0 +1,151 @@
import store from "@/store"
import constant from "@/utils/constant.js"
import * as commonUtils from "@/utils/common.js"
import {
deptTreeSelectByRole,
getManagerGroundList,
} from "@/api/index.js"
class land {
static isFirst = true //是否第一次加载
static userId = null;
static list = [];
static selectCId = null;
static selectItem = null;
//接收创建来的数据
constructor() {
this.isFirst = true;
this.userId = null;
this.list = [];
this.selectCId = null;
this.selectItem = null;
}
// 获取列表
getList(userId) {
console.error("isFirst:",this.isFirst);
this.userId = userId;
if (this.isFirst) {
const lands = uni.getStorageSync(constant.lands);
if (lands && lands.userId == userId) {
this.list = lands.data;
}
}
if (this.isFirst) {
this.isFirst = false;
this.getNewList(userId);
}
console.error("list:",this.list);
}
// 获取最新数据
async getNewList(userId) {
this.userId = userId;
// 如果是第一次获取,则重新查询一遍数据,更新旧数据
let company = await deptTreeSelectByRole();
// console.error("company:",company);
if (company.data.length) {
let companys = [];
if (company.data.length == 1 && company.data[0].id == 100) {
companys = companys.concat(company.data[0].children)
} else {
companys = company.data;
}
let land = await getManagerGroundList(userId);
// console.error("land:", land);
if (land.data.length) {
this.handleData(companys, land.data);
// 持久化到本地缓存中
this.setStorage(1, {
userId: this.userId,
data: this.list,
});
this.setStorage(2, this.selectItem);
} else {
commonUtils.toast("无数据");
// 持久化到本地缓存中
this.setStorage(1, null);
this.setStorage(2, null);
}
} else {
commonUtils.toast("无数据");
this.setStorage(1, null);
this.setStorage(2, null);
}
}
// 组织数据
handleData(companys, lands) {
let id = null;
let selectCId = null;
let selectItem = null;
const landItem = uni.getStorageSync(constant.landItem);
if (landItem) {
id = landItem.id;
}
const companyObj = companys.reduce((accumulator, current) => {
accumulator[current.id] = current;
return accumulator;
}, {});
let groups = {};
lands.map(item => {
let param = {
companyId: item.companyId,
companyName: companyObj[item.companyId] ? companyObj[item.companyId].label : "",
id: item.id,
name: item.landName,
landIcon: item.landIcon || '',
valueNum: item.valveNum,
controlFlag: item.controlFlag, //设备是否可控0是 1否
enableFlapValve: item.enableFlapValve == 0, //启用蝶阀
landManualOperation: item.landManualOperation == 0, //启用批量控制
mapContent: null,
isSelect: false
}
// 获取地图信息
if (item.landMap != null) {
param.mapContent = JSON.parse(decodeURIComponent(item.landMap.mapContent)) //地块地图 地图标点
}
// 判断是否当前选中的数据
if (param.id == id) {
param.isSelect = true;
selectItem = param;
}
// 判断公司是否已经分组,如果未分组,则添加分组
if (!groups[item.companyId]) {
groups[item.companyId] = [];
}
groups[item.companyId].push(param);
})
companys.forEach(item => {
item.children = groups[item.id] || [];
});
let index = 0;
while (!selectItem) {
if (companys[index].children.length) {
companys[index].isLoad = true;
companys[index].children[0].isSelect = true;
selectItem = companys[index].children[0];
}
}
this.selectCId = selectItem.companyId;
this.list = companys;
this.selectItem = selectItem;
}
// 缓存数据
setStorage(type, data) {
if (type == 1) {
uni.setStorageSync(constant.lands, data);
} else if (type == 2) {
uni.setStorageSync(constant.landItem, data);
} else {
commonUtils.toast("数据持久化异常");
}
}
}
export default land

View File

@ -4,7 +4,9 @@ import constant from './constant'
let storageKey = 'storage_data'
// 存储节点变量名
let storageNodeKeys = [constant.avatar, constant.name, constant.roles, constant.permissions]
let storageNodeKeys = [constant.avatar, constant.name, constant.roles, constant.permissions,
constant.username, constant.password, constant.rememberPassword, constant.company, constant.user
]
// 存储的数据
let storageData = uni.getStorageSync(storageKey) || {}