Browse Source

组件属性重命名及拆分属性

main
likunming 1 year ago
parent
commit
1b5fb9d221
  1. 206
      io.sc.platform.core.frontend/src/platform/components/grid/WGrid.vue
  2. 137
      io.sc.platform.core.frontend/src/views/likm/Grid.vue

206
io.sc.platform.core.frontend/src/platform/components/grid/WGrid.vue

@ -10,7 +10,7 @@
:separator="'cell'"
:rows="table.rows"
:columns="extractTableColumns"
:rows-per-page-options="props.tablePagination.rowsPerPage && table.refHeightWidth.middleWidth > 600 ? table.pagination.rowsPerPageOptions : []"
:rows-per-page-options="pagination.rowsPerPage && table.refHeightWidth.middleWidth > 600 ? table.pagination.rowsPerPageOptions : []"
:loading="table.loading"
:no-data-label="table.noDataLabel"
:loading-label="table.loadingLabel"
@ -23,12 +23,13 @@
<template #top="scope">
<q-resize-observer @resize="onResize" />
<div class="col">
<w-form ref="queryFormRef" v-bind="props.queryForm" :fields="table.queryFormFields">
<w-form ref="queryFormRef" v-bind="props.queryFormAttrs" :fields="table.queryFormFields">
<div class="pt-2.5 flex flex-nowrap">
<div class="flex-none text-[18px] pt-[9px]">{{ title }}</div>
<div class="flex-1">
<w-toolbar
v-bind="toolbar_"
v-bind="toolbarConfigre"
:buttons="buttons_"
:grid-prop="{
gridSelected: table.selected,
gridRefs: {
@ -41,7 +42,7 @@
}"
></w-toolbar>
</div>
<div v-if="canFullScreen" class="flex-none pl-1">
<div v-if="fullScreenButton" class="flex-none pl-1">
<q-btn :icon="scope.inFullscreen ? IconEnum.退出全屏 : IconEnum.全屏" unelevated outline @click="scope.toggleFullscreen">
<q-tooltip transition-show="rotate" transition-hide="rotate">
{{ scope.inFullscreen ? '退出全屏' : '全屏' }}
@ -61,7 +62,7 @@
:style="moreColumnTitleTableSelectionStyle"
>
</q-th>
<q-th v-if="rIndex === 0 && props.showSortNo" :rowspan="columnTitleState.columnTitleRowNum" :style="moreColumnTitleTableSortNoStyle"> 序号 </q-th>
<q-th v-if="rIndex === 0 && props.sortNo" :rowspan="columnTitleState.columnTitleRowNum" :style="moreColumnTitleTableSortNoStyle"> 序号 </q-th>
<q-th
v-for="c in r"
:key="c.name"
@ -92,28 +93,43 @@
<q-td v-if="!attrs.selection || attrs.selection !== 'none'" class="text-center">
<q-checkbox v-model="scope.selected" />
</q-td>
<q-td
v-for="col in scope.cols"
:key="col.name"
draggable="true"
:props="scope"
:title="col.classes?.indexOf('truncate') > -1 ? col.value : ''"
@dragenter="onDragEnter($event, scope)"
@dragleave="onDragLeave"
@dragover="onDragOver($event, scope)"
@drop="onDrop($event, scope)"
@dragstart="onDragStart($event, scope)"
>
<template v-if="col.name === '_sortNo_'">
{{ scope.rowIndex + 1 }}
</template>
<template v-else-if="col.value && typeof col.value === 'object' && col.value.type && col.value._vuecomp_">
<component :is="col.value.type" v-bind="col.value.props"></component>
</template>
<template v-else>
{{ col.value }}
</template>
</q-td>
<template v-if="draggable">
<q-td
v-for="col in scope.cols"
:key="col.name"
draggable="true"
:props="scope"
:title="col.classes?.indexOf('truncate') > -1 ? col.value : ''"
@dragenter="onDragEnter($event, scope)"
@dragleave="onDragLeave"
@dragover="onDragOver($event, scope)"
@drop="onDrop($event, scope)"
@dragstart="onDragStart($event, scope)"
>
<template v-if="col.name === '_sortNo_'">
{{ scope.rowIndex + 1 }}
</template>
<template v-else-if="col.value && typeof col.value === 'object' && col.value.type && col.value._vuecomp_">
<component :is="col.value.type" v-bind="col.value.props"></component>
</template>
<template v-else>
{{ col.value }}
</template>
</q-td>
</template>
<template v-else>
<q-td v-for="col in scope.cols" :key="col.name" :props="scope" :title="col.classes?.indexOf('truncate') > -1 ? col.value : ''">
<template v-if="col.name === '_sortNo_'">
{{ scope.rowIndex + 1 }}
</template>
<template v-else-if="col.value && typeof col.value === 'object' && col.value.type && col.value._vuecomp_">
<component :is="col.value.type" v-bind="col.value.props"></component>
</template>
<template v-else>
{{ col.value }}
</template>
</q-td>
</template>
</q-tr>
</template>
<template #loading>
@ -121,8 +137,9 @@
<q-spinner-gears size="50px" color="primary" />
</q-inner-loading>
</template>
<template #pagination="scope">
<template v-if="props.tablePagination.rowsPerPage">
<template #pagination="scope"
>p
<template v-if="props.pagination.rowsPerPage">
<template v-if="table.refHeightWidth.middleWidth > 600">
<q-pagination
v-model="table.pagination.page"
@ -162,12 +179,12 @@
</div>
</template>
</q-table>
<w-dialog ref="dialogRef" v-bind="addEdit.dialog" :title="dialog.dialogTitle" :buttons="dialog.dialogButtons">
<w-form ref="dialogFormRef" v-bind="addEdit.form" class="pt-1.5 px-1.5"></w-form>
<w-dialog ref="dialogRef" v-bind="editor.dialog" :title="dialog.dialogTitle" :buttons="dialog.dialogButtons">
<w-form ref="dialogFormRef" v-bind="editor.form" class="pt-1.5 px-1.5"></w-form>
</w-dialog>
<w-drawer ref="drawerRef" title="查看" v-bind="view.drawer">
<w-drawer ref="drawerRef" title="查看" v-bind="viewer.drawer">
<div class="p-2.5">
<w-info-panel v-bind="view.infoPanel" :info="viewInfo.infoArray"></w-info-panel>
<w-info-panel v-bind="viewer.panel" :info="viewInfo.infoArray"></w-info-panel>
</div>
</w-drawer>
</div>
@ -175,7 +192,7 @@
<script setup lang="ts">
import { ref, reactive, computed, onMounted, nextTick, toRaw, useAttrs } from 'vue';
import { axios, Environment, NotifyManager } from '@/platform';
import { axios, Environment, NotifyManager, TreeBuilder } from '@/platform';
import { useQuasar, getCssVar, exportFile } from 'quasar';
import { IconEnum } from '@/platform/enums';
import { extractTableColumnsProps, arrayToMap, OperatorTypeEnum, isEmpty, PageStatusEnum } from '@/platform/components/utils';
@ -189,51 +206,68 @@ const stickyBgColor = gc.theme.dark ? darkBgColor : gc.theme?.grid?.stickyBgColo
const props = defineProps({
height: { type: Number, default: 0 }, //
spaceHeight: { type: Number, default: 4 }, //
title: { type: String, default: '' }, //
autoLoadData: { type: Boolean, default: true }, //
autoFetchData: { type: Boolean, default: true }, //
rowKey: { type: String, default: 'id' }, //
rowDrag: { type: Boolean, default: false }, //
canFullScreen: { type: Boolean, default: true }, //
draggable: { type: Boolean, default: false }, //
fullScreenButton: { type: Boolean, default: true }, //
templateGridId: { type: String, default: '' }, // ID
getDataUrl: { type: String, default: '' }, // url
dataUrl: { type: String, default: '' }, // URL
fetchDataUrl: { type: String, default: '' }, // URL
addDataUrl: { type: String, default: '' }, // url
editDataUrl: { type: String, default: '' }, // url
removeDataUrl: { type: String, default: '' }, // url
columnTitleDense: { type: Boolean, default: false }, //
showSortNo: { type: Boolean, default: false }, //
leftColumnStickyNumber: { type: Number, default: 0 }, // 1-10
denseHeader: { type: Boolean, default: false }, //
denseBody: { type: Boolean, default: false }, //
sortNo: { type: Boolean, default: false }, //
leftColumnStickyNumber: { type: Number, default: 0 }, // 1-10el
clickSelectedRow: { type: Boolean, default: true }, // selection'none'
tree: { type: Boolean, default: false }, //
columns: {
type: Array,
default: () => {
return [];
},
},
queryForm: {
type: Object,
queryFormFields: {
type: Array,
default: () => {
return {
rowNum: 1,
fields: [],
};
return [];
},
},
toolbar: {
queryFormColsNum: {
type: [Number, Object],
default: 0,
},
queryFormRowNum: { type: Number, default: 1 },
queryFormAttrs: {
type: Object,
default: () => {
return {
buttons: [],
};
return {};
},
},
tablePagination: {
toolbarActions: {
type: Array,
default: () => {
return [];
},
},
toolbarConfigre: {
type: Object,
default: () => {
return {};
},
},
addEdit: {
pagination: {
type: Object,
default: () => {
return {
reqPageStart: 0,
rowsPerPage: 10,
};
},
},
editor: {
type: Object,
default: () => {
return {
@ -242,12 +276,12 @@ const props = defineProps({
};
},
},
view: {
viewer: {
type: Object,
default: () => {
return {
drawer: {},
infoPanel: {
panel: {
fields: [],
},
};
@ -321,7 +355,7 @@ const dialogRef = ref();
const drawerRef = ref();
const dialogFormRef = ref();
const tableColumnsMap = arrayToMap('name', props.columns);
const queryFormFieldsMap = arrayToMap('name', props.queryForm.fields);
const queryFormFieldsMap = arrayToMap('name', props.queryFormFields);
/**
* 内置按钮枚举
@ -357,7 +391,7 @@ const buttonObj = {
icon: IconEnum.更多查询,
label: '更多查询',
enableIf: () => {
if (props.queryForm.fields.length <= table.queryFormFields.length && !table.moreQueryStatus) {
if (props.queryFormFields.length <= table.queryFormFields.length && !table.moreQueryStatus) {
return false;
} else {
return true;
@ -466,7 +500,7 @@ const buttonObj = {
}).onOk(() => {
let requestParams: any = {
method: 'DELETE',
url: (props.removeDataUrl ? props.removeDataUrl : props.getDataUrl) + '/' + table.selected[0][props.rowKey],
url: (props.removeDataUrl ? props.removeDataUrl : props.dataUrl) + '/' + table.selected[0][props.rowKey],
};
if (props.templateGridId) {
const data = <any>[];
@ -509,8 +543,8 @@ const buttonObj = {
NotifyManager.warn('请选择要查看的记录');
} else {
viewInfo.infoArray = <any>[];
if (props.view.infoPanel.fields && props.view.infoPanel.fields.length > 0) {
for (let item of props.view.infoPanel.fields) {
if (props.viewer.infoPanel.fields && props.viewer.infoPanel.fields.length > 0) {
for (let item of props.viewer.infoPanel.fields) {
if (item.format) {
viewInfo.infoArray.push({ label: item.label, value: item.format(table.selected[0][item.name]) });
} else {
@ -565,7 +599,6 @@ const buttonObj = {
};
// toobar
const { buttons, ...other } = props.toolbar;
const buttons_ = <any>[];
const handleChildrenBtn = (arr) => {
const tempArr = <any>[];
@ -586,7 +619,7 @@ const handleChildrenBtn = (arr) => {
}
return tempArr;
};
buttons.forEach((btn, index) => {
props.toolbarActions.forEach((btn, index) => {
if (typeof btn === 'string' && buttonObj[btn]) {
buttons_.push(buttonObj[btn]);
} else if (Array.isArray(btn) && btn.length > 0) {
@ -598,7 +631,6 @@ buttons.forEach((btn, index) => {
buttons_.push(btn);
}
});
const toolbar_ = { ...other, buttons: buttons_ };
const extractTableColumns = extractTableColumnsProps(props);
// props
@ -614,7 +646,8 @@ const titleScopeHandler = (column: any, scope: any) => {
const table = reactive({
selected: <any>[],
headerCellHeight: props.columnTitleDense || attrs.dense ? 24 : 48,
spaceHeight: 4,
headerCellHeight: props.denseHeader || attrs.dense ? 24 : 48,
bodyCellHeight: attrs.dense ? 24 : 48,
noDataLabel: '没有可用数据',
loading: false,
@ -629,11 +662,11 @@ const table = reactive({
ellipses: false, //
maxPages: 5, // 0
},
sortBy: props.tablePagination.sortBy ? props.tablePagination.sortBy : '',
descending: props.tablePagination.descending ? props.tablePagination.descending : false,
reqPageStart: Object.hasOwnProperty.call(props.tablePagination, 'reqPageStart') ? props.tablePagination.reqPageStart : 1,
sortBy: props.pagination.sortBy ? props.pagination.sortBy : '',
descending: props.pagination.descending ? props.pagination.descending : false,
reqPageStart: Object.hasOwnProperty.call(props.pagination, 'reqPageStart') ? props.pagination.reqPageStart : 1,
page: 1,
rowsPerPage: props.tablePagination.rowsPerPage ? props.tablePagination.rowsPerPage : 0,
rowsPerPage: props.pagination.rowsPerPage ? props.pagination.rowsPerPage : 0,
rowsNumber: 10,
rowsPerPageOptions: [5, 10, 20, 50, 100],
},
@ -825,7 +858,7 @@ const tableHeightComputed = computed(() => {
//
const mainContainerPaddingBottom = gc.theme.main.containerPaddingBottom || 0;
// 4px
const otherHeight = props.spaceHeight || 4;
const otherHeight = table.spaceHeight || 4;
const resultHeight =
screenHeight -
table.refHeightWidth.yLocation -
@ -852,7 +885,7 @@ const noDataBottomHeightComputed = computed(() => {
// XX
const footerHeight = gc.theme.footer.enable ? gc.theme.footer.height : 0;
// 4px
const otherHeight = props.spaceHeight || 4;
const otherHeight = table.spaceHeight || 4;
//
const mainPaddingBottom = gc.theme.main.paddingBottom || 0;
//
@ -978,7 +1011,7 @@ const pageChange = (value) => {
};
const requestHandle = async (ops) => {
const reqParams: any = {};
if (props.tablePagination.rowsPerPage) {
if (props.pagination.rowsPerPage) {
reqParams.page = ops.pagination.page;
reqParams.size = ops.pagination.rowsPerPage;
}
@ -1007,7 +1040,7 @@ const requestHandle = async (ops) => {
queryFormDataJson = handlerRequestParams;
});
reqParams.params = JSON.stringify(queryFormDataJson);
const resp = await axios.post(props.getDataUrl || Environment.apiContextPath('api/jdbc/list'), reqParams).catch((error) => {
const resp = await axios.post(props.fetchDataUrl || props.dataUrl || Environment.apiContextPath('api/jdbc/list'), reqParams).catch((error) => {
table.loading = false;
});
return resp;
@ -1019,7 +1052,7 @@ const requestHandle = async (ops) => {
emit('requestDataBefore', urlSearchParams, (handlerRequestParams: URLSearchParams | any) => {
urlSearchParams = handlerRequestParams;
});
const resp = await axios.get(props.getDataUrl, { params: urlSearchParams }).catch((error) => {
const resp = await axios.get(props.fetchDataUrl || props.dataUrl, { params: urlSearchParams }).catch((error) => {
console.info('error-------------', error);
table.loading = false;
});
@ -1031,9 +1064,9 @@ const onRequest = async (ops: any) => {
const resp: any = await requestHandle(ops);
table.loading = false;
// const result = platformRequestResultHandle($q, resp.data);
if (resp && resp.data) {
if (resp && resp.data && !props.tree) {
const responseData = resp.data;
if (props.tablePagination.rowsPerPage) {
if (props.pagination.rowsPerPage) {
table.pagination.page = table.pagination.reqPageStart === 0 ? responseData.number + 1 : responseData.number;
table.pagination.rowsPerPage = responseData.size;
}
@ -1041,6 +1074,11 @@ const onRequest = async (ops: any) => {
table.pagination.sortBy = ops.pagination.sortBy;
table.pagination.descending = ops.pagination.descending;
table.rows = responseData.content;
} else if (resp && resp.data && props.tree) {
const treeData = TreeBuilder.build(resp.data);
table.pagination.rowsNumber = resp.data.length;
console.info('treeData============', treeData);
table.rows = treeData;
}
stickyHeaderColumn();
};
@ -1071,8 +1109,8 @@ const save = async () => {
formStatus === PageStatusEnum.新增
? props.addDataUrl
? props.addDataUrl
: props.getDataUrl
: (props.editDataUrl ? props.editDataUrl : props.getDataUrl) + '/' + table.selected[0][props.rowKey],
: props.dataUrl
: (props.editDataUrl ? props.editDataUrl : props.dataUrl) + '/' + table.selected[0][props.rowKey],
};
if (props.templateGridId) {
requestParams = {
@ -1303,7 +1341,7 @@ const excludeColumnNum = computed(() => {
if (!attrs.selection || attrs.selection !== 'none') {
num += 1;
}
if (props.showSortNo) {
if (props.sortNo) {
num += 1;
}
return num;
@ -1358,7 +1396,7 @@ const moreColumnTitleTableSelectionStyle = computed(() => {
return '';
});
const moreColumnTitleTableSortNoStyle = computed(() => {
if (props.showSortNo && props.leftColumnStickyNumber > 0) {
if (props.sortNo && props.leftColumnStickyNumber > 0) {
return 'z-index: 3;position: sticky;left: var(--columnWidth-1-1);';
}
return '';
@ -1632,13 +1670,13 @@ const onDrop = (e, scope) => {
const handlerQueryFormShowField = () => {
table.queryFormFields = [];
if (table.moreQueryStatus) {
props.queryForm.fields.forEach((item) => {
props.queryFormFields.forEach((item) => {
table.queryFormFields.push(item);
});
} else {
const rowColsNum = queryFormRef.value.getRowColsNum() * (props.queryForm.rowNum || 1);
const rowColsNum = queryFormRef.value.getRowColsNum() * (props.queryFormRowNum || 1);
let currRowColsNum = 0;
props.queryForm.fields.forEach((item) => {
props.queryFormFields.forEach((item) => {
if (item.hasOwnProperty('colspan')) {
currRowColsNum += item.colspan;
} else {
@ -1656,7 +1694,7 @@ onMounted(() => {
handlerMoreRowColumnTitle();
}
handlerQueryFormShowField();
if (props.autoLoadData) {
if (props.autoFetchData) {
onRequest({
pagination: table.pagination,
});

137
io.sc.platform.core.frontend/src/views/likm/Grid.vue

@ -2,19 +2,15 @@
<div>
<w-grid
:title="testGrid.title"
:row-drag="true"
draggable
:row-key="testGrid.rowKey"
:auto-load-data="testGrid.autoLoadData"
:get-data-url="testGrid.tableDataUrl"
:show-sort-no="testGrid.tableShowSortNo"
:data-url="testGrid.tableDataUrl"
sort-no
:columns="testGrid.tableColumns"
:left-column-sticky-number="testGrid.tableLeftColumnStickyNumber"
:column-title-dense="true"
:toolbar="testGrid.toolbar"
:query-form="testGrid.queryForm"
:table-pagination="testGrid.tablePagination"
:add-edit="testGrid.addEdit"
:view="testGrid.view"
:toolbar-actions="testGrid.toolbar"
:query-form-fields="testGrid.queryForm"
:editor="testGrid.addEdit"
:viewer="testGrid.view"
@selection="selection"
@row-click="rowClick"
@row-db-click="rowDbClick"
@ -40,76 +36,65 @@ const rowDbClick = (evt, row, index) => {
const testGrid = {
hideBottom: false,
autoLoadData: true,
tableLeftColumnStickyNumber: 0,
tableLeftColumnStickyNumber: 1,
title: '用户列表',
rowKey: 'id',
tableDataUrl: Environment.apiContextPath('api/system/user'),
tablePagination: {
sortBy: 'lastModifyDate',
descending: true,
reqPageStart: 0,
rowsPerPage: 10,
},
toolbar: {
buttons: [
['query', 'separator', 'moreQuery'],
'reset',
'refresh',
'separator',
toolbar: [
['query', 'separator', 'moreQuery'],
'reset',
'refresh',
'separator',
{
name: 'custBtn',
extend: 'add',
icon: undefined,
label: '自定义按钮',
enableIf: (selected) => {
if (selected && selected.length > 0) {
return true;
}
return false;
},
// beforeClick: (selected, context, gridRefs) => {
// console.info('before');
// context.aaa = '111';
// },
click: (selected, context, _click, gridRefs) => {
_click();
},
afterClick: (selected, context, gridRefs) => {
gridRefs.addEditFormRef.setFieldValue('userName', '李四');
},
},
[
{
name: 'custBtn',
extend: 'add',
icon: undefined,
label: '自定义按钮',
enableIf: (selected) => {
if (selected && selected.length > 0) {
return true;
}
return false;
},
// beforeClick: (selected, context, gridRefs) => {
// console.info('before');
// context.aaa = '111';
// },
click: (selected, context, _click, gridRefs) => {
_click();
},
afterClick: (selected, context, gridRefs) => {
gridRefs.addEditFormRef.setFieldValue('userName', '李四');
},
name: 'op',
icon: 'difference',
label: '操作',
},
[
{
name: 'op',
icon: 'difference',
label: '操作',
},
'add',
'edit',
'clone',
'remove',
'separator',
'view',
'export',
],
'add',
'edit',
'clone',
'remove',
'separator',
'view',
'export',
],
},
'separator',
],
tableShowSortNo: true,
queryForm: {
rowNum: 1,
fields: [
{ label: '登录名', name: 'loginName', type: 'w-text' },
{ label: '用户名', name: 'userName', type: 'w-text' },
{ label: '描述', name: 'description', type: 'w-text' },
{ label: '是否可用', name: 'enable', type: 'w-select' },
// { label: '', name: 'email', type: 'w-text' },
// { label: '', name: 'phone', type: 'w-text' },
// { label: '', name: 'mobile', type: 'w-number' },
// { label: '', name: 'lastModifier', type: 'w-text' },
// { label: '', name: 'lastModifyDate', type: 'w-date' },
],
},
queryForm: [
{ label: '登录名', name: 'loginName', type: 'w-text' },
{ label: '用户名', name: 'userName', type: 'w-text' },
{ label: '描述', name: 'description', type: 'w-text' },
{ label: '是否可用', name: 'enable', type: 'w-select' },
// { label: '', name: 'email', type: 'w-text' },
// { label: '', name: 'phone', type: 'w-text' },
// { label: '', name: 'mobile', type: 'w-number' },
// { label: '', name: 'lastModifier', type: 'w-text' },
// { label: '', name: 'lastModifyDate', type: 'w-date' },
],
tableColumns: [
{
name: 'info',
@ -135,7 +120,7 @@ const testGrid = {
{ name: 'qq', label: 'QQ' },
],
},
{ name: 'description', label: '描述' },
{ name: 'description', label: '描述', width: 400 },
{
name: 'enable',
label: '是否可用',
@ -161,7 +146,7 @@ const testGrid = {
return {
_vuecomp_: true,
type: 'q-icon',
props: {
attr: {
name: val ? IconEnum.是状态 : IconEnum.否状态,
color: val ? 'green' : 'red',
size: 'sm',
@ -193,7 +178,7 @@ const testGrid = {
},
},
view: {
infoPanel: {
panel: {
columnNum: 2,
fields: [
{ name: 'id', label: '主键' },

Loading…
Cancel
Save