查询界面显示明细表1
文档说明
注意:这是最新版本vue3语法的实现方式,旧版本或者在[表.jsx]中实现,见旧版本文档,查看
1.效果图

2.目录结构

3.代码实现
上面菜单设置的是哪张表,就在对应[表.vue]文件或者[表.jsx]文件实现
查看代码
MES_Process.vue(生成的vue文件)
<template>
<view-grid
ref="grid"
:columns="columns"
:detail="detail"
:editFormFields="editFormFields"
:editFormOptions="editFormOptions"
:searchFormFields="searchFormFields"
:searchFormOptions="searchFormOptions"
:table="table"
:extend="extend"
:onInit="onInit"
:onInited="onInited"
:searchBefore="searchBefore"
:searchAfter="searchAfter"
:addBefore="addBefore"
:updateBefore="updateBefore"
:rowClick="rowClick"
:modelOpenBefore="modelOpenBefore"
:modelOpenAfter="modelOpenAfter"
>
<!-- 自定义组件数据槽扩展,更多数据槽slot见文档 -->
<template #gridFooter>
<grid-footer ref="footerRef"></grid-footer>
</template>
</view-grid>
</template>
<script setup lang="jsx">
import gridFooter from './MES_ProcessFooter.vue'
import extend from '@/extension/mes/mes/MES_Process.jsx'
import viewOptions from './MES_Process/options.js'
import { ref, reactive, getCurrentInstance, watch, onMounted } from 'vue'
const grid = ref(null)
const { proxy } = getCurrentInstance()
//http请求,proxy.http.post/get
const {
table,
editFormFields,
editFormOptions,
searchFormFields,
searchFormOptions,
columns,
detail
} = reactive(viewOptions())
detail.columns.forEach((x) => {
if (x.link) {
x.link = false
}
})
let gridRef //对应[表.jsx]文件中this.使用方式一样
//生成对象属性初始化
const onInit = async ($vm) => {
gridRef = $vm
//启用明细表排序
gridRef.detailOptions.sortable = true
gridRef.pagination.sortName = 'ProcessSequence' //设置排序字段,多个字段排序用逗号隔开,如:a,b,c
gridRef.pagination.order = 'asc' //排序方式desc或者asc
gridRef.detailOptions.pagination.sortName = 'RouteDescription' //明细表排序字字段
gridRef.detailOptions.pagination.order = 'asc' //明细表排序方式desc或者asc
//与jsx中的this.xx使用一样,只需将this.xx改为gridRef.xx
//更多属性见:https://doc.volcore.xyz/docs/view-grid
}
//生成对象属性初始化后,操作明细表配置用到
const onInited = async () => {
gridRef.height = gridRef.height - 280
}
const searchBefore = async (param) => {
//界面查询前,可以给param.wheres添加查询参数
//返回false,则不会执行查询
return true
}
const searchAfter = async (rows, result) => {
return true
}
const addBefore = async (formData) => {
//新建保存前formData为对象,包括明细表,可以给给表单设置值,自己输出看formData的值
return true
}
const updateBefore = async (formData) => {
//编辑保存前formData为对象,包括明细表、删除行的Id
return true
}
const footerRef = ref()
//查询界面点击行事件,加载明细表数据
const rowClick = ({ row, column, event }) => {
// grid.value.toggleRowSelection(row); //单击行时选中当前行;
footerRef.value.gridRowClick(row)
}
const modelOpenBefore = async (row) => {
//弹出框打开后方法
return true //返回false,不会打开弹出框
}
const modelOpenAfter = (row) => {
//弹出框打开后方法,设置表单默认值,按钮操作等
}
//监听表单输入,做实时计算
//watch(() => editFormFields.字段,(newValue, oldValue) => { })
//对外暴露数据
defineExpose({})
</script>
MES_ProcessFooter.vue(显示的明细手动添加)
<template>
<div style="padding: 0 4px;border-top: 10px solid #eee;">
<vol-title style="padding: 10px;" title="工艺路线"></vol-title>
<!-- <h3>
<i class="ivu-icon ivu-icon-ios-information-circle-outline"></i>订单明细
</h3> -->
<div style="padding:10px;background: white;padding-top: 0;">
<!-- 更多table配置见文档:http://doc.volcore.xyz/table 或使用element plus原生table -->
<vol-table ref="tableRef" :ck="false" :loadKey="true" :columns="columns" :pagination-hide="true"
:height="230" :defaultLoadPage="false" @loadBefore="loadBefore" :url="url"
:row-index="true"></vol-table>
</div>
</div>
</template>
<script setup>
import { reactive, ref } from 'vue';
const loadBefore = (params, callback) => {//表格数据加载时触发
//更多table配置见文档:http://doc.volcore.xyz/table
// 这里也可以设置一些查询条件
params.order='asc'
return callback(true);
}
const tableRef = ref();
const gridRowClick = (row) => { //主表点击行加载明细表
//load方法可参照voltable组件api文档
tableRef.value?.load({ value: row.ProcessID, sort: "RouteSequence" })
}
const url = ref('api/MES_Process/getDetailPage')//指定从某个接口获取table数据
//更多table配置见文档:http://doc.volcore.xyz/table
//明细表格配置,从生成的vue文件中可以复制过来
const columns = reactive( [{field:'RouteID',title:'路线ID',type:'string',width:90,hidden:true,readonly:true,require:true,align:'left'},
{field:'ProcessID',title:'工序',type:'string',width:90,hidden:true,align:'left'},
{field:'ProductID',title:'产品ID',type:'string',width:90,hidden:true,align:'left'},
{field:'ProductName',title:'路线名称',type:'string',width:90,edit:{type:''},require:true,align:'left'},
{field:'RouteSequence',title:'路线顺序',type:'int',width:90,edit:{type:''},require:true,align:'left'},
{field:'RouteDescription',title:'路线描述',type:'string',width:90,edit:{type:''},align:'left'}])
defineExpose({ gridRowClick })
</script>
<style scoped>
h3 {
font-weight: 500;
padding-left: 10px;
background: white;
margin-top: 8px;
padding-bottom: 5px;
}
</style>
************************************************************************************************************************
查询界面显示明细表2
差异说明
与上面的示例区别,这里引用的明细表是生成的vue文件,可以在当前页面同时修改编辑明细表

代码实现
查看代码
MES_Bom_Main.vue(生成的页面制造BOM主表)
<template>
<view-grid ref="grid" :columns="columns" :detail="detail" :editFormFields="editFormFields"
:editFormOptions="editFormOptions" :searchFormFields="searchFormFields" :searchFormOptions="searchFormOptions"
:table="table" :extend="extend" :onInit="onInit" :onInited="onInited" :searchBefore="searchBefore"
:searchAfter="searchAfter" :addBefore="addBefore" :updateBefore="updateBefore" :rowClick="rowClick"
:modelOpenBefore="modelOpenBefore" :modelOpenAfter="modelOpenAfter" :detailSortEnd="detailSortEnd">
<!-- 自定义组件数据槽扩展,更多数据槽slot见文档 -->
<template #gridHeader> </template>
<template #gridFooter>
<div class="bom-detail">
<bom-detail ref="bomDetailRef"></bom-detail>
</div>
</template>
<template #modelBody>
<el-alert style="margin-bottom: -1px" title="可拖动明细表对【序号】自动完成排序" class="alert-primary"
:closable="false"></el-alert>
</template>
</view-grid>
</template>
<script setup lang="jsx">
//引用生成的vue文件(明细表)
import bomDetail from './MES_Bom_Detail.vue'
import extend from '@/extension/mes/mes/MES_Bom_Main.jsx'
import viewOptions from './MES_Bom_Main/options.js'
import { ref, reactive, getCurrentInstance, watch, onMounted } from 'vue'
const grid = ref(null)
const { proxy } = getCurrentInstance()
//http请求,proxy.http.post/get
const {
table,
editFormFields,
editFormOptions,
searchFormFields,
searchFormOptions,
columns,
detail
} = reactive(viewOptions())
const bomDetailRef = ref();
let gridRef //对应[表.jsx]文件中this.使用方式一样
//生成对象属性初始化
const onInit = async ($vm) => {
gridRef = $vm
//缓存主表方法,返回主表选中的行,在下面的bom明细表[MES_Bom_Detail]中会调用
proxy.base.setItem('getBomSelectRow', () => {
return gridRef.getTable(true).getSelected();
})
//设置弹出框编辑宽度
gridRef.boxOptions.width = 1100
//启用明细表排序
gridRef.detailOptions.sortable = true
gridRef.detailOptions.pagination.sortName = "Sequence"; //明细表排序字字段
gridRef.detailOptions.pagination.order = "asc"; //明细表排序方式desc或者asc
}
//生成对象属性初始化后,操作明细表配置用到
const onInited = async () => {
gridRef.height = gridRef.height - 310;
if (gridRef.height < 200) {
gridRef.height = 200;
}
}
const searchBefore = async (param) => {
//界面查询前,可以给param.wheres添加查询参数
//返回false,则不会执行查询
return true
}
const searchAfter = async (rows, result) => {
return true
}
const addBefore = async (formData) => {
//新建保存前formData为对象,包括明细表,可以给给表单设置值,自己输出看formData的值
return true
}
const updateBefore = async (formData) => {
//编辑保存前formData为对象,包括明细表、删除行的Id
return true
}
const rowClick = ({ row, column, event }) => {
//点击行清除选中的行(用于下面明细表判断)
grid.value.clearSelection();
//点击行默认选中
grid.value.toggleRowSelection(row); //单击行时选中当前行;
//加载明细表
bomDetailRef.value.$refs.grid.search();
}
const modelOpenBefore = async (row) => {
//弹出框打开后方法
return true //返回false,不会打开弹出框
}
const modelOpenAfter = (row) => {
//弹出框打开后方法,设置表单默认值,按钮操作等
}
const detailSortEnd = (rows, newIndex, oldIndex, table) => {
rows.forEach((x, index) => {
x.Sequence = index + 1
})
}
//监听表单输入,做实时计算
//watch(() => editFormFields.字段,(newValue, oldValue) => { })
//对外暴露数据
defineExpose({})
</script>
<style lang="less" scoped>
.bom-detail {
margin-top: 13px;
border-top: 7px solid #eee;
}
</style>
MES_Bom_Detail.vue(生成的底部明细主表)
明细的vue文件只需要在onInit设置表格高度,与查询条件
<template>
<view-grid ref="grid" :columns="columns" :detail="detail" :editFormFields="editFormFields"
:editFormOptions="editFormOptions" :searchFormFields="searchFormFields" :searchFormOptions="searchFormOptions"
:table="table" :extend="extend" :onInit="onInit" :onInited="onInited" :searchBefore="searchBefore"
:searchAfter="searchAfter" :addBefore="addBefore" :updateBefore="updateBefore" :rowClick="rowClick"
:modelOpenBefore="modelOpenBefore" :modelOpenAfter="modelOpenAfter">
<!-- 自定义组件数据槽扩展,更多数据槽slot见文档 -->
<template #gridHeader>
</template>
</view-grid>
</template>
<script setup lang="jsx">
import extend from "@/extension/mes/mes/MES_Bom_Detail.jsx";
import viewOptions from './MES_Bom_Detail/options.js'
import { ref, reactive, getCurrentInstance, watch, onMounted } from "vue";
const grid = ref(null);
const { proxy } = getCurrentInstance()
//http请求,proxy.http.post/get
const { table, editFormFields, editFormOptions, searchFormFields, searchFormOptions, columns, detail } = reactive(viewOptions())
let gridRef;//对应[表.jsx]文件中this.使用方式一样
//生成对象属性初始化
const onInit = async ($vm) => {
gridRef = $vm;
//默认不加载数据
gridRef.load = false
}
//隐藏高级查询按钮
const onInited = async () => {
gridRef.height = 200;
gridRef.buttons.forEach(x => {
if (x.name == '高级查询') {
x.hidden = true;
}
})
}
const searchBefore = async (param) => {
//界面查询前,可以给param.wheres添加查询参数
//返回false,则不会执行查询
const bomRows = getBomSelectRow();
if (!bomRows.length) {
proxy.$message.error('请先选择【制造BOM】数据')
return false;
}
//查询前获取bom的id,查询明细表
param.wheres.push({ name: "BomId", value: bomRows[0].BomId })
return true;
}
const searchAfter = async (rows, result) => {
return true;
}
const addBefore = async (formData) => {
//明细表新建前获取【制造bom】选中的主键BomId值(若不获取,写入的明细表数据无法知道属于哪个nom)
const BomId = getBomSelectRow()[0].BomId;
formData.mainData['BomId'] = BomId
return true;
}
const updateBefore = async (formData) => {
//编辑保存前formData为对象,包括明细表、删除行的Id
return true;
}
const rowClick = ({ row, column, event }) => {
//查询界面点击行事件
}
//获取MES_Bom_Main.vue中缓存的方法,读取bom主表选中的行,保存数据时可以知道是哪条bom数据的明细
const getBomSelectRow = () => {
const fn = proxy.base.getItem('getBomSelectRow');
return fn();
}
const modelOpenBefore = async (row) => {//弹出框打开后方法
//获取MES_Bom_Main.vue中缓存的方法,读取bom主表选中的行,保存数据时可以知道是哪条bom数据的明细
const bomRows = getBomSelectRow();
if (!bomRows.length) {
proxy.$message.error('请先选择【制造BOM】数据')
return false;
}
return true;//返回false,不会打开弹出框
}
const modelOpenAfter = (row) => {
//弹出框打开后方法,设置表单默认值,按钮操作等
}
//监听表单输入,做实时计算
//watch(() => editFormFields.字段,(newValue, oldValue) => { })
//对外暴露数据
defineExpose({})
</script>