From 5a1616f169d75ece07d2d12a8edac3e5f660a920 Mon Sep 17 00:00:00 2001
From: Your Name <123456>
Date: 星期四, 08 九月 2022 09:36:16 +0800
Subject: [PATCH] 合并
---
src/views/intellectInspect/inspectBasic/discriminate/components/RFIDDialog.vue | 147 ++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 128 insertions(+), 19 deletions(-)
diff --git a/src/views/intellectInspect/inspectBasic/discriminate/components/RFIDDialog.vue b/src/views/intellectInspect/inspectBasic/discriminate/components/RFIDDialog.vue
index 1d2e3d8..a54d140 100644
--- a/src/views/intellectInspect/inspectBasic/discriminate/components/RFIDDialog.vue
+++ b/src/views/intellectInspect/inspectBasic/discriminate/components/RFIDDialog.vue
@@ -5,12 +5,22 @@
<el-row :gutter="35">
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
<el-form-item label="RFID名称" prop="rfidName">
- <el-input class="input-length" v-model.trim="RFIDForm.rfidName" placeholder="请输入RFID名称" clearable></el-input>
+ <el-input class="input-add" v-model.trim="RFIDForm.rfidName" placeholder="请输入RFID名称" clearable></el-input>
</el-form-item>
</el-col>
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
<el-form-item label="RFID编码" prop="rfid">
- <el-input class="input-length" v-model.trim="RFIDForm.rfid" placeholder="请输入RFID编码" clearable></el-input>
+ <el-input class="input-add" v-model.trim="RFIDForm.rfid" placeholder="请输入RFID编码" clearable></el-input>
+ </el-form-item>
+ </el-col>
+ <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
+ <el-form-item label="上传图片" prop="rfidImage">
+ <el-upload accept="image/*" :on-preview="handlePictureCardPreview" :limits="1" v-model:file-list="fileList" :http-request="upload" :action="uploadUrl" list-type="picture-card" :on-remove="handleRemove" :before-remove="beforeRemove" :before-upload="getUploadUrl">
+ <el-icon><Plus /></el-icon>
+ <template #tip>
+ <div class="el-upload__tip">上传 jpg/png 图片尺寸小于500KB</div>
+ </template>
+ </el-upload>
</el-form-item>
</el-col>
</el-row>
@@ -22,6 +32,9 @@
</span>
</template>
</el-dialog>
+ <el-dialog v-model="dialogVisible">
+ <img w-full :src="dialogImageUrl" alt="Preview Image" />
+ </el-dialog>
</div>
</template>
@@ -31,14 +44,23 @@
RFIDForm: {
rfid: string;
rfidName: string;
+ rfidImage: string | null;
};
title: string;
+ dialogVisible: Boolean;
+ dialogImageUrl: string | null;
RFIDFormRules: {};
+ uploadUrl: string;
+ fileList: Array<file>;
}
-interface levelListState {}
+interface file {
+ url: string;
+}
import { reactive, toRefs, ref } from 'vue';
import { RFIDApi } from '/@/api/intellectInspectSystem/RFID';
-import { ElMessage } from 'element-plus';
+import { ElMessage, ElMessageBox } from 'element-plus';
+import type { UploadProps, UploadUserFile } from 'element-plus';
+import axios from 'axios';
export default {
name: 'RFIDDialog',
setup(props: any, context: any) {
@@ -48,44 +70,124 @@
isShowRFIDDialog: false,
RFIDForm: {
rfid: '',
- rfidName: ''
+ rfidName: '',
+ rfidImage: null
},
+ uploadUrl: '',
+ dialogVisible: false,
+ dialogImageUrl: null,
RFIDFormRules: {
rfid: [{ required: true, message: '请填写RFID编码', trigger: 'blur' }],
rfidName: [{ required: true, message: '请填写RFID名称', trigger: 'change' }],
riskLevel: [{ required: true, message: '请选择风险等级', trigger: 'change' }],
location: [{ required: true, message: '请填写区域位置', trigger: 'blur' }]
- }
- });
+ },
+ fileList: []
+ });
//打开模态框
const openRFIDDialog = (type: string, value: object) => {
+ state.fileList = [];
state.isShowRFIDDialog = true;
setTimeout(() => {
RFIDFormRef.value.clearValidate();
});
if (type === '新增') {
- state.title = '新增巡检指标';
+ state.title = '新增RFID';
state.RFIDForm = {
rfid: '',
- rfidName: ''
+ rfidName: '',
+ rfidImage: ''
};
} else {
- state.title = '修改巡检指标';
+ state.title = '修改RFID';
state.RFIDForm = JSON.parse(JSON.stringify(value));
+ if (state.RFIDForm.rfidImage === null) return;
+ state.fileList = [{ url: state.RFIDForm.rfidImage }];
}
+ };
+
+ // // 图片上传
+ // const fileList = ref<UploadUserFile[]>([]);
+ //
+ // const handleRemove = () => {
+ // ElMessageBox.confirm(`此操作将永久删除该图片,是否继续?`, '提示', {
+ // confirmButtonText: '确认',
+ // cancelButtonText: '取消',
+ // type: 'warning'
+ // })
+ // .then(() => {
+ // state.RFIDForm.rfidImage = null;
+ // state.fileList = [];
+ // })
+ // .catch(() => {});
+ // };
+
+ const handlePreview: UploadProps['onPreview'] = (uploadFile) => {
+ console.log(uploadFile);
+ };
+
+ const getUploadUrl = async (rawFile: any) => {
+ const res = await RFIDApi().getUploadUrl(rawFile.name);
+ state.RFIDForm.rfidImage = res.data.rfidImage;
+ state.uploadUrl = res.data.uploadUrl;
+ };
+
+ const upload = async (params: any) => {
+ // const formData = new FormData();
+ // formData.append('file', state.fileList[0].raw);
+ let reader = new FileReader();
+ reader.readAsArrayBuffer(params.file);
+ reader.onload = async () => {
+ axios
+ .put(state.uploadUrl, reader.result, {
+ header: { 'Content-Type': 'multipart/form-data' }
+ })
+ .then(() => {
+ if (state.fileList.length === 2) {
+ state.fileList.splice(0, 1);
+ }
+ });
+ // let res = await RFIDApi().uploadFile(state.uploadUrl, reader.result);
+ // if (res.data.code === '200') {
+ // } else {
+ // ElMessage({
+ // type: 'warning',
+ // message: res.data.msg
+ // });
+ // }
+ };
+ };
+
+ const beforeRemove = (file: {}, fileList: []) => {
+ const result = new Promise((resolve, reject) => {
+ ElMessageBox.confirm('此操作将删除该图片, 是否继续?', '提示', {
+ confirmButtonText: '确定',
+ cancelButtonText: '取消',
+ type: 'warning'
+ })
+ .then(() => {
+ state.RFIDForm.rfidImage = null;
+ state.fileList = [];
+ // 请求删除接口
+ })
+ .catch(() => {
+ reject(false);
+ });
+ });
+ return result;
};
//新增修改提交
const submitRFID = async () => {
RFIDFormRef.value.validate(async (valid: Boolean) => {
if (valid) {
- if (state.title === '新增巡检指标') {
+ if (state.title === '新增RFID') {
let res = await RFIDApi().addRFID(state.RFIDForm);
if (res.data.code === '200') {
ElMessage({
type: 'success',
- message: '巡检指标新增成功',
+ message: 'RFID新增成功',
duration: 2000
});
state.isShowRFIDDialog = false;
@@ -101,7 +203,7 @@
if (res.data.code === '200') {
ElMessage({
type: 'success',
- message: '巡检指标修改成功',
+ message: 'RFID修改成功',
duration: 2000
});
state.isShowRFIDDialog = false;
@@ -122,18 +224,25 @@
});
};
+ const handlePictureCardPreview = (uploadFile: { url: string }) => {
+ state.dialogImageUrl = uploadFile.url!;
+ state.dialogVisible = true;
+ };
+
return {
...toRefs(state),
RFIDFormRef,
+ // fileList,
+ upload,
+ getUploadUrl,
+ handlePreview,
+ beforeRemove,
submitRFID,
- openRFIDDialog
+ openRFIDDialog,
+ handlePictureCardPreview
};
}
};
</script>
-<style scoped>
-.input-length {
- width: 85%;
-}
-</style>
+<style scoped></style>
--
Gitblit v1.9.2