隐藏/显示 Table Row(s)

[table]
|| 第一行||
||第二行||
||第三行||
[/table]

现在要动态 show/hide 第2行。

方法如下,兼容(ff&&ie).

1)首先得用tbody包围相关的行,并设置id attribute。
 <table width="90%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td/><td>第一行</td><td/>
</tr>
<tbody id ="secondaryline">
<tr>
<td/><td>第二行</td><td/>
</tr>
</tbody>
<tr>
<td/><td>第三行</td><td/>
</tr>
</table>


2)使用javascript.
function showRow(id) {
row = document.getElementById(id);
(typeof row != 'undefined' && row != null) && (row.style.display = '');
}

function hideRow(id) {
row = document.getElementById(id);
(typeof row != 'undefined' && row != null) && (row.style.display = 'none');
}
<div id="purAccountDetail-print" class="print-container" > <el-row type="flex" class="row-bg" justify="space-between" align="middle"> <el-col><div class="grid-content center"><h2>{{datas.list[0]?.trader.name}}</h2></div></el-col> </el-row> <el-row type="flex" class="row-bg" justify="space-between" align="middle"> <el-col><div class="grid-content center" ><h3>往来对帐单</h3></div></el-col> </el-row> <el-row type="flex" class="row-bg" justify="space-between" align="middle"> <el-col :span="8"><div class="grid-content left">供货单位:{{datas.list[0]?.supplier.name}}</div></el-col> <el-col :span="8"><div class="grid-content center">对帐日期:{{formatDate(new Date())}}</div></el-col> <el-col :span="8"><div class="grid-content right">上期余额:{{datas.previousBalance}}</div></el-col> </el-row> <el-row> <el-table ref="tableRef" :data="datas.list" table-layout="fixed" border class="table-print" style="width: 100%" :summary-method="getSummaries" show-summary highlight-current-row> <el-table-column prop="purFormDetail.purForm.opTime" label="时间" /> <el-table-column prop="purPayment.paymentMethod.name" label="付款方式" /> <el-table-column prop="purPayment.company.name" label="汇款帐户名称" /> <el-table-column prop="purPayment.amount" label="汇款金额" :formatter="formatScore" /> <el-table-column prop="purFormDetail.storePosition.product.name" label="产品名称" /> <el-table-column prop="purFormDetail.storePosition.productSpec.name" label="规格" /> <el-table-column prop="purFormDetail.storePosition.productState.name" label="交货状态" /> <el-table-column prop="purFormDetail.quantity" label="数量" :formatter="formatScore" /> <el-table-column prop="purFormDetail.storePosition.productUnit.name" label="单位" width="50" /> <el-table-column prop="purFormDetail.number" label="辅助数量" :formatter="formatScore" /> <el-table-column prop="purFormDetail.storePosition.supportUnit.name" label="单位" width="50"/> <el-table-column prop="purFormDetail.price" label="价格" :formatter="formatScore" /> <el-table-column prop="purFormDetail.priceType.name" label="价格类型" /> <el-table-column prop="purFormDetail.amounts" :formatter="formatScore" label="发货金额"/> <el-table-column label="期未余额"> <template #default="{row,$index}"> {{getEndBalance(row,$index)}} </template> </el-table-column> </el-table> </el-row> <!-- 添加页码容器 --> <div class="page-number"> 第 {{ currentPageNumber }} 页 / 共 {{ totalPages }} 页 </div> </div> printJS({ printable: 'purAccountDetail-print', type: 'html', targetStyles: ['*'], maxWidth: 1400, font_size: 'llllll', style: `@media print { body { zoom: 58%; } @page { margin: 0; /* 设置页面边距 */ size: A4; /* 页面大小自适应 */ /* 隐藏页眉和页脚 */ @top-left { content: 'TCM管理软件'; font-size: 10px; } @top-center { content: ''; } @top-right { content: ''; } @bottom-left { content: ''; } @bottom-center { content: ''; } @bottom-right { content: ''; } } #purAccountDetail-print::before { content: "TCM 管理软件"; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) rotate(-45deg); font-size: 48px; opacity: 0.1; /* 调整透明度 */ color: #000; pointer-events: none; z-index: 9999; } }` });网页显示正常,打印预览中表格的行数总和的高度超出表格的高度,导致显示不完整
07-21
<div id="purAccountDetail-print" class="print-container" > <el-row type="flex" class="row-bg" justify="space-between" align="middle"> <el-col><div class="grid-content center"><h2>{{datas.list[0]?.trader.name}}</h2></div></el-col> </el-row> <el-row type="flex" class="row-bg" justify="space-between" align="middle"> <el-col><div class="grid-content center" ><h3>往来对帐单</h3></div></el-col> </el-row> <el-row type="flex" class="row-bg" justify="space-between" align="middle"> <el-col :span="8"><div class="grid-content left">供货单位:{{datas.list[0]?.supplier.name}}</div></el-col> <el-col :span="8"><div class="grid-content center">对帐日期:{{formatDate(new Date())}}</div></el-col> <el-col :span="8"><div class="grid-content right">上期余额:{{datas.previousBalance}}</div></el-col> </el-row> <el-row> <el-table ref="tableRef" :data="datas.list" table-layout="fixed" border class="table-print" style="width: 100%" :summary-method="getSummaries" show-summary highlight-current-row> <el-table-column prop="purFormDetail.purForm.opTime" label="时间" /> <el-table-column prop="purPayment.paymentMethod.name" label="付款方式" /> <el-table-column prop="purPayment.company.name" label="汇款帐户名称" /> <el-table-column prop="purPayment.amount" label="汇款金额" :formatter="formatScore" /> <el-table-column prop="purFormDetail.storePosition.product.name" label="产品名称" /> <el-table-column prop="purFormDetail.storePosition.productSpec.name" label="规格" /> <el-table-column prop="purFormDetail.storePosition.productState.name" label="交货状态" /> <el-table-column prop="purFormDetail.quantity" label="数量" :formatter="formatScore" /> <el-table-column prop="purFormDetail.storePosition.productUnit.name" label="单位" width="50" /> <el-table-column prop="purFormDetail.number" label="辅助数量" :formatter="formatScore" /> <el-table-column prop="purFormDetail.storePosition.supportUnit.name" label="单位" width="50"/> <el-table-column prop="purFormDetail.price" label="价格" :formatter="formatScore" /> <el-table-column prop="purFormDetail.priceType.name" label="价格类型" /> <el-table-column prop="purFormDetail.amounts" :formatter="formatScore" label="发货金额"/> <el-table-column label="期未余额"> <template #default="{row,$index}"> {{getEndBalance(row,$index)}} </template> </el-table-column> </el-table> </el-row> <!-- 添加页码容器 --> <div class="page-number"> 第 {{ currentPageNumber }} 页 / 共 {{ totalPages }} 页 </div> </div> printJS({ printable: 'purAccountDetail-print', type: 'html', targetStyles: ['*'], maxWidth: 1400, font_size: 'llllll', style: `@media print { body { zoom: 58%; } @page { margin: 0; /* 设置页面边距 */ size: A4; /* 页面大小自适应 */ /* 隐藏页眉和页脚 */ @top-left { content: 'TCM管理软件'; font-size: 10px; } @top-center { content: ''; } @top-right { content: ''; } @bottom-left { content: ''; } @bottom-center { content: ''; } @bottom-right { content: ''; } } #purAccountDetail-print::before { content: "TCM 管理软件"; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) rotate(-45deg); font-size: 48px; opacity: 0.1; /* 调整透明度 */ color: #000; pointer-events: none; z-index: 9999; } }` });打印时表格的高度超出容器的高度,导致显示不完整
07-21
<div id="purAccountDetail-print" class="print-container" > <el-row type="flex" class="row-bg" justify="space-between" align="middle"> <el-col><div class="grid-content center"><h2>{{datas.list[0]?.trader.name}}</h2></div></el-col> </el-row> <el-row type="flex" class="row-bg" justify="space-between" align="middle"> <el-col><div class="grid-content center" ><h3>往来对帐单</h3></div></el-col> </el-row> <el-row type="flex" class="row-bg" justify="space-between" align="middle"> <el-col :span="8"><div class="grid-content left">供货单位:{{datas.list[0]?.supplier.name}}</div></el-col> <el-col :span="8"><div class="grid-content center">对帐日期:{{formatDate(new Date())}}</div></el-col> <el-col :span="8"><div class="grid-content right">上期余额:{{datas.previousBalance}}</div></el-col> </el-row> <el-row> <el-table ref="tableRef" :data="datas.list" table-layout="fixed" border class="table-print" style="width: 100%" :summary-method="getSummaries" show-summary highlight-current-row> <el-table-column prop="purFormDetail.purForm.opTime" label="时间" /> <el-table-column prop="purPayment.paymentMethod.name" label="付款方式" /> <el-table-column prop="purPayment.company.name" label="汇款帐户名称" /> <el-table-column prop="purPayment.amount" label="汇款金额" :formatter="formatScore" /> <el-table-column prop="purFormDetail.storePosition.product.name" label="产品名称" /> <el-table-column prop="purFormDetail.storePosition.productSpec.name" label="规格" /> <el-table-column prop="purFormDetail.storePosition.productState.name" label="交货状态" /> <el-table-column prop="purFormDetail.quantity" label="数量" :formatter="formatScore" /> <el-table-column prop="purFormDetail.storePosition.productUnit.name" label="单位" width="50" /> <el-table-column prop="purFormDetail.number" label="辅助数量" :formatter="formatScore" /> <el-table-column prop="purFormDetail.storePosition.supportUnit.name" label="单位" width="50"/> <el-table-column prop="purFormDetail.price" label="价格" :formatter="formatScore" /> <el-table-column prop="purFormDetail.priceType.name" label="价格类型" /> <el-table-column prop="purFormDetail.amounts" :formatter="formatScore" label="发货金额"/> <el-table-column label="期未余额"> <template #default="{row,$index}"> {{getEndBalance(row,$index)}} </template> </el-table-column> </el-table> </el-row> <!-- 添加页码容器 --> <div class="page-number"> 第 {{ currentPageNumber }} 页 / 共 {{ totalPages }} 页 </div> </div> printJS({ printable: 'purAccountDetail-print', type: 'html', targetStyles: ['*'], maxWidth: 1400, font_size: 'llllll', style: `@media print { body { zoom: 58%; } @page { margin: 0; /* 设置页面边距 */ size: A4; /* 页面大小自适应 */ /* 隐藏页眉和页脚 */ @top-left { content: 'TCM管理软件'; font-size: 10px; } @top-center { content: ''; } @top-right { content: ''; } @bottom-left { content: ''; } @bottom-center { content: ''; } @bottom-right { content: ''; } } #purAccountDetail-print::before { content: "TCM 管理软件"; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) rotate(-45deg); font-size: 48px; opacity: 0.1; /* 调整透明度 */ color: #000; pointer-events: none; z-index: 9999; } }` });网页显示正常,打印预览中表格的高度超出容器的高度,导致显示不完整,容器的高度可以根据表格的高度自适应吗
07-21
<template> <div class="app-container"> <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"> <el-form-item label="菜单名称" prop="menuName"> <el-input v-model="queryParams.menuName" placeholder="请输入菜单名称" clearable @keyup.enter.native="handleQuery" /> </el-form-item> <el-form-item label="状态" prop="status"> <el-select v-model="queryParams.status" placeholder="菜单状态" clearable> <el-option v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.label" :value="dict.value" /> </el-select> </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"> <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['system:menu:add']" >新增</el-button> </el-col> <el-col :span="1.5"> <el-button type="info" plain icon="el-icon-sort" size="mini" @click="toggleExpandAll" >展开/折叠</el-button> </el-col> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> </el-row> <el-table v-if="refreshTable" v-loading="loading" :data="menuList" row-key="menuId" :default-expand-all="isExpandAll" :tree-props="{children: 'children', hasChildren: 'hasChildren'}" > <el-table-column prop="menuName" label="菜单名称" :show-overflow-tooltip="true" width="160"></el-table-column> <el-table-column prop="icon" label="图标" align="center" width="100"> <template slot-scope="scope"> <svg-icon :icon-class="scope.row.icon" /> </template> </el-table-column> <el-table-column prop="orderNum" label="排序" width="60"></el-table-column> <el-table-column prop="perms" label="权限标识" :show-overflow-tooltip="true"></el-table-column> <el-table-column prop="component" label="组件路径" :show-overflow-tooltip="true"></el-table-column> <el-table-column prop="status" label="状态" width="80"> <template slot-scope="scope"> <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/> </template> </el-table-column> <el-table-column label="创建时间" align="center" prop="createTime"> <template slot-scope="scope"> <span>{{ parseTime(scope.row.createTime) }}</span> </template> </el-table-column> <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> <template slot-scope="scope"> <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:menu:edit']" >修改</el-button> <el-button size="mini" type="text" icon="el-icon-plus" @click="handleAdd(scope.row)" v-hasPermi="['system:menu:add']" >新增</el-button> <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['system:menu:remove']" >删除</el-button> </template> </el-table-column> </el-table> <!-- 添加或修改菜单对话框 --> <el-dialog :title="title" :visible.sync="open" width="680px" append-to-body> <el-form ref="form" :model="form" :rules="rules" label-width="100px"> <el-row> <el-col :span="24"> <el-form-item label="上级菜单" prop="parentId"> <treeselect v-model="form.parentId" :options="menuOptions" :normalizer="normalizer" :show-count="true" placeholder="选择上级菜单" /> </el-form-item> </el-col> </el-row> <el-row> <el-col :span="24"> <el-form-item label="菜单类型" prop="menuType"> <el-radio-group v-model="form.menuType"> <el-radio label="M">目录</el-radio> <el-radio label="C">菜单</el-radio> <el-radio label="F">按钮</el-radio> </el-radio-group> </el-form-item> </el-col> </el-row> <el-row> <el-col :span="12" v-if="form.menuType != 'F'"> <el-form-item label="菜单图标" prop="icon"> <el-popover placement="bottom-start" width="460" trigger="click" @show="$refs['iconSelect'].reset()" > <IconSelect ref="iconSelect" @selected="selected" :active-icon="form.icon" /> <el-input slot="reference" v-model="form.icon" placeholder="点击选择图标" readonly> <svg-icon v-if="form.icon" slot="prefix" :icon-class="form.icon" style="width: 25px;" /> <i v-else slot="prefix" class="el-icon-search el-input__icon" /> </el-input> </el-popover> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label="显示排序" prop="orderNum"> <el-input-number v-model="form.orderNum" controls-position="right" :min="0" /> </el-form-item> </el-col> </el-row> <el-row> <el-col :span="12"> <el-form-item label="菜单名称" prop="menuName"> <el-input v-model="form.menuName" placeholder="请输入菜单名称" /> </el-form-item> </el-col> <el-col :span="12" v-if="form.menuType == 'C'"> <el-form-item prop="routeName"> <el-input v-model="form.routeName" placeholder="请输入路由名称" /> <span slot="label"> <el-tooltip content="默认不填则和路由地址相同:如地址为:`user`,则名称为`User`(注意:为避免名字的冲突,特殊情况下请自定义,保证唯一性)" placement="top"> <i class="el-icon-question"></i> </el-tooltip> 路由名称 </span> </el-form-item> </el-col> </el-row> <el-row> <el-col :span="12" v-if="form.menuType != 'F'"> <el-form-item prop="isFrame"> <span slot="label"> <el-tooltip content="选择是外链则路由地址需要以`http(s)://`开头" placement="top"> <i class="el-icon-question"></i> </el-tooltip> 是否外链 </span> <el-radio-group v-model="form.isFrame"> <el-radio label="0">是</el-radio> <el-radio label="1">否</el-radio> </el-radio-group> </el-form-item> </el-col> <el-col :span="12" v-if="form.menuType != 'F'"> <el-form-item prop="path"> <span slot="label"> <el-tooltip content="访问的路由地址,如:`user`,如外网地址需内链访问则以`http(s)://`开头" placement="top"> <i class="el-icon-question"></i> </el-tooltip> 路由地址 </span> <el-input v-model="form.path" placeholder="请输入路由地址" /> </el-form-item> </el-col> </el-row> <el-row> <el-col :span="12" v-if="form.menuType == 'C'"> <el-form-item prop="component"> <span slot="label"> <el-tooltip content="访问的组件路径,如:`system/user/index`,默认在`views`目录下" placement="top"> <i class="el-icon-question"></i> </el-tooltip> 组件路径 </span> <el-input v-model="form.component" placeholder="请输入组件路径" /> </el-form-item> </el-col> <el-col :span="12" v-if="form.menuType != 'M'"> <el-form-item prop="perms"> <el-input v-model="form.perms" placeholder="请输入权限标识" maxlength="100" /> <span slot="label"> <el-tooltip content="控制器中定义的权限字符,如:@PreAuthorize(`@ss.hasPermi('system:user:list')`)" placement="top"> <i class="el-icon-question"></i> </el-tooltip> 权限字符 </span> </el-form-item> </el-col> </el-row> <el-row> <el-col :span="12" v-if="form.menuType == 'C'"> <el-form-item prop="query"> <el-input v-model="form.query" placeholder="请输入路由参数" maxlength="255" /> <span slot="label"> <el-tooltip content='访问路由的默认传递参数,如:`{"id": 1, "name": "ry"}`' placement="top"> <i class="el-icon-question"></i> </el-tooltip> 路由参数 </span> </el-form-item> </el-col> <el-col :span="12" v-if="form.menuType == 'C'"> <el-form-item prop="isCache"> <span slot="label"> <el-tooltip content="选择是则会被`keep-alive`缓存,需要匹配组件的`name`和地址保持一致" placement="top"> <i class="el-icon-question"></i> </el-tooltip> 是否缓存 </span> <el-radio-group v-model="form.isCache"> <el-radio label="0">缓存</el-radio> <el-radio label="1">不缓存</el-radio> </el-radio-group> </el-form-item> </el-col> </el-row> <el-row> <el-col :span="12" v-if="form.menuType != 'F'"> <el-form-item prop="visible"> <span slot="label"> <el-tooltip content="选择隐藏则路由将不会出现在侧边栏,但仍然可以访问" placement="top"> <i class="el-icon-question"></i> </el-tooltip> 显示状态 </span> <el-radio-group v-model="form.visible"> <el-radio v-for="dict in dict.type.sys_show_hide" :key="dict.value" :label="dict.value" >{{dict.label}}</el-radio> </el-radio-group> </el-form-item> </el-col> <el-col :span="12"> <el-form-item prop="status"> <span slot="label"> <el-tooltip content="选择停用则路由将不会出现在侧边栏,也不能被访问" placement="top"> <i class="el-icon-question"></i> </el-tooltip> 菜单状态 </span> <el-radio-group v-model="form.status"> <el-radio v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.value" >{{dict.label}}</el-radio> </el-radio-group> </el-form-item> </el-col> </el-row> </el-form> <div slot="footer" class="dialog-footer"> <el-button type="primary" @click="submitForm">确 定</el-button> <el-button @click="cancel">取 消</el-button> </div> </el-dialog> </div> </template> <script> import { listMenu, getMenu, delMenu, addMenu, updateMenu } from "@/api/system/menu" import Treeselect from "@riophae/vue-treeselect" import "@riophae/vue-treeselect/dist/vue-treeselect.css" import IconSelect from "@/components/IconSelect" export default { name: "Menu", dicts: ['sys_show_hide', 'sys_normal_disable'], components: { Treeselect, IconSelect }, data() { return { // 遮罩层 loading: true, // 显示搜索条件 showSearch: true, // 菜单表格树数据 menuList: [], // 菜单树选项 menuOptions: [], // 弹出层标题 title: "", // 是否显示弹出层 open: false, // 是否展开,默认全部折叠 isExpandAll: false, // 重新渲染表格状态 refreshTable: true, // 查询参数 queryParams: { menuName: undefined, visible: undefined }, // 表单参数 form: {}, // 表单校验 rules: { menuName: [ { required: true, message: "菜单名称不能为空", trigger: "blur" } ], orderNum: [ { required: true, message: "菜单顺序不能为空", trigger: "blur" } ], path: [ { required: true, message: "路由地址不能为空", trigger: "blur" } ] } } }, created() { this.getList() }, methods: { // 选择图标 selected(name) { this.form.icon = name }, /** 查询菜单列表 */ getList() { this.loading = true listMenu(this.queryParams).then(response => { this.menuList = this.handleTree(response.data, "menuId") this.loading = false }) }, /** 转换菜单数据结构 */ normalizer(node) { if (node.children && !node.children.length) { delete node.children } return { id: node.menuId, label: node.menuName, children: node.children } }, /** 查询菜单下拉树结构 */ getTreeselect() { listMenu().then(response => { this.menuOptions = [] const menu = { menuId: 0, menuName: '主类目', children: [] } menu.children = this.handleTree(response.data, "menuId") this.menuOptions.push(menu) }) }, // 取消按钮 cancel() { this.open = false this.reset() }, // 表单重置 reset() { this.form = { menuId: undefined, parentId: 0, menuName: undefined, icon: undefined, menuType: "M", orderNum: undefined, isFrame: "1", isCache: "0", visible: "0", status: "0" } this.resetForm("form") }, /** 搜索按钮操作 */ handleQuery() { this.getList() }, /** 重置按钮操作 */ resetQuery() { this.resetForm("queryForm") this.handleQuery() }, /** 新增按钮操作 */ handleAdd(row) { this.reset() this.getTreeselect() if (row != null && row.menuId) { this.form.parentId = row.menuId } else { this.form.parentId = 0 } this.open = true this.title = "添加菜单" }, /** 展开/折叠操作 */ toggleExpandAll() { this.refreshTable = false this.isExpandAll = !this.isExpandAll this.$nextTick(() => { this.refreshTable = true }) }, /** 修改按钮操作 */ handleUpdate(row) { this.reset() this.getTreeselect() getMenu(row.menuId).then(response => { this.form = response.data this.open = true this.title = "修改菜单" }) }, /** 提交按钮 */ submitForm: function() { this.$refs["form"].validate(valid => { if (valid) { if (this.form.menuId != undefined) { updateMenu(this.form).then(response => { this.$modal.msgSuccess("修改成功") this.open = false this.getList() }) } else { addMenu(this.form).then(response => { this.$modal.msgSuccess("新增成功") this.open = false this.getList() }) } } }) }, /** 删除按钮操作 */ handleDelete(row) { this.$modal.confirm('是否确认删除名称为"' + row.menuName + '"的数据项?').then(function() { return delMenu(row.menuId) }).then(() => { this.getList() this.$modal.msgSuccess("删除成功") }).catch(() => {}) } } } </script> 美化
最新发布
09-24
<template> <a-spin :spinning="loading"> <div class="sc-table" :style="{height}"> <div class="sc-table-header"> <div></div> <div> <!-- 字段显示隐藏 --> <ColumnCheck v-if="showColumnCheck" :columns="columns" :showColumnCache="showColumnCache" :showColumns="showColumns" @change="onCheckBoxChange"></ColumnCheck> </div> </div> <div class="sc-table-content" ref="tableContent"> <div class="sc-table-scroll" :style="{width: `${tableWidth}px`}"> <div class="sc-table-thead"> <table class="sc-table-level" border="1"> <TableColgroup :columns="columnsShow"></TableColgroup> <TableHead :columns="columnsShow"> <template #checkbox> <a-checkbox v-if="tableData.length" :indeterminate="indeterminate" :checked="checkAll" @change="onCheckAllChange"> </a-checkbox> </template> </TableHead> </table> </div> <a-checkbox-group class="sc-table-body" v-model="selectedRowKeys" @change="selectionChange"> <table class="sc-table-level" border="1"> <TableColgroup :columns="columnsShow"></TableColgroup> <TrComponent v-model="selectedRowKeys" :rowKey="rowKey" :serialKey="serialKey" :columns="columnsShow" :data="tableData" :checkStrictly="checkStrictly" :theadNums="theadNums" :checkDisabled="checkDisabled" @updateCheckAllKeys="updateCheckAllKeys" @updateCheckAllRows="updateCheckAllRows"> <!-- 自定义操作 --> <template v-for="c in scopedSlots" :slot="c.scopedSlots && c.scopedSlots.customRender ? c.scopedSlots.customRender : ''" slot-scope="{row, text}"> <slot :name="c.scopedSlots.customRender" :row="row" :text="text" ></slot> </template> <!-- 一级层级扩展 --> <template slot="expandedRowRender" slot-scope="{row}"> <slot name="expandedRowRender" :row="row"></slot> </template> </TrComponent> </table> </a-checkbox-group> </div> <!-- <div class="sc-table-fixed-right"> <table class="sc-table-level" border="1"> --> <!-- <TableColgroup :columns="columnsShow"></TableColgroup> <TrComponent :columns="columnsShow" :data="tableData"> <template v-for="c in columnsShow" :slot="c.scopedSlots && c.scopedSlots.customRender ? c.scopedSlots.customRender : ''" slot-scope="{row, text}"> <slot v-if="c.scopedSlots && c.scopedSlots.customRender" :name="c.scopedSlots.customRender" :row="row" :text="text" ></slot> </template> </TrComponent> --> <!-- </table> </div> --> </div> <div class="sc-table-footer"> <div></div> <a-pagination v-if="isPagination && page.total" v-model="page.current" :total="page.total" :pageSize.sync="page.pageSize" :page-size-options="pagination.pageSizeOptions" :show-size-changer="pagination.showSizeChanger" :show-quick-jumper="pagination.showQuickJumper" :show-total="pagination.showTotal" @change="getTableList" @showSizeChange="getTableList" ></a-pagination> </div> </div> </a-spin> </template> <script> import { httpAction } from '@ythApi/ythApiManage' export default { name: "", components: { ColumnCheck: () => import('./columnCheck'), TrComponent: () => import('./TrComponent'), TableColgroup: () => import('./tableColgroup'), TableHead: () => import('./tableHead'), }, props: { // 当columns 存在checkbox=true时有效,当前选中项的 rowKey 数组 value: { type: [Array], }, // 表格行 key 的取值,可以是字符串或一个函数,当checkbox=true时为必要的属性 rowKey: { type: [String, Function], default: 'id', }, // 表格序号key的取值 serialKey: { type: [String, Function], default: null, }, // 表格列的配置 columns: { type: Array, required: true, default: () => ([]), }, // 在显示复选框的情况下,是否严格的遵循父子不互相关联的做法,默认为 false。false关联,true不互相关联 checkStrictly: { type: Boolean, default: false, }, // 在显示复选框的情况下,节点选择框是否禁用, 返回true 或 false; checkDisabled: { type: Function }, // table 数据请求配置 tableServers: { type: Object, default: () => { return { server: null, method: 'post' } }, }, //查询参数 query: { type: Object, required: false, default: () => {} }, // 是否显示字段显隐项 showColumnCheck: { type: Boolean, default: true, }, // 是否使用显示字段显隐项缓存 showColumnCache: { ype: Boolean, default: false, }, // 初始化显影项 showColumns: { type: Array, required: false, default: () => ([]), }, // 是否分页查询 isPagination: { type: Boolean, required: false, default: true, }, // 分页参数 pagination: { type: Object, required: false, default: function () { return { total: 0, current: 1, pageSize: 10, pageSizeOptions: ['10', '20', '30'], showQuickJumper: true, showSizeChanger: true, showTotal: (total, range) => `共${total}条`, } } }, // 查询参数是否装换 isToLine:{ type: Boolean, required: false, default: true, }, height: { type: String, }, }, data() { return { loading: false, page: { current: this.pagination.current || 1, total: this.pagination.total || 0, pageSize: this.pagination.pageSize || 10, }, theadNums: 0, tableWidth: 0, scopedSlots: [], tableData: [], columnsShow: this.showColumnCheck ? [] : this.columns, // 列表配置 updateComponent: '', checkAllKeys: [], checkAllRows: [], selectedRowKeys: this.value || [], // table checkbox 选中项的 rowKey 数组 selectedRows: [], // table checkbox 选中项的 rowKey 数组 } }, computed: { // 所有值 tableDataAll() { let tableData = this.tableData //递归获取子数据 function getAllData(dataArray) { let result = [] dataArray.forEach(item => { result.push(item) if (item.children&&item.children.length>0) { result = result.concat(getAllData(item.children)) } }) return result } return getAllData(tableData) }, // 设置 checkbox 是否全选状态 checkAll() { return this.selectedRowKeys.length === this.checkAllKeys.length; }, // 设置 checkbox indeterminate 状态,只负责样式控制 indeterminate() { return this.selectedRowKeys.length > 0 && this.selectedRowKeys.length < this.checkAllKeys.length; }, // 固定列 }, watch: { tableServers: { immediate: true, deep: true, handler: function(newVal,oldVal) { if (JSON.stringify(newVal)!==JSON.stringify(oldVal)) this.getTableList(1) } }, selectedRowKeys: { immediate: true, deep: true, handler: function(newVal,oldVal) { if (JSON.stringify(newVal)!==JSON.stringify(oldVal)) { this.$emit('input', newVal) } } } }, methods: { // 暴露给父级组件使用,作为静态注入数据 setTableData(data) { this.tableData = this.$listeners.recastData ? this.$listeners.recastData(data) : data }, //获取页面数据 getTableData() { return this.tableData }, //列表显隐回调 onCheckBoxChange({columns, tableWidth, scopedSlots, theadNums}) { this.theadNums = theadNums; this.tableWidth = tableWidth + 8 + 2; this.scopedSlots = scopedSlots; this.columnsShow = columns this.updateComponent = + new Date(); }, //刷新 reload () { this.getTableList(1) }, /** * 获取当前table页数据 * @param current {number} 当前页 */ getTableList(current) { if (!this.tableServers.server) return; if (!!current) this.page.current = current; // 初始化 this.loading = true this.tableData = [] const queryParams = this.getQueryParams() const action = this.tableServers.action || httpAction const method = this.tableServers.method || 'POST' action( this.tableServers.server, queryParams, method).then((res) => { let tableData = [] if (Array.isArray(res)) { this.pagination = false tableData = res } else if (Array.isArray(res.result)) { this.pagination = false tableData = res.result } else { if (this.isPagination && (res.total || res.total == 0)) { this.page.total = Array.isArray(res.total) ? res.total[0] : res.total; } tableData = res.result?.records || res.rows || [] } this.setTableData(tableData) // 接口数据加载成功,回调事件 this.$nextTick(()=>{ this.$emit("onLoadSuccess",this.tableData); }) }).finally(() => { this.loading = false }) }, /** * 获取查询参数 */ getQueryParams() { //基础参数 let data = { ...this.query } // 分页 if (this.isPagination) { data.page = this.page.current data.rows = this.page.pageSize } return data }, /** * 驼峰转换下划线 */ toLine(name) { return name.replace(/([A-Z])/g, '_$1').toLowerCase() }, /** * table checkbox 选中项发生改变时触发 */ selectionChange(checkedValues) { this.selectedRowKeys = checkedValues; this.selectedRows = checkedValues.map(value => { return this.tableDataAll.filter(row => row[this.rowKey] === value)[0] }) this.$emit('selection-change', checkedValues, this.selectedRows) }, /** * 全选发生变化时回调函数 */ onCheckAllChange(e) { this.selectedRowKeys = e.target.checked ? this.checkAllKeys : []; this.selectedRows = e.target.checked ? this.checkAllRows : []; }, /** * 更新当前选中checkbox全部keys数据 */ updateCheckAllKeys(allKeys) { this.checkAllKeys = allKeys }, /** * 更新当前选中checkbox全部rows数据 * */ updateCheckAllRows(allRows) { this.checkAllRows = allRows } } } </script> <style lang="less" > .sc-table { width: 100%; height: 100%; min-height: 300px; display: flex; flex-direction: column; .sc-table-content { width: 100%; flex: 1; overflow: auto; background-color: #ffffff; .sc-table-scroll { min-width: 100%; height: 100%; display: flex; flex-direction: column; table { width: 100%; background-color: #ffffff; border-style: solid; border-color: #e8e8e8; table-layout: fixed; } .sc-table-thead { overflow: hidden scroll; } .sc-table-body { width: 100%; flex: 1; overflow: hidden scroll; } } } } .sc-table-header, .sc-table-footer { display: flex; justify-content: space-between; margin: 10px 0; } .sc-table-header { .btn-icon { border-radius: 50%; border: 1px solid #d9d9d9; background-color: #fff; width: 32px; height: 32px; line-height: 32px; text-align: center; font-size: 15px; cursor: pointer; &:hover { opacity: .9; } } } .sc-table-level { .icon-expand { margin-right: 8px; cursor: pointer; display: inline-block; &::before { content: '-'; width: 18px; height: 18px; display: flex; justify-content: center; align-items: center; border: 1px solid #e8e8e8; border-radius: 2px; background-color: #fff; box-sizing: border-box; transition: color .2s, border-color .2s; } &:hover::before { color: #40a9ff; border-color: #40a9ff; } } tr[data-row-collapse="false"] { .icon-expand::before { content: '+'; } } tr.table-expanded-row { > td { padding: 0; > * { padding: 10px; } > a, > span { display: inline-block; } } } tr.table-expanded-row, tr.table-expanded-row:hover { background: #fbfbfb; } tr:hover { background: rgba(24, 144, 255, 0.18); } // tr[data-highlight-1] { // background: rgba(24, 144, 255, 0.08); // } // tr[data-highlight-2] { // background: rgba(24, 144, 255, 0.06); // } // tbody > tr:nth-of-type(2n) { // background: rgba(24, 144, 255, 0.03); // } tr { transition: background 1s; } th { background: #fafafa; } td { word-wrap: break-word; overflow-wrap: break-word; white-space: normal; } td, th { padding: 10px; box-sizing: border-box; } } </style> 该组件的构成为 <header><显隐组件></header> <content> <表格标题组件head> <表格内容组件body> </content> <footer><分页组件></footer> 解决方案同时满足以下条件: 1.表头在y轴滚动时固定 2.x轴和y轴滚动条始终可见 3.复选框和序号列随x轴滚动而滚动
06-13
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值