Commit b7eb4a7c authored by Sendya's avatar Sendya

feat: add

parent 7efe7908
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
}, },
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@ant-design/icons": "^4.0.0-alpha.11", "@ant-design/icons-vue": "2.0.0",
"ant-design-vue": "^1.6.2", "ant-design-vue": "^1.6.2",
"core-js": "^3.1.2", "core-js": "^3.1.2",
"vue-i18n": "^8.15.0", "vue-i18n": "^8.15.0",
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
"vuex": "^3.0.1" "vuex": "^3.0.1"
}, },
"devDependencies": { "devDependencies": {
"@ant-design/colors": "4.0.0",
"@ant-design/icons": "2.0.0",
"@vue/cli-plugin-babel": "^4.0.0", "@vue/cli-plugin-babel": "^4.0.0",
"@vue/cli-plugin-eslint": "^4.0.0", "@vue/cli-plugin-eslint": "^4.0.0",
"@vue/cli-plugin-router": "^4.0.0", "@vue/cli-plugin-router": "^4.0.0",
...@@ -39,6 +41,7 @@ ...@@ -39,6 +41,7 @@
"eslint": "^5.16.0", "eslint": "^5.16.0",
"eslint-plugin-html": "^6.0.0", "eslint-plugin-html": "^6.0.0",
"eslint-plugin-vue": "^5.0.0", "eslint-plugin-vue": "^5.0.0",
"file-loader": "^6.2.0",
"less": "^3.0.4", "less": "^3.0.4",
"less-loader": "^5.0.0", "less-loader": "^5.0.0",
"vue-svg-icon-loader": "^2.1.1", "vue-svg-icon-loader": "^2.1.1",
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
<pro-layout <pro-layout
:menus="menus" :menus="menus"
:collapsed="collapsed" :collapsed="collapsed"
:openOnceKey="false"
:mediaQuery="query" :mediaQuery="query"
:isMobile="isMobile" :isMobile="isMobile"
:handleMediaQuery="handleMediaQuery" :handleMediaQuery="handleMediaQuery"
...@@ -67,6 +68,11 @@ export default { ...@@ -67,6 +68,11 @@ export default {
menus: [], menus: [],
// 侧栏收起状态 // 侧栏收起状态
collapsed: false, collapsed: false,
// 选中的菜单项
selectedKeys: [],
// 打开的菜单项
openKeys: [],
// 自动隐藏头部栏 // 自动隐藏头部栏
autoHideHeader: false, autoHideHeader: false,
// 媒体查询 // 媒体查询
...@@ -99,9 +105,35 @@ export default { ...@@ -99,9 +105,35 @@ export default {
}, },
created () { created () {
this.menus = asyncRouterMap.find(item => item.path === '/').children this.menus = asyncRouterMap.find(item => item.path === '/').children
this.$watch('$route', () => {
this.handleRouteUpdate()
})
},
mounted () {
// this.handleRouteUpdate()
this.openKeys = ['/dashboard', '/form']
}, },
methods: { methods: {
i18nRender, i18nRender,
handleRouteUpdate () {
const routes = this.$route.matched.concat()
const { hidden } = this.$route.meta
if (routes.length >= 3 && hidden) {
routes.pop()
this.selectedKeys = [routes[routes.length - 1].path]
} else {
this.selectedKeys = [routes.pop().path]
}
const openKeys = []
if (this.layout === 'sidemenu') {
routes.forEach(item => {
item.path && openKeys.push(item.path)
})
}
this.openKeys = openKeys
},
handleMediaQuery (val) { handleMediaQuery (val) {
this.query = val this.query = val
if (this.isMobile && !val['screen-xs']) { if (this.isMobile && !val['screen-xs']) {
...@@ -116,6 +148,14 @@ export default { ...@@ -116,6 +148,14 @@ export default {
handleCollapse (val) { handleCollapse (val) {
this.collapsed = val this.collapsed = val
}, },
handleSelect (selectedKeys) {
console.log('handleSelect', selectedKeys)
this.selectedKeys = selectedKeys
},
handleOpenChange (openKeys) {
console.log('handleOpenChange', openKeys)
this.openKeys = openKeys
},
handleSettingChange ({ type, value }) { handleSettingChange ({ type, value }) {
console.log('type', type, value) console.log('type', type, value)
type && (this.settings[type] = value) type && (this.settings[type] = value)
......
...@@ -34,7 +34,7 @@ const defaultConfig = { ...@@ -34,7 +34,7 @@ const defaultConfig = {
configureWebpack: { configureWebpack: {
plugins: [ plugins: [
// Ignore all locale files of moment.js // Ignore all locale files of moment.js
new IgnorePlugin(/^\.\/locale$/, /moment$/) // new IgnorePlugin(/^\.\/locale$/, /moment$/)
], ],
resolve: { resolve: {
alias: { alias: {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -77,7 +77,7 @@ const BasicLayout = { ...@@ -77,7 +77,7 @@ const BasicLayout = {
functional: true, functional: true,
props: BasicLayoutProps, props: BasicLayoutProps,
render (h, content) { render (h, content) {
const { props, children } = content const { props, children, listeners } = content
const { const {
layout, layout,
// theme, // theme,
...@@ -113,7 +113,8 @@ const BasicLayout = { ...@@ -113,7 +113,8 @@ const BasicLayout = {
collapsedButtonRender, collapsedButtonRender,
breadcrumbRender, breadcrumbRender,
headerContentRender, headerContentRender,
menuRender menuRender,
...listeners,
} }
return ( return (
......
...@@ -15,6 +15,9 @@ export const RouteMenuProps = { ...@@ -15,6 +15,9 @@ export const RouteMenuProps = {
theme: PropTypes.string.def('dark'), theme: PropTypes.string.def('dark'),
mode: PropTypes.string.def('inline'), mode: PropTypes.string.def('inline'),
collapsed: PropTypes.bool.def(false), collapsed: PropTypes.bool.def(false),
openKeys: PropTypes.array.def(undefined),
selectedKeys: PropTypes.array.def(undefined),
openOnceKey: PropTypes.bool.def(true),
i18nRender: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]).def(false), i18nRender: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]).def(false),
} }
...@@ -84,40 +87,42 @@ const RouteMenu = { ...@@ -84,40 +87,42 @@ const RouteMenu = {
props: RouteMenuProps, props: RouteMenuProps,
data () { data () {
return { return {
openKeys: [], sOpenKeys: [],
selectedKeys: [], sSelectedKeys: [],
cachedOpenKeys: [], cachedOpenKeys: [],
cachedSelectedKeys: [], cachedSelectedKeys: [],
} }
}, },
render (h) { render (h, ctx) {
const { mode, theme, menus, i18nRender } = this const { mode, theme, menus, i18nRender, openOnceKey } = this
const handleOpenChange = (openKeys) => { const handleOpenChange = (openKeys) => {
// 在水平模式下时,不再执行后续 // 在水平模式下时,不再执行后续
if (mode === 'horizontal') { if (mode === 'horizontal') {
this.openKeys = openKeys this.sOpenKeys = openKeys
return return
} }
const latestOpenKey = openKeys.find(key => !this.openKeys.includes(key)) const latestOpenKey = openKeys.find(key => !this.sOpenKeys.includes(key))
if (!this.rootSubmenuKeys.includes(latestOpenKey)) { if (!openOnceKey) {
this.openKeys = openKeys this.sOpenKeys = openKeys
} else { } else {
this.openKeys = latestOpenKey ? [latestOpenKey] : [] this.sOpenKeys = latestOpenKey ? [latestOpenKey] : []
} }
this.$emit('openChange', openKeys)
} }
const dynamicProps = { const dynamicProps = {
props: { props: {
mode, mode,
theme, theme,
openKeys: this.openKeys, openKeys: this.openKeys || this.sOpenKeys,
selectedKeys: this.selectedKeys selectedKeys: this.selectedKeys || this.sSelectedKeys
}, },
on: { on: {
select: menu => { select: args => {
this.$emit('select', menu) this.$emit('select', args.selectedKeys)
if (!httpReg.test(menu.key)) { if (!httpReg.test(args.key)) {
this.selectedKeys = menu.selectedKeys this.sSelectedKeys = args.selectedKeys
} }
}, },
openChange: handleOpenChange openChange: handleOpenChange
...@@ -135,13 +140,16 @@ const RouteMenu = { ...@@ -135,13 +140,16 @@ const RouteMenu = {
methods: { methods: {
updateMenu () { updateMenu () {
const routes = this.$route.matched.concat() const routes = this.$route.matched.concat()
const { hidden } = this.$route.meta if (this.selectedKeys === undefined) {
if (routes.length >= 3 && hidden) { const { hidden } = this.$route.meta
routes.pop() if (routes.length >= 3 && hidden) {
this.selectedKeys = [routes[routes.length - 1].path] routes.pop()
} else { this.sSelectedKeys = [routes[routes.length - 1].path]
this.selectedKeys = [routes.pop().path] } else {
this.sSelectedKeys = [routes.pop().path]
}
} }
const openKeys = [] const openKeys = []
if (this.mode === 'inline') { if (this.mode === 'inline') {
routes.forEach(item => { routes.forEach(item => {
...@@ -149,13 +157,12 @@ const RouteMenu = { ...@@ -149,13 +157,12 @@ const RouteMenu = {
}) })
} }
this.collapsed ? (this.cachedOpenKeys = openKeys) : (this.openKeys = openKeys) this.collapsed ? (this.cachedOpenKeys = openKeys) : (this.sOpenKeys = openKeys)
} }
}, },
computed: { computed: {
rootSubmenuKeys: vm => { rootSubmenuKeys: vm => {
const keys = [] const keys =vm.menus.map(item => item.path) || []
vm.menus.forEach(item => keys.push(item.path))
return keys return keys
} }
}, },
...@@ -166,11 +173,18 @@ const RouteMenu = { ...@@ -166,11 +173,18 @@ const RouteMenu = {
this.$watch('collapsed', val => { this.$watch('collapsed', val => {
if (val) { if (val) {
this.cachedOpenKeys = this.openKeys.concat() this.cachedOpenKeys = this.openKeys.concat()
this.openKeys = [] this.sOpenKeys = []
} else { } else {
this.openKeys = this.cachedOpenKeys this.sOpenKeys = this.cachedOpenKeys
} }
}) })
if (this.selectedKeys !== undefined) {
this.sSelectedKeys = this.selectedKeys
}
if (this.openKeys !== undefined) {
this.sOpenKeys = this.openKeys
}
}, },
mounted () { mounted () {
this.updateMenu() this.updateMenu()
......
...@@ -15,6 +15,9 @@ export const SiderMenuProps = { ...@@ -15,6 +15,9 @@ export const SiderMenuProps = {
contentWidth: PropTypes.oneOf(['Fluid', 'Fixed']).def('Fluid'), contentWidth: PropTypes.oneOf(['Fluid', 'Fixed']).def('Fluid'),
collapsible: PropTypes.bool, collapsible: PropTypes.bool,
collapsed: PropTypes.bool, collapsed: PropTypes.bool,
openKeys: PropTypes.array.def(undefined),
selectedKeys: PropTypes.array.def(undefined),
openOnceKey: PropTypes.bool.def(true),
handleCollapse: PropTypes.func, handleCollapse: PropTypes.func,
menus: PropTypes.array, menus: PropTypes.array,
siderWidth: PropTypes.number.def(256), siderWidth: PropTypes.number.def(256),
...@@ -26,6 +29,10 @@ export const SiderMenuProps = { ...@@ -26,6 +29,10 @@ export const SiderMenuProps = {
// render function or vnode // render function or vnode
menuHeaderRender: PropTypes.oneOfType([PropTypes.func, PropTypes.array, PropTypes.object, PropTypes.bool]), menuHeaderRender: PropTypes.oneOfType([PropTypes.func, PropTypes.array, PropTypes.object, PropTypes.bool]),
menuRender: PropTypes.oneOfType([PropTypes.func, PropTypes.array, PropTypes.object, PropTypes.bool]), menuRender: PropTypes.oneOfType([PropTypes.func, PropTypes.array, PropTypes.object, PropTypes.bool]),
// listeners
openChange: PropTypes.func,
select: PropTypes.func,
} }
export const defaultRenderLogo = (h, logo) => { export const defaultRenderLogo = (h, logo) => {
...@@ -75,6 +82,14 @@ const SiderMenu = { ...@@ -75,6 +82,14 @@ const SiderMenu = {
const { const {
collapsible, collapsible,
collapsed, collapsed,
selectedKeys,
openKeys,
openChange = () => null,
select = () => null,
openOnceKey,
siderWidth, siderWidth,
fixSiderbar, fixSiderbar,
mode, mode,
...@@ -124,7 +139,18 @@ const SiderMenu = { ...@@ -124,7 +139,18 @@ const SiderMenu = {
&& menuRender(h, this.$props) && menuRender(h, this.$props)
|| menuRender || menuRender
) || ( ) || (
<BaseMenu collapsed={collapsed} menus={menus} mode={mode} theme={theme} i18nRender={i18nRender} /> <BaseMenu
collapsed={collapsed}
openKeys={openKeys}
selectedKeys={selectedKeys}
openOnceKey={openOnceKey}
onOpenChange={openChange}
onSelect={select}
menus={menus}
mode={mode}
theme={theme}
i18nRender={i18nRender}
/>
)} )}
</Sider>) </Sider>)
} }
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment