<template>
|
<div class="app-container">
|
<el-row :gutter="20">
|
<el-col :span="24">
|
<el-form :model="queryParams" ref="queryFormRef" :inline="true" v-show="showSearch" label-width="68px">
|
<el-form-item label="空调名称" prop="name">
|
<el-input
|
v-model="queryParams.name"
|
placeholder="请输入空调名称"
|
clearable
|
@keyup.enter="handleQuery"
|
/>
|
</el-form-item>
|
<el-form-item label="安装位置" prop="location">
|
<el-input
|
v-model="queryParams.location"
|
placeholder="请输入安装位置"
|
clearable
|
@keyup.enter="handleQuery"
|
/>
|
</el-form-item>
|
<el-form-item label="状态" prop="status">
|
<el-select v-model="queryParams.status" placeholder="空调状态" clearable>
|
<el-option
|
v-for="dict in statusOptions"
|
:key="dict.label"
|
:label="dict.label"
|
:value="dict.label"
|
/>
|
</el-select>
|
</el-form-item>
|
<el-form-item>
|
<el-button type="primary" :icon="Search" @click="handleQuery">搜索</el-button>
|
<el-button :icon="Refresh" @click="resetQuery">重置</el-button>
|
</el-form-item>
|
</el-form>
|
|
<el-row :gutter="10" class="mb8">
|
<el-col :span="1.5">
|
<el-button
|
type="primary"
|
plain
|
:icon="Plus"
|
@click="handleAdd"
|
v-hasPermi="['system:airconditioner:add']"
|
>新增</el-button>
|
</el-col>
|
<el-col :span="1.5">
|
<el-button
|
type="success"
|
plain
|
:icon="Edit"
|
:disabled="single"
|
@click="handleUpdate"
|
v-hasPermi="['system:airconditioner:edit']"
|
>修改</el-button>
|
</el-col>
|
<el-col :span="1.5">
|
<el-button
|
type="danger"
|
plain
|
:icon="Delete"
|
:disabled="multiple"
|
@click="handleDelete"
|
v-hasPermi="['system:airconditioner:remove']"
|
>删除</el-button>
|
</el-col>
|
<right-toolbar v-model:show-search="showSearch" @queryTable="getList"></right-toolbar>
|
</el-row>
|
|
<el-table v-loading="loading" :data="airConditionerList" @selection-change="handleSelectionChange">
|
<el-table-column type="selection" width="55" align="center" />
|
<el-table-column label="空调ID" align="center" prop="id" />
|
<el-table-column label="空调名称" align="center" prop="name" />
|
<el-table-column label="控制器ID" align="center" prop="controllerId" />
|
<el-table-column label="安装位置" align="center" prop="location" />
|
<el-table-column label="状态" align="center" prop="status">
|
<template #default="scope">
|
<dict-tag :options="statusOptions" :value="scope.row.status"/>
|
</template>
|
</el-table-column>
|
<el-table-column label="控制" align="center" width="300">
|
<template #default="scope">
|
<el-button
|
type="primary"
|
size="small"
|
|
@click="handleControl('0', scope.row)"
|
>制冷开机</el-button>
|
<el-button
|
type="success"
|
size="small"
|
|
@click="handleControl('1', scope.row)"
|
>制热开机</el-button>
|
<el-button
|
type="warning"
|
size="small"
|
|
@click="handleControl('2', scope.row)"
|
>关机</el-button>
|
</template>
|
</el-table-column>
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
<template #default="scope">
|
<el-button
|
type="primary"
|
link
|
:icon="Edit"
|
@click="handleUpdate(scope.row)"
|
v-hasPermi="['system:airconditioner:edit']"
|
>修改</el-button>
|
<el-button
|
type="primary"
|
link
|
:icon="Delete"
|
@click="handleDelete(scope.row)"
|
v-hasPermi="['system:airconditioner:remove']"
|
>删除</el-button>
|
<el-button
|
type="primary"
|
link
|
:icon="Timer"
|
@click="handleShowSchedule(scope.row)"
|
>定时</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
|
<pagination
|
v-show="total>0"
|
v-model:page="queryParams.pageNum"
|
v-model:limit="queryParams.pageSize"
|
:total="total"
|
@pagination="getList"
|
/>
|
</el-col>
|
</el-row>
|
|
<!-- 添加或修改空调对话框 -->
|
<el-dialog :title="title" v-model="open" width="500px" append-to-body>
|
<el-form ref="formRef" :model="form" :rules="rules" label-width="80px">
|
<el-form-item label="空调名称" prop="name">
|
<el-input v-model="form.name" placeholder="请输入空调名称" />
|
</el-form-item>
|
<el-form-item label="控制器ID" prop="controllerId">
|
<el-input v-model="form.controllerId" placeholder="请输入控制器ID" />
|
</el-form-item>
|
<el-form-item label="安装位置" prop="location">
|
<el-input v-model="form.location" placeholder="请输入安装位置" />
|
</el-form-item>
|
<el-form-item label="状态">
|
<el-radio-group v-model="form.status">
|
<el-radio
|
v-for="dict in statusOptions"
|
:key="dict.value"
|
:label="dict.value"
|
>{{dict.label}}</el-radio>
|
</el-radio-group>
|
</el-form-item>
|
<el-form-item label="备注" prop="remark">
|
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
|
</el-form-item>
|
</el-form>
|
<template #footer>
|
<div class="dialog-footer">
|
<el-button type="primary" @click="submitForm">确 定</el-button>
|
<el-button @click="cancel">取 消</el-button>
|
</div>
|
</template>
|
</el-dialog>
|
<!-- 空调定时任务弹窗 -->
|
<el-dialog
|
title="空调定时任务"
|
v-model="scheduleDialogVisible"
|
width="900px"
|
append-to-body
|
|
>
|
<air-conditioner-schedule ref="scheduleDialogRef" />
|
</el-dialog>
|
</div>
|
</template>
|
|
<script setup name="AirConditionerList">
|
import { ref, reactive, onMounted, getCurrentInstance, nextTick } from 'vue'
|
import { Search, Refresh, Plus, Edit, Delete, Setting, Timer, ArrowDown } from '@element-plus/icons-vue'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { listAirConditioner, getAirConditioner, addAirConditioner, updateAirConditioner, delAirConditioner, controlAirConditioner } from "@/api/airconditioner/airconditioner"
|
import AirConditionerSchedule from './schedule.vue'
|
// 获取父组件实例
|
const { proxy } = getCurrentInstance()
|
const scheduleDialogRef = ref(null)
|
// 遮罩层
|
const loading = ref(true)
|
// 选中数组
|
const ids = ref([])
|
// 非单个禁用
|
const single = ref(true)
|
// 非多个禁用
|
const multiple = ref(true)
|
// 显示搜索条件
|
const showSearch = ref(true)
|
// 总条数
|
const total = ref(0)
|
// 空调表格数据
|
const airConditionerList = ref([])
|
// 弹出层标题
|
const title = ref('')
|
// 是否显示弹出层
|
const open = ref(false)
|
// 表单参数
|
const form = ref({})
|
// 表单校验
|
const rules = {
|
name: [
|
{ required: true, message: "空调名称不能为空", trigger: "blur" }
|
],
|
controllerId: [
|
{ required: true, message: "控制器ID不能为空", trigger: "blur" }
|
],
|
location: [
|
{ required: true, message: "安装位置不能为空", trigger: "blur" }
|
]
|
}
|
|
// 状态字典
|
const statusOptions = [
|
{
|
label: "制冷",
|
value: "0"
|
},
|
{
|
label: "制热",
|
value: "1"
|
},
|
{
|
label: "关机",
|
value: "2"
|
}
|
]
|
|
// 查询参数
|
const queryParams = ref({
|
pageNum: 1,
|
pageSize: 10,
|
name: null,
|
location: null,
|
status: null
|
})
|
|
// 表单ref
|
const formRef = ref()
|
const queryFormRef = ref()
|
|
/** 查询空调列表 */
|
function getList() {
|
loading.value = true
|
listAirConditioner(queryParams.value).then(response => {
|
airConditionerList.value = response.rows
|
total.value = response.total
|
loading.value = false
|
})
|
}
|
|
// 取消按钮
|
function cancel() {
|
open.value = false
|
reset()
|
}
|
|
// 表单重置
|
function reset() {
|
form.value = {
|
id: null,
|
name: null,
|
controllerId: null,
|
location: null,
|
status: "2", // 默认为关机状态
|
remark: null
|
}
|
nextTick(() => {
|
if (formRef.value) {
|
formRef.value.resetFields()
|
}
|
})
|
}
|
|
/** 搜索按钮操作 */
|
function handleQuery() {
|
queryParams.value.pageNum = 1
|
getList()
|
}
|
|
/** 重置按钮操作 */
|
function resetQuery() {
|
queryFormRef.value.resetFields()
|
handleQuery()
|
}
|
|
// 多选框选中数据
|
function handleSelectionChange(selection) {
|
ids.value = selection.map(item => item.id)
|
single.value = selection.length !== 1
|
multiple.value = !selection.length
|
}
|
|
/** 新增按钮操作 */
|
function handleAdd() {
|
reset()
|
open.value = true
|
title.value = "添加空调"
|
}
|
|
/** 修改按钮操作 */
|
function handleUpdate(row) {
|
reset()
|
const id = row.id || ids.value[0]
|
getAirConditioner(id).then(response => {
|
form.value = response.data
|
open.value = true
|
title.value = "修改空调"
|
})
|
}
|
|
/** 提交按钮 */
|
function submitForm() {
|
formRef.value.validate(valid => {
|
if (valid) {
|
if (form.value.id != null) {
|
updateAirConditioner(form.value).then(response => {
|
ElMessage.success("修改成功")
|
open.value = false
|
getList()
|
})
|
} else {
|
addAirConditioner(form.value).then(response => {
|
ElMessage.success("新增成功")
|
open.value = false
|
getList()
|
})
|
}
|
}
|
})
|
}
|
|
/** 删除按钮操作 */
|
function handleDelete(row) {
|
const deleteIds = row.id || ids.value
|
ElMessageBox.confirm('是否确认删除空调编号为"' + deleteIds + '"的数据项?')
|
.then(() => {
|
return delAirConditioner(deleteIds)
|
})
|
.then(() => {
|
getList()
|
ElMessage.success("删除成功")
|
})
|
.catch(() => {})
|
}
|
|
/** 控制空调操作 */
|
function handleControl(command, row) {
|
const id = row.id
|
const modeName = command === '0' ? '制冷开机' : command === '1' ? '制热开机' : '关机'
|
ElMessageBox.confirm('是否确认对空调"' + row.name + '"执行' + modeName + '操作?')
|
.then(() => {
|
return controlAirConditioner(id, command, '0') // 0表示手动操作
|
})
|
.then(() => {
|
// 更新本地状态,避免等待刷新
|
row.status = command
|
ElMessage.success(modeName + "操作成功")
|
// 刷新列表数据
|
getList()
|
})
|
.catch(() => {})
|
}
|
|
/** 定时任务操作 */
|
function handleSchedule(row) {
|
// 调用父组件的handleShowSchedule方法,传递空调ID
|
proxy.$parent.handleShowSchedule(row.id)
|
}
|
|
// 定时任务弹窗显示状态
|
const scheduleDialogVisible = ref(false)
|
|
|
|
// 处理显示定时任务弹窗的方法(通过按钮点击)
|
function handleShowSchedule(airConditionerId) {
|
scheduleDialogVisible.value = true
|
// 等待DOM更新后调用定时任务组件的方法
|
nextTick(() => {
|
if (scheduleDialogRef.value) {
|
scheduleDialogRef.value.loadScheduleByAirConditioner(airConditionerId)
|
}
|
})
|
}
|
|
onMounted(() => {
|
getList()
|
})
|
|
// 暴露方法给父组件调用
|
defineExpose({
|
getList
|
})
|
</script>
|