feat:联动控制,定时控制,通知推送功能代码提交。
This commit is contained in:
513
src/views/fishery/timingCtrl/index.vue
Normal file
513
src/views/fishery/timingCtrl/index.vue
Normal file
@@ -0,0 +1,513 @@
|
||||
<template>
|
||||
<div class="p-2">
|
||||
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
|
||||
<div v-show="showSearch" class="mb-[10px]">
|
||||
<el-card shadow="hover">
|
||||
<el-form ref="queryFormRef" :model="queryParams" :inline="true">
|
||||
<el-form-item label="用户信息" prop="params.userKeyword">
|
||||
<el-input v-model="queryParams.params.userKeyword" placeholder="请输入用户名或手机号" clearable @keyup.enter="handleQuery" />
|
||||
</el-form-item>
|
||||
<el-form-item label="设备信息" prop="params.deviceKeyword">
|
||||
<el-input v-model="queryParams.params.deviceKeyword" placeholder="请输入设备名称或设备编号" clearable @keyup.enter="handleQuery" />
|
||||
</el-form-item>
|
||||
<el-form-item label="开关名称" prop="params.switchKeyword">
|
||||
<el-input v-model="queryParams.params.switchKeyword" placeholder="请输入开关名称" clearable @keyup.enter="handleQuery" />
|
||||
</el-form-item>
|
||||
<el-form-item label="循环类型" prop="loopType">
|
||||
<el-select v-model="queryParams.loopType" placeholder="请选择循环类型" clearable >
|
||||
<el-option v-for="dict in loop_type" :key="dict.value" :label="dict.label" :value="dict.value"/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="是否启用" prop="isOpen">
|
||||
<el-select v-model="queryParams.isOpen" placeholder="请选择是否启用" clearable >
|
||||
<el-option v-for="dict in open_close" :key="dict.value" :label="dict.label" :value="dict.value"/>
|
||||
</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-card>
|
||||
</div>
|
||||
</transition>
|
||||
|
||||
<el-card shadow="never">
|
||||
<template #header>
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['fishery:timingCtrl:add']">新增</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['fishery:timingCtrl:edit']">修改</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['fishery:timingCtrl:remove']">删除</el-button>
|
||||
</el-col>
|
||||
<!-- <el-col :span="1.5">
|
||||
<el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['fishery:timingCtrl:export']">导出</el-button>
|
||||
</el-col> -->
|
||||
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<el-table v-loading="loading" border :data="timingCtrlList" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column label="用户名" align="center" prop="userName" />
|
||||
<el-table-column label="手机号" align="center" prop="mobilePhone" />
|
||||
<el-table-column label="设备编号" align="center" prop="serialNum" />
|
||||
<el-table-column label="设备名称" align="center" prop="deviceName"/>
|
||||
<el-table-column label="开关名称" align="center" prop="switchName"/>
|
||||
<el-table-column label="开启时间" align="center" prop="openTime" width="180">
|
||||
</el-table-column>
|
||||
<el-table-column label="关闭时间" align="center" prop="closeTime" width="180">
|
||||
</el-table-column>
|
||||
<el-table-column label="循环类型" align="center" prop="loopType">
|
||||
<template #default="scope">
|
||||
<dict-tag :options="loop_type" :value="scope.row.loopType"/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="是否启用" align="center" prop="isOpen">
|
||||
<template #default="scope">
|
||||
<dict-tag :options="open_close" :value="scope.row.isOpen"/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width">
|
||||
<template #default="scope">
|
||||
<el-tooltip content="修改" placement="top">
|
||||
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['fishery:timingCtrl:edit']"></el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip content="删除" placement="top">
|
||||
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['fishery:timingCtrl:remove']"></el-button>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
|
||||
</el-card>
|
||||
<!-- 添加或修改开关定时控制对话框 -->
|
||||
<el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
|
||||
<el-form ref="timingCtrlFormRef" :model="form" :rules="rules" label-width="80px">
|
||||
<el-form-item label="开关" prop="switchId">
|
||||
<el-input
|
||||
v-model="selectedSwitchDisplay"
|
||||
placeholder="请选择开关"
|
||||
readonly
|
||||
style="width: calc(100% - 90px); cursor: pointer;"
|
||||
@click="openSwitchSelect"
|
||||
>
|
||||
<template #suffix>
|
||||
<el-icon><Search /></el-icon>
|
||||
</template>
|
||||
</el-input>
|
||||
<el-button
|
||||
type="primary"
|
||||
style="margin-left: 10px;"
|
||||
@click="openSwitchSelect"
|
||||
>
|
||||
选择
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item label="开启时间" prop="openTime">
|
||||
<el-date-picker clearable
|
||||
v-model="form.openTime"
|
||||
type="datetime"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
placeholder="请选择开启时间">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
<el-form-item label="关闭时间" prop="closeTime">
|
||||
<el-date-picker clearable
|
||||
v-model="form.closeTime"
|
||||
type="datetime"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
placeholder="请选择关闭时间">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
<el-form-item label="循环类型" prop="loopType">
|
||||
<el-select v-model="form.loopType" placeholder="请选择循环类型">
|
||||
<el-option
|
||||
v-for="dict in loop_type"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="parseInt(dict.value)"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="是否启用" prop="isOpen">
|
||||
<el-select v-model="form.isOpen" placeholder="请选择是否启用">
|
||||
<el-option
|
||||
v-for="dict in open_close"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="parseInt(dict.value)"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</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 :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 开关选择对话框 -->
|
||||
<el-dialog title="选择开关" v-model="switchSelectVisible" width="1200px" append-to-body>
|
||||
<!-- 搜索条件 -->
|
||||
<el-form :model="switchQueryParams" :inline="true" class="mb-4">
|
||||
<el-form-item label="用户信息">
|
||||
<el-input
|
||||
v-model="switchQueryParams.params.userKeyword"
|
||||
placeholder="请输入用户名或手机号"
|
||||
clearable
|
||||
style="width: 200px"
|
||||
@keyup.enter="handleSwitchQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="设备编号">
|
||||
<el-input
|
||||
v-model="switchQueryParams.params.deviceKeyword"
|
||||
placeholder="请输入设备编号"
|
||||
clearable
|
||||
style="width: 180px"
|
||||
@keyup.enter="handleSwitchQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="开关名称">
|
||||
<el-input
|
||||
v-model="switchQueryParams.switchName"
|
||||
placeholder="请输入开关名称"
|
||||
clearable
|
||||
style="width: 180px"
|
||||
@keyup.enter="handleSwitchQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="Search" @click="handleSwitchQuery">搜索</el-button>
|
||||
<el-button icon="Refresh" @click="resetSwitchQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<!-- 开关表格 -->
|
||||
<el-table
|
||||
:data="switchList"
|
||||
highlight-current-row
|
||||
height="400px"
|
||||
border
|
||||
>
|
||||
<el-table-column label="用户名" align="center" prop="userName" />
|
||||
<el-table-column label="手机号" align="center" prop="mobilePhone" />
|
||||
<el-table-column label="设备编号" align="center" prop="serialNum" width="150"/>
|
||||
<el-table-column label="设备名称" align="center" prop="deviceName" />
|
||||
<el-table-column label="开关序号" align="center" prop="index" width="100" />
|
||||
<el-table-column label="开关名称" align="center" prop="switchName" />
|
||||
<el-table-column label="塘口名称" align="center" prop="pondName" />
|
||||
<el-table-column label="当前状态" align="center" prop="isOpen" width="100">
|
||||
<template #default="scope">
|
||||
<dict-tag :options="open_close" :value="scope.row.isOpen"/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" align="center" width="100">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
type="primary"
|
||||
size="small"
|
||||
@click="handleSwitchSelect(scope.row)"
|
||||
>
|
||||
选择
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 分页 -->
|
||||
<pagination
|
||||
v-show="switchTotal > 0"
|
||||
:total="switchTotal"
|
||||
v-model:page="switchQueryParams.pageNum"
|
||||
v-model:limit="switchQueryParams.pageSize"
|
||||
@pagination="handleSwitchPaginationChange"
|
||||
class="mt-4"
|
||||
/>
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="cancelSwitchSelect">取 消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="TimingCtrl" lang="ts">
|
||||
import { listTimingCtrl, getTimingCtrl, delTimingCtrl, addTimingCtrl, updateTimingCtrl } from '@/api/fishery/timingCtrl';
|
||||
import { TimingCtrlVO, TimingCtrlQuery, TimingCtrlForm } from '@/api/fishery/timingCtrl/types';
|
||||
import { listDeviceSwitch } from '@/api/fishery/deviceSwitch';
|
||||
import { DeviceSwitchVO } from '@/api/fishery/deviceSwitch/types';
|
||||
|
||||
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||
const { loop_type,open_close } = toRefs<any>(proxy?.useDict('loop_type','open_close'));
|
||||
|
||||
const timingCtrlList = ref<TimingCtrlVO[]>([]);
|
||||
const buttonLoading = ref(false);
|
||||
const loading = ref(true);
|
||||
const showSearch = ref(true);
|
||||
const ids = ref<Array<string | number>>([]);
|
||||
const single = ref(true);
|
||||
const multiple = ref(true);
|
||||
const total = ref(0);
|
||||
|
||||
// 开关选择相关
|
||||
const switchList = ref<DeviceSwitchVO[]>([]);
|
||||
const selectedSwitch = ref<DeviceSwitchVO | null>(null);
|
||||
const switchSelectVisible = ref(false);
|
||||
const switchQueryParams = reactive<{
|
||||
pageNum: number;
|
||||
pageSize: number;
|
||||
switchName?: string;
|
||||
params: {
|
||||
userKeyword?: string;
|
||||
deviceKeyword?: string;
|
||||
};
|
||||
}>({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
switchName: undefined,
|
||||
params: {
|
||||
userKeyword: undefined,
|
||||
deviceKeyword: undefined
|
||||
}
|
||||
});
|
||||
const switchTotal = ref(0);
|
||||
|
||||
// 开关显示文本
|
||||
const selectedSwitchDisplay = computed(() => {
|
||||
if (selectedSwitch.value) {
|
||||
const deviceName = (selectedSwitch.value as any).deviceName || '';
|
||||
return `${selectedSwitch.value.switchName}${deviceName ? ' - ' + deviceName : ''} (序号:${selectedSwitch.value.index})`;
|
||||
}
|
||||
return '';
|
||||
});
|
||||
|
||||
const queryFormRef = ref<ElFormInstance>();
|
||||
const timingCtrlFormRef = ref<ElFormInstance>();
|
||||
|
||||
const dialog = reactive<DialogOption>({
|
||||
visible: false,
|
||||
title: ''
|
||||
});
|
||||
|
||||
const initFormData: TimingCtrlForm = {
|
||||
id: undefined,
|
||||
switchId: undefined,
|
||||
openTime: undefined,
|
||||
closeTime: undefined,
|
||||
loopType: undefined,
|
||||
isOpen: undefined,
|
||||
remark: undefined
|
||||
}
|
||||
const data = reactive<PageData<TimingCtrlForm, TimingCtrlQuery>>({
|
||||
form: {...initFormData},
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
switchId: undefined,
|
||||
loopType: undefined,
|
||||
isOpen: undefined,
|
||||
params: {
|
||||
}
|
||||
},
|
||||
rules: {
|
||||
switchId: [
|
||||
{ required: true, message: "开关不能为空", trigger: "blur" }
|
||||
],
|
||||
openTime: [
|
||||
{ required: true, message: "开启时间不能为空", trigger: "blur" }
|
||||
],
|
||||
closeTime: [
|
||||
{ required: true, message: "关闭时间不能为空", trigger: "blur" }
|
||||
],
|
||||
loopType: [
|
||||
{ required: true, message: "循环类型不能为空", trigger: "change" }
|
||||
],
|
||||
isOpen: [
|
||||
{ required: true, message: "是否启用不能为空", trigger: "blur" }
|
||||
],
|
||||
}
|
||||
});
|
||||
|
||||
const { queryParams, form, rules } = toRefs(data);
|
||||
|
||||
/** 查询开关定时控制列表 */
|
||||
const getList = async () => {
|
||||
loading.value = true;
|
||||
const res = await listTimingCtrl(queryParams.value);
|
||||
timingCtrlList.value = res.rows;
|
||||
total.value = res.total;
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
/** 取消按钮 */
|
||||
const cancel = () => {
|
||||
reset();
|
||||
dialog.visible = false;
|
||||
}
|
||||
|
||||
/** 表单重置 */
|
||||
const reset = () => {
|
||||
form.value = {...initFormData};
|
||||
selectedSwitch.value = null;
|
||||
timingCtrlFormRef.value?.resetFields();
|
||||
}
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
const handleQuery = () => {
|
||||
queryParams.value.pageNum = 1;
|
||||
getList();
|
||||
}
|
||||
|
||||
/** 重置按钮操作 */
|
||||
const resetQuery = () => {
|
||||
queryFormRef.value?.resetFields();
|
||||
handleQuery();
|
||||
}
|
||||
|
||||
/** 多选框选中数据 */
|
||||
const handleSelectionChange = (selection: TimingCtrlVO[]) => {
|
||||
ids.value = selection.map(item => item.id);
|
||||
single.value = selection.length != 1;
|
||||
multiple.value = !selection.length;
|
||||
}
|
||||
|
||||
/** 新增按钮操作 */
|
||||
const handleAdd = () => {
|
||||
reset();
|
||||
dialog.visible = true;
|
||||
dialog.title = "添加开关定时控制";
|
||||
}
|
||||
|
||||
/** 修改按钮操作 */
|
||||
const handleUpdate = async (row?: TimingCtrlVO) => {
|
||||
reset();
|
||||
const _id = row?.id || ids.value[0]
|
||||
const res = await getTimingCtrl(_id);
|
||||
Object.assign(form.value, res.data);
|
||||
|
||||
// 回显开关信息
|
||||
if (form.value.switchId) {
|
||||
try {
|
||||
const switchRes = await listDeviceSwitch({
|
||||
pageNum: 1,
|
||||
pageSize: 1000
|
||||
});
|
||||
const switchListData = switchRes.rows || switchRes.data || [];
|
||||
const switchItem = switchListData.find(s => s.id.toString() === form.value.switchId.toString());
|
||||
if (switchItem) {
|
||||
selectedSwitch.value = switchItem;
|
||||
} else {
|
||||
selectedSwitch.value = null;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载开关信息失败:', error);
|
||||
selectedSwitch.value = null;
|
||||
}
|
||||
} else {
|
||||
selectedSwitch.value = null;
|
||||
}
|
||||
|
||||
dialog.visible = true;
|
||||
dialog.title = "修改开关定时控制";
|
||||
}
|
||||
|
||||
/** 提交按钮 */
|
||||
const submitForm = () => {
|
||||
timingCtrlFormRef.value?.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
buttonLoading.value = true;
|
||||
if (form.value.id) {
|
||||
await updateTimingCtrl(form.value).finally(() => buttonLoading.value = false);
|
||||
} else {
|
||||
await addTimingCtrl(form.value).finally(() => buttonLoading.value = false);
|
||||
}
|
||||
proxy?.$modal.msgSuccess("操作成功");
|
||||
dialog.visible = false;
|
||||
await getList();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** 删除按钮操作 */
|
||||
const handleDelete = async (row?: TimingCtrlVO) => {
|
||||
const _ids = row?.id || ids.value;
|
||||
await proxy?.$modal.confirm('是否确认删除开关定时控制编号为"' + _ids + '"的数据项?').finally(() => loading.value = false);
|
||||
await delTimingCtrl(_ids);
|
||||
proxy?.$modal.msgSuccess("删除成功");
|
||||
await getList();
|
||||
}
|
||||
|
||||
/** 导出按钮操作 */
|
||||
const handleExport = () => {
|
||||
proxy?.download('fishery/timingCtrl/export', {
|
||||
...queryParams.value
|
||||
}, `timingCtrl_${new Date().getTime()}.xlsx`)
|
||||
}
|
||||
|
||||
/** 获取开关列表 */
|
||||
const getSwitchList = async () => {
|
||||
const res = await listDeviceSwitch(switchQueryParams);
|
||||
switchList.value = res.rows || res.data || [];
|
||||
switchTotal.value = res.total || 0;
|
||||
};
|
||||
|
||||
/** 打开开关选择对话框 */
|
||||
const openSwitchSelect = () => {
|
||||
switchQueryParams.pageNum = 1;
|
||||
switchQueryParams.switchName = undefined;
|
||||
switchQueryParams.params.userKeyword = undefined;
|
||||
switchQueryParams.params.deviceKeyword = undefined;
|
||||
getSwitchList();
|
||||
switchSelectVisible.value = true;
|
||||
};
|
||||
|
||||
/** 搜索开关 */
|
||||
const handleSwitchQuery = () => {
|
||||
switchQueryParams.pageNum = 1;
|
||||
getSwitchList();
|
||||
};
|
||||
|
||||
/** 重置开关搜索 */
|
||||
const resetSwitchQuery = () => {
|
||||
switchQueryParams.pageNum = 1;
|
||||
switchQueryParams.switchName = undefined;
|
||||
switchQueryParams.params.userKeyword = undefined;
|
||||
switchQueryParams.params.deviceKeyword = undefined;
|
||||
getSwitchList();
|
||||
};
|
||||
|
||||
/** 开关分页改变 */
|
||||
const handleSwitchPaginationChange = () => {
|
||||
getSwitchList();
|
||||
};
|
||||
|
||||
/** 选择开关 */
|
||||
const handleSwitchSelect = (switchItem: DeviceSwitchVO) => {
|
||||
selectedSwitch.value = switchItem;
|
||||
form.value.switchId = switchItem.id;
|
||||
switchSelectVisible.value = false;
|
||||
};
|
||||
|
||||
/** 取消开关选择 */
|
||||
const cancelSwitchSelect = () => {
|
||||
switchSelectVisible.value = false;
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
getList();
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user