yudao-dev/src/views/core/base/equipment/index.vue

639 lines
14 KiB
Vue
Raw Normal View History

2023-08-10 16:52:47 +08:00
<template>
2023-08-16 14:29:29 +08:00
<div class="app-container">
<!-- 搜索工作栏 -->
<SearchBar
:formConfigs="searchBarFormConfig"
ref="search-bar"
@headBtnClick="handleSearchBarBtnClick" />
2023-08-10 16:52:47 +08:00
2023-08-16 14:29:29 +08:00
<!-- 列表 -->
<base-table
:table-props="tableProps"
:page="queryParams.pageNo"
:limit="queryParams.pageSize"
:table-data="list"
@emitFun="handleEmitFun">
<method-btn
v-if="tableBtn.length"
slot="handleBtn"
2023-09-15 15:45:37 +08:00
:width="120"
2023-08-16 14:29:29 +08:00
label="操作"
:method-list="tableBtn"
@clickBtn="handleTableBtnClick" />
</base-table>
2023-08-10 16:52:47 +08:00
2023-08-16 14:29:29 +08:00
<!-- 分页组件 -->
<pagination
v-show="total > 0"
:total="total"
:page.sync="queryParams.pageNo"
:limit.sync="queryParams.pageSize"
@pagination="getList" />
2023-08-10 16:52:47 +08:00
2023-08-22 15:53:02 +08:00
<!-- 对话框(添加) -->
2023-08-16 14:29:29 +08:00
<base-dialog
:dialogTitle="title"
:dialogVisible="open"
@close="cancel"
@cancel="cancel"
2023-10-12 11:08:51 +08:00
width="60%"
2023-08-16 14:29:29 +08:00
@confirm="submitForm">
2023-08-24 15:36:38 +08:00
<DialogForm
v-if="open"
key="index-dialog-form"
ref="form"
2023-10-12 11:08:51 +08:00
label-position="top"
size="small"
2023-08-24 15:36:38 +08:00
:dataForm="form"
2023-10-12 17:03:07 +08:00
:rows="computedRows" />
2023-08-16 14:29:29 +08:00
</base-dialog>
2023-08-22 15:53:02 +08:00
<!-- 设备 详情 - 编辑 -->
<EquipmentDrawer
v-if="editVisible"
2023-08-22 17:00:43 +08:00
ref="drawer"
2023-08-22 15:53:02 +08:00
:mode="editMode"
2023-10-16 13:35:43 +08:00
@update-mode="editMode = $event"
2023-08-24 11:07:55 +08:00
:data-id="form.id"
2023-08-22 17:00:43 +08:00
:sections="[
2023-08-23 15:15:29 +08:00
{
name: '基本信息',
key: 'base',
2023-10-12 17:03:07 +08:00
rows: computedRows,
2023-10-17 15:22:17 +08:00
url: '/base/core-equipment/get',
urlUpdate: '/base/core-equipment/update',
urlCreate: '/base/core-equipment/create',
2023-08-23 15:15:29 +08:00
queryParams: { id: form.id },
},
2023-08-22 17:00:43 +08:00
{
name: '属性列表',
key: 'attrs',
props: drawerListProps,
2023-08-23 15:15:29 +08:00
url: '/base/equipment-attr/page',
2023-08-24 11:07:55 +08:00
urlCreate: '/base/equipment-attr/create',
urlUpdate: '/base/equipment-attr/update',
urlDelete: '/base/equipment-attr/delete',
urlDetail: '/base/equipment-attr/get',
2023-08-23 15:15:29 +08:00
queryParams: {
equipmentId: form.id,
pageNo: 1,
pageSize: 10,
},
2023-08-24 11:07:55 +08:00
tableBtn: [
this.$auth.hasPermi('base:equipment-attr:update')
? {
type: 'edit',
btnName: '修改',
}
: undefined,
this.$auth.hasPermi('base:equipment-attr:delete')
? {
type: 'delete',
btnName: '删除',
}
: undefined,
].filter((v) => v),
2023-08-23 15:15:29 +08:00
allowAdd: true,
2023-08-22 17:00:43 +08:00
},
]"
2023-08-23 15:15:29 +08:00
@refreshDataList="getList"
2023-10-12 17:03:07 +08:00
@cancel="cancelEdit"
@destroy="cancelEdit" />
2023-08-16 14:29:29 +08:00
</div>
2023-08-10 16:52:47 +08:00
</template>
<script>
2023-08-16 14:29:29 +08:00
import moment from 'moment';
import basicPageMixin from '@/mixins/lb/basicPageMixin';
2023-08-22 15:53:02 +08:00
import EquipmentDrawer from './components/EquipmentDrawer';
2023-08-16 14:29:29 +08:00
import {
createEquipment,
updateEquipment,
deleteEquipment,
getEquipment,
getEquipmentPage,
exportEquipmentExcel,
} from '@/api/base/equipment';
2023-08-10 16:52:47 +08:00
import Editor from '@/components/Editor';
2023-10-12 17:03:07 +08:00
import AssetsUpload from './components/AssetsUpload.vue';
2023-08-10 16:52:47 +08:00
export default {
2023-08-16 14:29:29 +08:00
name: 'Equipment',
components: {
Editor,
2023-08-22 15:53:02 +08:00
EquipmentDrawer,
2023-08-16 14:29:29 +08:00
},
mixins: [basicPageMixin],
data() {
return {
searchBarKeys: ['name', 'code'],
tableBtn: [
2023-10-17 17:02:53 +08:00
this.$auth.hasPermi(`base:equipment:update`)
? {
type: 'detail',
btnName: '详情',
}
: undefined,
2023-08-16 14:29:29 +08:00
this.$auth.hasPermi('base:equipment:update')
? {
type: 'edit',
btnName: '修改',
}
: undefined,
this.$auth.hasPermi('base:equipment:delete')
? {
type: 'delete',
btnName: '删除',
}
: undefined,
].filter((v) => v),
tableProps: [
{
prop: 'createTime',
label: '添加时间',
fixed: true,
width: 180,
filter: (val) => moment(val).format('yyyy-MM-DD HH:mm:ss'),
},
2023-09-15 14:30:19 +08:00
{ prop: 'name', label: '设备名称' },
2023-10-12 11:08:51 +08:00
{ width: 256, prop: 'code', label: '设备编码' },
2023-09-15 14:30:19 +08:00
{ prop: 'equipmentType', label: '设备类型' },
{ prop: 'enName', label: '英文名称' },
{ prop: 'abbr', label: '缩写' },
2023-10-09 16:27:44 +08:00
// {
// action: 'show-detail',
// label: '详情',
// subcomponent: {
// props: ['injectData'],
// render: function (h) {
// const _this = this;
// return h(
// 'el-button',
// {
// props: { type: 'text', size: 'mini' },
// on: {
// click: function () {
// console.log('inejctdata', _this.injectData);
// _this.$emit('emitData', {
// action: _this.injectData.action,
// value: _this.injectData.id,
// });
// },
// },
// },
// '查看详情'
// );
// },
// },
// },
2023-08-16 14:29:29 +08:00
],
searchBarFormConfig: [
{
type: 'input',
label: '名称',
placeholder: '请输入设备名称',
param: 'name',
},
{
type: 'input',
label: '编码',
placeholder: '请输入设备编码',
2023-08-24 15:36:38 +08:00
param: 'code',
2023-08-16 14:29:29 +08:00
},
{
type: 'button',
btnName: '查询',
name: 'search',
color: 'primary',
},
{
type: 'separate',
},
2023-10-17 17:02:53 +08:00
{
type: this.$auth.hasPermi('base:equipment:export') ? 'button' : '',
btnName: '导出',
name: 'export',
plain: true,
color: 'primary',
},
2023-08-16 14:29:29 +08:00
{
type: this.$auth.hasPermi('base:equipment:create') ? 'button' : '',
btnName: '新增',
name: 'add',
plain: true,
color: 'success',
},
],
rows: [
[
{
input: true,
label: '设备名称',
prop: 'name',
rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
// bind: {
2023-08-24 11:07:55 +08:00
// disabled: this.editMode == 'detail', // some condition, like detail mode...
2023-08-16 14:29:29 +08:00
// }
},
{
input: true,
label: '设备编码',
prop: 'code',
2023-10-17 15:22:17 +08:00
url: '/base/core-equipment/getCode',
2023-08-16 14:29:29 +08:00
},
{
input: true,
label: '英文名称',
prop: 'enName',
// rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
// bind: {
// disabled: true, // some condition, like detail mode...
// }
},
2023-10-12 11:08:51 +08:00
],
[
2023-08-16 14:29:29 +08:00
{
input: true,
label: '缩写',
prop: 'abbr',
// rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
// bind: {
// disabled: true, // some condition, like detail mode...
// }
},
2023-10-12 11:08:51 +08:00
2023-08-16 14:29:29 +08:00
{
select: true,
label: '设备类型',
prop: 'equipmentTypeId',
2023-10-17 15:22:17 +08:00
url: '/base/core-equipment-type/page?pageNo=1&pageSize=100',
2023-10-12 11:08:51 +08:00
bind: {
filterable: true,
},
2023-08-16 14:29:29 +08:00
},
2023-08-18 16:56:53 +08:00
// {
// select: true,
// label: '设备分组',
// prop: 'groupId',
// url: '/base/equipment-group/page?pageNo=1&pageSize=100',
// },
{ input: true, label: '备注', prop: 'remark' },
2023-08-16 14:29:29 +08:00
],
[
{
2023-08-22 15:53:02 +08:00
datetime: true,
2023-08-16 14:29:29 +08:00
label: '生产日期',
prop: 'productionTime',
},
{
2023-08-22 15:53:02 +08:00
datetime: true,
2023-08-16 14:29:29 +08:00
label: '进厂日期',
prop: 'enterTime',
},
{
2023-08-22 15:53:02 +08:00
input: true,
2023-08-18 16:56:53 +08:00
prop: 'tvalue',
2023-08-16 14:29:29 +08:00
label: '设备TT值',
rules: [
{ required: true, message: '不能为空', trigger: 'blur' },
{
type: 'number',
message: '请输入正确的数字值',
trigger: 'blur',
transform: (val) => Number(val),
},
],
},
2023-10-12 11:08:51 +08:00
],
[
2023-08-16 14:29:29 +08:00
{
2023-08-22 15:53:02 +08:00
input: true,
2023-10-12 11:08:51 +08:00
label: '产品加工时间s',
2023-08-16 14:29:29 +08:00
prop: 'processingTime',
rules: [
2023-10-12 11:08:51 +08:00
{ required: true, message: '不能为空', trigger: 'blur' },
2023-08-16 14:29:29 +08:00
{
type: 'number',
message: '请输入正确的数字值',
trigger: 'blur',
transform: (val) => Number(val),
},
],
},
2023-10-12 11:08:51 +08:00
2023-08-16 14:29:29 +08:00
{
2023-08-22 15:53:02 +08:00
input: true,
2023-08-16 14:29:29 +08:00
label: '制造商',
// rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
prop: 'manufacturer',
},
{
2023-08-22 15:53:02 +08:00
input: true,
2023-08-16 14:29:29 +08:00
label: '设备规格',
prop: 'spec',
},
],
[
{
textarea: true,
label: '功能描述',
// rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
prop: 'description',
},
],
2023-10-12 17:03:07 +08:00
// [
// {
// assetUpload: true,
// label: '上传资料',
// fieldName: 'assets',
// subcomponent: AssetsUpload
// },
// ],
// [
// {
// assetUpload: true,
// label: '上传图片',
// fieldName: 'images',
// subcomponent: AssetsUpload
// },
// ],
// [
// {
// upload: true,
// label: '上传资料',
// prop: 'uploadFiles',
// url: process.env.VUE_APP_BASE_API + '/admin-api/infra/file/upload', // 请求地址
// uploadFnName: 'assetsUpload', // 上传方法名
// bind: {
// headers: { Authorization: 'Bearer ' + getAccessToken() },
// 'show-file-list': false,
// },
// },
// {
// diy: true,
// key: 'eq-assets',
// label: '设备资料',
// prop: 'fileNames',
// subcomponent: EquipmentAssets,
// },
// ],
// [
// {
// upload: true,
// label: '上传图片',
// prop: 'uploadImages',
// url: process.env.VUE_APP_BASE_API + '/admin-api/infra/file/upload', // 请求地址
// uploadFnName: 'imagesUpload', // 上传方法名
// bind: {
// headers: { Authorization: 'Bearer ' + getAccessToken() },
// 'show-file-list': false,
// },
// },
// {
// diy: true,
// key: 'eq-pics',
// label: '设备图片',
// prop: 'fileUrls',
// subcomponent: EquipmentPics,
// pictures: async () => {
// // some async request
// return [];
// },
// },
// ],
// [
// {
// diy: true,
// key: 'eq-pics',
// label: '设备图片',
// prop: 'fileUrls',
// subcomponent: EquipmentPics,
// pictures: async () => {
// // some async request
// return [];
// },
// },
// ],
2023-08-16 14:29:29 +08:00
],
2023-08-22 15:53:02 +08:00
editVisible: false,
editMode: 'edit', // 'edit', 'detail'
2023-08-22 17:00:43 +08:00
// drawer 里的设备属性列表配置项
drawerListProps: [
{
prop: 'createTime',
label: '添加时间',
fixed: true,
width: 180,
filter: (val) => moment(val).format('yyyy-MM-DD HH:mm:ss'),
},
2023-09-15 14:30:19 +08:00
{ prop: 'name', label: '属性名称' },
{ prop: 'value', label: '属性值' },
2023-08-22 17:00:43 +08:00
],
// 是否显示弹出层
open: false,
2023-08-16 14:29:29 +08:00
// 查询参数
queryParams: {
pageNo: 1,
pageSize: 10,
2023-08-18 16:56:53 +08:00
code: '',
name: '',
2023-08-16 14:29:29 +08:00
},
// 表单参数
2023-08-23 15:15:29 +08:00
form: {
id: null,
},
2023-10-12 17:03:07 +08:00
showUploadComponents: false, // 是否显示上传组件
2023-08-16 14:29:29 +08:00
};
},
created() {
this.getList();
},
2023-10-12 17:03:07 +08:00
computed: {
computedRows() {
return this.showUploadComponents
? [
...this.rows,
[
{
assetUpload: true,
key: 'eq-assets', // 用于区分不同的上传组件
label: '上传资料',
fieldName: 'assets',
subcomponent: AssetsUpload,
2023-10-16 13:35:43 +08:00
prop: 'uploadedAssets',
default: [],
2023-10-13 17:01:49 +08:00
bind: {
'is-pic-mode': false,
},
2023-10-12 17:03:07 +08:00
},
],
[
{
assetUpload: true,
key: 'eq-pics', // 用于区分不同的上传组件
label: '上传图片',
fieldName: 'images',
subcomponent: AssetsUpload,
2023-10-16 13:35:43 +08:00
// prop: '',
// default: [],
2023-10-13 17:01:49 +08:00
bind: {
'is-pic-mode': true,
},
2023-10-12 17:03:07 +08:00
},
],
]
: this.rows;
},
},
2023-08-16 14:29:29 +08:00
methods: {
/** 查询列表 */
getList() {
this.loading = true;
// 执行查询
getEquipmentPage(this.queryParams).then((response) => {
this.list = response.data.list;
this.total = response.data.total;
this.loading = false;
});
},
/** 取消按钮 */
cancel() {
this.open = false;
this.reset();
},
2023-10-12 17:03:07 +08:00
cancelEdit() {
this.showUploadComponents = false;
this.editVisible = false;
},
2023-08-16 14:29:29 +08:00
/** 表单重置 */
reset() {
this.form = {
id: undefined,
code: undefined,
name: undefined,
enName: undefined,
abbr: undefined,
enterTime: undefined,
productionTime: undefined,
equipmentTypeId: undefined,
groupId: undefined,
tvalue: undefined,
processingTime: undefined,
manufacturer: undefined,
spec: undefined,
description: undefined,
remark: undefined,
};
this.resetForm('form');
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
2023-10-12 17:03:07 +08:00
this.showUploadComponents = false;
2023-08-16 14:29:29 +08:00
this.title = '添加设备';
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
2023-10-12 17:03:07 +08:00
this.showUploadComponents = true;
2023-08-16 14:29:29 +08:00
const id = row.id;
getEquipment(id).then((response) => {
this.form = response.data;
this.open = true;
this.title = '修改设备';
});
},
/** 提交按钮 */
submitForm() {
this.$refs['form'].validate((valid) => {
if (!valid) {
return;
}
// 修改的提交
if (this.form.id != null) {
updateEquipment(this.form).then((response) => {
this.$modal.msgSuccess('修改成功');
this.open = false;
this.getList();
});
return;
}
// 添加的提交
createEquipment(this.form).then((response) => {
this.$modal.msgSuccess('新增成功');
this.open = false;
this.getList();
});
});
},
/** 删除按钮操作 */
handleDelete(row) {
const id = row.id;
this.$modal
2023-09-22 16:54:16 +08:00
.confirm('是否确认删除设备名称为"' + row.name + '"的数据项?')
2023-08-16 14:29:29 +08:00
.then(function () {
return deleteEquipment(id);
})
.then(() => {
this.getList();
this.$modal.msgSuccess('删除成功');
})
.catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
// 处理查询参数
let params = { ...this.queryParams };
params.pageNo = undefined;
params.pageSize = undefined;
this.$modal
.confirm('是否确认导出所有设备数据项?')
.then(() => {
this.exportLoading = true;
return exportEquipmentExcel(params);
})
.then((response) => {
this.$download.excel(response, '设备.xls');
this.exportLoading = false;
})
.catch(() => {});
},
2023-08-24 11:07:55 +08:00
// 查看详情
viewDetail(id) {
this.reset();
this.editMode = 'detail';
2023-10-12 17:03:07 +08:00
this.showUploadComponents = true;
2023-08-24 11:07:55 +08:00
this.form.id = id;
this.editVisible = true;
this.$nextTick(() => {
this.$refs['drawer'].init();
});
},
// overwrite basicPageMixin 里的 处理表格按钮 方法
2023-08-22 15:53:02 +08:00
handleTableBtnClick({ data, type }) {
switch (type) {
case 'edit':
this.reset();
2023-08-23 15:15:29 +08:00
this.editMode = 'edit';
2023-10-12 17:03:07 +08:00
this.showUploadComponents = true;
2023-08-23 15:15:29 +08:00
this.form.id = data.id;
this.editVisible = true;
this.$nextTick(() => {
this.$refs['drawer'].init();
2023-08-22 15:53:02 +08:00
});
break;
case 'delete':
this.handleDelete(data);
break;
2023-10-09 16:27:44 +08:00
case 'detail':
const { id } = data;
this.viewDetail(id);
break;
2023-08-22 15:53:02 +08:00
}
},
2023-08-16 14:29:29 +08:00
},
2023-08-10 16:52:47 +08:00
};
</script>