|
|
@ -14,6 +14,15 @@ |
|
|
|
import { useDesign } from '/@/hooks/web/useDesign'; |
|
|
|
import { useDesign } from '/@/hooks/web/useDesign'; |
|
|
|
import { ScrollContainer } from '/@/components/Container'; |
|
|
|
import { ScrollContainer } from '/@/components/Container'; |
|
|
|
import { useAppStore } from '/@/store/modules/app'; |
|
|
|
import { useAppStore } from '/@/store/modules/app'; |
|
|
|
|
|
|
|
import { isArray } from '/@/utils/is'; |
|
|
|
|
|
|
|
import { useMessage } from '/@/hooks/web/useMessage'; |
|
|
|
|
|
|
|
import { propTypes } from '/@/utils/propTypes'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const props = defineProps({ |
|
|
|
|
|
|
|
limit: propTypes.number.def(0), |
|
|
|
|
|
|
|
title: propTypes.string.def('用户选择'), |
|
|
|
|
|
|
|
emitEventNameClosable: propTypes.bool.def(false) |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
/** 类型规范统一声明定义区域 */ |
|
|
|
/** 类型规范统一声明定义区域 */ |
|
|
|
interface TableState { |
|
|
|
interface TableState { |
|
|
@ -21,13 +30,15 @@ |
|
|
|
single: boolean; |
|
|
|
single: boolean; |
|
|
|
multiple: boolean; |
|
|
|
multiple: boolean; |
|
|
|
searchInfo: Recordable; |
|
|
|
searchInfo: Recordable; |
|
|
|
tag: string, |
|
|
|
tag: string; |
|
|
|
|
|
|
|
emitEventName: string; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** 通用变量统一声明区域 */ |
|
|
|
/** 通用变量统一声明区域 */ |
|
|
|
const appStore = useAppStore(); |
|
|
|
const appStore = useAppStore(); |
|
|
|
const darkMode = appStore.getDarkMode; |
|
|
|
const darkMode = appStore.getDarkMode; |
|
|
|
const { prefixCls } = useDesign('user-picker'); |
|
|
|
const { prefixCls } = useDesign('user-picker'); |
|
|
|
|
|
|
|
const { createMessage } = useMessage(); |
|
|
|
const state = reactive<TableState>({ |
|
|
|
const state = reactive<TableState>({ |
|
|
|
// 选中数组 |
|
|
|
// 选中数组 |
|
|
|
ids: [], |
|
|
|
ids: [], |
|
|
@ -39,8 +50,10 @@ |
|
|
|
searchInfo: {}, |
|
|
|
searchInfo: {}, |
|
|
|
// 操作标签 |
|
|
|
// 操作标签 |
|
|
|
tag: '', |
|
|
|
tag: '', |
|
|
|
|
|
|
|
// 组件触发的自定义名称 |
|
|
|
|
|
|
|
emitEventName: '' |
|
|
|
}); |
|
|
|
}); |
|
|
|
const [registerTable, { reload, clearSelectedRowKeys, redoHeight }] = useTable({ |
|
|
|
const [registerTable, { reload, clearSelectedRowKeys, getSelectRows, setSelectedRowKeys }] = useTable({ |
|
|
|
title: '用户列表', |
|
|
|
title: '用户列表', |
|
|
|
api: listUser, |
|
|
|
api: listUser, |
|
|
|
rowKey: 'id', |
|
|
|
rowKey: 'id', |
|
|
@ -66,29 +79,26 @@ |
|
|
|
}); |
|
|
|
}); |
|
|
|
const modal = ref(); |
|
|
|
const modal = ref(); |
|
|
|
/** https://v3.cn.vuejs.org/api/options-data.html#emits */ |
|
|
|
/** https://v3.cn.vuejs.org/api/options-data.html#emits */ |
|
|
|
const emit = defineEmits(['success', 'register']); |
|
|
|
const emit = defineEmits(['success', 'register'] as Recordable); |
|
|
|
const [registerModal, { setModalProps, closeModal, changeLoading }] = useModalInner(async (data: BoxPayload = { _tag: '' }) => { |
|
|
|
const [registerModal, { setModalProps, closeModal, changeLoading }] = useModalInner(async (data: BoxPayload = { _tag: '' }) => { |
|
|
|
changeLoading(true); |
|
|
|
changeLoading(true); |
|
|
|
// 处理清除脏数据 |
|
|
|
// 处理清除脏数据 |
|
|
|
|
|
|
|
await handleRefreshTable(); |
|
|
|
// 处理设置数据 |
|
|
|
// 处理设置数据 |
|
|
|
state.tag = data._tag; |
|
|
|
state.tag = data._tag; |
|
|
|
|
|
|
|
const { ids, emitEventName } = data.record as Recordable; |
|
|
|
const regionId = data.record?.id; |
|
|
|
isArray(ids) && setSelectedRowKeys(ids); |
|
|
|
const props: Partial<ModalProps> = { confirmLoading: false }; |
|
|
|
const modalProps: Partial<ModalProps> = { title: props.title }; |
|
|
|
props.title = '用户选择'; |
|
|
|
state.emitEventName = emitEventName || 'success'; |
|
|
|
// 采用tag标签区分操作 |
|
|
|
// 为后续扩展做准备,采用tag标签区分操作(预留) |
|
|
|
switch (state.tag) { |
|
|
|
switch (state.tag) { |
|
|
|
case 'add': |
|
|
|
case 'single': |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'edit': |
|
|
|
case 'multiple': |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 尾部:设置处理后的最终配置数据 |
|
|
|
// 尾部:设置处理后的最终配置数据 |
|
|
|
setModalProps(props); |
|
|
|
setModalProps(modalProps); |
|
|
|
changeLoading(false); |
|
|
|
changeLoading(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -115,18 +125,15 @@ |
|
|
|
/** 处理弹出框提交 */ |
|
|
|
/** 处理弹出框提交 */ |
|
|
|
async function handleSubmit() { |
|
|
|
async function handleSubmit() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
// 采用tag标签区分操作 |
|
|
|
if (props.limit !== 0 && props.limit < getSelectRows().length) { |
|
|
|
switch (state.tag) { |
|
|
|
return createMessage.error(`你最多只能选择${props.limit}个用户`); |
|
|
|
case 'add': |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'edit': |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// 处理提交完成之后逻辑 |
|
|
|
|
|
|
|
closeModal(); |
|
|
|
closeModal(); |
|
|
|
emit('success'); |
|
|
|
if (props.emitEventNameClosable) { |
|
|
|
|
|
|
|
emit('success', state.emitEventName ,(getSelectRows())); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
emit(state.emitEventName, toRaw(getSelectRows())); |
|
|
|
|
|
|
|
} |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
setModalProps({ confirmLoading: false }); |
|
|
|
setModalProps({ confirmLoading: false }); |
|
|
|
} |
|
|
|
} |
|
|
@ -152,16 +159,12 @@ |
|
|
|
</a-layout-content> |
|
|
|
</a-layout-content> |
|
|
|
<a-layout-sider :theme="darkMode"> |
|
|
|
<a-layout-sider :theme="darkMode"> |
|
|
|
<ScrollContainer class="pl-2"> |
|
|
|
<ScrollContainer class="pl-2"> |
|
|
|
<div v-loading="true"> |
|
|
|
<a-tag v-for="row in getSelectRows()" |
|
|
|
<a-tag color="pink">pink</a-tag> |
|
|
|
:key="row.id" |
|
|
|
<a-tag color="pink">pink</a-tag> |
|
|
|
color="processing" |
|
|
|
<a-tag color="pink">pink</a-tag> |
|
|
|
> |
|
|
|
<a-tag color="pink">pink</a-tag> |
|
|
|
{{ row.username }} |
|
|
|
<a-tag color="pink">pink</a-tag> |
|
|
|
</a-tag> |
|
|
|
<a-tag color="pink">pink</a-tag> |
|
|
|
|
|
|
|
<a-tag color="pink">pink</a-tag> |
|
|
|
|
|
|
|
<a-tag color="pink">pink</a-tag> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
</ScrollContainer> |
|
|
|
</ScrollContainer> |
|
|
|
</a-layout-sider> |
|
|
|
</a-layout-sider> |
|
|
|
</a-layout> |
|
|
|
</a-layout> |
|
|
@ -183,6 +186,10 @@ |
|
|
|
|
|
|
|
|
|
|
|
.scroll-container { |
|
|
|
.scroll-container { |
|
|
|
max-height: 720px; |
|
|
|
max-height: 720px; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.ant-tag { |
|
|
|
|
|
|
|
margin: 0 0 5px 8px; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|