<template>
<div class="top-bottom-page">
<!-- 请更改根节点 class 名称 以 "page" 结尾-->
<!-- TODO -->
<FilterForm
class="common-search"
:model-value="searchModel"
:config="searchFormConfig"
:loading="gridOptions.loading"
@query="handleQuery"
@reset="handleReset"
/>
<div class="common-table">
<VxeGrid ref="gridRef" v-bind="gridOptions" v-on="gridEvents">
<!-- 其他slot -->
<!-- <template #test> </template> -->
<!-- ...TODO... -->
</VxeGrid>
</div>
</div>
</template>
<script setup lang="tsx">
import { onMounted, reactive, useTemplateRef } from 'vue';
import { FilterForm, VxeGrid } from '@erp/biz';
import { getGridOptions, getSearchForm } from './top-bottom-page';
import type { VxeGridInstance, VxeGridListeners } from '@erp/biz';
const searchFormConfig = getSearchForm();
// 搜索数据模型
const searchModel = reactive({
// 配置模型 键值对跟 配置挂钩
// ... TODO
});
// grid实例 引用
const gridRef = useTemplateRef<VxeGridInstance>('gridRef');
// grid配置
const gridOptions = getGridOptions(searchModel);
// grid 事件
const gridEvents: VxeGridListeners = {
async menuClick({ menu, $grid, row }) {
// 处理右键
},
toolbarButtonClick({ $grid, code }) {
// 处理按钮
},
cellMenu({ $grid, row }) {
row && $grid.setCurrentRow(row);
},
};
// 查询
const handleQuery = () => {
gridRef.value.commitProxy('reload');
};
// 重置
const handleReset = () => {
gridRef.value.commitProxy('reload');
};
onMounted(() => {
// 初始化表格数据
});
</script>
<style lang="scss" scoped>
// @import './style.scss'; 也可用
.top-bottom-page {
// TODO 高度在页面中应该是 100%
height: 800px;
width: 100%;
padding: 16px 16px 0;
display: flex;
flex-direction: column;
.common-search {
width: 100%;
padding: 12px;
border-radius: 4px;
background-color: var(--color-fill-1);
}
.common-table {
flex: 1;
height: calc(100% - 56px);
width: 100%;
}
}
</style>import { reactive } from 'vue';
import { mergeGridProps } from '@erp/biz';
import dataJson from './data.json';
import type { SearchFormI, VxeGridProps } from '@erp/biz';
/**
* @zh 获取查询配置
* @returns
*/
export function getSearchForm() {
const formConfig: SearchFormI = {
components: {
// 自定义组件配置 TODO
},
// 查询池ID配置,在开发过程中关闭,以免保存后的查询池配置影响开发
// queryPool: '',
// 响应布局 TODO
gridProps: {
cols: {
xxl: 5,
xl: 4,
lg: 3,
md: 2,
sm: 2,
xs: 2,
},
colGap: 14,
rowGap: 10,
},
labelLayout: 'inner',
fields: [
{
key: 'name',
label: '应用名称',
type: 'text',
},
{
key: 'app_key',
label: '应用key',
type: 'text',
},
{
key: 'status',
label: '应用状态',
type: 'select',
options: [
{ label: '全部', value: '' },
{ label: '启用', value: '1' },
{ label: '禁用', value: '2' },
],
},
],
};
return formConfig;
}
/**
* 获取表格配置
* @returns
*/
export function getGridOptions<T = any>(model: Record<string, any>) {
const gridOptions: VxeGridProps<T> = reactive(
mergeGridProps({
// 表格列配置ID,唯一,命名跟页面url配置一致 TODO
// id: 'application-config-page-table',
height: 'auto',
columnConfig: {
width: 160,
},
resizeConfig: {
refreshDelay: 300,
},
proxyConfig: {
response: {
result: 'list',
total: 'total',
},
ajax: {
// 请求接口 TODO
query({ page }) {
const reqParams = {
...model,
page: page.current,
page_size: page.pageSize,
};
// 请求接口处理
// return getDataApi(reqParams);
// 测试数据 TODO
return new Promise(resolve => {
setTimeout(() => {
resolve(dataJson);
}, 500);
});
},
},
},
// 头部按钮配置 TODO
toolbarConfig: {
buttons: [
{
code: 'disable',
label: '禁用',
type: 'secondary',
icon: 'erpfont icon-close1',
},
{
code: 'enable',
label: '启动',
type: 'secondary',
icon: 'erpfont icon-check1',
},
{
code: 'add',
label: '新增',
type: 'primary',
icon: 'erpfont icon-plus',
},
],
},
// 右键菜单配置 TODO
menuConfig: {
trigger: 'cell',
body: {
options: [
[
{
code: 'edit',
name: '应用修改',
prefixIcon: 'erpfont icon-edit',
},
{
code: 'delete',
name: '应用删除',
prefixIcon: 'erpfont icon-delete',
},
{
code: 'refresh-table',
name: '刷新表格',
prefixIcon: 'erpfont icon-rotate-cw',
},
{
code: 'refresh-page',
name: '刷新页面',
prefixIcon: 'erpfont icon-sync',
},
],
],
},
},
// 列表表配置 TODO
columns: [
{
type: 'checkbox',
width: 55,
fixed: 'left',
align: 'center',
headerAlign: 'center',
},
{
type: 'seq',
width: 55,
fixed: 'left',
align: 'center',
headerAlign: 'center',
},
{ field: 'id', title: 'AppID', fixed: 'left', width: 80 },
{
field: 'name',
title: '应用名称',
},
{ field: 'app_key', title: '应用key' },
{
field: 'status',
title: '应用状态',
width: 90,
},
{
field: 'type',
title: '应用类型',
width: 90,
},
{ field: 'begin_at', title: '开始时间' },
{ field: 'end_at', title: '结束时间' },
{ field: 'app_url', title: '接口域名' },
{
field: 'is_erp',
title: '是否ERP',
},
],
}),
);
return gridOptions;
}