-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: edit-row-table support save loading
- Loading branch information
Showing
9 changed files
with
315 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 79 additions & 36 deletions
115
src/components/core/dynamic-table/src/components/table-action.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,98 @@ | ||
<template> | ||
<template v-for="(actionItem, _index) in actionFilters" :key="`${_index}-${actionItem.label}`"> | ||
<template v-for="(actionItem, index) in actionFilters" :key="`${index}-${actionItem.label}`"> | ||
<component | ||
:is="actionItem.popConfirm ? Popconfirm : 'span'" | ||
:is="actionItem.popConfirm ? 'a-popconfirm' : 'span'" | ||
:title="actionItem.title" | ||
v-bind="actionItem.popConfirm" | ||
> | ||
<a-button type="link" v-bind="actionItem">{{ actionItem.label }}</a-button> | ||
<a-button | ||
type="link" | ||
:loading="loadingMap.get(getKey(actionItem, index))" | ||
v-bind="actionItem" | ||
> | ||
{{ actionItem.label }} | ||
</a-button> | ||
</component> | ||
</template> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { computed } from 'vue'; | ||
<script lang="ts"> | ||
import { defineComponent, computed, ref } from 'vue'; | ||
import { Popconfirm } from 'ant-design-vue'; | ||
import type { PropType } from 'vue'; | ||
import type { ActionItem } from '../types/tableAction'; | ||
import type { CustomRenderParams } from '../types/column'; | ||
import { verifyAuth } from '@/core/permission/'; | ||
import { isString, isObject } from '@/utils/is'; | ||
import { isString, isObject, isAsyncFunction } from '@/utils/is'; | ||
const props = defineProps({ | ||
actions: { | ||
// 表格行动作 | ||
type: Array as PropType<ActionItem[]>, | ||
default: () => [], | ||
export default defineComponent({ | ||
components: { [Popconfirm.name]: Popconfirm }, | ||
props: { | ||
actions: { | ||
// 表格行动作 | ||
type: Array as PropType<ActionItem[]>, | ||
default: () => [], | ||
}, | ||
columnParams: { | ||
type: Object as PropType<CustomRenderParams>, | ||
default: () => ({}), | ||
}, | ||
rowKey: [String, Number] as PropType<Key>, | ||
}, | ||
}); | ||
setup(props) { | ||
const loadingMap = ref(new Map<string, boolean>()); | ||
const actionFilters = computed(() => { | ||
return props.actions | ||
.filter((item) => { | ||
const auth = item.auth; | ||
if (Object.is(auth, undefined)) { | ||
return true; | ||
} | ||
if (isString(auth)) { | ||
const isValid = verifyAuth(auth); | ||
item.disabled ??= !isValid; | ||
if (item.disabled && !isValid) { | ||
item.title = '对不起,您没有该操作权限!'; | ||
} | ||
return isValid; | ||
} | ||
if (isObject(auth)) { | ||
const isValid = verifyAuth(auth.perm); | ||
const isDisable = auth.effect !== 'delete'; | ||
item.disabled ??= !isValid && isDisable; | ||
if (item.disabled && !isValid) { | ||
item.title = '对不起,您没有该操作权限!'; | ||
} | ||
return isValid || isDisable; | ||
} | ||
}) | ||
.map((item, index) => { | ||
const onClick = item.onClick; | ||
const actionFilters = computed(() => { | ||
return props.actions.filter((item) => { | ||
const auth = item.auth; | ||
if (isAsyncFunction(onClick)) { | ||
item.onClick = async () => { | ||
const key = getKey(item, index); | ||
loadingMap.value.set(key, true); | ||
await onClick(props.columnParams).finally(() => { | ||
loadingMap.value.delete(key); | ||
}); | ||
}; | ||
} | ||
return item; | ||
}); | ||
}); | ||
if (Object.is(auth, undefined)) { | ||
return true; | ||
} | ||
if (isString(auth)) { | ||
const isValid = verifyAuth(auth); | ||
item.disabled ??= !isValid; | ||
if (item.disabled && !isValid) { | ||
item.title = '对不起,您没有该操作权限!'; | ||
} | ||
return isValid; | ||
} | ||
if (isObject(auth)) { | ||
const isValid = verifyAuth(auth.perm); | ||
const isDisable = auth.effect !== 'delete'; | ||
item.disabled ??= !isValid && isDisable; | ||
if (item.disabled && !isValid) { | ||
item.title = '对不起,您没有该操作权限!'; | ||
} | ||
return isValid || isDisable; | ||
} | ||
}); | ||
const getKey = (actionItem: ActionItem, index: number) => { | ||
return `${props.rowKey}${index}${actionItem.label}`; | ||
}; | ||
return { | ||
actionFilters, | ||
loadingMap, | ||
getKey, | ||
}; | ||
}, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
b24e25a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
vue3-antd-admin – ./
vue3-antd-admin-buqiyuan.vercel.app
vue3-antd-admin.vercel.app
vue3-antd-admin-git-main-buqiyuan.vercel.app