2024-09-06 10:48:22 +08:00
|
|
|
<!--
|
|
|
|
|
- @Author XXX
|
|
|
|
|
- @Link XXX
|
|
|
|
|
-->
|
2023-06-08 21:09:28 +08:00
|
|
|
<template>
|
2024-09-06 10:48:22 +08:00
|
|
|
<div class="ma-content-block">
|
|
|
|
|
<a-space class="flex">
|
|
|
|
|
<a-button type="primary" @click="visible = true">
|
|
|
|
|
<template #icon><icon-select-all /></template>{{ props.text }}
|
|
|
|
|
</a-button>
|
|
|
|
|
<a-tag size="large" color="blue" v-if="props.isEcho">已选择 {{ isArray(selecteds) ? selecteds.length : 0 }} 位</a-tag>
|
|
|
|
|
<a-input-tag v-model="userList" v-if="props.isEcho" :style="{ width:'320px' }" :placeholder="'请点击前面按钮' + props.text" :max-tag-count="3" disabled/>
|
|
|
|
|
</a-space>
|
2023-06-08 21:09:28 +08:00
|
|
|
|
2024-09-06 10:48:22 +08:00
|
|
|
<a-modal v-model:visible="visible" width="1000px" draggable :on-before-ok="close" unmountOnClose>
|
|
|
|
|
<template #title>{{ props.text }}</template>
|
2023-06-08 21:09:28 +08:00
|
|
|
|
2024-09-06 10:48:22 +08:00
|
|
|
<ma-crud
|
|
|
|
|
ref="crudRef"
|
|
|
|
|
:options="crud"
|
|
|
|
|
:columns="columns"
|
|
|
|
|
v-model:selected-keys="selecteds"
|
|
|
|
|
@selection-change="selectHandler"
|
|
|
|
|
/>
|
|
|
|
|
</a-modal>
|
|
|
|
|
</div>
|
2023-06-08 21:09:28 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2024-09-06 10:48:22 +08:00
|
|
|
import { onMounted, ref, watch } from 'vue'
|
|
|
|
|
import commonApi from '@/api/common'
|
|
|
|
|
import { Message } from '@arco-design/web-vue'
|
2024-09-06 11:31:32 +08:00
|
|
|
import { isArray, isEmpty } from 'lodash-es'
|
2023-06-08 21:09:28 +08:00
|
|
|
|
2024-09-06 10:48:22 +08:00
|
|
|
const props = defineProps({
|
2023-06-08 21:09:28 +08:00
|
|
|
modelValue: { type: Array },
|
|
|
|
|
isEcho: { type: Boolean, default: false },
|
|
|
|
|
multiple: { type: Boolean, default: true },
|
|
|
|
|
onlyId: { type: Boolean, default: true },
|
2024-09-06 10:48:22 +08:00
|
|
|
text: { type: String, default: '选择用户' }
|
|
|
|
|
})
|
2023-06-08 21:09:28 +08:00
|
|
|
|
2024-09-06 10:48:22 +08:00
|
|
|
const emit = defineEmits(['update:modelValue', 'success'])
|
2023-06-08 21:09:28 +08:00
|
|
|
|
2024-09-06 10:48:22 +08:00
|
|
|
const visible = ref(false)
|
|
|
|
|
const selecteds = ref([])
|
|
|
|
|
const userList = ref([])
|
2023-06-08 21:09:28 +08:00
|
|
|
|
2024-09-06 10:48:22 +08:00
|
|
|
onMounted(() => {
|
2023-06-08 21:09:28 +08:00
|
|
|
if (props.isEcho && props.onlyId) selecteds.value = props.modelValue
|
2024-09-06 10:48:22 +08:00
|
|
|
})
|
2023-06-08 21:09:28 +08:00
|
|
|
|
2024-09-06 10:48:22 +08:00
|
|
|
watch(
|
|
|
|
|
() => props.modelValue,
|
|
|
|
|
val => {
|
|
|
|
|
if (props.isEcho && props.onlyId) selecteds.value = val
|
2023-06-08 21:09:28 +08:00
|
|
|
}
|
2024-09-06 10:48:22 +08:00
|
|
|
)
|
2023-06-08 21:09:28 +08:00
|
|
|
|
2024-09-06 10:48:22 +08:00
|
|
|
const selectHandler = (rows) => {
|
2023-06-08 21:09:28 +08:00
|
|
|
selecteds.value = rows
|
2024-09-06 10:48:22 +08:00
|
|
|
}
|
2023-06-08 21:09:28 +08:00
|
|
|
|
2024-09-06 10:48:22 +08:00
|
|
|
const close = async (done) => {
|
2023-06-08 21:09:28 +08:00
|
|
|
if (isArray(selecteds.value) && selecteds.value.length > 0) {
|
2024-09-06 10:48:22 +08:00
|
|
|
const response = await commonApi.getUserInfoByIds({ ids: selecteds.value })
|
|
|
|
|
if (! isEmpty(response) && isArray(response.data)) {
|
|
|
|
|
userList.value = response.data.map( item => {
|
|
|
|
|
return `${item.username}(${item.id})`
|
|
|
|
|
})
|
|
|
|
|
if (props.onlyId) {
|
|
|
|
|
emit('update:modelValue', selecteds.value)
|
|
|
|
|
} else {
|
|
|
|
|
emit('update:modelValue', response.data)
|
2023-06-08 21:09:28 +08:00
|
|
|
}
|
2024-09-06 10:48:22 +08:00
|
|
|
emit('success', true)
|
|
|
|
|
Message.success('选择成功')
|
|
|
|
|
}
|
2023-06-08 21:09:28 +08:00
|
|
|
} else {
|
2024-09-06 10:48:22 +08:00
|
|
|
emit('update:modelValue', [])
|
|
|
|
|
userList.value = []
|
2023-06-08 21:09:28 +08:00
|
|
|
}
|
|
|
|
|
done(true)
|
2024-09-06 10:48:22 +08:00
|
|
|
}
|
2023-06-08 21:09:28 +08:00
|
|
|
|
2024-09-06 10:48:22 +08:00
|
|
|
const crud = ref({
|
2023-06-08 21:09:28 +08:00
|
|
|
showIndex: false,
|
|
|
|
|
api: commonApi.getUserList,
|
2024-09-06 10:48:22 +08:00
|
|
|
rowSelection: props.multiple ? { type: 'checkbox', showCheckedAll: true } : { type: 'radio' }
|
|
|
|
|
})
|
2023-06-08 21:09:28 +08:00
|
|
|
|
2024-09-06 10:48:22 +08:00
|
|
|
const columns = ref([
|
|
|
|
|
{ title: '账户', dataIndex: 'username', search: true },
|
|
|
|
|
{ title: '昵称', dataIndex: 'nickname', search: true },
|
|
|
|
|
{ title: '手机', dataIndex: 'phone', search: true },
|
|
|
|
|
{ title: '邮箱', dataIndex: 'email', search: true },
|
2023-06-08 21:09:28 +08:00
|
|
|
{
|
2024-09-06 10:48:22 +08:00
|
|
|
title: '部门',
|
|
|
|
|
dataIndex: 'dept_id',
|
|
|
|
|
search: true,
|
|
|
|
|
formType: 'tree-select',
|
|
|
|
|
hide: true,
|
|
|
|
|
dict: { url: 'system/common/getDeptTreeList' }
|
2023-06-08 21:09:28 +08:00
|
|
|
},
|
|
|
|
|
{
|
2024-09-06 10:48:22 +08:00
|
|
|
title: '角色',
|
|
|
|
|
dataIndex: 'role_id',
|
|
|
|
|
search: true,
|
|
|
|
|
formType: 'select',
|
|
|
|
|
hide: true,
|
|
|
|
|
dict: { url: 'system/common/getRoleList', props: { label: 'name', value: 'code' } }
|
2023-06-08 21:09:28 +08:00
|
|
|
},
|
|
|
|
|
{
|
2024-09-06 10:48:22 +08:00
|
|
|
title: '岗位',
|
|
|
|
|
dataIndex: 'post_id',
|
|
|
|
|
search: true,
|
|
|
|
|
formType: 'select',
|
|
|
|
|
hide: true,
|
|
|
|
|
dict: { url: 'system/common/getPostList', props: { label: 'name', value: 'code' } }
|
|
|
|
|
},
|
|
|
|
|
])
|
2023-06-08 21:09:28 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
:deep(.arco-tabs-nav-type-capsule .arco-tabs-nav-tab) {
|
2024-09-06 10:48:22 +08:00
|
|
|
justify-content: flex-start;
|
2023-06-08 21:09:28 +08:00
|
|
|
}
|
|
|
|
|
</style>
|