前端功能的增加以及后端数据的查询和显示
1.零件追溯系统的实现与优化
1.1搜索框的功能实现
首先基于Element UI库构建基本的框架
el-form:
:model="queryParams"
:将表单数据绑定到组件中的queryParams
对象上,用于存储输入框的值。ref="queryForm"
:为表单设置一个引用,以便在代码中可以通过该引用操作表单。:inline="true"
:使表单以内联方式展示,即输入框和标签在同一行显示。v-show="showSearch"
:根据showSearch
的值决定表单是否显示。label-width="68px"
:设置表单项标签的宽度为 68px。
el-form-item(多个,每个对应一个输入框):
- 每个
el-form-item
表示表单中的一个项,包含一个标签和一个输入框。 label
属性定义了标签的文本内容。prop
属性指定了与表单数据模型 (queryParams
) 中对应属性的名称,用于表单验证
el-input(多个,每个对应一个输入框)
v-model
指令将输入框的值双向绑定到queryParams
对象中的相应属性。placeholder
属性为输入框提供了占位符文本。clearable
属性设置输入框是否可以清空。size="small"
设置输入框的大小为小尺寸。@keyup.enter.native="handleQuery"
监听回车键事件,当用户在输入框内按下回车键时调用handleQuery
方法进行查询。
el-button:
- 两个按钮用于执行搜索和重置操作。
type="primary"
:将第一个按钮设置为主要按钮样式。icon="el-icon-search"
:给第一个按钮添加搜索图标。@click="handleQuery"
:当按钮被点击时调用handleQuery
方法进行搜索。- 第二个按钮使用了重置图标和
resetQuery
方法来重置表单数据。
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="零件编号" prop="crankshaftId">
<el-input
v-model="queryParams.crankshaftId"
placeholder="请输入零件编号"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="工序名称" prop="processName">
<el-input
v-model="queryParams.processName"
placeholder="请输入工序名称"
clearable
size="small"
@keyup.enter.native="handleQuery">
</el-input>
</el-form-item>
<el-form-item label="工序编号" prop="processNumber">
<el-input v-model="queryParams.processNumber"
placeholder="请输入工序编号"
clearable
size="small"
@keyup.enter.native="handleQuery"
>
</el-input>
</el-form-item>
<el-form-item label="设备编号" prop="deviceNumber">
<el-input v-model="queryParams.deviceNumber"
placeholder="请输入设备编号"
clearable
size="small"
@keyup.enter.native="handleQuery"
>
</el-input>
</el-form-item>
<el-form-item label="部门名称" prop="depamentName">
<el-input v-model="queryParams.depamentName"
placeholder="请输入部门名称"
clearable
size="small"
@keyup.enter.native="handleQuery"
>
</el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
1.2管理plf的列表、添加、修改、删除和导出操作。以下是代码的主要功能
1. 导入所需的API函数,如listTimeLine、getTime、delTime、addTime、updateTime和exportTime。
2. 定义一个名为Trace的Vue组件,包含一些属性和方法。
3. 在data()方法中定义了一些变量,如timeList(plf列表)、queryParams(查询参数)等。
4. 在methods对象中定义了一些方法,如getList()(获取plf列表)、handleQuery()(处理查询按钮点击事件)、resetQuery()(重置查询表单)、handleAdd()(处理添加按钮点击事件)、handleUpdate()(处理修改按钮点击事件)、submitForm()(提交表单)、handleDelete()(处理删除按钮点击事件)和handleExport()(处理导出按钮点击事件)。
5. 在mounted()生命周期钩子中调用getList()方法,以在组件挂载时获取plf列表。
6. 在created()生命周期钩子中调用getList()方法,以在组件创建时获取plf列表。
<script>
import { listTimeLine, getTime, delTime, addTime, updateTime, exportTime,listTime } from "@/api/system/time";
import Timeline from "@/api/system/Timeline";
export default {
components: {
Timeline,
},
computed: {},
name: "Trace",
props: [],
data() {
return {
nomore: false,
// 遮罩层
loading: true,
// 导出遮罩层
exportLoading: false,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
total1: 0,
// plf表格数据
timeList: [],
oneTimeList:[],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
crankshaftId: null,
beginTime: null,
endTime: null,
processId: null,
deviceId: null,
productId: null,
flagQuafilied: null,
flagInspect: 0,
flagWork:null
},
queryParams1: {
pageNum: 1,
pageSize: 9999,
crankshaftId: null,
beginTime: null,
endTime: null,
processId: null,
deviceId: null,
productId: null,
flagQuafilied: null,
flagInspect: null,
flagWork:null,
processname: undefined,
processid: undefined,
equipmentid: undefined,
departmentname: undefined,
},
// 表单参数
formData: {
processname: undefined,
processid: undefined,
equipmentid: undefined,
departmentname: undefined,
},
// 表单校验
rules: {
processname: [{
required: true,
message: '请输入工序名称',
trigger: 'blur'
}],
processid: [{
required: true,
message: '请输入工序编号',
trigger: 'blur'
}],
equipmentid: [{
required: true,
message: '请输入设备编号',
trigger: 'blur'
}],
departmentname: [{
required: true,
message: '请输入部门名称',
trigger: 'blur'
}],
},
};
},
watch: {},
mounted() {},
created() {
this.getList();
},
methods: {
/** 查询plf列表 */
getList() {
this.loading = true;
listTime(this.queryParams).then(response => {
this.timeList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.timeList = [];
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length!==1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加plf";
},
/** 修改按钮操作 */
getListLine(row) {
//this.reset();
this.loading = true;
this.queryParams1.crankshaftId=row.crankshaftId;
listTimeLine(this.queryParams1).then(response => {
this.oneTimeList = response.rows;
this.total1 = response.total;
this.loading = false;
this.open = true;
});
},
handleUpdate(row) {
this.reset();
const id = row.id || this.ids
getTime(id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改plf";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.id != null) {
updateTime(this.form).then(response => {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addTime(this.form).then(response => {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.id || this.ids;
this.$confirm('是否确认删除plf编号为"' + ids + '"的数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return delTime(ids);
}).then(() => {
this.getList();
this.msgSuccess("删除成功");
}).catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
this.$confirm('是否确认导出所有plf数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(() => {
this.exportLoading = true;
return exportTime(queryParams);
}).then(response => {
this.download(response.msg);
this.exportLoading = false;
}).catch(() => {});
}
}
};
</script>