TenantUserSelectModal.vue
3.9 KB
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
<!--套餐中使用的用户选择框-->
<template>
<div>
<BasicModal
v-bind="$attrs"
@register="register"
:title="modalTitle"
width="900px"
wrapClassName="j-user-select-modal"
@ok="handleOk"
destroyOnClose
>
<BasicTable ref="tableRef" @register="registerTable" :rowSelection="rowSelection">
<template #tableTitle></template>
</BasicTable>
</BasicModal>
</div>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { getTenantUserList } from '../tenant.api';
import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
import { useListPage } from '/@/hooks/system/useListPage';
import { userColumns, userSearchFormSchema } from '../tenant.data';
export default defineComponent({
name: 'TenantUserSelectModal',
components: {
//此处需要异步加载BasicTable
BasicModal,
BasicTable: createAsyncComponent(() => import('/@/components/Table/src/BasicTable.vue'), {
loading: true,
}),
},
props: {
//选择框标题
modalTitle: {
type: String,
default: '选择用户',
},
//查询参数
tenantId: {
type: Number,
default: 0,
},
//排除用户id的集合
excludeUserIdList: {
type: Array,
default: [],
},
},
emits: ['register', 'on-select'],
setup(props, { emit, refs }) {
const tableScroll = ref<any>({ x: false });
const tableRef = ref();
//注册弹框
const [register, { closeModal }] = useModalInner(() => {
if (window.innerWidth < 900) {
tableScroll.value = { x: 900 };
} else {
tableScroll.value = { x: false };
}
setTimeout(() => {
if (tableRef.value) {
tableRef.value.setSelectedRowKeys([]);
}
}, 800);
});
//定义表格列
const columns = [
{
title: '账号',
dataIndex: 'username',
width: 40,
align: 'left',
},
{
title: '姓名',
dataIndex: 'realname',
width: 40,
},
{
title: '性别',
dataIndex: 'sex_dictText',
width: 20,
},
{
title: '手机号码',
dataIndex: 'phone',
width: 30,
},
{
title: '邮箱',
dataIndex: 'email',
width: 40,
},
{
title: '状态',
dataIndex: 'status_dictText',
width: 20,
},
];
// 列表页面公共参数、方法
const { prefixCls, tableContext } = useListPage({
designScope: 'tenant-template',
tableProps: {
api: getTenantUserList,
columns: userColumns,
scroll: { y: 390 },
rowKey: 'id',
showActionColumn: false,
formConfig: {
schemas: userSearchFormSchema,
labelWidth: 60,
actionColOptions: {
xs: 24,
sm: 8,
md: 8,
lg: 8,
xl: 8,
xxl: 8,
},
},
beforeFetch: (params) => {
return Object.assign(params, { userTenantId: props.tenantId });
},
},
});
const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
/**
* 确定选择
*/
function handleOk() {
//返回选中事件
emit('on-select', rowSelection.selectedRows, rowSelection.selectedRowKeys);
}
return {
handleOk,
register,
columns,
rowSelection,
tableScroll,
tableRef,
registerTable,
};
},
});
</script>
<style scoped>
:deep(.ant-input-suffix) {
display: none;
}
</style>