-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat use layout #223
Feat use layout #223
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,41 @@ | ||
{ | ||
"name": "@fesjs/plugin-layout", | ||
"version": "5.1.7", | ||
"description": "@fesjs/plugin-layout", | ||
"main": "lib/index.js", | ||
"files": [ | ||
"lib", | ||
"types.d.ts" | ||
], | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/WeBankFinTech/fes.js.git", | ||
"directory": "packages/fes-plugin-layout" | ||
}, | ||
"keywords": [ | ||
"fes" | ||
], | ||
"author": "harrywan", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/WeBankFinTech/fes.js/issues" | ||
}, | ||
"homepage": "https://github.com/WeBankFinTech/fes.js#readme", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@fesjs/utils": "^3.0.1" | ||
}, | ||
"peerDependencies": { | ||
"@fesjs/fes": "^3.1.4", | ||
"@fesjs/fes-design": ">=0.7.0", | ||
"vue": "^3.2.47", | ||
"vue-router": "^4.0.1" | ||
}, | ||
"typings": "./types.d.ts" | ||
"name": "@fesjs/plugin-layout", | ||
"version": "5.1.7", | ||
"description": "@fesjs/plugin-layout", | ||
"author": "harrywan", | ||
"license": "MIT", | ||
"homepage": "https://github.com/WeBankFinTech/fes.js#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/WeBankFinTech/fes.js.git", | ||
"directory": "packages/fes-plugin-layout" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/WeBankFinTech/fes.js/issues" | ||
}, | ||
"keywords": [ | ||
"fes" | ||
], | ||
"main": "lib/index.js", | ||
"files": [ | ||
"lib", | ||
"types.d.ts" | ||
], | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"peerDependencies": { | ||
"@fesjs/fes": "^3.1.4", | ||
"@fesjs/fes-design": ">=0.7.0", | ||
"vue": "^3.2.47", | ||
"vue-router": "^4.0.1" | ||
}, | ||
"dependencies": { | ||
"@fesjs/utils": "^3.0.1", | ||
"@vueuse/core": "^10.7.0" | ||
}, | ||
"typings": "./types.d.ts" | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { readFileSync } from 'fs'; | ||
import { join } from 'path'; | ||
import { readFileSync } from 'node:fs'; | ||
import { join } from 'node:path'; | ||
import { winPath } from '@fesjs/utils'; | ||
import { name } from '../package.json'; | ||
|
||
|
@@ -40,7 +40,7 @@ export default (api) => { | |
|
||
const iconNames = helper.getIconNamesFromMenu(userConfig.menus); | ||
|
||
const iconsString = iconNames.map((iconName) => `import { ${iconName} } from '@fesjs/fes-design/icon'`); | ||
const iconsString = iconNames.map(iconName => `import { ${iconName} } from '@fesjs/fes-design/icon'`); | ||
api.writeTmpFile({ | ||
path: join(namespace, 'icons.js'), | ||
content: ` | ||
|
@@ -84,15 +84,15 @@ export default (api) => { | |
|
||
api.addPluginExports(() => [ | ||
{ | ||
specifiers: ['Page', 'useTabTitle'], | ||
specifiers: ['Page', 'useTabTitle', 'useLayout'], | ||
source: join(namespace, 'index.js'), | ||
}, | ||
]); | ||
|
||
// 把 BaseLayout插入到路由配置中,作为根路由 | ||
// 添加 403 和 404 路由 | ||
api.modifyRoutes((routes) => { | ||
if (!routes.find((item) => item.path === '/403')) { | ||
if (!routes.find(item => item.path === '/403')) { | ||
routes.push({ | ||
path: '/403', | ||
name: 'Exception403', | ||
|
@@ -102,7 +102,7 @@ export default (api) => { | |
}, | ||
}); | ||
} | ||
if (!routes.find((item) => item.path === '/404')) { | ||
if (!routes.find(item => item.path === '/404')) { | ||
routes.push({ | ||
path: '/404', | ||
name: 'Exception404', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 以下是代码补丁,请帮我进行简要的代码审查。欢迎指出任何错误风险和/或改进建议。:
这段代码补丁主要做了以下更改:
对于这段代码补丁的风险和改进建议,没有明显的错误风险。改进方面,可以考虑增加一些注释来解释代码的目的和功能。此外,处理错误的逻辑可能需要更详细的实现,具体取决于代码的上下文。 |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as Page } from './views/page.vue'; | ||
export { useTabTitle } from './useTitle'; | ||
export * from './useLayout'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这段代码看起来很简单,只有两行。第一行导出了一个名为"Page"的默认组件,从"./views/page.vue"文件中引入。第二行导出了一个名为"useTabTitle"的函数,从"./useTitle"文件中引入。 新增加的第三行是导出"./useLayout"中的所有内容。 在这个简短的代码片段中,我没有发现任何明显的错误风险。如果代码的其他部分也正确,那么这应该是一个有效的代码补丁。 关于改进建议,由于这段代码非常简洁,很难提出具体的优化建议。如果你愿意提供更多上下文或与该代码片段相关的其他信息,我可能能够提供更具体的帮助和建议。 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { createSharedComposable } from '@vueuse/core'; | ||
import { shallowReactive } from 'vue'; | ||
|
||
function _useLayout() { | ||
const state = shallowReactive({ | ||
closeTab: () => {}, | ||
}); | ||
|
||
return state; | ||
} | ||
|
||
export const useLayout = createSharedComposable(_useLayout); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 提供的代码补丁的目的是创建一个名为
该代码补丁的风险和改进建议如下:
请注意,由于限制回答长度,上述内容仅提供了简要审核和一些建议。实际上,代码审核应基于更多上下文信息和具体项目要求进行。 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,16 @@ import { useRoute } from '@@/core/coreExports'; | |
|
||
const cache = reactive(new Map()); | ||
|
||
export const getTitle = (path) => cache.get(path); | ||
export const getTitle = path => cache.get(path); | ||
|
||
export const deleteTitle = (patch) => cache.delete(patch); | ||
export const deleteTitle = patch => cache.delete(patch); | ||
|
||
export const useTabTitle = (title) => { | ||
export function useTabTitle(title) { | ||
const route = useRoute(); | ||
const titleRef = ref(title); | ||
const path = route.path; | ||
|
||
cache.set(path, titleRef); | ||
|
||
return titleRef; | ||
}; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 代码补丁如下,请帮我简要进行代码审核。欢迎提出任何缺陷风险和/或改进建议:
修复后的代码如下所示: import { useRoute } from '@@/core/coreExports';
const cache = reactive(new Map());
export function getTitle(path) {
return cache.get(path);
}
export function deleteTitle(patch) {
return cache.delete(patch);
}
export function useTabTitle(title) {
const route = useRoute();
const titleRef = ref(title);
const path = route.path;
cache.set(path, titleRef);
return titleRef;
} 请留意代码风格和文档注释等方面是否符合项目约定。 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
<template> | ||
<template v-if="multiTabs"> | ||
<FTabs | ||
:modelValue="route.path" | ||
:model-value="route.path" | ||
closable | ||
:tabsPadding="24" | ||
:tabs-padding="24" | ||
type="card" | ||
class="layout-content-tabs" | ||
@close="handleCloseTab" | ||
|
@@ -21,17 +21,19 @@ | |
</FDropdown> | ||
</template> | ||
</FTabs> | ||
<Page ref="pageRef" :pageKey="getPageKey" isAllKeepAlive /> | ||
<Page ref="pageRef" :page-key="getPageKey" is-all-keep-alive /> | ||
</template> | ||
<Page v-else /> | ||
</template> | ||
|
||
<script> | ||
import { computed, unref, ref } from 'vue'; | ||
import { FTabs, FTabPane, FDropdown } from '@fesjs/fes-design'; | ||
import { ReloadOutlined, MoreOutlined } from '@fesjs/fes-design/icon'; | ||
import { useRouter, useRoute } from '@@/core/coreExports'; | ||
import { computed, ref, unref } from 'vue'; | ||
import { FDropdown, FTabPane, FTabs } from '@fesjs/fes-design'; | ||
import { MoreOutlined, ReloadOutlined } from '@fesjs/fes-design/icon'; | ||
import { useRoute, useRouter } from '@@/core/coreExports'; | ||
import { transTitle } from '../helpers/pluginLocale'; | ||
import { getTitle, deleteTitle } from '../useTitle'; | ||
import { deleteTitle, getTitle } from '../useTitle'; | ||
import { useLayout } from '../useLayout'; | ||
import Page from './page.vue'; | ||
|
||
let i = 0; | ||
|
@@ -52,6 +54,8 @@ export default { | |
const pageRef = ref(); | ||
const route = useRoute(); | ||
const router = useRouter(); | ||
const layoutState = useLayout(); | ||
|
||
const createPage = (_route) => { | ||
const computedTitle = computed(() => { | ||
const customTitle = unref(getTitle(_route.path)); | ||
|
@@ -78,15 +82,16 @@ export default { | |
}, | ||
]; | ||
|
||
const findPage = (path) => pageList.value.find((item) => unref(item.path) === unref(path)); | ||
const findPage = path => pageList.value.find(item => unref(item.path) === unref(path)); | ||
|
||
router.beforeEach((to) => { | ||
const page = findPage(to.path); | ||
if (!page) { | ||
if (!page) | ||
pageList.value = [...pageList.value, createPage(to)]; | ||
} else { | ||
|
||
else | ||
page.route = to; | ||
} | ||
|
||
return true; | ||
}); | ||
|
||
|
@@ -102,28 +107,30 @@ export default { | |
} | ||
}; | ||
const handleCloseTab = async (targetKey) => { | ||
targetKey = targetKey || route.path; | ||
const selectedPage = findPage(targetKey); | ||
const list = [...pageList.value]; | ||
const index = list.indexOf(selectedPage); | ||
if (route.path === selectedPage.path) { | ||
if (list.length > 1) { | ||
if (list.length - 1 === index) { | ||
if (list.length - 1 === index) | ||
await switchPage(list[index - 1].path); | ||
} else { | ||
|
||
else | ||
await switchPage(list[index + 1].path); | ||
} | ||
} | ||
} | ||
list.splice(index, 1); | ||
pageList.value = list; | ||
pageRef.value.removeKeepAlive(selectedPage.name); | ||
deleteTitle(selectedPage.path); | ||
}; | ||
layoutState.closeTab = handleCloseTab; | ||
|
||
const reloadPage = (path) => { | ||
const selectedPage = findPage(path || unref(route.path)); | ||
if (selectedPage) { | ||
if (selectedPage) | ||
selectedPage.key = getKey(); | ||
} | ||
}; | ||
const closeOtherPage = (path) => { | ||
const selectedPage = findPage(path || unref(route.path)); | ||
|
@@ -132,9 +139,9 @@ export default { | |
}; | ||
const getPageKey = (_route) => { | ||
const selectedPage = findPage(_route.path); | ||
if (selectedPage) { | ||
if (selectedPage) | ||
return selectedPage.key; | ||
} | ||
|
||
return ''; | ||
}; | ||
const handlerMore = (key) => { | ||
|
@@ -163,6 +170,7 @@ export default { | |
}, | ||
}; | ||
</script> | ||
|
||
<style lang="less"> | ||
.layout-content-tabs { | ||
background: rgb(255, 255, 255); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 代码补丁存在以下问题和改进建议:
以上是关于提供的代码补丁的简要代码审查。我希望这些建议能够帮助您改进代码。 |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,35 @@ | ||
<template> | ||
<monaco-editor ref="editorRef" v-model="json" :language="language" height="200px" check /> | ||
<MonacoEditor ref="editorRef" v-model="json" :language="language" height="200px" check /> | ||
{{ json }} | ||
</template> | ||
|
||
<config> | ||
{ | ||
"name": "editor", | ||
"title": "$editor" | ||
} | ||
</config> | ||
|
||
<script> | ||
import { onMounted, ref } from 'vue'; | ||
import { MonacoEditor } from '@fesjs/fes'; | ||
import { MonacoEditor, useLayout } from '@fesjs/fes'; | ||
|
||
export default { | ||
components: { | ||
MonacoEditor, | ||
}, | ||
setup() { | ||
console.log('editor.vue'); | ||
const { closeTab } = useLayout(); | ||
|
||
const editorRef = ref(); | ||
const json = ref(''); | ||
const language = ref('json'); | ||
onMounted(() => { | ||
setTimeout(() => { | ||
language.value = 'html'; | ||
}, 2000); | ||
setTimeout(() => { | ||
closeTab(); | ||
}, 3000); | ||
}); | ||
return { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 代码补丁进行了如下的更改和添加:
在进行代码审核时,以下是可能存在的问题和改进建议:
以上是对代码补丁的简要评审,希望对您有所帮助! |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
<template> | ||
<div class="page"> | ||
home | ||
<FButton class="m-2" @click="go">Button</FButton> | ||
<FButton class="m-2" @click="go"> | ||
Button | ||
</FButton> | ||
</div> | ||
</template> | ||
|
||
|
@@ -13,12 +15,13 @@ defineRouteMeta({ | |
name: 'index', | ||
title: '$home', | ||
}); | ||
|
||
console.log('123123'.replaceAll('123', '234')); | ||
|
||
const router = useRouter(); | ||
const go = () => { | ||
function go() { | ||
router.push('/editor'); | ||
}; | ||
} | ||
</script> | ||
|
||
<style> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 提供的代码补丁已经在模板和脚本部分进行了修改。以下是对代码的简洁审核和改进建议:
总体而言,这些是较小的更改,没有明显的错误风险。可以考虑添加更多功能,如输入验证或错误处理,具体取决于代码的上下文和要求。 |
||
|
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.
这段代码的主要变动如下:
代码看起来没有明显的错误风险。推荐的改进: