fix: 修复白名单切换和空间成员名字问题

This commit is contained in:
sudoooooo 2024-08-07 22:07:00 +08:00
parent 6fb337633c
commit c5698ad631
6 changed files with 38 additions and 11 deletions

View File

@ -373,6 +373,16 @@ export class WorkspaceController {
workspaceList.map((item) => item._id.toString()), workspaceList.map((item) => item._id.toString()),
); );
// 查询成员姓名
const userList = await this.userService.getUserListByIds({
idList: workspaceMemberList.map((member) => member.userId),
});
const userInfoMap = userList.reduce((pre, cur) => {
const id = cur._id.toString();
pre[id] = cur;
return pre;
}, {});
const temp: Record<string, WorkspaceMember[]> = {}; const temp: Record<string, WorkspaceMember[]> = {};
const list = workspaceList.map( const list = workspaceList.map(
(item: Workspace & { members: WorkspaceMember[] }) => { (item: Workspace & { members: WorkspaceMember[] }) => {
@ -381,7 +391,8 @@ export class WorkspaceController {
}, },
); );
workspaceMemberList.forEach((member) => { workspaceMemberList.forEach((member: WorkspaceMember) => {
(member as any).username = userInfoMap[member.userId.toString()].username;
temp[member.workspaceId.toString()].push(member); temp[member.workspaceId.toString()].push(member);
}); });

View File

@ -152,7 +152,7 @@ export class WorkspaceMemberService {
order: { order: {
_id: -1, _id: -1,
}, },
select: ['_id', 'userId', 'username', 'role', 'workspaceId'], select: ['_id', 'userId', 'role', 'workspaceId'],
}); });
} }
} }

View File

@ -46,8 +46,8 @@ import setterLoader from '@/materials/setters/setterLoader'
import { FORM_CHANGE_EVENT_KEY } from '@/materials/setters/constant' import { FORM_CHANGE_EVENT_KEY } from '@/materials/setters/constant'
interface Props { interface Props {
formConfigList: Array<any> formConfigList: Array<any> //
moduleConfig: any moduleConfig: any // schema
customComponents?: Record<string, Component> customComponents?: Record<string, Component>
} }
@ -83,9 +83,11 @@ const init = ref<boolean>(true)
const components = shallowRef<any>(props.customComponents || {}) const components = shallowRef<any>(props.customComponents || {})
const handleFormChange = (data: any, formConfig: any) => { const handleFormChange = (data: any, formConfig: any) => {
//
if (_isFunction(formConfig?.valueSetter)) { if (_isFunction(formConfig?.valueSetter)) {
const resultData = formConfig.valueSetter(data) const resultData = formConfig.valueSetter(data)
//
if (Array.isArray(resultData)) { if (Array.isArray(resultData)) {
resultData.forEach((item) => { resultData.forEach((item) => {
emit(FORM_CHANGE_EVENT_KEY, item) emit(FORM_CHANGE_EVENT_KEY, item)
@ -125,7 +127,7 @@ const normalizationValues = (configList: Array<any> = []) => {
.map((item: any) => { .map((item: any) => {
return { return {
...item, ...item,
value: formatValue({ item, moduleConfig: props.moduleConfig }) // value: formatValue({ item, moduleConfig: props.moduleConfig }) //
} }
}) })
} }
@ -170,14 +172,13 @@ const registerComponents = async (formFieldData: any) => {
} }
watch( watch(
() => props.formConfigList, () => props.formConfigList, //
async (newVal: Array<any>) => { async (newVal: Array<any>) => {
init.value = true init.value = true
if (!newVal || !newVal.length) { if (!newVal || !newVal.length) {
return return
} }
await registerComponents(newVal) await registerComponents(newVal)
init.value = false init.value = false
formFieldData.value = normalizationValues(newVal) formFieldData.value = normalizationValues(newVal)
@ -189,7 +190,7 @@ watch(
) )
watch( watch(
() => props.moduleConfig, () => props.moduleConfig, // schema
() => { () => {
// value // value
if (init.value) { if (init.value) {

View File

@ -66,7 +66,7 @@ const getSpaceMenus = async () => {
label: v.name, label: v.name,
children: members?.map((v) => ({ children: members?.map((v) => ({
id: v.userId, id: v.userId,
label: v.role label: v.username
})) }))
}) })
}) })

View File

@ -53,7 +53,21 @@ export default {
label: '白名单', label: '白名单',
value: 'CUSTOM' value: 'CUSTOM'
} }
] ],
// 批量修改value
valueSetter(data) {
return [
data,
{
key: 'whitelistTip', // 切换tab清空名单登录提示语
value: ''
},
{
key: 'whitelist', // 切换tab清空名单列表
value: []
}
]
}
}, },
white_placeholder: { white_placeholder: {
key: 'whitelistTip', key: 'whitelistTip',

View File

@ -50,7 +50,7 @@ export const useWorkSpaceStore = defineStore('workSpace', () => {
const res: any = await getSpaceListReq(params) const res: any = await getSpaceListReq(params)
if (res.code === CODE_MAP.SUCCESS) { if (res.code === CODE_MAP.SUCCESS) {
const { list } = res.data const { list, count } = res.data
const workSpace = list.map((item: SpaceDetail) => { const workSpace = list.map((item: SpaceDetail) => {
return { return {
id: item._id, id: item._id,
@ -58,6 +58,7 @@ export const useWorkSpaceStore = defineStore('workSpace', () => {
} }
}) })
workSpaceList.value = list workSpaceList.value = list
workSpaceListTotal.value = count
spaceMenus.value[1].children = workSpace spaceMenus.value[1].children = workSpace
} else { } else {
ElMessage.error('getSpaceList' + res.errmsg) ElMessage.error('getSpaceList' + res.errmsg)