1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
| <!--通过部门选择用户-->
| <template>
| <BasicModal v-bind="$attrs" @register="register" :title="modalTitle" width="1200px" @ok="handleOk" destroyOnClose @visible-change="visibleChange">
| <a-row :gutter="10">
| <a-col :md="7" :sm="24">
| <a-card :style="{ minHeight: '613px', overflow: 'auto' }">
| <!--组织机构-->
| <BasicTree
| ref="treeRef"
| :style="{ minWidth: '250px' }"
| selectable
| @select="onDepSelect"
| :load-data="loadChildrenTreeData"
| :treeData="departTree"
| :selectedKeys="selectedDepIds"
| :expandedKeys="expandedKeys"
| :clickRowToExpand="false"
| ></BasicTree>
| </a-card>
| </a-col>
| <a-col :md="17" :sm="24">
| <a-card :style="{ minHeight: '613px', overflow: 'auto' }">
| <!--用户列表-->
| <BasicTable ref="tableRef" v-bind="getBindValue" :searchInfo="searchInfo" :api="getTableList" :rowSelection="rowSelection"></BasicTable>
| </a-card>
| </a-col>
| </a-row>
| </BasicModal>
| </template>
| <script lang="ts">
| import { defineComponent, unref, ref } from 'vue';
| import { BasicModal, useModalInner } from '/@/components/Modal';
| import { BasicTree } from '/@/components/Tree/index';
| import { queryTreeList, getTableList } from '/@/api/common/api';
| import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
| import { useSelectBiz } from '/@/components/Form/src/jeecg/hooks/useSelectBiz';
| import { useAttrs } from '/@/hooks/core/useAttrs';
| import { queryDepartTreeSync } from '/@/views/system/depart/depart.api';
| import { selectProps } from '/@/components/Form/src/jeecg/props/props';
| export default defineComponent({
| name: 'UserSelectByDepModal',
| components: {
| //此处需要异步加载BasicTable
| BasicModal,
| BasicTree,
| BasicTable: createAsyncComponent(() => import('/@/components/Table/src/BasicTable.vue'), {
| loading: true,
| }),
| },
| props: {
| ...selectProps,
| //选择框标题
| modalTitle: {
| type: String,
| default: '部门用户选择',
| },
| },
| emits: ['register', 'getSelectResult'],
| setup(props, { emit, refs }) {
| const tableRef = ref();
| const treeRef = ref();
| //注册弹框
| const [register, { closeModal }] = useModalInner(async (data) => {
| await queryDepartTree();
| });
| const attrs = useAttrs();
| const departTree = ref([]);
| const selectedDepIds = ref([]);
| const expandedKeys = ref([]);
| const searchInfo = {};
| /**
| *表格配置
| */
| const tableProps = {
| columns: [
| {
| title: '用户账号',
| dataIndex: 'username',
| width: 50,
| },
| {
| title: '用户姓名',
| dataIndex: 'realname',
| width: 50,
| },
| {
| title: '性别',
| dataIndex: 'sex_dictText',
| width: 50,
| },
| {
| title: '手机号码',
| dataIndex: 'phone',
| width: 50,
| },
| ],
| useSearchForm: true,
| canResize: false,
| showIndexColumn: false,
| striped: true,
| bordered: true,
| size: 'small',
| formConfig: {
| //labelWidth: 200,
| baseColProps: {
| xs: 24,
| sm: 8,
| md: 6,
| lg: 8,
| xl: 6,
| xxl: 10,
| },
| schemas: [
| {
| label: '账号',
| field: 'username',
| component: 'Input',
| },
| ],
| resetFunc: customResetFunc,
| },
| };
| const getBindValue = Object.assign({}, unref(props), unref(attrs), tableProps);
| const [{ rowSelection, visibleChange, indexColumnProps, getSelectResult, reset }] = useSelectBiz(getTableList, getBindValue);
| /**
| * 加载树形数据
| */
| function queryDepartTree() {
| queryDepartTreeSync().then((res) => {
| if (res) {
| departTree.value = res;
| // 默认展开父节点
| //expandedKeys.value = unref(departTree).map(item => item.id)
| }
| });
| }
| /**
| * 加载子级部门
| */
| async function loadChildrenTreeData(treeNode) {
| try {
| const result = await queryDepartTreeSync({
| pid: treeNode.eventKey,
| });
| const asyncTreeAction = unref(treeRef);
| if (asyncTreeAction) {
| asyncTreeAction.updateNodeByKey(treeNode.eventKey, { children: result });
| asyncTreeAction.setExpandedKeys([treeNode.eventKey, ...asyncTreeAction.getExpandedKeys()]);
| }
| } catch (e) {
| console.error(e);
| }
| return Promise.resolve();
| }
| /**
| * 点击树节点,筛选出对应的用户
| */
| function onDepSelect(keys) {
| if (keys[0] != null) {
| if (unref(selectedDepIds)[0] !== keys[0]) {
| selectedDepIds.value = [keys[0]];
| }
| searchInfo['departId'] = unref(selectedDepIds).join(',');
| tableRef.value.reload();
| }
| }
| /**
| * 自定义重置方法
| * */
| async function customResetFunc() {
| console.log('自定义查询');
| //树节点清空
| selectedDepIds.value = [];
| //查询条件清空
| searchInfo['departId'] = '';
| //选择项清空
| reset();
| }
| /**
| * 确定选择
| */
| function handleOk() {
| getSelectResult((options, values) => {
| //回传选项和已选择的值
| emit('getSelectResult', options, values);
| //关闭弹窗
| closeModal();
| });
| }
|
| return {
| //config,
| handleOk,
| searchInfo,
| register,
| indexColumnProps,
| visibleChange,
| getBindValue,
| rowSelection,
|
| departTree,
| selectedDepIds,
| expandedKeys,
| treeRef,
| tableRef,
| getTableList,
| onDepSelect,
| loadChildrenTreeData,
| };
| },
| });
| </script>
|
| <style scoped lang="less"></style>
|
|