Skip to content

Commit 1a069c8

Browse files
committed
feat: update org tree demo
1 parent a4560c5 commit 1a069c8

File tree

3 files changed

+123
-5
lines changed

3 files changed

+123
-5
lines changed

src/components/Tree/Tree.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export default {
2121
}
2222
},
2323
methods: {
24-
handlePlus (...args) {
25-
this.$emit('onAdd', { args })
24+
handlePlus (item) {
25+
this.$emit('add', item)
2626
},
2727
handleTitleClick (...args) {
2828
this.$emit('titleClick', { args })
@@ -44,7 +44,7 @@ export default {
4444
<Item key={item.key}>
4545
{ this.renderIcon(item.icon) }
4646
{ item.title }
47-
<a class="btn"><a-icon type="plus" onClick={() => this.handlePlus(item)} /></a>
47+
<a class="btn" style="width: 20px;z-index:1300" {...{ on: { click: () => this.handlePlus(item) } }}><a-icon type="plus"/></a>
4848
</Item>
4949
)
5050
},

src/views/list/TreeList.vue

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<a-card :bordered="false">
33
<a-row :gutter="8">
44
<a-col :span="5">
5-
<s-tree :dataSource="orgTree" :search="true" @click="handleClick"></s-tree>
5+
<s-tree :dataSource="orgTree" :search="true" @click="handleClick" @add="handleAdd" @titleClick="handleTitleClick"></s-tree>
66
</a-col>
77
<a-col :span="19">
88
<s-table
@@ -38,19 +38,23 @@
3838
</s-table>
3939
</a-col>
4040
</a-row>
41+
42+
<org-modal ref="modal" @ok="handleSaveOk" @close="handleSaveClose" />
4143
</a-card>
4244
</template>
4345

4446
<script>
4547
import STree from '@/components/Tree/Tree'
4648
import STable from '@/components/table/'
49+
import OrgModal from './modules/OrgModal'
4750
import { getOrgTree, getServiceList } from '@/api/manage'
4851
4952
export default {
5053
name: 'TreeList',
5154
components: {
5255
STable,
53-
STree
56+
STree,
57+
OrgModal
5458
},
5559
data () {
5660
return {
@@ -118,9 +122,23 @@ export default {
118122
}
119123
this.$refs.table.refresh(true)
120124
},
125+
handleAdd (item) {
126+
console.log('add button, item', item)
127+
this.$message.info(`提示:你点了 ${item.key} - ${item.title} ` )
128+
this.$refs.modal.add(item.key)
129+
},
130+
handleTitleClick (item) {
131+
console.log('handleTitleClick', item)
132+
},
121133
titleClick (e) {
122134
console.log('titleClick', e)
123135
},
136+
handleSaveOk () {
137+
138+
},
139+
handleSaveClose () {
140+
141+
},
124142
125143
onSelectChange (selectedRowKeys, selectedRows) {
126144
this.selectedRowKeys = selectedRowKeys

src/views/list/modules/OrgModal.vue

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<template>
2+
<a-modal
3+
title="操作"
4+
:width="600"
5+
:visible="visible"
6+
:confirmLoading="confirmLoading"
7+
@ok="handleOk"
8+
@cancel="handleCancel"
9+
>
10+
<a-spin :spinning="confirmLoading">
11+
<a-form :form="form">
12+
13+
<a-form-item
14+
label="父级ID"
15+
>
16+
<a-input v-decorator="['parentId', {}]" disabled />
17+
</a-form-item>
18+
19+
<a-form-item
20+
label="机构名称"
21+
>
22+
<a-input v-decorator="['orgName', {}]" />
23+
</a-form-item>
24+
</a-form>
25+
</a-spin>
26+
</a-modal>
27+
</template>
28+
29+
<script>
30+
export default {
31+
name: 'OrgModal',
32+
data () {
33+
return {
34+
labelCol: {
35+
xs: { span: 24 },
36+
sm: { span: 5 },
37+
},
38+
wrapperCol: {
39+
xs: { span: 24 },
40+
sm: { span: 16 },
41+
},
42+
visible: false,
43+
confirmLoading: false,
44+
mdl: {},
45+
}
46+
},
47+
beforeCreate () {
48+
this.form = this.$form.createForm(this)
49+
console.log('form::', this.form)
50+
},
51+
created () {
52+
53+
},
54+
methods: {
55+
add (id) {
56+
this.edit({ parentId: id })
57+
},
58+
edit (record) {
59+
this.mdl = Object.assign({}, record)
60+
this.visible = true
61+
this.$nextTick(() => {
62+
this.form.setFieldsValue( { ...record } )
63+
})
64+
},
65+
close () {
66+
this.$emit('close')
67+
this.visible = false
68+
},
69+
handleOk () {
70+
const _this = this
71+
// 触发表单验证
72+
this.form.validateFields((err, values) => {
73+
// 验证表单没错误
74+
if (!err) {
75+
console.log('form values', values)
76+
77+
_this.confirmLoading = true
78+
// 模拟后端请求 2000 毫秒延迟
79+
new Promise((resolve) => {
80+
setTimeout(() => resolve(), 2000)
81+
}).then(() => {
82+
// Do something
83+
_this.$message.success('保存成功')
84+
_this.$emit('ok')
85+
}).catch(() => {
86+
// Do something
87+
}).finally(() => {
88+
_this.confirmLoading = false
89+
_this.close()
90+
})
91+
}
92+
})
93+
},
94+
handleCancel () {
95+
this.close()
96+
}
97+
98+
}
99+
}
100+
</script>

0 commit comments

Comments
 (0)