Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/plugin/components/form/dialog.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div @click="handleShowDialog">
<div @click.stop="handleShowDialog">
<slot />
<el-dialog
:visible="visible"
Expand Down
20 changes: 16 additions & 4 deletions src/plugin/components/source-page/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
:table-events="tablePageEvents"
:table-props="tableProps"
:action-column-props="actionColumnProps"
:on-table-cell-form-submit="handleTableCellFormSubmit"
ref="tablePage"
>
<template #after-filter>
Expand Down Expand Up @@ -49,7 +50,7 @@
:columns="sourcePageFormColumns"
:loading="formLoading"
v-model="state.data"
@submit="handleSubmit"
@submit="handleFormPageSubmit"
>
<template v-slot:action="{ value }">
<slot name="form-action" :value="value" />
Expand Down Expand Up @@ -285,10 +286,19 @@ export default class AdminSourcePage extends Vue {
}
}

async handleSubmit(data) {
handleTableCellFormSubmit({ data, scope }) {
const originData = scope.row;
return this.handleSubmit({ data: { id: originData.id, ...data }, originData });
}

handleFormPageSubmit(data) {
return this.handleSubmit({ data });
}

async handleSubmit({ data, originData = this.originData, state = this.state } = {}) {
try {
this.formLoading = true;
const hookParams = { data, originData: this.originData, state: this.state, type: this.type, resource: this.resource, namespace: this.namespace };
const hookParams = { data, originData, state, type: this.type, resource: this.resource, namespace: this.namespace };
if (_.isFunction(this.onFormSubmit)) {
await this.onFormSubmit(hookParams);
} else {
Expand All @@ -305,7 +315,9 @@ export default class AdminSourcePage extends Vue {
if (_.isFunction(this.afterSubmit)) {
this.afterSubmit(hookParams, newData)
} else {
this.$router.push({ name: `${this.resource}.show`, params: { id: data.id } });
if (this.type !== 'index') {
this.$router.push({ name: `${this.resource}.show`, params: { id: data.id } });
}
}
}
} finally {
Expand Down
2 changes: 2 additions & 0 deletions src/plugin/components/source-page/table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
:actions="actions"
:action-column-props="actionColumnProps"
:default-sort="defaultSort"
:on-table-cell-form-submit="onTableCellFormSubmit"
@sort-change="handleSortChange"
/>
</div>
Expand Down Expand Up @@ -62,6 +63,7 @@ export default class AdminSourcePageTable extends Vue {
@Prop({ type: Object, default: () => ({}) }) filterProps;
@Prop({ type: Object, default: () => ({}) }) paginationProps;
@Prop({ type: Object, default: () => ({}) }) tableEvents;
@Prop({ type: Function, default: _.noop }) onTableCellFormSubmit;

filterForm = {};
defaultSort = {};
Expand Down
61 changes: 53 additions & 8 deletions src/plugin/components/table.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<script>
import { Vue, Component, Prop } from 'vue-property-decorator';
import _ from 'lodash';
import DialogForm from './form/dialog';

@Component
export default class AdminTable extends Vue {
@Prop({ type: Array, default: () => [] }) columns;
@Prop({ type: Array, default: () => [] }) value;
@Prop({ type: [Function, Array] }) actions;
@Prop({ type: Object, default: () => ({}) }) actionColumnProps;
@Prop({ type: Function, default: _.noop }) onTableCellFormSubmit;

get actionColumn() {
const ColumnRender = require('./column-render').default;
Expand Down Expand Up @@ -60,22 +62,65 @@ export default class AdminTable extends Vue {
));
}

renderCellForm({ column, scope }) {
const formColumn = _.isFunction(column.form) ? column.form(scope) : column.form;
if (formColumn) {
const formColumns = [
{
prop: column.prop,
label: column.label,
...formColumn
}
];
const submitHandler = async (data) => {
if (_.isFunction(formColumn.submitHandler)) {
await formColumn.submitHandler({ data, scope })
} else {
await this.onTableCellFormSubmit({ data, scope });
}
Object.assign(scope.row, data);
}
return (
<DialogForm
columns={formColumns}
value={_.pick(scope.row, column.prop)}
title={column.label}
submitHandler={submitHandler}
label-position="top"
>
<el-button
icon="el-icon-edit"
size="mini"
style="margin-left: 5px; padding: 4px"
circle
/>
</DialogForm>
)
}
return null;
}

renderCell(column) {
const ColumnRender = require('./column-render').default;
return scope => {
return <ColumnRender
key={column.prop}
value={_.get(scope.row, column.prop)}
scope={scope}
column={column}
renderCell={column.renderCell}
/>
return (
<div class="table-cell">
<ColumnRender
key={column.prop}
value={_.get(scope.row, column.prop)}
scope={scope}
column={column}
renderCell={column.renderCell || (() => <span>{_.get(scope, `row.${column.prop}`, '/')}</span>)}
/>
{this.renderCellForm({ column, scope })}
</div>
)
}
}

renderTableColumn(column) {
const scopedSlots = {};
if (column.renderCell) {
if (column.prop) {
scopedSlots.default = this.renderCell(column);
}
return (
Expand Down
6 changes: 6 additions & 0 deletions src/plugin/styles/table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,11 @@
margin-bottom: 10px;
}
}

.table-cell {
display: inline-flex;
align-items: center;
flex-wrap: wrap;
}
}
}