|
|
@@ -3,12 +3,9 @@
|
|
|
<el-tree
|
|
|
:data="treeList"
|
|
|
:props="defaultProps"
|
|
|
- :default-expand-all="defaultExpandAll"
|
|
|
- :default-expanded-keys="defaultExpandedKeys"
|
|
|
v-loading="treeLoading"
|
|
|
- node-key="id"
|
|
|
+ :node-key="nodeKey"
|
|
|
ref="tree"
|
|
|
- :expand-on-click-node="expandOnClickNode"
|
|
|
:highlight-current="true"
|
|
|
@node-click="handleNodeClick"
|
|
|
v-bind="$attrs"
|
|
|
@@ -18,51 +15,52 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
- import { getTreeByType } from '@/api/classifyManage';
|
|
|
+ import { getTreeByPid, getTreeByType } from '@/api/classifyManage';
|
|
|
// let originId = '';
|
|
|
// let originType = '';
|
|
|
export default {
|
|
|
props: {
|
|
|
+ // treeList私有化处理
|
|
|
+ treeFormate: {
|
|
|
+ type: Function,
|
|
|
+ default: null
|
|
|
+ },
|
|
|
defaultProps: {
|
|
|
type: Object,
|
|
|
default: function () {
|
|
|
return {
|
|
|
children: 'children',
|
|
|
- value: 'code',
|
|
|
+ value: 'id',
|
|
|
label: 'name'
|
|
|
};
|
|
|
}
|
|
|
},
|
|
|
- defaultExpandAll: {
|
|
|
- type: Boolean,
|
|
|
- default: true
|
|
|
- },
|
|
|
+ // 初始请求treeList
|
|
|
init: {
|
|
|
type: Boolean,
|
|
|
- default: false
|
|
|
- },
|
|
|
- defaultExpandedKeys: {
|
|
|
- type: Array,
|
|
|
- default: function () {
|
|
|
- return [];
|
|
|
- }
|
|
|
+ default: true
|
|
|
},
|
|
|
- expandOnClickNode: {
|
|
|
- type: Boolean,
|
|
|
- default: false
|
|
|
+ // 接口分父级id 和 类型筛选
|
|
|
+ paramsType: {
|
|
|
+ type: String,
|
|
|
+ default: 'id'
|
|
|
},
|
|
|
type: {
|
|
|
type: String,
|
|
|
default: ''
|
|
|
},
|
|
|
+ id: {
|
|
|
+ type: String,
|
|
|
+ default: '0'
|
|
|
+ },
|
|
|
+ nodeKey: {
|
|
|
+ type: String,
|
|
|
+ default: 'id'
|
|
|
+ }
|
|
|
// appendRoot: {
|
|
|
// type: Boolean,
|
|
|
// default: false
|
|
|
// },
|
|
|
- treeFormate: {
|
|
|
- type: Function,
|
|
|
- default: null
|
|
|
- }
|
|
|
},
|
|
|
data () {
|
|
|
return {
|
|
|
@@ -86,9 +84,14 @@
|
|
|
async getTreeData () {
|
|
|
try {
|
|
|
this.treeLoading = true;
|
|
|
- const res = await getTreeByType(type);
|
|
|
+ const requestApi =
|
|
|
+ this.paramsType === 'type'
|
|
|
+ ? getTreeByType.bind(null, this.type)
|
|
|
+ : getTreeByPid.bind(null, this.id);
|
|
|
+
|
|
|
+ const res = await requestApi();
|
|
|
this.treeLoading = false;
|
|
|
- if (res.success) {
|
|
|
+ if (res?.code === '0') {
|
|
|
this.treeList = res.data;
|
|
|
|
|
|
if (this.treeFormate) {
|
|
|
@@ -150,6 +153,12 @@
|
|
|
<style lang="scss" scoped>
|
|
|
.tree-wrapper {
|
|
|
width: 100%;
|
|
|
+ height: 100%;
|
|
|
overflow: auto;
|
|
|
+
|
|
|
+ :deep(.el-tree) {
|
|
|
+ display: inline-block;
|
|
|
+ min-width: 100%;
|
|
|
+ }
|
|
|
}
|
|
|
</style>
|