更新后台详情
This commit is contained in:
parent
a055e3538a
commit
4cea486fe0
|
@ -0,0 +1,294 @@
|
|||
<template>
|
||||
<div class="edit-popup">
|
||||
<popup
|
||||
ref="popupRef"
|
||||
:title="popupTitle"
|
||||
:async="true"
|
||||
width="550px"
|
||||
@confirm="handleSubmit"
|
||||
@close="handleClose"
|
||||
>
|
||||
<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-input v-model="formData.code" clearable placeholder="请输入设备编码" />
|
||||
</el-form-item>
|
||||
<el-form-item label="设备名称" prop="name">
|
||||
<el-input v-model="formData.name" clearable placeholder="请输入设备名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="设备类型" prop="type">
|
||||
<el-select class="flex-1" v-model="formData.type" clearable placeholder="请选择设备类型">
|
||||
<el-option
|
||||
v-for="(item, index) in dictData.device_type"
|
||||
:key="index"
|
||||
:label="item.name"
|
||||
:value="parseInt(item.value)"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="监测项" prop="monitor_item">
|
||||
<el-select class="flex-1" v-model="formData.monitor_item" multiple clearable placeholder="请选择设备监测项">
|
||||
<el-option
|
||||
v-for="(item, index) in dictData.monitor_item"
|
||||
:key="index"
|
||||
:label="item.name"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="设备状态" prop="status">
|
||||
<el-select class="flex-1" v-model="formData.status" clearable placeholder="请选择设备状态">
|
||||
<el-option
|
||||
v-for="(item, index) in dictData.device_status"
|
||||
:key="index"
|
||||
:label="item.name"
|
||||
:value="parseInt(item.value)"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="是否在线" prop="is_online">
|
||||
<el-select class="flex-1" v-model="formData.is_online" clearable placeholder="请选择是否在线">
|
||||
<el-option
|
||||
v-for="(item, index) in dictData.device_online_status"
|
||||
:key="index"
|
||||
:label="item.name"
|
||||
:value="parseInt(item.value)"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="是否绑定土地" prop="is_bind">
|
||||
<el-select class="flex-1" v-model="formData.is_bind" clearable placeholder="请选择是否绑定土地">
|
||||
<el-option
|
||||
v-for="(item, index) in dictData.device_bind_status"
|
||||
:key="index"
|
||||
:label="item.name"
|
||||
:value="parseInt(item.value)"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</popup>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup name="deviceEdit">
|
||||
import type { FormInstance } from 'element-plus'
|
||||
import Popup from '@/components/popup/index.vue'
|
||||
import { apiDeviceAdd, apiDeviceEdit, apiDeviceDetail, getUserList, apiProductLists} from '@/api/device'
|
||||
import { timeFormat } from '@/utils/util'
|
||||
import type { PropType } from 'vue'
|
||||
defineProps({
|
||||
dictData: {
|
||||
type: Object as PropType<Record<string, any[]>>,
|
||||
default: () => ({})
|
||||
}
|
||||
})
|
||||
const emit = defineEmits(['success', 'close'])
|
||||
const formRef = shallowRef<FormInstance>()
|
||||
const popupRef = shallowRef<InstanceType<typeof Popup>>()
|
||||
const mode = ref('add')
|
||||
|
||||
|
||||
// 弹窗标题
|
||||
const popupTitle = computed(() => {
|
||||
return mode.value == 'edit' ? '编辑设备' : '新增设备'
|
||||
})
|
||||
|
||||
// 表单数据
|
||||
const formData = reactive({
|
||||
id: '',
|
||||
user_id: '',
|
||||
product_id: '',
|
||||
code: '',
|
||||
name: '',
|
||||
type: '',
|
||||
monitor_item: '',
|
||||
status: '',
|
||||
is_online: '',
|
||||
is_bind: '',
|
||||
})
|
||||
|
||||
|
||||
// 表单验证
|
||||
const formRules = reactive<any>({
|
||||
user_id: [{
|
||||
required: true,
|
||||
message: '请输入用户ID',
|
||||
trigger: ['blur']
|
||||
}],
|
||||
product_id: [{
|
||||
required: true,
|
||||
message: '请输入产品id',
|
||||
trigger: ['blur']
|
||||
}],
|
||||
code: [{
|
||||
required: true,
|
||||
message: '请输入设备编码',
|
||||
trigger: ['blur']
|
||||
}],
|
||||
name: [{
|
||||
required: true,
|
||||
message: '请输入设备名称',
|
||||
trigger: ['blur']
|
||||
}],
|
||||
type: [{
|
||||
required: true,
|
||||
message: '请选择设备类型',
|
||||
trigger: ['blur']
|
||||
}],
|
||||
monitor_item: [{
|
||||
required: true,
|
||||
message: '请选择设备监测项',
|
||||
trigger: ['blur']
|
||||
}],
|
||||
status: [{
|
||||
required: true,
|
||||
message: '请选择设备状态',
|
||||
trigger: ['blur']
|
||||
}],
|
||||
is_online: [{
|
||||
required: true,
|
||||
message: '请选择是否在线',
|
||||
trigger: ['blur']
|
||||
}],
|
||||
is_bind: [{
|
||||
required: true,
|
||||
message: '请选择是否绑定土地',
|
||||
trigger: ['blur']
|
||||
}],
|
||||
})
|
||||
|
||||
|
||||
// 获取详情
|
||||
const setFormData = async (data: Record<any, any>) => {
|
||||
for (const key in formData) {
|
||||
if (data[key] != null && data[key] != undefined) {
|
||||
//@ts-ignore
|
||||
formData[key] = data[key]
|
||||
}
|
||||
}
|
||||
console.log(dictData.monitor_item)
|
||||
}
|
||||
|
||||
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 data = await apiDeviceDetail({
|
||||
id: row.id
|
||||
})
|
||||
setFormData(data)
|
||||
}
|
||||
|
||||
|
||||
// 提交按钮
|
||||
const handleSubmit = async () => {
|
||||
await formRef.value?.validate()
|
||||
const data = { ...formData, }
|
||||
mode.value == 'edit'
|
||||
? await apiDeviceEdit(data)
|
||||
: await apiDeviceAdd(data)
|
||||
popupRef.value?.close()
|
||||
emit('success')
|
||||
}
|
||||
|
||||
//打开弹窗
|
||||
const open = (type = 'add') => {
|
||||
mode.value = type
|
||||
popupRef.value?.open()
|
||||
}
|
||||
|
||||
// 关闭回调
|
||||
const handleClose = () => {
|
||||
emit('close')
|
||||
}
|
||||
|
||||
|
||||
|
||||
defineExpose({
|
||||
open,
|
||||
setFormData,
|
||||
getDetail
|
||||
})
|
||||
</script>
|
|
@ -96,20 +96,20 @@
|
|||
<el-table-column label="ID" prop="id" width="80" show-overflow-tooltip />
|
||||
<el-table-column label="用户信息" width="200">
|
||||
<template #default="{ row }">
|
||||
<el-tag class="mr-2">ID: {{ row.user_id }}</el-tag>
|
||||
<el-tag class="mr-2">账户: {{ row.account }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">ID: {{ row.user_id }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">账户: {{ row.account }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="土地信息" width="200">
|
||||
<template #default="{ row }">
|
||||
<el-tag class="mr-2">ID: {{ row.land_id }}</el-tag>
|
||||
<el-tag class="mr-2">名称: {{ row.land_title }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">ID: {{ row.land_id }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">名称: {{ row.land_title }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="产品信息" width="200">
|
||||
<template #default="{ row }">
|
||||
<el-tag class="mr-2">ID: {{ row.product_id }}</el-tag>
|
||||
<el-tag class="mr-2">名称: {{ row.product_name }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">ID: {{ row.product_id }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">名称: {{ row.product_name }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="设备编码" width="120" prop="code" show-overflow-tooltip />
|
||||
|
@ -139,7 +139,7 @@
|
|||
<span>{{ row.create_time ? timeFormat(row.create_time, 'yyyy-mm-dd hh:MM:ss') : '' }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="200" align="center" fixed="right">
|
||||
<el-table-column label="操作" width="260" align="center" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button
|
||||
v-perms="['device.device/edit']"
|
||||
|
@ -149,6 +149,22 @@
|
|||
>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
v-perms="['device.device/detail']"
|
||||
type="primary"
|
||||
link
|
||||
>
|
||||
<router-link
|
||||
:to="{
|
||||
path: getRoutePath('device.device/detail'),
|
||||
query: {
|
||||
device_id: row.id
|
||||
}
|
||||
}"
|
||||
>
|
||||
查看详情
|
||||
</router-link>
|
||||
</el-button>
|
||||
<el-button
|
||||
v-perms="['device.monitor_alarm/lists']"
|
||||
type="primary"
|
||||
|
|
|
@ -45,13 +45,13 @@
|
|||
<el-table-column label="ID" prop="id" width="80" show-overflow-tooltip />
|
||||
<el-table-column label="用户信息" width="200">
|
||||
<template #default="{ row }">
|
||||
<el-tag class="mr-2">ID: {{ row.user_id }}</el-tag>
|
||||
<el-tag class="mr-2">账户: {{ row.user.account }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">ID: {{ row.user_id }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">账户: {{ row.user.account }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="土地名称">
|
||||
<template #default="{ row }">
|
||||
<el-tag class="mr-2">{{ row.title }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">{{ row.title }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="土地面积" prop="total_area" show-overflow-tooltip />
|
||||
|
|
|
@ -52,14 +52,14 @@
|
|||
<el-table-column label="ID" prop="id" width="80" show-overflow-tooltip />
|
||||
<el-table-column label="用户信息" width="200">
|
||||
<template #default="{ row }">
|
||||
<el-tag class="mr-2">ID: {{ row.user_id }}</el-tag>
|
||||
<el-tag class="mr-2">账户: {{ row.account }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">ID: {{ row.user_id }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">账户: {{ row.account }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="土地信息" width="200">
|
||||
<template #default="{ row }">
|
||||
<el-tag class="mr-2">ID: {{ row.land_id }}</el-tag>
|
||||
<el-tag class="mr-2">名称: {{ row.title }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">ID: {{ row.land_id }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">名称: {{ row.title }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="种植种类" prop="kind" show-overflow-tooltip />
|
||||
|
|
|
@ -42,14 +42,14 @@
|
|||
<el-table-column label="ID" prop="id" width="80" show-overflow-tooltip />
|
||||
<el-table-column label="用户信息" width="200">
|
||||
<template #default="{ row }">
|
||||
<el-tag class="mr-2">ID: {{ row.user_id }}</el-tag>
|
||||
<el-tag class="mr-2">账户: {{ row.account }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">ID: {{ row.user_id }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">账户: {{ row.account }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="土地种植信息" width="200">
|
||||
<template #default="{ row }">
|
||||
<el-tag class="mr-2">ID: {{ row.plant_id }}</el-tag>
|
||||
<el-tag class="mr-2">类型: {{ row.kind }} 品牌: {{ row.breed }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">ID: {{ row.plant_id }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">类型: {{ row.kind }} 品牌: {{ row.breed }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="种植操作类型" align="center" prop="type">
|
||||
|
|
|
@ -39,8 +39,8 @@
|
|||
<el-table-column label="ID" prop="id" width="80" show-overflow-tooltip />
|
||||
<el-table-column label="设备信息" width="200">
|
||||
<template #default="{ row }">
|
||||
<el-tag class="mr-2">ID: {{ row.device_id }}</el-tag>
|
||||
<el-tag class="mr-2">名称: {{ row.device.name }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">ID: {{ row.device_id }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">名称: {{ row.device.name }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="监测类型" align="center" prop="type">
|
||||
|
|
|
@ -62,14 +62,14 @@
|
|||
<el-table-column label="ID" prop="id" width="80" show-overflow-tooltip />
|
||||
<el-table-column label="用户信息" width="200">
|
||||
<template #default="{ row }">
|
||||
<el-tag class="mr-2">ID: {{ row.user_id }}</el-tag>
|
||||
<el-tag class="mr-2">账户: {{ row.account }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">ID: {{ row.user_id }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">账户: {{ row.account }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="土地信息" width="200">
|
||||
<template #default="{ row }">
|
||||
<el-tag class="mr-2">ID: {{ row.land_id }}</el-tag>
|
||||
<el-tag class="mr-2">名称: {{ row.title }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">ID: {{ row.land_id }}</el-tag>
|
||||
<el-tag class="mr-2" effect="dark">名称: {{ row.title }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="产品编号" prop="code" show-overflow-tooltip />
|
||||
|
@ -84,7 +84,7 @@
|
|||
<span>{{ row.create_time ? timeFormat(row.create_time, 'yyyy-mm-dd hh:MM:ss') : '' }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="140" align="center" fixed="right">
|
||||
<el-table-column label="操作" width="200" align="center" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button
|
||||
v-perms="['land.product/edit']"
|
||||
|
@ -94,6 +94,18 @@
|
|||
>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button v-perms="['device.device/lists']" type="primary" link >
|
||||
<router-link
|
||||
:to="{
|
||||
path: getRoutePath('device.device/lists'),
|
||||
query: {
|
||||
product_id: row.id
|
||||
}
|
||||
}"
|
||||
>
|
||||
查看设备
|
||||
</router-link>
|
||||
</el-button>
|
||||
<el-button
|
||||
v-perms="['land.product/delete']"
|
||||
type="danger"
|
||||
|
@ -116,6 +128,7 @@
|
|||
|
||||
<script lang="ts" setup name="productLists">
|
||||
import { usePaging } from '@/hooks/usePaging'
|
||||
import { getRoutePath } from '@/router'
|
||||
import { useDictData } from '@/hooks/useDictOptions'
|
||||
import { apiProductLists, apiProductDelete } from '@/api/product'
|
||||
import { timeFormat } from '@/utils/util'
|
||||
|
|
Loading…
Reference in New Issue