更新设备管理
This commit is contained in:
parent
aa5958b3b8
commit
a424d10d91
|
@ -1,5 +1,15 @@
|
||||||
import request from '@/utils/request'
|
import request from '@/utils/request'
|
||||||
|
|
||||||
|
// 用户列表
|
||||||
|
export function getUserList(params: any) {
|
||||||
|
return request.get({ url: '/user.user/lists', params }, { ignoreCancelToken: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
// 产品列表列表
|
||||||
|
export function apiProductLists(params: any) {
|
||||||
|
return request.get({ url: '/land.product/lists', params })
|
||||||
|
}
|
||||||
|
|
||||||
// 监测设备列表
|
// 监测设备列表
|
||||||
export function apiDeviceLists(params: any) {
|
export function apiDeviceLists(params: any) {
|
||||||
return request.get({ url: '/device.device/lists', params })
|
return request.get({ url: '/device.device/lists', params })
|
||||||
|
|
|
@ -9,6 +9,42 @@
|
||||||
@close="handleClose"
|
@close="handleClose"
|
||||||
>
|
>
|
||||||
<el-form ref="formRef" :model="formData" label-width="120px" :rules="formRules">
|
<el-form ref="formRef" :model="formData" label-width="120px" :rules="formRules">
|
||||||
|
<el-form-item label="用户ID" prop="user_id">
|
||||||
|
<el-select
|
||||||
|
v-model="formData.user_id"
|
||||||
|
filterable
|
||||||
|
remote
|
||||||
|
reserve-keyword
|
||||||
|
placeholder="请输入用户信息"
|
||||||
|
:remote-method="queryUser"
|
||||||
|
:loading="loading"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="item in userOptions"
|
||||||
|
:key="item.value"
|
||||||
|
:label="item.label"
|
||||||
|
:value="item.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="产品ID" prop="product_id">
|
||||||
|
<el-select
|
||||||
|
v-model="formData.product_id"
|
||||||
|
filterable
|
||||||
|
remote
|
||||||
|
reserve-keyword
|
||||||
|
placeholder="请输入产品信息"
|
||||||
|
:remote-method="queryProduct"
|
||||||
|
:loading="loading"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="item in productOptions"
|
||||||
|
:key="item.value"
|
||||||
|
:label="item.label"
|
||||||
|
:value="item.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
<el-form-item label="设备编码" prop="code">
|
<el-form-item label="设备编码" prop="code">
|
||||||
<el-input v-model="formData.code" clearable placeholder="请输入设备编码" />
|
<el-input v-model="formData.code" clearable placeholder="请输入设备编码" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
@ -63,7 +99,7 @@
|
||||||
<script lang="ts" setup name="deviceEdit">
|
<script lang="ts" setup name="deviceEdit">
|
||||||
import type { FormInstance } from 'element-plus'
|
import type { FormInstance } from 'element-plus'
|
||||||
import Popup from '@/components/popup/index.vue'
|
import Popup from '@/components/popup/index.vue'
|
||||||
import { apiDeviceAdd, apiDeviceEdit, apiDeviceDetail } from '@/api/device'
|
import { apiDeviceAdd, apiDeviceEdit, apiDeviceDetail, getUserList, apiProductLists} from '@/api/device'
|
||||||
import { timeFormat } from '@/utils/util'
|
import { timeFormat } from '@/utils/util'
|
||||||
import type { PropType } from 'vue'
|
import type { PropType } from 'vue'
|
||||||
defineProps({
|
defineProps({
|
||||||
|
@ -86,6 +122,8 @@ const popupTitle = computed(() => {
|
||||||
// 表单数据
|
// 表单数据
|
||||||
const formData = reactive({
|
const formData = reactive({
|
||||||
id: '',
|
id: '',
|
||||||
|
user_id: '',
|
||||||
|
product_id: '',
|
||||||
code: '',
|
code: '',
|
||||||
name: '',
|
name: '',
|
||||||
type: '',
|
type: '',
|
||||||
|
@ -97,6 +135,16 @@ const formData = reactive({
|
||||||
|
|
||||||
// 表单验证
|
// 表单验证
|
||||||
const formRules = reactive<any>({
|
const formRules = reactive<any>({
|
||||||
|
user_id: [{
|
||||||
|
required: true,
|
||||||
|
message: '请输入用户ID',
|
||||||
|
trigger: ['blur']
|
||||||
|
}],
|
||||||
|
product_id: [{
|
||||||
|
required: true,
|
||||||
|
message: '请输入产品id',
|
||||||
|
trigger: ['blur']
|
||||||
|
}],
|
||||||
code: [{
|
code: [{
|
||||||
required: true,
|
required: true,
|
||||||
message: '请输入设备编码',
|
message: '请输入设备编码',
|
||||||
|
@ -138,10 +186,57 @@ const setFormData = async (data: Record<any, any>) => {
|
||||||
formData[key] = data[key]
|
formData[key] = data[key]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ListItem {
|
||||||
|
value: string
|
||||||
|
label: string
|
||||||
|
}
|
||||||
|
const productOptions = ref<ListItem[]>([])
|
||||||
|
const userOptions = ref<ListItem[]>([])
|
||||||
|
const loading = ref(false)
|
||||||
|
|
||||||
|
const queryUser = async (query: string) => {
|
||||||
|
if (query) {
|
||||||
|
loading.value = true
|
||||||
|
const userList = await getUserList({
|
||||||
|
keyword: query
|
||||||
|
})
|
||||||
|
loading.value = false
|
||||||
|
if (userList.count > 0) {
|
||||||
|
userOptions.value = userList.lists.map((user: any) => {
|
||||||
|
return { value: `${user.id}`, label: `ID: ${user.id} / 账户: ${user.account}` }
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
userOptions.value = []
|
||||||
|
}
|
||||||
|
loading.value = false
|
||||||
|
} else {
|
||||||
|
userOptions.value = []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const queryProduct = async (query: string) => {
|
||||||
|
if (query) {
|
||||||
|
loading.value = true
|
||||||
|
const productList = await apiProductLists({
|
||||||
|
name: query
|
||||||
|
})
|
||||||
|
loading.value = false
|
||||||
|
if (productList.count > 0) {
|
||||||
|
productOptions.value = productList.lists.map((product: any) => {
|
||||||
|
return { value: `${product.id}`, label: `ID: ${product.id} / 名称: ${product.name}` }
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
productOptions.value = []
|
||||||
|
}
|
||||||
|
loading.value = false
|
||||||
|
} else {
|
||||||
|
productOptions.value = []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const getDetail = async (row: Record<string, any>) => {
|
const getDetail = async (row: Record<string, any>) => {
|
||||||
const data = await apiDeviceDetail({
|
const data = await apiDeviceDetail({
|
||||||
id: row.id
|
id: row.id
|
||||||
|
|
|
@ -6,6 +6,12 @@
|
||||||
:model="queryParams"
|
:model="queryParams"
|
||||||
inline
|
inline
|
||||||
>
|
>
|
||||||
|
<el-form-item label="用户ID" prop="user_id">
|
||||||
|
<el-input class="w-[280px]" v-model="queryParams.user_id" clearable placeholder="请输入用户ID" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="产品ID" prop="product_id">
|
||||||
|
<el-input class="w-[280px]" v-model="queryParams.product_id" clearable placeholder="请输入产品ID" />
|
||||||
|
</el-form-item>
|
||||||
<el-form-item label="设备编码" prop="code">
|
<el-form-item label="设备编码" prop="code">
|
||||||
<el-input class="w-[280px]" v-model="queryParams.code" clearable placeholder="请输入设备编码" />
|
<el-input class="w-[280px]" v-model="queryParams.code" clearable placeholder="请输入设备编码" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
@ -63,14 +69,36 @@
|
||||||
</el-form>
|
</el-form>
|
||||||
</el-card>
|
</el-card>
|
||||||
<el-card class="!border-none" v-loading="pager.loading" shadow="never">
|
<el-card class="!border-none" v-loading="pager.loading" shadow="never">
|
||||||
|
<el-button v-perms="['device.device/add']" type="primary" @click="handleAdd">
|
||||||
|
<template #icon>
|
||||||
|
<icon name="el-icon-Plus" />
|
||||||
|
</template>
|
||||||
|
新增
|
||||||
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
v-perms="['device.device/delete']"
|
||||||
|
:disabled="!selectData.length"
|
||||||
|
@click="handleDelete(selectData)"
|
||||||
|
>
|
||||||
|
删除
|
||||||
|
</el-button>
|
||||||
<div class="mt-4">
|
<div class="mt-4">
|
||||||
<el-table :data="pager.lists" @selection-change="handleSelectionChange">
|
<el-table :data="pager.lists" @selection-change="handleSelectionChange" style="width: 100%">
|
||||||
<el-table-column type="selection" width="55" />
|
<el-table-column type="selection" width="55" />
|
||||||
<el-table-column label="ID" prop="id" show-overflow-tooltip />
|
<el-table-column label="ID" prop="id" show-overflow-tooltip />
|
||||||
|
<el-table-column label="用户信息" width="200">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-tag class="mr-2" type="success">ID: {{ row.user_id }}</el-tag>
|
||||||
|
<el-tag class="mr-2" type="success">账户: {{ row.user_id }}</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="产品信息">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-tag class="mr-2" type="success">{{ row.user_id }}</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
<el-table-column label="设备编码" prop="code" show-overflow-tooltip />
|
<el-table-column label="设备编码" prop="code" show-overflow-tooltip />
|
||||||
<el-table-column label="设备名称" prop="name" show-overflow-tooltip />
|
<el-table-column label="设备名称" prop="name" show-overflow-tooltip />
|
||||||
<el-table-column label="土地ID" prop="land_id" show-overflow-tooltip />
|
|
||||||
<el-table-column label="土地名称" prop="title" show-overflow-tooltip />
|
|
||||||
<el-table-column label="设备类型" prop="type">
|
<el-table-column label="设备类型" prop="type">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<dict-value :options="dictData.device_type" :value="row.type" />
|
<dict-value :options="dictData.device_type" :value="row.type" />
|
||||||
|
@ -191,19 +219,26 @@ import { timeFormat } from '@/utils/util'
|
||||||
import feedback from '@/utils/feedback'
|
import feedback from '@/utils/feedback'
|
||||||
import EditPopup from './edit.vue'
|
import EditPopup from './edit.vue'
|
||||||
|
|
||||||
|
const { query } = useRoute()
|
||||||
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
|
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
|
||||||
// 是否显示编辑框
|
// 是否显示编辑框
|
||||||
const showEdit = ref(false)
|
const showEdit = ref(false)
|
||||||
|
|
||||||
|
let product_id = query.product_id
|
||||||
|
if (typeof product_id == 'undefined') {
|
||||||
|
product_id = ''
|
||||||
|
}
|
||||||
|
|
||||||
// 查询条件
|
// 查询条件
|
||||||
const queryParams = reactive({
|
const queryParams = reactive({
|
||||||
|
user_id: '',
|
||||||
|
product_id: product_id,
|
||||||
code: '',
|
code: '',
|
||||||
name: '',
|
name: '',
|
||||||
type: '',
|
type: '',
|
||||||
status: '',
|
status: '',
|
||||||
is_online: '',
|
is_online: '',
|
||||||
is_bind: '',
|
is_bind: ''
|
||||||
})
|
})
|
||||||
|
|
||||||
// 选中数据
|
// 选中数据
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
删除
|
删除
|
||||||
</el-button>
|
</el-button>
|
||||||
<div class="mt-4">
|
<div class="mt-4">
|
||||||
<el-table :data="pager.lists" @selection-change="handleSelectionChange">
|
<el-table :data="pager.lists" @selection-change="handleSelectionChange" style="width: 100%">
|
||||||
<el-table-column type="selection" width="55" />
|
<el-table-column type="selection" width="55" />
|
||||||
<el-table-column label="ID" prop="id" width="80" show-overflow-tooltip />
|
<el-table-column label="ID" prop="id" width="80" show-overflow-tooltip />
|
||||||
<el-table-column label="用户信息" width="200">
|
<el-table-column label="用户信息" width="200">
|
||||||
|
|
|
@ -38,7 +38,8 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||||
public function setSearch(): array
|
public function setSearch(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'=' => ['p.user_id', 'p.code', 'p.name', 'p.status'],
|
'%like%' => ['p.name'],
|
||||||
|
'=' => ['p.user_id', 'p.code', 'p.status'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ class DeviceLogic extends BaseLogic
|
||||||
{
|
{
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
Device::create([
|
$device = Device::create([
|
||||||
'code' => $params['code'],
|
'code' => $params['code'],
|
||||||
'name' => $params['name'],
|
'name' => $params['name'],
|
||||||
'type' => $params['type'],
|
'type' => $params['type'],
|
||||||
|
@ -48,7 +48,13 @@ class DeviceLogic extends BaseLogic
|
||||||
'is_online' => $params['is_online'],
|
'is_online' => $params['is_online'],
|
||||||
'is_bind' => $params['is_bind'],
|
'is_bind' => $params['is_bind'],
|
||||||
]);
|
]);
|
||||||
|
Db::name('product_device')->insert([
|
||||||
|
'product_id' => $params['product_id'],
|
||||||
|
'device_id' => $device['id'],
|
||||||
|
'device_type' => $params['type'],
|
||||||
|
'create_time' => time(),
|
||||||
|
'update_time' => time()
|
||||||
|
]);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -70,7 +76,7 @@ class DeviceLogic extends BaseLogic
|
||||||
{
|
{
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
Device::where('id', $params['id'])->update([
|
$device = Device::where('id', $params['id'])->update([
|
||||||
'code' => $params['code'],
|
'code' => $params['code'],
|
||||||
'name' => $params['name'],
|
'name' => $params['name'],
|
||||||
'type' => $params['type'],
|
'type' => $params['type'],
|
||||||
|
@ -78,7 +84,14 @@ class DeviceLogic extends BaseLogic
|
||||||
'is_online' => $params['is_online'],
|
'is_online' => $params['is_online'],
|
||||||
'is_bind' => $params['is_bind'],
|
'is_bind' => $params['is_bind'],
|
||||||
]);
|
]);
|
||||||
|
Db::name('product_device')->where('device_id', $params['id'])->delete();
|
||||||
|
Db::name('product_device')->insert([
|
||||||
|
'product_id' => $params['product_id'],
|
||||||
|
'device_id' => $params['id'],
|
||||||
|
'device_type' => $params['type'],
|
||||||
|
'create_time' => time(),
|
||||||
|
'update_time' => time()
|
||||||
|
]);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace app\adminapi\validate\land;
|
||||||
|
|
||||||
|
|
||||||
use app\common\validate\BaseValidate;
|
use app\common\validate\BaseValidate;
|
||||||
|
use think\facade\Db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Product验证器
|
* Product验证器
|
||||||
|
@ -84,7 +84,7 @@ class ProductValidate extends BaseValidate
|
||||||
*/
|
*/
|
||||||
public function sceneDelete()
|
public function sceneDelete()
|
||||||
{
|
{
|
||||||
return $this->only(['id']);
|
return $this->only(['id'])->append('id', 'require|checkProduct');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -99,4 +99,13 @@ class ProductValidate extends BaseValidate
|
||||||
return $this->only(['id']);
|
return $this->only(['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function checkProduct($value, $rule, $data)
|
||||||
|
{
|
||||||
|
$productDevice = Db::name('product_device')->where('product_id', $value)->findOrEmpty();
|
||||||
|
if (!empty($productDevice)) {
|
||||||
|
return '存在关联设备,无法删除';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue