relation view bugfix

This commit is contained in:
pycook
2019-12-08 00:20:55 +08:00
parent f424ad6864
commit d5fbe42ed7
14 changed files with 99 additions and 47 deletions

View File

@@ -15,8 +15,10 @@
:wrapper-col="formItemLayout.wrapperCol"
label="角色列表"
>
<a-select name="otherID" v-decorator="['otherID', {rules: [{ required: true, message: '请选择另一个角色'}]} ]">
<a-select-option v-for="role in allRoles" v-if="role.id != current_record.id" :key="role.id">{{ role.name }}</a-select-option>
<a-select name="otherID" :filterOption="filterOption" v-decorator="['otherID', {rules: [{ required: true, message: '请选择另一个角色'}]} ]">
<template v-for="role in allRoles">
<a-select-option v-if="role.id != current_record.id" :key="role.id">{{ role.name }}</a-select-option>
</template>
</a-select>
</a-form-item>
@@ -97,10 +99,13 @@ export default {
} : {}
}
},
mounted () {
},
methods: {
filterOption (input, option) {
return (
option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
)
},
onClose () {
this.form.resetFields()
this.drawerVisible = false

View File

@@ -151,7 +151,6 @@ export default {
handleEdit (record) {
this.drawerVisible = true
console.log(record)
this.$nextTick(() => {
this.form.setFieldsValue({
id: record.id,
@@ -165,8 +164,6 @@ export default {
e.preventDefault()
this.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values)
values.app_id = this.$route.name.split('_')[0]
values.perms = this.perms
if (values.id) {

View File

@@ -138,8 +138,6 @@ export default {
e.preventDefault()
this.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values)
values.app_id = this.$route.name.split('_')[0]
if (values.id) {
this.updateResource(values.id, values)

View File

@@ -132,7 +132,6 @@ export default {
handleEdit (record) {
this.drawerVisible = true
console.log(record)
this.perms = record.perms
this.$nextTick(() => {
this.form.setFieldsValue({
@@ -147,8 +146,6 @@ export default {
e.preventDefault()
this.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values)
values.app_id = this.$route.name.split('_')[0]
values.perms = this.perms
if (values.id) {

View File

@@ -29,8 +29,11 @@
<a-select
v-model="selectedParents"
placeholder="可选择继承角色"
mode="multiple">
<a-select-option v-for="role in allRoles" v-if="current_id !== role.id" :key="role.id">{{ role.name }}</a-select-option>
mode="multiple"
:filterOption="filterOption">
<template v-for="role in allRoles">
<a-select-option v-if="current_id !== role.id" :key="role.id">{{ role.name }}</a-select-option>
</template>
</a-select>
</a-form-item>
<a-form-item
@@ -119,11 +122,13 @@ export default {
} : {}
}
},
mounted () {
},
methods: {
filterOption (input, option) {
return (
option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
)
},
handleCreate () {
this.drawerTitle = '新增'
this.drawerVisible = true
@@ -162,7 +167,6 @@ export default {
e.preventDefault()
this.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values)
values.app_id = this.$route.name.split('_')[0]
if (values.id) {
this.updateRole(values.id, values)

View File

@@ -205,7 +205,6 @@ export default {
handleEdit (record) {
this.drawerVisible = true
console.log(record)
this.$nextTick(() => {
this.form.setFieldsValue({
id: record.uid,
@@ -225,8 +224,6 @@ export default {
e.preventDefault()
this.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values)
if (values.id) {
this.updateUser(values.id, values)
} else {

View File

@@ -155,7 +155,6 @@ export default {
delete parameter.pageNo
delete parameter.pageSize
Object.assign(parameter, this.queryParam)
console.log('loadData.parameter', parameter)
return searchResourceType(parameter)
.then(res => {
@@ -165,7 +164,6 @@ export default {
res.totalPage = Math.ceil(res.numfound / parameter.pageSize)
res.data = res.groups
this.id2perms = res.id2perms
console.log('loadData.res', res)
return res
})
},

View File

@@ -155,7 +155,6 @@ export default {
delete parameter.pageNo
delete parameter.pageSize
Object.assign(parameter, this.queryParam)
console.log('loadData.parameter', parameter)
return searchResourceType(parameter)
.then(res => {
@@ -165,7 +164,6 @@ export default {
res.totalPage = Math.ceil(res.numfound / parameter.pageSize)
res.data = res.groups
this.id2perms = res.id2perms
console.log('loadData.res', res)
return res
})
},
@@ -249,7 +247,6 @@ export default {
}
}
record.perms = perms
console.log(record)
this.$refs.resourceTypeForm.handleEdit(record)
},
handleDelete (record) {

View File

@@ -155,7 +155,6 @@ export default {
delete parameter.pageNo
delete parameter.pageSize
Object.assign(parameter, this.queryParam)
console.log('loadData.parameter', parameter)
return searchRole(parameter)
.then(res => {
@@ -165,7 +164,6 @@ export default {
res.totalPage = Math.ceil(res.numfound / parameter.pageSize)
res.data = res.roles
console.log('loadData.res', res)
this.allRoles = res.roles
this.id2parents = res.id2parents
return res

View File

@@ -218,7 +218,6 @@ export default {
delete parameter.pageNo
delete parameter.pageSize
Object.assign(parameter, this.queryParam)
console.log('loadData.parameter', parameter)
return searchUser(parameter)
.then(res => {
@@ -228,7 +227,6 @@ export default {
res.totalPage = Math.ceil(res.numfound / parameter.pageSize)
res.data = res.users
console.log('loadData.res', res)
this.allUsers = res.users
return res
})

View File

@@ -62,7 +62,9 @@ export default {
relationViews: {},
levels: [],
showTypeIds: [],
origShowTypeIds: [],
showTypes: [],
origShowTypes: [],
leaf2showTypes: {},
node2ShowTypes: {},
leaf: [],
@@ -84,7 +86,7 @@ export default {
console.log(parameter, 'load instances')
this.parameter = parameter
const params = Object.assign(parameter || {}, this.$refs.search.queryParam)
let q = `q=_type:${this.currentTypeId[0]}`
let q = ''
Object.keys(params).forEach(key => {
if (!['pageNo', 'pageSize', 'sortField', 'sortOrder'].includes(key) && params[key] + '' !== '') {
if (typeof params[key] === 'object' && params[key].length > 1) {
@@ -109,8 +111,13 @@ export default {
}
q += `&sort=${order}${params['sortField']}`
}
if (q && q[0] === ',') {
q = q.slice(1)
}
if (this.treeKeys.length === 0) {
this.judgeCITypes(q)
q = `q=_type:${this.currentTypeId[0]},` + q
return searchCI(q).then(res => {
const result = {}
result.pageNo = res.page
@@ -123,7 +130,7 @@ export default {
setTimeout(() => {
this.setColumnWidth()
console.log('set column')
}, 300)
}, 100)
}
this.loadRoot()
return result
@@ -133,13 +140,6 @@ export default {
q += `&root_id=${this.treeKeys[this.treeKeys.length - 1].split('_')[0]}`
const typeId = parseInt(this.treeKeys[this.treeKeys.length - 1].split('_')[1])
this.showTypes = this.node2ShowTypes[typeId + '']
const showTypeIds = []
this.showTypes.forEach(item => {
showTypeIds.push(item.id)
})
this.showTypeIds = showTypeIds
let level = []
if (!this.leaf.includes(typeId)) {
let startIdx = 0
@@ -160,9 +160,8 @@ export default {
level = [1]
}
q += `&level=${level.join(',')}`
if (q[0] === '&') {
q = q.slice(1)
}
this.judgeCITypes(q)
q = `q=_type:${this.currentTypeId[0]},` + q
return searchCIRelation(q).then(res => {
const result = {}
result.pageNo = res.page
@@ -176,7 +175,7 @@ export default {
setTimeout(() => {
this.setColumnWidth()
console.log('set column')
}, 300)
}, 100)
this.loadNoRoot(this.treeKeys[this.treeKeys.length - 1], level)
}
return result
@@ -212,6 +211,55 @@ export default {
}, 100)
},
async judgeCITypes (q) {
const showTypeIds = []
let _showTypes = []
let _showTypeIds = []
if (this.treeKeys.length) {
const typeId = parseInt(this.treeKeys[this.treeKeys.length - 1].split('_')[1])
_showTypes = this.node2ShowTypes[typeId + '']
_showTypes.forEach(item => {
_showTypeIds.push(item.id)
})
} else {
_showTypeIds = JSON.parse(JSON.stringify(this.origShowTypeIds))
_showTypes = JSON.parse(JSON.stringify(this.origShowTypes))
}
const promises = _showTypeIds.map(typeId => {
const _q = (`q=_type:${typeId},` + q).replace(/count=\d*/, 'count=1')
if (this.treeKeys.length === 0) {
return searchCI(_q).then(res => {
if (res.numfound !== 0) {
showTypeIds.push(typeId)
}
})
} else {
return searchCIRelation(_q).then(res => {
if (res.numfound !== 0) {
showTypeIds.push(typeId)
}
})
}
})
await Promise.all(promises)
if (showTypeIds.length && showTypeIds.length !== this.showTypeIds.length) {
const showTypes = []
_showTypes.forEach(item => {
if (showTypeIds.includes(item.id)) {
showTypes.push(item)
}
})
this.showTypes = showTypes
this.showTypeIds = showTypeIds
if (this.currentTypeId.length && !this.showTypeIds.includes(this.currentTypeId[0])) {
this.currentTypeId = this.showTypeIds[0]
}
}
},
async loadRoot () {
searchCI(`q=_type:(${this.levels[0].join(';')})&count=10000`).then(async res => {
const facet = []
@@ -335,17 +383,17 @@ export default {
}
})
this.levels = this.relationViews.views[this.viewName].topo
this.showTypes = this.relationViews.views[this.viewName].show_types
this.origShowTypes = this.relationViews.views[this.viewName].show_types
const showTypeIds = []
this.showTypes.forEach(item => {
this.origShowTypes.forEach(item => {
showTypeIds.push(item.id)
})
this.showTypeIds = showTypeIds
this.origShowTypeIds = showTypeIds
this.leaf2showTypes = this.relationViews.views[this.viewName].leaf2show_types
this.node2ShowTypes = this.relationViews.views[this.viewName].node2show_types
this.leaf = this.relationViews.views[this.viewName].leaf
this.currentView = [this.viewId]
this.currentTypeId = [this.showTypeIds[0]]
this.currentTypeId = [this.origShowTypeIds[0]]
this.typeId = this.levels[0][0]
this.loadColumns()
this.$refs.table && this.$refs.table.refresh(true)