diff --git a/examples/views/docs/component/schema-filter.md b/examples/views/docs/component/schema-filter.md
index 6820450..8f644fd 100644
--- a/examples/views/docs/component/schema-filter.md
+++ b/examples/views/docs/component/schema-filter.md
@@ -1,4 +1,4 @@
-# Schema Filter 筛选
+# Schema Filter 方案筛选
通过配置JSON Schema的方式快速生成一个筛选表单
diff --git a/examples/views/docs/component/schema-table.md b/examples/views/docs/component/schema-table.md
index f436981..8821f76 100644
--- a/examples/views/docs/component/schema-table.md
+++ b/examples/views/docs/component/schema-table.md
@@ -1,30 +1,32 @@
-# Schema Table 表格
+# Schema Table 方案表格
-根据JSON Schema配置自动生成表格
+通过配置JSON Schema的方式快速生成一个表格
## 基础用法
-配置`list`属性设置JSON Schema配置列表
+`schema`设置配置项,其中**props**参数与`z-table`组件参数相同,**items**则对应`z-table`组件的`columns`。
-::: snippet `tableProps`设置表格参数
+::: snippet 本质上是通过`schema`的方式实现生成一个`z-table`
```html
-
+
```
:::
-::: snippet `slot`插槽式渲染
+## 列渲染
+
+除了使用插槽自定义列的内容之外,也支持直接在配置项中写渲染函数
+
+::: snippet 配置项中的`render`可以设置对应列单元格的渲染
```html
-
-
- {{ value }}
-
-
+
```
:::
-
+## 追加列
-## 层级分组
+使用配置项时,**新增的列**则默认追加在**配置项列**之后,使用`left`插槽可在表格的最左侧插入列,顺序在**配置项列**之前
-支持`group`分组,兼容form组件,使同一个schema能够同时复用在`table`、`form`上
-
-::: snippet `group`设置分组,其中`key`设置分组对象名称
+::: snippet 用法与`z-table`相同
```html
-
+
+
+
+
+
+ 内容 {{ $index }}
+
+
+
+
+
+ 编辑第{{ $index + 1 }}行
+
+
+
```
@@ -144,10 +170,7 @@ export default {
参数|说明|类型|可选值|默认值
-|-|-|-|-
value | 表格数据 | Array | - | -
-list | JSON Schema配置项列表 | Array | - | []
-tableProps | 表格参数 | Object | - | -
-tableEvents | 表格参数 | Object | - | -
-minWidth | 列宽 | Number | - | -
+schema | JSON Schema配置项列表 | Array | - | []
## Events 事件
diff --git a/examples/views/docs/component/table.md b/examples/views/docs/component/table.md
index 6a2a360..c0ae9b7 100644
--- a/examples/views/docs/component/table.md
+++ b/examples/views/docs/component/table.md
@@ -132,15 +132,19 @@ export default {
编辑模式:
+ 编辑全部:
双击编辑:
-
+
男
女
+
+ {{ value }}
+
删除
@@ -154,6 +158,7 @@ export default {
export default {
data() {
return {
+ editall: false,
editable: true,
clickable: true,
tableData: [
diff --git a/packages/schema-table/cell-editable.vue b/packages/schema-table/cell-editable.vue
deleted file mode 100644
index 9dba927..0000000
--- a/packages/schema-table/cell-editable.vue
+++ /dev/null
@@ -1,90 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{ $_get(row, item.agentKey || item.fullKey) }}
-
-
-
-
-
-
diff --git a/packages/schema-table/cell-value-render.js b/packages/schema-table/cell-value-render.js
deleted file mode 100644
index 8834bdb..0000000
--- a/packages/schema-table/cell-value-render.js
+++ /dev/null
@@ -1,20 +0,0 @@
-import { get } from '../utils';
-
-export default {
- props: { row: Object, column: Object, index: [Number, String], item: Object },
- render(h) {
- const { row, column, index, item } = this;
- if (typeof item.render === 'function') {
- return item.render(h, { row, value: get(row, item.fullKey), $index: index, column });
- } else {
- if (item.render.children instanceof Function) {
- return h(
- item.render.type,
- { props: item.render.props, attrs: item.render.props, style: item.render.style },
- item.render.children({ row, value: get(row, item.fullKey), $index: index, column }),
- );
- }
- return h(item.render.type, { props: item.render.props, attrs: item.render.props, style: item.render.style }, item.render.children || get(row, item.fullKey));
- }
- },
-};
diff --git a/packages/schema-table/editable.vue b/packages/schema-table/editable.vue
deleted file mode 100644
index e668f91..0000000
--- a/packages/schema-table/editable.vue
+++ /dev/null
@@ -1,319 +0,0 @@
-
-
-
-
-
- 新增
- 编辑
- 完成
- 取消
- 删除
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/packages/schema-table/index.vue b/packages/schema-table/index.vue
index f30beb4..1bc429c 100644
--- a/packages/schema-table/index.vue
+++ b/packages/schema-table/index.vue
@@ -1,197 +1,39 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/packages/select/index.bak.vue b/packages/select/index.bak.vue
deleted file mode 100644
index bd1391a..0000000
--- a/packages/select/index.bak.vue
+++ /dev/null
@@ -1,268 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/packages/table/editable.vue b/packages/table/editable.vue
index 7163b24..431ff71 100644
--- a/packages/table/editable.vue
+++ b/packages/table/editable.vue
@@ -27,23 +27,26 @@
-
+
-
+
onCellInput(value, row, column, $index)"
+ @edit-click="setRowEditor(row, column, $index)"
+ @edit-confirm="value => onEditConfirm(value, row, column, $index)"
>
-
-
+
+
+
+
+
@@ -72,7 +75,7 @@ export default {
},
watch: {
editable(val) {
- if (val && this.component === 'el-input') {
+ if (!this.disabled && val && this.component === 'el-input') {
this.$nextTick(() => {
this.$children[0] && this.$children[0].focus && this.$children[0].focus();
});
@@ -91,8 +94,8 @@ export default {
},
}),
];
- if (this.$scopedSlots.default) {
- editorRender = [this.$scopedSlots.default()];
+ if (this.$scopedSlots.editor) {
+ editorRender = [this.$scopedSlots.editor()];
}
if (!this.disabled) {
const handlerItems = [h('i', { attrs: { title: '确定', class: 'el-icon-check' }, on: { click: () => this.$emit('edit-confirm', this.value) } })];
@@ -102,7 +105,10 @@ export default {
}
return h('span', { class: 'z-table-column__cell-editable' }, editorRender);
}
- const valueRender = [h('span', this.value)];
+ let valueRender = [h('span', this.value)];
+ if (this.$scopedSlots.default) {
+ valueRender = [this.$scopedSlots.default()];
+ }
if (!this.disabled) {
valueRender.push(h('i', { attrs: { title: '编辑', class: 'el-icon-edit' }, on: { click: () => this.$emit('edit-click') } }));
}
@@ -123,6 +129,7 @@ export default {
return [];
},
},
+ editall: Boolean,
clickable: Boolean,
disabled: Boolean,
...tableProps,
@@ -134,13 +141,13 @@ export default {
data(val) {
this.tableData = val || [];
},
+ tableData(val) {
+ this.$emit('input', val || []);
+ },
},
data() {
return {
tableData: this.value,
- tableRowTemplate: { $editable: true }, // 行数据模板
- tableEditCell: {}, // 正在编辑的单元格
- tableSelection: [], // 表格已选中
};
},
filters: {
@@ -156,32 +163,51 @@ export default {
},
onCellClick(row, column) {
if (this.clickable) {
- if (row.$index !== this.tableEditCell.index || column.property !== this.tableEditCell.prop) {
- this.tableEditCell = {};
- }
+ const prop = column.property;
+ let tableData = cloneDeep(this.tableData);
+ tableData.forEach((item, index) => {
+ if (!(index === row.$index && item.$editor && item.$editor.includes(prop))) {
+ item.$editor = [];
+ }
+ });
+ this.tableData = tableData;
}
},
onCellDblclick(row, column) {
if (this.clickable) {
- this.setEditCell(row, column);
+ this.setRowEditor(row, column, row.$index);
}
},
- setEditCell(row, column) {
- this.tableEditCell = { index: row.$index, prop: column.property };
+ setRowEditor(row, column, index) {
+ this.cancelEditCell();
+ let tableRow = this.tableData[index];
+ if (tableRow) {
+ if (tableRow.$editor) {
+ tableRow.$editor = [...tableRow.$editor, column.property];
+ } else {
+ tableRow.$editor = [column.property];
+ }
+ this.$set(this.tableData, index, tableRow);
+ }
},
- onEditConfirm(value) {
- this.$emit('cell-edit-confirm', { ...this.tableEditCell, value });
+ onEditConfirm(value, row, column, index) {
+ this.$emit('cell-edit-confirm', { row, index, prop: column.property, value });
this.cancelEditCell();
},
cancelEditCell() {
- this.tableEditCell = {};
+ this.tableData = this.tableData.map((item, index) => {
+ const newItem = cloneDeep(item);
+ delete newItem.$index;
+ delete newItem.$editor;
+ return newItem;
+ });
},
- onCellInput(value) {
+ onCellInput(value, row, column, index) {
const tableData = cloneDeep(this.tableData);
- const tableRow = tableData[this.tableEditCell.index];
- set(tableRow, this.tableEditCell.prop, value);
- tableData[this.tableEditCell.index] = tableRow;
- this.$set(this.tableData, this.tableEditCell.index, tableRow);
+ const tableRow = tableData[index];
+ set(tableRow, column.property, value);
+ tableData[index] = tableRow;
+ this.$set(this.tableData, index, tableRow);
},
},
};
diff --git a/packages/table/index.js b/packages/table/index.js
index f2f38f6..6c45488 100644
--- a/packages/table/index.js
+++ b/packages/table/index.js
@@ -16,6 +16,7 @@ export default {
},
},
editable: Boolean,
+ editall: Boolean,
clickable: Boolean,
disabled: Boolean,
...tableProps,
diff --git a/packages/table/normal.vue b/packages/table/normal.vue
index 467bd06..1a94b6a 100644
--- a/packages/table/normal.vue
+++ b/packages/table/normal.vue
@@ -1,5 +1,5 @@
-
+
@@ -7,6 +7,9 @@
+
+
+
@@ -19,6 +22,17 @@ import tableProps from './props';
export default {
name: 'TableNormal',
+ components: {
+ CellRender: {
+ functional: true,
+ render(h, context) {
+ const props = context.props;
+ const item = props.item || {};
+ const content = item.render(props.value, props.row, h, props.index);
+ return typeof content === 'string' ? h('span', {}, [content]) : content;
+ },
+ },
+ },
inject: {
elForm: {
default: '',
@@ -62,6 +76,16 @@ export default {
tableSize() {
return this.size || this._elFormItemSize || (this.elForm || {}).size || (this.$ELEMENT || {}).size;
},
+ bindProps() {
+ const tablePropsKeys = Object.keys(tableProps);
+ let props = {};
+ Object.keys(this._props).forEach(key => {
+ if (tablePropsKeys.includes(key)) {
+ props[key] = this._props[key];
+ }
+ });
+ return props;
+ },
},
};
--
libgit2 0.21.0