添加设备权限

This commit is contained in:
jsy_zjg 2024-11-25 10:37:57 +08:00
parent 495b0fcefc
commit 74f7c83242
2 changed files with 249 additions and 214 deletions

View File

@ -10,13 +10,8 @@
</template>
<view class="tips">
<text style="color: red">注意</text>
<text>1.选中的开关为没有控制权限;</text>
<text> 2.不建议选择全关按钮;</text>
<text>1.选中的开关为有控制权限;</text>
<view style="float: right;margin-right: 15px;border: 1px solid;">
<!-- <u-checkbox-group class="checkBox" style="margin: 0;" iconPlacement="left" placement="row"
@change="handleChangeAll">
<u-checkbox activeColor="#35842E" label="全选" :checked="false" name="all"></u-checkbox>
</u-checkbox-group> -->
<u-button style="height: 25px;" type="primary" size="small" :plain="true" :hairline="true"
@click="handleChangeAll">
{{ selectAll ? '反选':'全选' }}
@ -24,7 +19,48 @@
</view>
</view>
<template #cell="{ item }">
<work-user-ground-device-item :item="item" @onCheckBoxChange="onCheckBoxChange" />
<view class="item-container">
<view class="flex-text" style="padding: 10px;">
<view class="flex-text-one">出水口</view>
<view>
<text>{{ item.waterOutletName }}</text>
<text style="font-size: 14px">{{ ` ${item.deviceCode}` }}</text>
</view>
<view style="margin-left: 50px;height: 25px;">
<u-checkbox-group class="checkBox" style="margin: 0;" iconPlacement="left" placement="row"
@change="handleChangeRow">
<u-checkbox activeColor="#35842E" label="全选"
:checked="item.valveClose && item.valveOpen && item.valveOneOpen && item.valveTwoOpen"
name="all"></u-checkbox>
</u-checkbox-group>
</view>
</view>
<u-gap height="1" bgColor="#D2D2D2"></u-gap>
<view v-if="item.deviceTypeId == 2 || item.deviceTypeId == 3">
<u-checkbox-group class="checkBox" iconPlacement="left" placement="row" @change="handleChange">
<u-checkbox activeColor="#35842E" label="全关" :checked="item.valveClose"
name="valveClose"></u-checkbox>
<u-checkbox activeColor="#35842E" label="全开" :checked="item.valveOpen"
name="valveOpen"></u-checkbox>
<u-checkbox activeColor="#35842E" label="①开 " :checked="item.valveOneOpen"
name="valveOneOpen"></u-checkbox>
<u-checkbox activeColor="#35842E" label="②开" :checked="item.valveTwoOpen"
name="valveTwoOpen"></u-checkbox>
</u-checkbox-group>
</view>
<view v-if="item.deviceTypeId == 13">
<u-checkbox-group class="checkBox" iconPlacement="left" placement="row" @change="handleChange">
<u-checkbox activeColor="#35842E" label="①开" :checked="item.valveOneOpen"
name="valveOneOpen"></u-checkbox>
<u-checkbox activeColor="#35842E" label="②开" :checked="item.valveTwoOpen"
name="valveTwoOpen"></u-checkbox>
<u-checkbox activeColor="#35842E" label="③开 " :checked="item.valveThreeOpen"
name="valveThreeOpen"></u-checkbox>
<u-checkbox activeColor="#35842E" label="④开" :checked="item.valveFourOpen"
name="valveFourOpen"></u-checkbox>
</u-checkbox-group>
</view>
</view>
</template>
<template #bottom>
<view class="button">
@ -36,226 +72,203 @@
</view>
</template>
<script setup>
import {
ref
} from "vue"
import {
onShow,
onLoad,
onReady
} from "@dcloudio/uni-app"
<script>
import store from "@/store"
import plugin from "@/plugins"
import storage from "@/utils/storage"
const landId = ref(0)
const dataList = ref([])
const tempList = ref([])
const tempValveData = ref({
valveClose: true,
valveOneOpen: true,
valveOpen: true,
valveTwoOpen: true,
valveThreeOpen: true,
valveFourOpen: true
})
const selectAll = ref(false)
const paging = ref(null)
const query = ref({
landId: 0,
deviceCode: null,
userId: 0
})
const disabled = ref(false)
onLoad(res => {
landId.value = res.landId
query.value.landId = res.landId
query.value.userId = res.userId
})
onShow(() => {
// if (paging.value != null) {
// paging.value.reload()
// }
})
//
function queryList() {
// plugin.modal.loading("...")
dataList.value = []
tempList.value = []
if (query.value.deviceCode == null || query.value.deviceCode == "") {
delete query.value["deviceCode"]
}
//
store
.dispatch("onGetUserControlList", query.value)
.then(res => {
let data = res.data[0].valveControls;
// console.error("data:", data);
if (data && data.length) {
data.forEach(item => {
let sortArr = item.waterOutletName.split("-");
switch (sortArr.length) {
case 0:
sortArr = [0, 0, 0, 0];
break;
case 1:
sortArr = sortArr.concat([0, 0, 0]);
break;
case 2:
sortArr = sortArr.concat([0, 0]);
break;
case 3:
sortArr = sortArr.concat([0]);
break;
}
item.sortArr = sortArr;
});
data = data.sort(compareData());
} else {
data = [];
plugin.modal.msg("该地块还没有安装或绑定阀门!")
export default {
data() {
return {
landId: null,
dataList: [],
tempList: [],
tempValveData: {
valveClose: true,
valveOneOpen: true,
valveOpen: true,
valveTwoOpen: true,
valveThreeOpen: true,
valveFourOpen: true
},
selectAll: false,
query: {
landId: 0,
deviceCode: null,
userId: 0
},
disabled: false
}
},
created() {
this.avatar = avatar;
},
onLoad(options) {
this.landId = options.landId
this.query.landId = options.landId
this.query.userId = options.userId
this.queryList();
},
onShow() {
if (this.userInfo) {
this.query.userId = this.userInfo.userId;
}
},
methods: {
queryList() {
if (!this.query.userId) {
return;
}
dataList.value = data;
paging.value.complete(dataList.value)
})
.catch(error => {
paging.value.complete([])
plugin.modal.msgError(error)
})
.finally(() => {
plugin.modal.closeLoading()
})
}
//
function compareData() {
return function(b, a) {
if (b.sortArr[0] < a.sortArr[0]) {
return -1;
} else if (b.sortArr[0] > a.sortArr[0]) {
return 1;
} else {
if (b.sortArr[1] < a.sortArr[1]) {
return -1;
} else if (b.sortArr[1] > a.sortArr[1]) {
return 1;
} else {
if (b.sortArr[2] < a.sortArr[2]) {
this.dataList = []
this.tempList = []
if (this.query.deviceCode == null || this.query.deviceCode == "") {
delete this.query["deviceCode"]
}
//
store
.dispatch("onGetUserControlList", this.query)
.then(res => {
let data = res.data[0].valveControls;
if (data && data.length) {
data.forEach(item => {
let sortArr = item.waterOutletName.split("-");
switch (sortArr.length) {
case 0:
sortArr = [0, 0, 0, 0];
break;
case 1:
sortArr = sortArr.concat([0, 0, 0]);
break;
case 2:
sortArr = sortArr.concat([0, 0]);
break;
case 3:
sortArr = sortArr.concat([0]);
break;
}
item.sortArr = sortArr;
});
data = data.sort(compareData());
} else {
data = [];
plugin.modal.msg("该地块还没有安装或绑定阀门!")
}
this.dataList= data;
this.$refs.paging.complete(dataList.value)
})
.catch(error => {
this.$refs.paging.complete([])
plugin.modal.msgError(error)
})
.finally(() => {
plugin.modal.closeLoading()
})
},
onSearchValue(e) {
this.query.landName = e;
this.queryList();
},
onClickPermission(item) {
plugin.tab.navigateTo(`/pages/work/user/device?landId=${item.landId}&userId=${item.userId}`)
},
//
compareData() {
return function(b, a) {
if (b.sortArr[0] < a.sortArr[0]) {
return -1;
} else if (b.sortArr[2] > a.sortArr[2]) {
} else if (b.sortArr[0] > a.sortArr[0]) {
return 1;
} else {
if (b.sortArr[3] < a.sortArr[3]) {
if (b.sortArr[1] < a.sortArr[1]) {
return -1;
} else if (b.sortArr[3] > a.sortArr[3]) {
} else if (b.sortArr[1] > a.sortArr[1]) {
return 1;
} else {
return 0;
if (b.sortArr[2] < a.sortArr[2]) {
return -1;
} else if (b.sortArr[2] > a.sortArr[2]) {
return 1;
} else {
if (b.sortArr[3] < a.sortArr[3]) {
return -1;
} else if (b.sortArr[3] > a.sortArr[3]) {
return 1;
} else {
return 0;
}
}
}
}
}
},
//
submit() {
let queryData = {
addValveControl: this.tempList
}
plugin.modal.loading("设置中...")
this.disabled = true;
//
store
.dispatch("onSetUserControlList", queryData)
.then(res => {
plugin.modal.msgSuccess("设置成功!")
//
this.queryList();
})
.catch(error => {
plugin.modal.msgError(error)
this.disabled = false;
})
.finally(() => {
plugin.modal.closeLoading()
this.disabled = false;
})
},
//
handleChangeAll() {
this.selectAll = !this.selectAll;
this.tempList = [];
this.dataList.forEach(item => {
if (item.deviceTypeId == 2 || item.deviceTypeId == 3) {
item.valveClose = this.selectAll;
item.valveOpen = this.selectAll;
item.valveOneOpen = this.selectAll;
item.valveTwoOpen = this.selectAll;
item.valveThreeOpen = false;
item.valveFourOpen = false;
}
if (item.deviceTypeId == 13) {
item.valveClose = false;
item.valveOpen = false;
item.valveOneOpen = this.selectAll;
item.valveTwoOpen = this.selectAll;
item.valveThreeOpen = this.selectAll;
item.valveFourOpen = this.selectAll;
}
this.tempList.push(item);
});
},
//
onCheckBoxChange(param) {
let index = this.tempList.findIndex(x => x.id == param.item.id && x.userId == param.item.userId && x
.deviceId == param.item.deviceId)
if (index != -1) {
this.tempList.splice(index, 1);
}
let itemSample = this.judgeValue(param.item, param.checkItem);
this.tempList.push(itemSample);
},
//
judgeValue(itemSample, param) {
itemSample.valveClose = param.indexOf("valveClose") > -1 ? true : false
itemSample.valveOpen = param.indexOf("valveOpen") > -1 ? true : false
itemSample.valveOneOpen = param.indexOf("valveOneOpen") > -1 ? true : false
itemSample.valveTwoOpen = param.indexOf("valveTwoOpen") > -1 ? true : false
itemSample.valveThreeOpen = param.indexOf("valveThreeOpen") > -1 ? true : false
itemSample.valveFourOpen = param.indexOf("valveFourOpen") > -1 ? true : false
return itemSample
}
}
}
//
function onSearchValue(keyword) {
query.value.deviceCode = keyword
paging.value.reload()
}
//
function submit() {
// if (tempList.value.length < 1) {
// plugin.modal.msg("!")
// return
// }
let queryData = {
addValveControl: tempList.value
}
plugin.modal.loading("设置中...")
disabled.value = true;
//
store
.dispatch("onSetUserControlList", queryData)
.then(res => {
plugin.modal.msgSuccess("设置成功!")
//
queryList();
// queryList(1, 10, "")
})
.catch(error => {
plugin.modal.msgError(error)
disabled.value = false;
})
.finally(() => {
plugin.modal.closeLoading()
disabled.value = false;
})
}
//
function handleChangeAll() {
selectAll.value = !selectAll.value;
tempList.value = [];
dataList.value.forEach(item => {
if (item.deviceTypeId == 2 || item.deviceTypeId == 3) {
item.valveClose = selectAll.value;
item.valveOpen = selectAll.value;
item.valveOneOpen = selectAll.value;
item.valveTwoOpen = selectAll.value;
item.valveThreeOpen = false;
item.valveFourOpen = false;
}
if (item.deviceTypeId == 13) {
item.valveClose = false;
item.valveOpen = false;
item.valveOneOpen = selectAll.value;
item.valveTwoOpen = selectAll.value;
item.valveThreeOpen = selectAll.value;
item.valveFourOpen = selectAll.value;
}
tempList.value.push(item);
});
}
//
function onCheckBoxChange(param) {
console.log(param)
let index = tempList.value.findIndex(x => x.id == param.item.id && x.userId == param.item.userId && x.deviceId ==
param.item.deviceId)
if (index != -1) {
tempList.value.splice(index, 1);
}
let itemSample = judgeValue(param.item, param.checkItem);
tempList.value.push(itemSample);
// //
// //
// let item = tempList.value.filter(res => {
// return res.id == param.itemId
// })
// //
// itemSample = judgeValue(itemSample, param)
// //
// if (!item.length) {
// tempList.value.push(itemSample)
// } else {
// //
// tempList.value = tempList.value.filter(res => {
// return res.itemId != param.itemId
// })
// tempList.value.push(itemSample)
// }
}
//
function judgeValue(itemSample, param) {
itemSample.valveClose = param.indexOf("valveClose") > -1 ? true : false
itemSample.valveOpen = param.indexOf("valveOpen") > -1 ? true : false
itemSample.valveOneOpen = param.indexOf("valveOneOpen") > -1 ? true : false
itemSample.valveTwoOpen = param.indexOf("valveTwoOpen") > -1 ? true : false
itemSample.valveThreeOpen = param.indexOf("valveThreeOpen") > -1 ? true : false
itemSample.valveFourOpen = param.indexOf("valveFourOpen") > -1 ? true : false
return itemSample
}
</script>
<style lang="scss" scoped>
@ -295,6 +308,30 @@
display: flex;
background: white;
}
.item-container {
margin-top: 10px;
background-color: white;
padding-bottom: 10px;
}
.flex-text {
display: flex;
align-items: center;
font-size: 16px;
.flex-text-one {
color: #939393;
font-weight: bold;
}
}
.checkBox {
// margin: 20px 0px;
margin: 10px 0px 0px 0px;
display: flex;
justify-content: space-around;
}
}
.tips {

View File

@ -74,7 +74,6 @@ export default {
onShow() {
if(this.userInfo){
this.query.userId = this.userInfo.userId;
}
},
methods: {
@ -112,7 +111,6 @@ export default {
}
}
</script>
<style lang="stylus">
.index-container{
background-color: #F6F3F3;