* 同一界面内,多CRUD共存

* 解决多crud,对inject修改造成注入混乱,弃用Vue注入方式

* 自定义数据id字段名

* 以$options.cruds()方式实例化crud,避免多组件实例共享crud
This commit is contained in:
Moxun
2020-03-06 20:32:09 +08:00
committed by GitHub
parent f04b9a03bb
commit 32dc525091
20 changed files with 108 additions and 70 deletions

View File

@@ -593,15 +593,24 @@ function lookupCrud(vm, tag) {
* crud主页
*/
function presenter(crud) {
if (crud) {
console.warn('[CRUD warn]: ' + 'please use $options.cruds() { return CRUD(...) or [CRUD(...), ...] }')
}
return {
beforeCreate() {
this.$crud = this.$crud || {}
if (this.$crud[crud.tag]) {
console.error('[CRUD error]: ' + 'crud with tag [' + crud.tag + ' is already exist')
let cruds = this.$options.cruds instanceof Function ? this.$options.cruds() : crud
if (!(cruds instanceof Array)) {
cruds = [cruds]
}
this.$crud[crud.tag] = crud
this.crud = crud
crud.registerVM('presenter', this, 0)
cruds.forEach(ele => {
if (this.$crud[ele.tag]) {
console.error('[CRUD error]: ' + 'crud with tag [' + ele.tag + ' is already exist')
}
this.$crud[ele.tag] = ele
ele.registerVM('presenter', this, 0)
})
this.crud = this.$crud['defalut'] || cruds.length > 0 ? cruds[0] : null
},
data() {
return {
@@ -612,12 +621,16 @@ function presenter(crud) {
parseTime
},
created() {
if (crud.queryOnPresenterCreated) {
crud.toQuery()
for (const k in this.$crud) {
if (this.$crud[k].queryOnPresenterCreated) {
this.$crud[k].toQuery()
}
}
},
destroyed() {
crud.unregisterVM(this)
for (const k in this.$crud) {
this.$crud[k].unregisterVM(this)
}
},
mounted() {
const columns = []