This commit is contained in:
chenbo 2024-01-13 16:27:53 +08:00
parent 249c59f701
commit 8756ffe09b
8 changed files with 741 additions and 0 deletions

View File

@ -0,0 +1,26 @@
import request from '@/utils/request'
// 档案RFID列表
export function apiAnimalRfidLists(params: any) {
return request.get({ url: '/rfid.animal_rfid/lists', params })
}
// 添加档案RFID
export function apiAnimalRfidAdd(params: any) {
return request.post({ url: '/rfid.animal_rfid/add', params })
}
// 编辑档案RFID
export function apiAnimalRfidEdit(params: any) {
return request.post({ url: '/rfid.animal_rfid/edit', params })
}
// 删除档案RFID
export function apiAnimalRfidDelete(params: any) {
return request.post({ url: '/rfid.animal_rfid/delete', params })
}
// 档案RFID详情
export function apiAnimalRfidDetail(params: any) {
return request.get({ url: '/rfid.animal_rfid/detail', params })
}

View File

@ -0,0 +1,153 @@
<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="90px" :rules="formRules">
<el-form-item label="RFID" prop="rfid">
<el-input v-model="formData.rfid" clearable placeholder="请输入" />
</el-form-item>
<el-form-item label="所属栏舍" prop="fence_house_id">
<el-select
v-model="formData.fence_house_id"
clearable
remote
filterable
placeholder="请选择"
:remote-method="queryFenceHouse"
:loading="loading"
>
<el-option
v-for="(item, index) in optionsData.fenceHouse"
:key="index"
:label="item.fencehouseinfo"
:value="item.id"
/>
</el-select>
</el-form-item>
</el-form>
</popup>
</div>
</template>
<script lang="ts" setup name="animalRfidEdit">
import type { FormInstance } from 'element-plus'
import Popup from '@/components/popup/index.vue'
import { apiAnimalRfidAdd, apiAnimalRfidEdit, apiAnimalRfidDetail } from '@/api/animal_rfid'
import { timeFormat } from '@/utils/util'
import type { PropType } from 'vue'
import {apiFenceHouseLists} from "@/api/monitor_threshold";
import {useDictOptions} from "@/hooks/useDictOptions";
import {apiLandLists, getUserList} from "@/api/product";
import {ref} 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' ? '编辑档案RFID' : '新增档案RFID'
})
//
const formData = reactive({
id: '',
rfid: '',
fence_house_id: '',
})
//
const formRules = reactive<any>({
rfid: [{
required: true,
message: '请输入',
trigger: ['blur']
}],
})
const { optionsData } = useDictOptions<{
fenceHouse: any[]
}>({
fenceHouse: {
api: apiFenceHouseLists
}
})
const loading = ref(false)
const queryFenceHouse = async (user_id: string) => {
loading.value = true
const fenceHouseList = await apiFenceHouseLists({
user_id: user_id ?? ''
})
optionsData.fenceHouse = fenceHouseList
loading.value = false
}
//
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 apiAnimalRfidDetail({
id: row.id
})
setFormData(data)
}
//
const handleSubmit = async () => {
await formRef.value?.validate()
const data = { ...formData, }
mode.value == 'edit'
? await apiAnimalRfidEdit(data)
: await apiAnimalRfidAdd(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,128 @@
<template>
<div>
<el-card class="!border-none mb-4" shadow="never">
<el-form
class="mb-[-16px]"
:model="queryParams"
inline
>
<el-form-item label="" prop="rfid">
<el-input class="w-[280px]" v-model="queryParams.rfid" clearable placeholder="请输入" />
</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">
<el-button v-perms="['rfid.animal_rfid/add']" type="primary" @click="handleAdd">
<template #icon>
<icon name="el-icon-Plus" />
</template>
新增
</el-button>
<el-button
v-perms="['rfid.animal_rfid/delete']"
:disabled="!selectData.length"
@click="handleDelete(selectData)"
>
删除
</el-button>
<div class="mt-4">
<el-table :data="pager.lists" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column label="" prop="rfid" show-overflow-tooltip />
<el-table-column label="" prop="fence_house_id" show-overflow-tooltip />
<el-table-column label="操作" width="120" fixed="right">
<template #default="{ row }">
<el-button
v-perms="['rfid.animal_rfid/edit']"
type="primary"
link
@click="handleEdit(row)"
>
编辑
</el-button>
<el-button
v-perms="['rfid.animal_rfid/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="animalRfidLists">
import { usePaging } from '@/hooks/usePaging'
import { useDictData } from '@/hooks/useDictOptions'
import { apiAnimalRfidLists, apiAnimalRfidDelete } from '@/api/animal_rfid'
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({
rfid: '',
})
//
const selectData = ref<any[]>([])
//
const handleSelectionChange = (val: any[]) => {
selectData.value = val.map(({ id }) => id)
}
//
const { dictData } = useDictData('')
//
const { pager, getLists, resetParams, resetPage } = usePaging({
fetchFun: apiAnimalRfidLists,
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 apiAnimalRfidDelete({ 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\rfid;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\rfid\AnimalRfidLists;
use app\adminapi\logic\rfid\AnimalRfidLogic;
use app\adminapi\validate\rfid\AnimalRfidValidate;
/**
* AnimalRfid控制器
* Class AnimalRfidController
* @package app\adminapi\controller\rfid
*/
class AnimalRfidController extends BaseAdminController
{
/**
* @notes 获取列表
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/13 16:21
*/
public function lists()
{
return $this->dataLists(new AnimalRfidLists());
}
/**
* @notes 添加
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/13 16:21
*/
public function add()
{
$params = (new AnimalRfidValidate())->post()->goCheck('add');
$result = AnimalRfidLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(AnimalRfidLogic::getError());
}
/**
* @notes 编辑
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/13 16:21
*/
public function edit()
{
$params = (new AnimalRfidValidate())->post()->goCheck('edit');
$result = AnimalRfidLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(AnimalRfidLogic::getError());
}
/**
* @notes 删除
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/13 16:21
*/
public function delete()
{
$params = (new AnimalRfidValidate())->post()->goCheck('delete');
AnimalRfidLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取详情
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/13 16:21
*/
public function detail()
{
$params = (new AnimalRfidValidate())->goCheck('detail');
$result = AnimalRfidLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,77 @@
<?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\rfid;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\rfid\AnimalRfid;
use app\common\lists\ListsSearchInterface;
/**
* AnimalRfid列表
* Class AnimalRfidLists
* @package app\adminapi\listsrfid
*/
class AnimalRfidLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/01/13 16:21
*/
public function setSearch(): array
{
return [
'=' => ['rfid'],
];
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/01/13 16:21
*/
public function lists(): array
{
return AnimalRfid::where($this->searchWhere)
->field(['id', 'rfid', 'fence_house_id'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author likeadmin
* @date 2024/01/13 16:21
*/
public function count(): int
{
return AnimalRfid::where($this->searchWhere)->count();
}
}

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\logic\rfid;
use app\common\model\rfid\AnimalRfid;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* AnimalRfid逻辑
* Class AnimalRfidLogic
* @package app\adminapi\logic\rfid
*/
class AnimalRfidLogic extends BaseLogic
{
/**
* @notes 添加
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/13 16:21
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
AnimalRfid::create([
'rfid' => $params['rfid'],
'fence_house_id' => $params['fence_house_id'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/13 16:21
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
AnimalRfid::where('id', $params['id'])->update([
'rfid' => $params['rfid'],
'fence_house_id' => $params['fence_house_id'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/13 16:21
*/
public static function delete(array $params): bool
{
return AnimalRfid::destroy($params['id']);
}
/**
* @notes 获取详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/01/13 16:21
*/
public static function detail($params): array
{
return AnimalRfid::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,96 @@
<?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\rfid;
use app\common\validate\BaseValidate;
/**
* AnimalRfid验证器
* Class AnimalRfidValidate
* @package app\adminapi\validate\rfid
*/
class AnimalRfidValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'rfid' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'rfid' => 'rfid',
];
/**
* @notes 添加场景
* @return AnimalRfidValidate
* @author likeadmin
* @date 2024/01/13 16:21
*/
public function sceneAdd()
{
return $this->only(['rfid']);
}
/**
* @notes 编辑场景
* @return AnimalRfidValidate
* @author likeadmin
* @date 2024/01/13 16:21
*/
public function sceneEdit()
{
return $this->only(['id','rfid']);
}
/**
* @notes 删除场景
* @return AnimalRfidValidate
* @author likeadmin
* @date 2024/01/13 16:21
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return AnimalRfidValidate
* @author likeadmin
* @date 2024/01/13 16:21
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -0,0 +1,45 @@
<?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\rfid;
use app\common\model\BaseModel;
/**
* AnimalRfid模型
* Class AnimalRfid
* @package app\common\model\rfid
*/
class AnimalRfid extends BaseModel
{
protected $name = 'animal_rfid';
/**
* @notes 关联fenceHouseAttr
* @return \think\model\relation\HasOne
* @author likeadmin
* @date 2024/01/13 16:21
*/
public function fenceHouseAttr()
{
return $this->hasOne(\app\common\model\fence_house\FenceHouse::class, 'id', 'fence_house_id');
}
}