From 184aa00784f19a710a29e2e4d729505cd0cfe241 Mon Sep 17 00:00:00 2001 From: chenbo <709206448@qq.com> Date: Mon, 29 Jan 2024 14:03:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=9F=E5=A7=8Brfid=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/src/views/animal_rfid/index.vue | 62 ++++++- .../controller/device/DeviceController.php | 22 +++ app/adminapi/lists/rfid/AnimalRfidLists.php | 153 +++++++++--------- app/common/model/rfid/AnimalRfid.php | 2 +- app/common/service/storage/engine/Server.php | 2 +- config/project.php | 4 + 6 files changed, 165 insertions(+), 80 deletions(-) diff --git a/admin/src/views/animal_rfid/index.vue b/admin/src/views/animal_rfid/index.vue index fa535ed..c8945ca 100644 --- a/admin/src/views/animal_rfid/index.vue +++ b/admin/src/views/animal_rfid/index.vue @@ -14,6 +14,7 @@ 查询 重置 + 导入 @@ -35,7 +36,17 @@ - + + + + @@ -80,11 +114,19 @@ import { apiAnimalRfidLists, apiAnimalRfidDelete } from '@/api/animal_rfid' import { timeFormat } from '@/utils/util' import feedback from '@/utils/feedback' import EditPopup from './edit.vue' +import { genFileId, ElMessage } from 'element-plus' +import type { UploadInstance, UploadProps, UploadRawFile } from 'element-plus' +import {ref} from "vue"; +import config from "@/config"; +import useUserStore from "@/stores/modules/user"; const editRef = shallowRef>() +const uploadImportRef = ref() // 是否显示编辑框 const showEdit = ref(false) - +const showImport = ref(false) +const uploadAction = ref(`${config.baseUrl}${config.urlPrefix}/device.device/importRfid`) +const userStore = useUserStore() // 查询条件 const queryParams = reactive({ rfid: '' @@ -128,6 +170,22 @@ const handleDelete = async (id: number | any[]) => { await apiAnimalRfidDelete({ id }) getLists() } +const handleImport = async () => { + showImport.value = true + await nextTick() +} +const handleExceed: UploadProps['onExceed'] = (files) => { + uploadImportRef.value!.clearFiles() + const file = files[0] as UploadRawFile + file.uid = genFileId() + uploadImportRef.value!.handleStart(file) +} +const submitUpload = () => { + uploadImportRef.value!.submit() + showImport.value=false + ElMessage.success('导入成功') + getLists() +} getLists() diff --git a/app/adminapi/controller/device/DeviceController.php b/app/adminapi/controller/device/DeviceController.php index f7274f4..5cfc6c3 100644 --- a/app/adminapi/controller/device/DeviceController.php +++ b/app/adminapi/controller/device/DeviceController.php @@ -20,7 +20,11 @@ use app\adminapi\controller\BaseAdminController; use app\adminapi\lists\device\DeviceLists; use app\adminapi\logic\device\DeviceLogic; use app\adminapi\validate\device\DeviceValidate; +use app\common\service\ConfigService; +use app\common\service\storage\Driver as StorageDriver; +use PhpOffice\PhpSpreadsheet\IOFactory; use Symfony\Component\HttpClient\HttpClient; +use think\facade\Db; /** @@ -148,4 +152,22 @@ class DeviceController extends BaseAdminController return $this->data($datas); } + public function importRfid() + { + $reader = IOFactory::createReader('Xls'); + // 打开文件 载入excel表格 + $spreadsheet = $reader->load($_FILES['file']['tmp_name']); + + $excelData = $spreadsheet->getActiveSheet()->toArray(); + array_shift($excelData); // 去除表头 + $insertData = []; + foreach ($excelData as $key =>$row) { + $insertData[$key]['origin_rfid'] = $row[0]; + $insertData[$key]['rfid'] = $row[1]; + } + Db::name('animal_rfid')->insertAll($insertData); + + return $this->success('导入成功'); + } + } \ No newline at end of file diff --git a/app/adminapi/lists/rfid/AnimalRfidLists.php b/app/adminapi/lists/rfid/AnimalRfidLists.php index eac1556..7c6c19a 100644 --- a/app/adminapi/lists/rfid/AnimalRfidLists.php +++ b/app/adminapi/lists/rfid/AnimalRfidLists.php @@ -1,77 +1,78 @@ - ['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(); - } - + ['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) + ->with(['fenceHouse']) + ->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(); + } + } \ No newline at end of file diff --git a/app/common/model/rfid/AnimalRfid.php b/app/common/model/rfid/AnimalRfid.php index ac401bc..9092b5e 100644 --- a/app/common/model/rfid/AnimalRfid.php +++ b/app/common/model/rfid/AnimalRfid.php @@ -37,7 +37,7 @@ class AnimalRfid extends BaseModel * @author likeadmin * @date 2024/01/13 16:21 */ - public function fenceHouseAttr() + public function fenceHouse() { return $this->hasOne(\app\common\model\fence_house\FenceHouse::class, 'id', 'fence_house_id'); } diff --git a/app/common/service/storage/engine/Server.php b/app/common/service/storage/engine/Server.php index 07bf0d5..27276e2 100644 --- a/app/common/service/storage/engine/Server.php +++ b/app/common/service/storage/engine/Server.php @@ -42,7 +42,7 @@ abstract class Server } // 校验上传文件后缀 - $limit = array_merge(config('project.file_image'), config('project.file_video')); + $limit = array_merge(config('project.file_image'), config('project.file_video'), config('project.file_file')); if (!in_array(strtolower($this->file->extension()), $limit)) { throw new Exception('不允许上传' . $this->file->extension() . '后缀文件'); } diff --git a/config/project.php b/config/project.php index 3ba585d..d26aa7a 100644 --- a/config/project.php +++ b/config/project.php @@ -74,6 +74,10 @@ return [ 'wmv', 'avi', 'mpg', 'mpeg', '3gp', 'mov', 'mp4', 'flv', 'f4v', 'rmvb', 'mkv' ], + // 文件上传限制 (文件) + 'file_file' => [ + 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pdf', 'txt','apk','ipa','wgt' + ], // 登录设置 'login' => [ // 登录方式:1-账号密码登录;2-手机短信验证码登录