Skip to content

Commit 816f2e5

Browse files
committed
Merge tag '2.0.0' into develop
no message
2 parents 71430a5 + f805a07 commit 816f2e5

15 files changed

+1345
-528
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
## 介绍
9-
[D2-Crud](https://github.com/d2-projects/d2-crud)是一套基于[Vue.js 2.2.0+](https://cn.vuejs.org/)[Element UI 2.0.0+](http://element-cn.eleme.io/#/zh-CN)的表格组件。`D2-Crud``Element` 的功能进行了封装,并增加了表格的增删改查、数据校验、表格内编辑等常用的功能。大部分功能可由配置 `json` 实现,在实现并扩展了 `Elememt` 表格组件功能的同时,降低了开发难度,减少了代码量,大大简化了开发流程。
9+
[D2-Crud](https://github.com/d2-projects/d2-crud)是一套基于[Vue.js 2.2.0+](https://cn.vuejs.org/)[Element UI 2.0.0+](http://element-cn.eleme.io/#/zh-CN)的表格组件。`D2-Crud``Element` 的功能进行了封装,并增加了表格的增删改查、数据校验、表格内编辑等常用的功能。大部分功能可由配置 `json` 实现,在实现并扩展了 `Element` 表格组件功能的同时,降低了开发难度,减少了代码量,大大简化了开发流程。
1010

1111

1212
## 文档和示例

dist/d2-crud.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/d2-crud.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@d2-projects/d2-crud",
33
"description": "A d2-projects project",
4-
"version": "1.3.5",
4+
"version": "2.0.3",
55
"author": "孙昊翔 <673686754@qq.com>",
66
"license": "MIT",
77
"private": false,
@@ -25,7 +25,7 @@
2525
"lodash.foreach": "^4.5.0",
2626
"lodash.get": "^4.4.2",
2727
"lodash.set": "^4.3.2",
28-
"vue": "^2.5.11"
28+
"vue": "^2.5.19"
2929
},
3030
"browserslist": [
3131
"> 1%",
@@ -43,7 +43,7 @@
4343
"node-sass": "^4.5.3",
4444
"sass-loader": "^6.0.6",
4545
"vue-loader": "^13.0.5",
46-
"vue-template-compiler": "^2.4.4",
46+
"vue-template-compiler": "^2.5.19",
4747
"webpack": "^3.6.0",
4848
"webpack-dev-server": "^2.9.1"
4949
}

src/d2-crud.vue

+103-70
Large diffs are not rendered by default.

src/mixin/add.js

+13-20
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,25 @@ import _forEach from 'lodash.foreach'
22
import _clonedeep from 'lodash.clonedeep'
33

44
export default {
5-
props: {
6-
/**
7-
* @description 是否显示新增按钮
8-
*/
9-
addMode: {
10-
type: Boolean,
11-
default: false
12-
},
13-
/**
14-
* @description 新增按钮配置
15-
*/
16-
addButton: {
17-
type: Object,
18-
default: null
19-
}
20-
},
215
methods: {
226
/**
237
* @description 新增行数据
248
*/
25-
handleAdd () {
9+
handleAdd (templage = null) {
2610
this.formMode = 'add'
27-
this.showDialog = true
28-
this.formData = this.formTemplate ? _clonedeep(this.formTemplate) : {}
11+
this.$emit('dialog-open', {
12+
mode: 'add'
13+
})
14+
this.isDialogShow = true
15+
if (templage) {
16+
this.formData = _clonedeep(templage)
17+
this.addTemplateStorage = _clonedeep(templage)
18+
} else {
19+
this.formData = this.addTemplate ? _clonedeep(this.addTemplate) : {}
20+
this.addTemplateStorage = this.addTemplate ? _clonedeep(this.addTemplate) : {}
21+
}
2922
_forEach(this.formData, (value, key) => {
30-
this.formData[key] = this.formTemplate[key].value
23+
this.formData[key] = this.addTemplateStorage[key].value
3124
})
3225
}
3326
}

src/mixin/base.js

-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
export default {
22
props: {
3-
/**
4-
* @description 表格标题
5-
*/
6-
title: {
7-
default: ''
8-
},
93
/**
104
* @description 表头数据
115
*/

src/mixin/data.js

+13-49
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,17 @@ export default {
1717
/**
1818
* @description 表格内部数据
1919
*/
20-
d2Data: [],
21-
/**
22-
* @description 表格当前分页数据
23-
*/
24-
d2PaginationData: [],
25-
/**
26-
* @description 编辑暂存数据,用于储存不在formTemplate中的数据
27-
*/
28-
editDataStorage: {}
20+
d2CrudData: []
2921
}
3022
},
3123
computed: {
32-
d2DataLength () {
33-
return this.d2Data.length
24+
d2CrudDataLength () {
25+
return this.d2CrudData.length
3426
}
3527
},
3628
watch: {
3729
data () {
3830
this.handleDataChange()
39-
},
40-
d2Data: {
41-
handler (val) {
42-
if (this.pagination) {
43-
this.d2PaginationData = this.d2Data.slice(this.paginationDataStart, this.paginationDataEnd)
44-
}
45-
this.$emit('d2-data-change', val)
46-
},
47-
deep: true
4831
}
4932
},
5033
mounted () {
@@ -60,30 +43,19 @@ export default {
6043
*/
6144
_set,
6245
/**
63-
* @description 同步外部表格数据到d2Data内部
46+
* @description 同步外部表格数据到d2CrudData内部
6447
*/
6548
handleDataChange () {
66-
if (this.d2Data !== this.data) {
67-
this.d2Data = _clonedeep(this.data)
68-
if (this.pagination) {
69-
this.d2PaginationData = this.d2Data.slice(this.paginationDataStart, this.paginationDataEnd)
70-
}
49+
if (this.d2CrudData !== this.data) {
50+
this.d2CrudData = _clonedeep(this.data)
7151
}
7252
},
7353
/**
7454
* @description 排序时数据变化
7555
*/
7656
handleSortDataChange () {
7757
this.$nextTick(() => {
78-
if (this.pagination) {
79-
let j = 0
80-
for (let i = this.paginationDataStart; i < this.paginationDataEnd; i++) {
81-
this.d2Data[i] = this.$refs.elTable.store.states.data[j]
82-
j += 1
83-
}
84-
} else {
85-
this.d2Data = this.$refs.elTable.store.states.data
86-
}
58+
this.d2CrudData = this.$refs.elTable.store.states.data
8759
})
8860
},
8961
/**
@@ -98,12 +70,8 @@ export default {
9870
* @param {Number} index 表格数据索引
9971
* @param {Object} row 更新的表格行数据
10072
*/
101-
updateRow (index, row) {
102-
if (this.pagination) {
103-
this.$set(this.d2Data, index + this.paginationDataStart, row)
104-
} else {
105-
this.$set(this.d2Data, index, row)
106-
}
73+
handleUpdateRow (index, row) {
74+
this.$set(this.d2CrudData, index, row)
10775
if (this.defaultSort) {
10876
this.handleSortDataChange()
10977
}
@@ -112,8 +80,8 @@ export default {
11280
* @description 新增行数据
11381
* @param {Object} row 新增的表格行数据
11482
*/
115-
addRow (row) {
116-
this.$set(this.d2Data, this.d2Data.length, row)
83+
handleAddRow (row) {
84+
this.$set(this.d2CrudData, this.d2CrudData.length, row)
11785
if (this.defaultSort) {
11886
this.handleSortDataChange()
11987
}
@@ -122,12 +90,8 @@ export default {
12290
* @description 删除行
12391
* @param {Object} index 被删除行索引
12492
*/
125-
removeRow (index) {
126-
if (this.pagination) {
127-
this.$delete(this.d2Data, index + this.paginationDataStart)
128-
} else {
129-
this.$delete(this.d2Data, index)
130-
}
93+
handleRemoveRow (index) {
94+
this.$delete(this.d2CrudData, index)
13195
if (this.defaultSort) {
13296
this.handleSortDataChange()
13397
}

src/mixin/dialog.js

+53-13
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,44 @@ export default {
1111
default: null
1212
},
1313
/**
14-
* @description 表单模板
14+
* @description dialog新增标题
1515
*/
16-
formTemplate: {
16+
addTitle: {
17+
type: String,
18+
default: '添加'
19+
},
20+
/**
21+
* @description dialog修改标题
22+
*/
23+
editTitle: {
24+
type: String,
25+
default: '编辑'
26+
},
27+
/**
28+
* @description 新增表单模板
29+
*/
30+
addTemplate: {
31+
type: Object,
32+
default: null
33+
},
34+
/**
35+
* @description 修改表单模板
36+
*/
37+
editTemplate: {
1738
type: Object,
1839
default: null
1940
},
2041
/**
21-
* @description 表单校验规则
42+
* @description 新增表单校验规则
2243
*/
23-
formRules: {
44+
addRules: {
45+
type: Object,
46+
default: null
47+
},
48+
/**
49+
* @description 编辑表单校验规则
50+
*/
51+
editRules: {
2452
type: Object,
2553
default: null
2654
}
@@ -30,15 +58,27 @@ export default {
3058
/**
3159
* @description dialog显示与隐藏
3260
*/
33-
showDialog: false,
61+
isDialogShow: false,
3462
/**
3563
* @description 表单数据
3664
*/
3765
formData: {},
3866
/**
3967
* @description 表单模式
4068
*/
41-
formMode: 'edit'
69+
formMode: 'edit',
70+
/**
71+
* @description 编辑暂存数据,用于储存不在editTemplate中的数据
72+
*/
73+
editDataStorage: {},
74+
/**
75+
* @description 新增表单模板暂存
76+
*/
77+
addTemplateStorage: {},
78+
/**
79+
* @description 修改表单模板暂存
80+
*/
81+
editTemplateStorage: {}
4282
}
4383
},
4484
methods: {
@@ -61,7 +101,7 @@ export default {
61101
row: rowData
62102
}, (param = null) => {
63103
if (param === false) {
64-
this.closeDialog()
104+
this.handleCloseDialog()
65105
return
66106
}
67107
this.handleDialogSaveDone({
@@ -75,7 +115,7 @@ export default {
75115
})
76116
this.$emit('row-add', rowData, (param = null) => {
77117
if (param === false) {
78-
this.closeDialog()
118+
this.handleCloseDialog()
79119
return
80120
}
81121
this.handleDialogSaveDone({
@@ -97,18 +137,18 @@ export default {
97137
*/
98138
handleDialogSaveDone (rowData) {
99139
if (this.formMode === 'edit') {
100-
this.updateRow(this.editIndex, rowData)
140+
this.handleUpdateRow(this.editIndex, rowData)
101141
this.editDataStorage = {}
102142
} else if (this.formMode === 'add') {
103-
this.addRow(rowData)
143+
this.handleAddRow(rowData)
104144
}
105-
this.closeDialog()
145+
this.handleCloseDialog()
106146
},
107147
/**
108148
* @description 关闭模态框
109149
*/
110-
closeDialog () {
111-
this.showDialog = false
150+
handleCloseDialog () {
151+
this.isDialogShow = false
112152
}
113153
}
114154
}

src/mixin/edit.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,22 @@ export default {
1616
* @param {Number} index 行所在索引
1717
* @param {Object} row 行数据
1818
*/
19-
handleEdit (index, row) {
19+
handleEdit (index, row, templage = null) {
2020
this.formMode = 'edit'
2121
this.editDataStorage = _clonedeep(row)
22-
this.showDialog = true
22+
this.isDialogShow = true
23+
this.$emit('dialog-open', {
24+
mode: 'edit',
25+
row
26+
})
2327
this.editIndex = index
24-
this.formData = this.formTemplate ? _clonedeep(this.formTemplate) : {}
28+
if (templage) {
29+
this.formData = _clonedeep(templage)
30+
this.editTemplateStorage = _clonedeep(templage)
31+
} else {
32+
this.formData = this.editTemplate ? _clonedeep(this.editTemplate) : {}
33+
this.editTemplateStorage = this.editTemplate ? _clonedeep(this.editTemplate) : {}
34+
}
2535
_forEach(this.formData, (value, key) => {
2636
this.formData[key] = row.hasOwnProperty(key) ? row[key] : ''
2737
})

0 commit comments

Comments
 (0)