Browse Source

优化表格组件

main
likunming 5 months ago
parent
commit
14817860f9
  1. 6
      io.sc.platform.core.frontend/src/platform/components/grid/GridBody.vue
  2. 7
      io.sc.platform.core.frontend/src/platform/components/grid/GridTd.vue
  3. 16
      io.sc.platform.core.frontend/src/platform/components/grid/TreeGridRow.vue
  4. 5
      io.sc.platform.core.frontend/src/platform/components/grid/WGrid.vue
  5. 7
      io.sc.platform.core.frontend/src/platform/components/grid/ts/grid.ts
  6. 1
      io.sc.platform.core.frontend/src/views/likm/Grid.vue

6
io.sc.platform.core.frontend/src/platform/components/grid/GridBody.vue

@ -22,8 +22,8 @@
<template v-else> <template v-else>
<q-tr <q-tr
ref="trRef" ref="trRef"
:no-hover="!props.grid.props.cellSelected ? false : true" :no-hover="props.grid.props.selectedMode === selectedMode.row ? false : true"
:class="props.scope.row[table.selectedField] && !props.grid.props.cellSelected ? 'selected' : ''" :class="props.scope.row[table.selectedField] && props.grid.props.selectedMode === selectedMode.row ? 'selected' : ''"
:props="props.scope" :props="props.scope"
:draggable="draggableComputed" :draggable="draggableComputed"
@click.stop="props.rowClick($event, scope.row, scope.rowIndex)" @click.stop="props.rowClick($event, scope.row, scope.rowIndex)"
@ -69,7 +69,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, inject, ref, toRaw } from 'vue'; import { computed, inject, ref, toRaw } from 'vue';
import { Tools, noErrorAxios, NotifyManager, t } from '@/platform'; import { Tools, noErrorAxios, NotifyManager, t } from '@/platform';
import { draggableImage, draggableMode } from './ts/grid'; import { draggableImage, draggableMode, selectedMode } from './ts/grid';
import TreeGridRow from './TreeGridRow.vue'; import TreeGridRow from './TreeGridRow.vue';
import GridTd from './GridTd.vue'; import GridTd from './GridTd.vue';
import GridEditToolbar from './GridEditToolbar.vue'; import GridEditToolbar from './GridEditToolbar.vue';

7
io.sc.platform.core.frontend/src/platform/components/grid/GridTd.vue

@ -3,10 +3,10 @@
:key="col.name" :key="col.name"
:props="scope" :props="scope"
:title="col.classes?.indexOf('truncate') > -1 && !Tools.isEmpty(value) && typeof value !== 'object' ? value : ''" :title="col.classes?.indexOf('truncate') > -1 && !Tools.isEmpty(value) && typeof value !== 'object' ? value : ''"
:class="props.grid.props.cellSelected ? tdClassComputed : ''" :class="props.grid.props.selectedMode === selectedMode.cell ? tdClassComputed : ''"
@click=" @click="
() => { () => {
if (table && props.grid.props.cellSelected) { if (table && props.grid.props.selectedMode === selectedMode.cell) {
table['cellSelected'] = { table['cellSelected'] = {
row: toRaw(scope.row), row: toRaw(scope.row),
rowKey: scope.row[props.rowKeyName], rowKey: scope.row[props.rowKeyName],
@ -46,6 +46,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { inject, computed, ref, toRaw } from 'vue'; import { inject, computed, ref, toRaw } from 'vue';
import { Tools } from '@/platform'; import { Tools } from '@/platform';
import { selectedMode } from './ts/grid.ts';
const componentRef = ref(); const componentRef = ref();
const props = defineProps({ const props = defineProps({
@ -90,7 +91,7 @@ const getComponentRef = () => {
const tdClassComputed = computed(() => { const tdClassComputed = computed(() => {
const tdClass = <any>[]; const tdClass = <any>[];
if (props.grid.props.cellSelected) { if (props.grid.props.selectedMode === selectedMode.cell) {
tdClass.push('cellSelected_hover'); tdClass.push('cellSelected_hover');
} }
if (table && table['cellSelected'] && Tools.hasOwnProperty(table['cellSelected'], 'colName')) { if (table && table['cellSelected'] && Tools.hasOwnProperty(table['cellSelected'], 'colName')) {

16
io.sc.platform.core.frontend/src/platform/components/grid/TreeGridRow.vue

@ -1,8 +1,8 @@
<template> <template>
<q-tr <q-tr
ref="trRef" ref="trRef"
:no-hover="!props.grid.props.cellSelected ? false : true" :no-hover="props.grid.props.selectedMode === selectedMode.row ? false : true"
:class="row[table.selectedField] && !props.grid.props.cellSelected ? 'selected' : ''" :class="row[table.selectedField] && props.grid.props.selectedMode === selectedMode.row ? 'selected' : ''"
:draggable="draggableComputed" :draggable="draggableComputed"
@click.stop.prevent="click($event, row, props.rowIndex)" @click.stop.prevent="click($event, row, props.rowIndex)"
@dblclick.stop.prevent="dbClick($event, row, props.rowIndex)" @dblclick.stop.prevent="dbClick($event, row, props.rowIndex)"
@ -12,10 +12,10 @@
@dragstart="draggableComputed ? onDragStart($event, row) : () => {}" @dragstart="draggableComputed ? onDragStart($event, row) : () => {}"
> >
<q-td <q-td
:class="props.grid.props.cellSelected ? firstTdClassComputed : 'nowrap text-nowrap'" :class="props.grid.props.selectedMode === selectedMode.cell ? firstTdClassComputed : 'nowrap text-nowrap'"
@click=" @click="
() => { () => {
if (table && props.grid.props.cellSelected) { if (table && props.grid.props.selectedMode === selectedMode.cell) {
table['cellSelected'] = { table['cellSelected'] = {
row: toRaw(props.row), row: toRaw(props.row),
rowKey: props.row[props.rowKey], rowKey: props.row[props.rowKey],
@ -81,12 +81,12 @@
<template v-for="(col, index) in cols" :key="col.name"> <template v-for="(col, index) in cols" :key="col.name">
<q-td <q-td
v-if="index > 0" v-if="index > 0"
:class="props.grid.props.cellSelected ? tdClassComputed(col) : col.__thClass + ' ' + col.classes" :class="props.grid.props.selectedMode === selectedMode.cell ? tdClassComputed(col) : col.__thClass + ' ' + col.classes"
:title="col.classes?.indexOf('truncate') > -1 && col.value && typeof col.value !== 'object' ? col.value : ''" :title="col.classes?.indexOf('truncate') > -1 && col.value && typeof col.value !== 'object' ? col.value : ''"
:style="col.style" :style="col.style"
@click=" @click="
() => { () => {
if (table && props.grid.props.cellSelected) { if (table && props.grid.props.selectedMode === selectedMode.cell) {
table['cellSelected'] = { table['cellSelected'] = {
row: toRaw(props.row), row: toRaw(props.row),
rowKey: props.row[props.rowKey], rowKey: props.row[props.rowKey],
@ -161,7 +161,7 @@
import { ref, computed, inject, toRaw } from 'vue'; import { ref, computed, inject, toRaw } from 'vue';
import { Tools, NotifyManager } from '@/platform'; import { Tools, NotifyManager } from '@/platform';
import GridEditToolbar from './GridEditToolbar.vue'; import GridEditToolbar from './GridEditToolbar.vue';
import { draggableImage, draggableMode } from './ts/grid'; import { draggableImage, draggableMode, selectedMode } from './ts/grid';
const trRef = ref(); const trRef = ref();
const tdDivRef = ref(); const tdDivRef = ref();
@ -267,7 +267,7 @@ const style = {
const firstTdClassComputed = computed(() => { const firstTdClassComputed = computed(() => {
const tdClass = <any>['nowrap', 'text-nowrap']; const tdClass = <any>['nowrap', 'text-nowrap'];
if (props.grid.props.cellSelected) { if (props.grid.props.selectedMode === selectedMode.cell) {
tdClass.push('cellSelected_hover'); tdClass.push('cellSelected_hover');
} }
if (table && table['cellSelected'] && Tools.hasOwnProperty(table['cellSelected'], 'colName')) { if (table && table['cellSelected'] && Tools.hasOwnProperty(table['cellSelected'], 'colName')) {

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

@ -123,6 +123,7 @@ import GridBody from './GridBody.vue';
import GridPagination from './GridPagination.vue'; import GridPagination from './GridPagination.vue';
import GridEditor from './GridEditor.vue'; import GridEditor from './GridEditor.vue';
import GridView from './GridView.vue'; import GridView from './GridView.vue';
import { selectedMode as selectedMode_ } from './ts/grid.ts';
import { columnDefaultProps } from './ts/grid.ts'; import { columnDefaultProps } from './ts/grid.ts';
@ -147,8 +148,8 @@ const props = defineProps({
title: { type: String, default: '' }, // title: { type: String, default: '' }, //
autoFetchData: { type: Boolean, default: true }, // autoFetchData: { type: Boolean, default: true }, //
// localMode: { type: Boolean, default: false },// autoFetchData // localMode: { type: Boolean, default: false },// autoFetchData
cellSelected: { type: Boolean, default: false }, // selectedMode: { type: String, default: selectedMode_.row }, //
draggable: { type: String, default: undefined }, // `local``remote` draggable: { type: String, default: undefined }, // `local``server`
draggableOrderBy: { type: String, default: 'order' }, // draggableOrderBy: { type: String, default: 'order' }, //
pageable: { type: Boolean, default: true }, // pageable: { type: Boolean, default: true }, //
configButton: { type: Boolean, default: true }, // configButton: { type: Boolean, default: true }, //

7
io.sc.platform.core.frontend/src/platform/components/grid/ts/grid.ts

@ -2,10 +2,15 @@ import { Tools, t } from '@/platform';
export const draggableMode = { export const draggableMode = {
local: 'local', local: 'local',
remote: 'remote', remote: 'server',
}; };
export const draggableImage = `data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' %3E%3Cpath /%3E%3C/svg%3E`; export const draggableImage = `data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' %3E%3Cpath /%3E%3C/svg%3E`;
export const selectedMode = {
row: 'row',
cell: 'cell',
};
// 列样式处理 // 列样式处理
const columnStyle = (item: any) => { const columnStyle = (item: any) => {
let style = ''; let style = '';

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

@ -5,6 +5,7 @@
title="示例列表" title="示例列表"
:data-url="Environment.apiContextPath('/api/system/application')" :data-url="Environment.apiContextPath('/api/system/application')"
db-click-operation="testAdd" db-click-operation="testAdd"
selected-mode="cell"
:cell-selected="true" :cell-selected="true"
:toolbar-actions="[ :toolbar-actions="[
'add', 'add',

Loading…
Cancel
Save