mirror of
https://github.com/kerwincui/FastBee.git
synced 2025-10-07 09:01:53 +08:00
分享单个或全部设备功能实现,用户设备列表接口调整,新增别人分享给自己的设备
This commit is contained in:
@@ -10,9 +10,9 @@ export function listDeviceUser(query) {
|
||||
}
|
||||
|
||||
// 查询设备用户详细
|
||||
export function getDeviceUser(deviceId) {
|
||||
export function getDeviceUser(deviceId, userId) {
|
||||
return request({
|
||||
url: '/iot/deviceUser/' + deviceId,
|
||||
url: '/iot/deviceUser/' + deviceId + '/' + userId,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
@@ -26,6 +26,15 @@ export function addDeviceUser(data) {
|
||||
})
|
||||
}
|
||||
|
||||
// 新增多个设备用户
|
||||
export function addDeviceUsers(data) {
|
||||
return request({
|
||||
url: '/iot/deviceUser/addDeviceUsers',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 修改设备用户
|
||||
export function updateDeviceUser(data) {
|
||||
return request({
|
||||
@@ -36,9 +45,10 @@ export function updateDeviceUser(data) {
|
||||
}
|
||||
|
||||
// 删除设备用户
|
||||
export function delDeviceUser(deviceId) {
|
||||
export function delDeviceUser(device) {
|
||||
return request({
|
||||
url: '/iot/deviceUser/' + deviceId,
|
||||
method: 'delete'
|
||||
url: '/iot/deviceUser',
|
||||
method: 'delete',
|
||||
data: device
|
||||
})
|
||||
}
|
||||
|
@@ -108,12 +108,12 @@
|
||||
<device-timer ref="deviceTimer" :device="form" />
|
||||
</el-tab-pane>
|
||||
|
||||
<!--
|
||||
|
||||
<el-tab-pane name="deviceUser" :disabled="form.deviceId==0">
|
||||
<span slot="label">设备用户</span>
|
||||
<device-user ref="deviceUser" :device="form" @userEvent="getUserData($event)" />
|
||||
</el-tab-pane>
|
||||
-->
|
||||
|
||||
|
||||
<el-tab-pane name="deviceLog" :disabled="form.deviceId==0">
|
||||
<span slot="label">设备日志</span>
|
||||
|
@@ -3,6 +3,7 @@
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="selectUser" v-hasPermi="['iot:deviceUser:add']">分享设备</el-button>
|
||||
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="selectUserShareAllDevice" v-hasPermi="['iot:deviceUser:add']">分享所有设备</el-button>
|
||||
</el-col>
|
||||
<right-toolbar @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
@@ -43,7 +44,7 @@
|
||||
</el-dialog>
|
||||
|
||||
<!-- 选择用户 -->
|
||||
<user-list ref="userList" :device="device" />
|
||||
<user-list ref="userList" :device="devices" />
|
||||
|
||||
</div>
|
||||
</template>
|
||||
@@ -56,6 +57,9 @@ import {
|
||||
delDeviceUser,
|
||||
updateDeviceUser
|
||||
} from "@/api/iot/deviceuser";
|
||||
import {
|
||||
listDeviceShort,
|
||||
} from "@/api/iot/device";
|
||||
|
||||
export default {
|
||||
name: "device-user",
|
||||
@@ -73,6 +77,7 @@ export default {
|
||||
// 获取到父组件传递的device后,刷新列表
|
||||
device: function (newVal, oldVal) {
|
||||
this.deviceInfo = newVal;
|
||||
this.devices = [newVal];
|
||||
if (this.deviceInfo && this.deviceInfo.deviceId != 0) {
|
||||
this.queryParams.deviceId = this.deviceInfo.deviceId;
|
||||
this.getList();
|
||||
@@ -81,6 +86,8 @@ export default {
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
// 设备列表
|
||||
devices: [],
|
||||
// 遮罩层
|
||||
loading: true,
|
||||
// 选中数组
|
||||
@@ -189,7 +196,7 @@ export default {
|
||||
handleUpdate(row) {
|
||||
this.reset();
|
||||
const deviceId = row.deviceId || this.ids
|
||||
getDeviceUser(deviceId).then(response => {
|
||||
getDeviceUser(deviceId, row.userId).then(response => {
|
||||
this.form = response.data;
|
||||
this.open = true;
|
||||
this.title = "用户备注";
|
||||
@@ -207,9 +214,9 @@ export default {
|
||||
},
|
||||
/** 删除按钮操作 */
|
||||
handleDelete(row) {
|
||||
const deviceIds = row.deviceId || this.ids;
|
||||
this.$modal.confirm('是否确认删除设备用户编号为"' + deviceIds + '"的数据项?').then(function () {
|
||||
return delDeviceUser(deviceIds);
|
||||
const deviceUser = row;
|
||||
this.$modal.confirm('是否确认删除设备用户编号为"' + deviceUser.deviceId + "-" + deviceUser.userId + '"的数据项?').then(function () {
|
||||
return delDeviceUser(deviceUser);
|
||||
}).then(() => {
|
||||
this.getList();
|
||||
this.$modal.msgSuccess("删除成功");
|
||||
@@ -223,8 +230,24 @@ export default {
|
||||
},
|
||||
// 选择用户
|
||||
selectUser() {
|
||||
this.devices = [this.device]
|
||||
this.$refs.userList.openSelectUser = true;
|
||||
},
|
||||
selectUserShareAllDevice() {
|
||||
this.loading = true;
|
||||
// 获取设备列表
|
||||
// 判断是否是admin角色
|
||||
if (this.$store.state.user.roles.indexOf("admin") === -1) {
|
||||
this.queryParams.userName = this.$store.state.user.name
|
||||
}
|
||||
listDeviceShort(this.queryParams).then(response => {
|
||||
let deviceList = response.rows;
|
||||
this.devices = deviceList
|
||||
this.loading = false;
|
||||
this.$refs.userList.openSelectUser = true;
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<el-dialog title="选择产品" :visible.sync="openSelectUser" width="800px">
|
||||
<el-dialog title="选择用户" :visible.sync="openSelectUser" width="800px">
|
||||
<div style="margin-top:-50px;">
|
||||
<el-divider></el-divider>
|
||||
</div>
|
||||
@@ -41,13 +41,14 @@ import {
|
||||
} from "@/api/system/user";
|
||||
import {
|
||||
addDeviceUser,
|
||||
addDeviceUsers,
|
||||
} from "@/api/iot/deviceuser";
|
||||
|
||||
export default {
|
||||
name: "user-list",
|
||||
props: {
|
||||
device: {
|
||||
type: Object,
|
||||
type: Array,
|
||||
default: null
|
||||
}
|
||||
},
|
||||
@@ -148,19 +149,42 @@ export default {
|
||||
},
|
||||
// 添加设备用户
|
||||
addDeviceUser() {
|
||||
if (this.deviceInfo.deviceId != null) {
|
||||
var form = {};
|
||||
form.deviceId = this.deviceInfo.deviceId;
|
||||
form.deviceName = this.deviceInfo.deviceName;
|
||||
form.userId = this.user.userId;
|
||||
form.userName = this.user.userName;
|
||||
form.phonenumber=this.user.phonenumber;
|
||||
addDeviceUser(form).then(response => {
|
||||
this.$modal.msgSuccess("新增成功");
|
||||
this.resetQuery();
|
||||
this.openSelectUser = false;
|
||||
this.$parent.getList();
|
||||
});
|
||||
if (this.deviceInfo != null && this.deviceInfo.length > 0 && this.user != null) {
|
||||
if (this.deviceInfo.length == 1) {
|
||||
var form = {};
|
||||
form.deviceId = this.deviceInfo[0].deviceId;
|
||||
form.deviceName = this.deviceInfo[0].deviceName;
|
||||
form.userId = this.user.userId;
|
||||
form.userName = this.user.userName;
|
||||
form.phonenumber=this.user.phonenumber;
|
||||
addDeviceUser(form).then(response => {
|
||||
this.$modal.msgSuccess("新增成功");
|
||||
this.resetQuery();
|
||||
this.openSelectUser = false;
|
||||
this.$parent.getList();
|
||||
});
|
||||
} else {
|
||||
var form = [];
|
||||
this.deviceInfo.forEach(device => {
|
||||
let data = {};
|
||||
data.deviceId = device.deviceId;
|
||||
data.deviceName = device.deviceName
|
||||
data.userId = this.user.userId;
|
||||
data.userName = this.user.userName;
|
||||
data.phonenumber=this.user.phonenumber;
|
||||
form.push(data);
|
||||
});
|
||||
|
||||
addDeviceUsers(form).then(response => {
|
||||
this.$modal.msgSuccess("新增成功");
|
||||
this.resetQuery();
|
||||
this.openSelectUser = false;
|
||||
this.$parent.getList();
|
||||
});
|
||||
|
||||
}
|
||||
} else {
|
||||
this.openSelectUser = false;
|
||||
}
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user