feat:Page operation menus can be configured. (#1428)

This commit is contained in:
xuanlid 2025-05-28 01:06:47 -07:00 committed by GitHub
parent 36a9e97359
commit a047a9edb5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 47 additions and 2 deletions

View File

@ -0,0 +1,41 @@
# 页面操作菜单支持配置
我们提供了页面操作菜单增加自定义操作
当前是默认操作菜单项
![页面默认操作菜单](./imgs/page-default-action.png)
## 通过配置项来定制
- `customPageOperations`:自定义操作配置项
- `type`:菜单项类型
- `label`:菜单项名称
- `action`:菜单项操作
```js
// registry.js
import { handleClickDelete } from './tests/utils'
export default {
// ...
plugins: [
// ...
[Page, { options: { ...Page.options, customPageOperations: [{type: 'delete', label: '删除', action: handleClickDelete}] } }]
// ...
]
// ...
}
```
![页面增加自定义操作菜单项](./imgs/page-custom-action.png)
方法中传有两个参数
```js
export const handleClickDelete = async (node, emit) => {
// node 为所选择的页面的信息, 可以直接调接口处理数据
// emit 可以调用页面父组件的方法,例如 在选择的页面下新建子页面 emit('createPage', 'staticPages', node.id)
}
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -66,6 +66,7 @@ import {
useNotify,
useMessage,
getMetaApi,
getOptions,
META_SERVICE
} from '@opentiny/tiny-engine-meta-register'
import { isEqual } from '@opentiny/vue-renderless/common/object'
@ -77,6 +78,7 @@ import { closeFolderSettingPanel } from './PageFolderSetting.vue'
import http from './http'
import DraggableTree from './Tree.vue'
import { SvgButton } from '@opentiny/tiny-engine-common'
import meta from '../meta'
const { PAGE_STATUS } = constants
@ -112,6 +114,7 @@ export default {
} = usePage()
const { fetchPageDetail, requestUpdatePage } = http
const getAppId = () => getMetaApi(META_SERVICE.GlobalService).getBaseInfo().id
const { customPageOperations = [] } = getOptions(meta.id)
const state = reactive({
pageSearchValue: '',
@ -250,7 +253,8 @@ export default {
{ type: 'divider' },
{ type: 'createPage', label: '新建子页面', action: createPage },
{ type: 'createFolder', label: '新建子文件夹', action: createFolder },
{ type: 'settingHome', label: '设置为主页', action: settingHome }
{ type: 'settingHome', label: '设置为主页', action: settingHome },
...customPageOperations
// TODO
// { type: 'divider' },
// { type: 'copy', label: '', action: copyPage },
@ -258,7 +262,7 @@ export default {
].map((item) => ({
...item,
action: (node) => {
item.action?.(node)
item.action?.(node, emit)
// action popover
popoverRefs[node.id]?.doClose?.()
}