feat: 优化数据集中对ztree相关的操作

main
wu.jian2 2 years ago
parent 992231d076
commit 64dd7f363a

@ -36,11 +36,15 @@
<el-button <el-button
class="bs-el-button-default" class="bs-el-button-default"
@click="cancel" @click="cancel"
>取消</el-button> >
取消
</el-button>
<el-button <el-button
type="primary" type="primary"
@click="submitForm('ruleForm')" @click="submitForm('ruleForm')"
>确定</el-button> >
确定
</el-button>
</span> </span>
</el-dialog> </el-dialog>
</template> </template>
@ -138,17 +142,18 @@ export default {
this.$message.success('保存成功') this.$message.success('保存成功')
this.cancel() this.cancel()
try { try {
this.$parent.init() this.$emit('addOrUpdateNode', params, this.nodeFlag)
} catch (error) { } catch (error) {
this.$parent.initLazyDatasetTypeTree() this.$parent.initLazyDatasetTypeTree()
} }
}) })
} else { } else {
categoryAdd(params).then((r) => { categoryAdd(params).then((r) => {
params.id = r
this.$message.success('保存成功') this.$message.success('保存成功')
this.cancel() this.cancel()
try { try {
this.$parent.init() this.$emit('addOrUpdateNode', params, this.nodeFlag)
} catch (error) { } catch (error) {
this.$parent.initLazyDatasetTypeTree() this.$parent.initLazyDatasetTypeTree()
} }

@ -139,10 +139,11 @@
</ul> </ul>
</div> </div>
</div> </div>
<org-edit-form <CategroyEditForm
v-if="editFormVisible" v-if="editFormVisible"
ref="editForm" ref="categroyEditForm"
:app-code="appCode" :app-code="appCode"
@addOrUpdateNode="addOrUpdateNode"
/> />
</div> </div>
</div> </div>
@ -158,11 +159,11 @@ import 'packages/assets/style/zTree/metroStyle.css'
import 'packages/assets/style/zTree/zTree.scss' import 'packages/assets/style/zTree/zTree.scss'
import 'packages/assets/style/zTree/zTreeSelect.scss' import 'packages/assets/style/zTree/zTreeSelect.scss'
import { getCategoryTree, categoryRemove } from 'packages/js/utils/datasetConfigService' import { getCategoryTree, categoryRemove } from 'packages/js/utils/datasetConfigService'
import OrgEditForm from './CategroyEditForm.vue' import CategroyEditForm from './CategroyEditForm.vue'
export default { export default {
name: 'DatasetTypeTreeIndex', name: 'DatasetTypeTreeIndex',
components: { components: {
OrgEditForm CategroyEditForm
}, },
props: { props: {
datasetTypeList: { datasetTypeList: {
@ -231,11 +232,11 @@ export default {
addRootNode () { addRootNode () {
this.editFormVisible = true this.editFormVisible = true
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.editForm.tableName = 'r_dataset' this.$refs.categroyEditForm.tableName = 'r_dataset'
this.$refs.editForm.dialogFormVisible = true this.$refs.categroyEditForm.dialogFormVisible = true
this.$refs.editForm.init({ parentId: 0 }, true) this.$refs.categroyEditForm.init({ parentId: 0 }, true)
this.$refs.editForm.radio = 0 this.$refs.categroyEditForm.radio = 0
this.$refs.editForm.title = '分组新增' this.$refs.categroyEditForm.title = '分组新增'
}) })
}, },
addDiyDom (treeId, treeNode) { addDiyDom (treeId, treeNode) {
@ -379,32 +380,32 @@ export default {
this.editFormVisible = true this.editFormVisible = true
if (editType === this.editTypeConstant.editOrg) { if (editType === this.editTypeConstant.editOrg) {
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.editForm.type = 'dataset' this.$refs.categroyEditForm.type = 'dataset'
this.$refs.editForm.dialogFormVisible = true this.$refs.categroyEditForm.dialogFormVisible = true
this.$refs.editForm.init(this.rightClickForm.org, false) this.$refs.categroyEditForm.init(this.rightClickForm.org, false)
this.$refs.editForm.title = '分组编辑' this.$refs.categroyEditForm.title = '分组编辑'
}) })
return return
} }
// //
if (editType === this.editTypeConstant.addSiblingOrg) { if (editType === this.editTypeConstant.addSiblingOrg) {
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.editForm.type = 'dataset' this.$refs.categroyEditForm.type = 'dataset'
this.$refs.editForm.dialogFormVisible = true this.$refs.categroyEditForm.dialogFormVisible = true
this.$refs.editForm.init(this.rightClickForm.org, true) this.$refs.categroyEditForm.init(this.rightClickForm.org, true, editType)
this.$refs.editForm.radio = 0 this.$refs.categroyEditForm.radio = 0
this.$refs.editForm.title = '分组新增' this.$refs.categroyEditForm.title = '分组新增'
}) })
return return
} }
// //
if (editType === this.editTypeConstant.addChildOrg) { if (editType === this.editTypeConstant.addChildOrg) {
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.editForm.type = 'dataset' this.$refs.categroyEditForm.type = 'dataset'
this.$refs.editForm.dialogFormVisible = true this.$refs.categroyEditForm.dialogFormVisible = true
this.$refs.editForm.init(this.rightClickForm.org, true) this.$refs.categroyEditForm.init(this.rightClickForm.org, true, editType)
this.$refs.editForm.radio = 1 this.$refs.categroyEditForm.radio = 1
this.$refs.editForm.title = '分组新增' this.$refs.categroyEditForm.title = '分组新增'
}) })
} }
}, },
@ -433,7 +434,10 @@ export default {
categoryRemove(org.id).then((data) => { categoryRemove(org.id).then((data) => {
this.$message.success('操作成功') this.$message.success('操作成功')
// this.ztreeObj.removeNode(org) // this.ztreeObj.removeNode(org)
this.initLazyDatasetTypeTree() // this.initLazyOrgTree()
const removeNode = this.ztreeObj.getNodeByParam('id', org.id, null)
this.ztreeObj.removeNode(removeNode)
this.getData()
// //
this.$emit('refreshData', org) this.$emit('refreshData', org)
}) })
@ -443,6 +447,35 @@ export default {
refreshData (cbObj) { refreshData (cbObj) {
// //
this.$emit('refreshData', cbObj) this.$emit('refreshData', cbObj)
},
//
addOrUpdateNode (params, isAdd) {
if (!isAdd) {
console.log(1)
const editNode = this.ztreeObj.getNodeByParam('id', params.id, null)
editNode.name = params.name
this.ztreeObj.editName(editNode)
this.ztreeObj.setEditable(false)
} else {
//
const parentNode = params.parentId === 0 ? null : this.ztreeObj.getNodeByParam('id', params.parentId, null)
this.ztreeObj.addNodes(parentNode, params)
}
this.redrawTree()
},
//
redrawTree () {
// ztree
getCategoryTree({ type: 'dataset', moduleCode: this.appCode }).then((res) => {
this.categoryData = res.map((item) => {
return { isParent: item.hasChildren, ...item }
})
this.categoryData.unshift({ name: '全部', id: '', parentId: '0' })
}).then((e) => {
this.loading = false
}).catch((e) => {
this.loading = false
})
} }
} }
} }

Loading…
Cancel
Save