新增设备管理模块

This commit is contained in:
yaooo 2023-11-24 16:09:15 +08:00
parent fd0e8b3322
commit 2a90a490be
11 changed files with 876 additions and 3 deletions

26
admin/src/api/device.ts Normal file
View File

@ -0,0 +1,26 @@
import request from '@/utils/request'
// 监测设备列表
export function apiDeviceLists(params: any) {
return request.get({ url: '/device.device/lists', params })
}
// 添加监测设备
export function apiDeviceAdd(params: any) {
return request.post({ url: '/device.device/add', params })
}
// 编辑监测设备
export function apiDeviceEdit(params: any) {
return request.post({ url: '/device.device/edit', params })
}
// 删除监测设备
export function apiDeviceDelete(params: any) {
return request.post({ url: '/device.device/delete', params })
}
// 监测设备详情
export function apiDeviceDetail(params: any) {
return request.get({ url: '/device.device/detail', params })
}

View File

@ -2,8 +2,8 @@ const config = {
terminal: 1, //终端
title: '后台管理系统', //网站默认标题
version: '1.6.0', //版本号
baseUrl: `${import.meta.env.VITE_APP_BASE_URL || ''}/`, //请求接口域名
// baseUrl: 'http://127.0.0.1:30005/',
// baseUrl: `${import.meta.env.VITE_APP_BASE_URL || ''}/`, //请求接口域名
baseUrl: 'http://127.0.0.1:30005/',
urlPrefix: 'adminapi', //请求默认前缀
timeout: 10 * 1000 //请求超时时长
}

View File

@ -0,0 +1,182 @@
<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="设备编码" 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="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 } 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: '',
code: '',
name: '',
type: '',
status: '',
is_online: '',
is_bind: '',
})
//
const formRules = reactive<any>({
code: [{
required: true,
message: '请输入设备编码',
trigger: ['blur']
}],
name: [{
required: true,
message: '请输入设备名称',
trigger: ['blur']
}],
type: [{
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]
}
}
}
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>

View File

@ -0,0 +1,186 @@
<template>
<div>
<el-card class="!border-none mb-4" shadow="never">
<el-form
class="mb-[-16px]"
:model="queryParams"
inline
>
<el-form-item label="设备编码" prop="code">
<el-input class="w-[280px]" v-model="queryParams.code" clearable placeholder="请输入设备编码" />
</el-form-item>
<el-form-item label="设备名称" prop="name">
<el-input class="w-[280px]" v-model="queryParams.name" clearable placeholder="请输入设备名称" />
</el-form-item>
<el-form-item label="设备类型" prop="type">
<el-select class="w-[280px]" v-model="queryParams.type" clearable placeholder="请选择设备类型">
<el-option label="全部" value=""></el-option>
<el-option
v-for="(item, index) in dictData.device_type"
:key="index"
:label="item.name"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item label="设备状态" prop="status">
<el-select class="w-[280px]" v-model="queryParams.status" clearable placeholder="请选择设备状态">
<el-option label="全部" value=""></el-option>
<el-option
v-for="(item, index) in dictData.device_status"
:key="index"
:label="item.name"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item label="是否在线" prop="is_online">
<el-select class="w-[280px]" v-model="queryParams.is_online" clearable placeholder="请选择是否在线">
<el-option label="全部" value=""></el-option>
<el-option
v-for="(item, index) in dictData.device_online_status"
:key="index"
:label="item.name"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item label="是否绑定土地" prop="is_bind">
<el-select class="w-[280px]" v-model="queryParams.is_bind" clearable placeholder="请选择是否绑定土地">
<el-option label="全部" value=""></el-option>
<el-option
v-for="(item, index) in dictData.device_bind_status"
:key="index"
:label="item.name"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="resetPage">查询</el-button>
<el-button @click="resetParams">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card class="!border-none" v-loading="pager.loading" shadow="never">
<div class="mt-4">
<el-table :data="pager.lists" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column label="ID" prop="id" 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="type">
<template #default="{ row }">
<dict-value :options="dictData.device_type" :value="row.type" />
</template>
</el-table-column>
<el-table-column label="设备状态" prop="status">
<template #default="{ row }">
<dict-value :options="dictData.device_status" :value="row.status" />
</template>
</el-table-column>
<el-table-column label="是否在线" prop="is_online">
<template #default="{ row }">
<dict-value :options="dictData.device_online_status" :value="row.is_online" />
</template>
</el-table-column>
<el-table-column label="是否绑定土地" prop="is_bind">
<template #default="{ row }">
<dict-value :options="dictData.device_bind_status" :value="row.is_bind" />
</template>
</el-table-column>
<el-table-column label="操作" width="120" fixed="right">
<template #default="{ row }">
<el-button
v-perms="['device.device/edit']"
type="primary"
link
@click="handleEdit(row)"
>
编辑
</el-button>
<el-button
v-perms="['device.device/delete']"
type="danger"
link
@click="handleDelete(row.id)"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<div class="flex mt-4 justify-end">
<pagination v-model="pager" @change="getLists" />
</div>
</el-card>
<edit-popup v-if="showEdit" ref="editRef" :dict-data="dictData" @success="getLists" @close="showEdit = false" />
</div>
</template>
<script lang="ts" setup name="deviceLists">
import { usePaging } from '@/hooks/usePaging'
import { useDictData } from '@/hooks/useDictOptions'
import { apiDeviceLists, apiDeviceDelete } from '@/api/device'
import { timeFormat } from '@/utils/util'
import feedback from '@/utils/feedback'
import EditPopup from './edit.vue'
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
//
const showEdit = ref(false)
//
const queryParams = reactive({
code: '',
name: '',
type: '',
status: '',
is_online: '',
is_bind: '',
})
//
const selectData = ref<any[]>([])
//
const handleSelectionChange = (val: any[]) => {
selectData.value = val.map(({ id }) => id)
}
//
const { dictData } = useDictData('device_type,device_status,device_online_status,device_bind_status')
//
const { pager, getLists, resetParams, resetPage } = usePaging({
fetchFun: apiDeviceLists,
params: queryParams
})
//
const handleAdd = async () => {
showEdit.value = true
await nextTick()
editRef.value?.open('add')
}
//
const handleEdit = async (data: any) => {
showEdit.value = true
await nextTick()
editRef.value?.open('edit')
editRef.value?.setFormData(data)
}
//
const handleDelete = async (id: number | any[]) => {
await feedback.confirm('确定要删除?')
await apiDeviceDelete({ id })
getLists()
}
getLists()
</script>

View File

@ -0,0 +1,108 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\controller\device;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\device\DeviceLists;
use app\adminapi\logic\device\DeviceLogic;
use app\adminapi\validate\device\DeviceValidate;
/**
* Device控制器
* Class DeviceController
* @package app\adminapi\controller\device
*/
class DeviceController extends BaseAdminController
{
/**
* @notes 获取列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/24 15:30
*/
public function lists()
{
return $this->dataLists(new DeviceLists());
}
/**
* @notes 添加
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/24 15:30
*/
public function add()
{
$params = (new DeviceValidate())->post()->goCheck('add');
$result = DeviceLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(DeviceLogic::getError());
}
/**
* @notes 编辑
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/24 15:30
*/
public function edit()
{
$params = (new DeviceValidate())->post()->goCheck('edit');
$result = DeviceLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(DeviceLogic::getError());
}
/**
* @notes 删除
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/24 15:30
*/
public function delete()
{
$params = (new DeviceValidate())->post()->goCheck('delete');
DeviceLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/24 15:30
*/
public function detail()
{
$params = (new DeviceValidate())->goCheck('detail');
$result = DeviceLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,79 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\lists\device;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\device\Device;
use app\common\model\land\LandDevice;
use app\common\model\land\Land;
use app\common\lists\ListsSearchInterface;
/**
* Device列表
* Class DeviceLists
* @package app\adminapi\listsdevice
*/
class DeviceLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/11/24 15:30
*/
public function setSearch(): array
{
return [
'=' => ['code', 'name', 'type', 'status', 'is_online', 'is_bind'],
];
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/11/24 15:30
*/
public function lists(): array
{
return Device::where($this->searchWhere)
->field(['id', 'code', 'name', 'type', 'status', 'is_online', 'is_bind'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author likeadmin
* @date 2023/11/24 15:30
*/
public function count(): int
{
return Device::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,116 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\device;
use app\common\model\device\Device;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* Device逻辑
* Class DeviceLogic
* @package app\adminapi\logic\device
*/
class DeviceLogic extends BaseLogic
{
/**
* @notes 添加
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/24 15:30
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
Device::create([
'code' => $params['code'],
'name' => $params['name'],
'type' => $params['type'],
'status' => $params['status'],
'is_online' => $params['is_online'],
'is_bind' => $params['is_bind'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/24 15:30
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
Device::where('id', $params['id'])->update([
'code' => $params['code'],
'name' => $params['name'],
'type' => $params['type'],
'status' => $params['status'],
'is_online' => $params['is_online'],
'is_bind' => $params['is_bind'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/24 15:30
*/
public static function delete(array $params): bool
{
return Device::destroy($params['id']);
}
/**
* @notes 获取详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/11/24 15:30
*/
public static function detail($params): array
{
return Device::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,106 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\device;
use app\common\validate\BaseValidate;
/**
* Device验证器
* Class DeviceValidate
* @package app\adminapi\validate\device
*/
class DeviceValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'code' => 'require',
'name' => 'require',
'type' => 'require',
'status' => 'require',
'is_online' => 'require',
'is_bind' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'code' => '设备编码',
'name' => '设备名称',
'type' => '设备类型',
'status' => '设备状态',
'is_online' => '是否在线',
'is_bind' => '是否绑定土地',
];
/**
* @notes 添加场景
* @return DeviceValidate
* @author likeadmin
* @date 2023/11/24 15:30
*/
public function sceneAdd()
{
return $this->only(['code','name','type','status','is_online','is_bind']);
}
/**
* @notes 编辑场景
* @return DeviceValidate
* @author likeadmin
* @date 2023/11/24 15:30
*/
public function sceneEdit()
{
return $this->only(['id','code','name','type','status','is_online','is_bind']);
}
/**
* @notes 删除场景
* @return DeviceValidate
* @author likeadmin
* @date 2023/11/24 15:30
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return DeviceValidate
* @author likeadmin
* @date 2023/11/24 15:30
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -0,0 +1,38 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\common\model\device;
use app\common\model\BaseModel;
/**
* Device模型
* Class Device
* @package app\common\model\device
*/
class Device extends BaseModel
{
protected $name = 'device';
/**
* @notes 关联land
* @return \think\model\relation\HasOne
* @author likeadmin
* @date 2023/11/23 11:32
*/
}

View File

@ -0,0 +1,32 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\common\model\land;
use app\common\model\BaseModel;
/**
* LandPlant模型
* Class LandPlant
* @package app\common\model\land
*/
class LandDevice extends BaseModel
{
protected $name = 'land_device';
}