Browse Source

feat: fix layout's problem (#7742)

3.0.0/version-upgrade
labbomb 3 years ago committed by GitHub
parent
commit
b2e6b69b09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 52
      dolphinscheduler-ui-next/src/layouts/content/components/sidebar/index.tsx
  2. 36
      dolphinscheduler-ui-next/src/layouts/content/index.tsx
  3. 36
      dolphinscheduler-ui-next/src/store/language/language.ts
  4. 22
      dolphinscheduler-ui-next/src/store/language/types.ts
  5. 36
      dolphinscheduler-ui-next/src/views/login/index.tsx

52
dolphinscheduler-ui-next/src/layouts/content/components/sidebar/index.tsx

@ -15,23 +15,19 @@
* limitations under the License. * limitations under the License.
*/ */
import { defineComponent, PropType, ref } from 'vue' import { defineComponent, PropType, ref, watch, onMounted } from 'vue'
import styles from './index.module.scss' import styles from './index.module.scss'
import { NLayoutSider, NMenu } from 'naive-ui' import { NLayoutSider, NMenu } from 'naive-ui'
import { useI18n } from 'vue-i18n'
import { useLanguageStore } from '@/store/language/language'
const Sidebar = defineComponent({ interface Props {
name: 'Sidebar', sideMenuOptions: Array<any>,
props: { isShowSide: boolean
sideMenuOptions: { }
type: Array as PropType<any>,
default: [], const Sidebar = (props: Props) => {
}, // console.log('props', JSON.stringify(props))
isShowSide: {
type: Boolean as PropType<boolean>,
default: false,
},
},
setup() {
const collapsedRef = ref(false) const collapsedRef = ref(false)
const defaultExpandedKeys = [ const defaultExpandedKeys = [
'workflow', 'workflow',
@ -40,28 +36,30 @@ const Sidebar = defineComponent({
'statistical-manage', 'statistical-manage',
] ]
return { collapsedRef, defaultExpandedKeys } watch(useI18n().locale, () => {
}, const languageStore = useLanguageStore()
render() { refreshOptionsRef.value = props.sideMenuOptions
// console.log(123, JSON.stringify(props))
})
const refreshOptionsRef = ref()
return ( return (
this.isShowSide && ( <NLayoutSider style={{display: props.isShowSide ? 'block' : 'none'}}
<NLayoutSider
bordered bordered
nativeScrollbar={false} nativeScrollbar={false}
show-trigger='bar' show-trigger='bar'
collapse-mode='width' collapse-mode='width'
collapsed={this.collapsedRef} collapsed={collapsedRef.value}
onCollapse={() => (this.collapsedRef = true)} onCollapse={() => (collapsedRef.value = true)}
onExpand={() => (this.collapsedRef = false)} onExpand={() => (collapsedRef.value = false)}
> >
<NMenu <NMenu
options={this.sideMenuOptions} options={props.sideMenuOptions || refreshOptionsRef.value}
defaultExpandedKeys={this.defaultExpandedKeys} defaultExpandedKeys={defaultExpandedKeys}
/> />
</NLayoutSider> </NLayoutSider>
) )
) }
},
})
export default Sidebar export default Sidebar

36
dolphinscheduler-ui-next/src/layouts/content/index.tsx

@ -15,50 +15,47 @@
* limitations under the License. * limitations under the License.
*/ */
import { defineComponent, ref, toRefs } from 'vue' import { ref } from 'vue'
import { NLayout, NLayoutContent, NLayoutHeader } from 'naive-ui' import { NLayout, NLayoutContent, NLayoutHeader } from 'naive-ui'
import NavBar from './components/navbar' import NavBar from './components/navbar'
import SideBar from './components/sidebar' import SideBar from './components/sidebar'
import { useDataList } from './use-dataList' import { useDataList } from './use-dataList'
import { useLanguageStore } from '@/store/language/language'
const Content = () => {
const Content = defineComponent({
name: 'Content',
setup() {
const { state, getHeaderMenuOptions } = useDataList() const { state, getHeaderMenuOptions } = useDataList()
const headerMenuOptions = getHeaderMenuOptions(state.menuOptions) const headerMenuOptions = getHeaderMenuOptions(state.menuOptions)
const sideMenuOptions = ref() const sideMenuOptions = ref()
const languageStore = useLanguageStore()
const getSideMenuOptions = (item: any) => { const getSideMenuOptions = (item: any) => {
// console.log('item', item)
languageStore.setMenuKey(item.key)
sideMenuOptions.value = sideMenuOptions.value =
state.menuOptions.filter((menu) => menu.key === item.key)[0].children || state.menuOptions.filter((menu) => menu.key === item.key)[0].children ||
[] []
state.isShowSide = sideMenuOptions.value.length !== 0 state.isShowSide = sideMenuOptions.value.length !== 0
// console.log('sideMenuOptions.value', sideMenuOptions.value)
// console.log('state.isShowSide', state.isShowSide)
} }
return {
...toRefs(state),
headerMenuOptions,
getSideMenuOptions,
sideMenuOptions,
}
},
render() {
return ( return (
<NLayout style='height: 100%;'> <NLayout style='height: 100%;'>
<NLayoutHeader style='height: 65px;'> <NLayoutHeader style='height: 65px;'>
<NavBar <NavBar
onHandleMenuClick={this.getSideMenuOptions} onHandleMenuClick={getSideMenuOptions}
headerMenuOptions={this.headerMenuOptions} headerMenuOptions={headerMenuOptions}
languageOptions={this.languageOptions} languageOptions={state.languageOptions}
profileOptions={this.profileOptions} profileOptions={state.profileOptions}
/> />
</NLayoutHeader> </NLayoutHeader>
<NLayout has-sider position='absolute' style='top: 65px;'> <NLayout has-sider position='absolute' style='top: 65px;'>
<SideBar <SideBar
sideMenuOptions={this.sideMenuOptions} sideMenuOptions={sideMenuOptions.value}
isShowSide={this.isShowSide} isShowSide={state.isShowSide}
/> />
<NLayoutContent native-scrollbar={false} style='padding: 16px 22px;'> <NLayoutContent native-scrollbar={false} style='padding: 16px 22px;'>
<router-view /> <router-view />
@ -66,7 +63,6 @@ const Content = defineComponent({
</NLayout> </NLayout>
</NLayout> </NLayout>
) )
}, }
})
export default Content export default Content

36
dolphinscheduler-ui-next/src/store/language/language.ts

@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { defineStore } from 'pinia'
import LanguageState from './types'
export const useLanguageStore = defineStore({
id: 'language',
state: (): LanguageState => ({
menuKey: '',
}),
getters: {
getMenuKey(): string {
return this.menuKey
},
},
actions: {
setMenuKey(menuKey: string): void {
this.menuKey = menuKey
},
},
})

22
dolphinscheduler-ui-next/src/store/language/types.ts

@ -0,0 +1,22 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
interface LanguageState {
menuKey: string
}
export default LanguageState

36
dolphinscheduler-ui-next/src/views/login/index.tsx

@ -15,30 +15,25 @@
* limitations under the License. * limitations under the License.
*/ */
import { defineComponent, toRefs, withKeys } from 'vue' import { withKeys } from 'vue'
import styles from './index.module.scss' import styles from './index.module.scss'
import { NInput, NButton, NSwitch, NForm, NFormItem } from 'naive-ui' import { NInput, NButton, NSwitch, NForm, NFormItem } from 'naive-ui'
import { useValidate } from './use-validate' import { useValidate } from './use-validate'
import { useTranslate } from './use-translate' import { useTranslate } from './use-translate'
import { useLogin } from './use-login' import { useLogin } from './use-login'
const login = defineComponent({ const login = () => {
name: 'login',
setup() {
const { state, t, locale } = useValidate() const { state, t, locale } = useValidate()
const { handleChange } = useTranslate(locale) const { handleChange } = useTranslate(locale)
const { handleLogin } = useLogin(state) const { handleLogin } = useLogin(state)
return { t, handleChange, handleLogin, ...toRefs(state) }
},
render() {
return ( return (
<div class={styles.container}> <div class={styles.container}>
<div class={styles['language-switch']}> <div class={styles['language-switch']}>
<NSwitch <NSwitch
onUpdateValue={this.handleChange} onUpdateValue={handleChange}
checked-value='en_US' checked-value='en_US'
unchecked-value='zh_CN' unchecked-value='zh_CN'
> >
@ -53,32 +48,32 @@ const login = defineComponent({
<div class={styles['logo-img']} /> <div class={styles['logo-img']} />
</div> </div>
<div class={styles['form-model']}> <div class={styles['form-model']}>
<NForm rules={this.rules} ref='loginFormRef'> <NForm rules={state.rules} ref='loginFormRef'>
<NFormItem <NFormItem
label={this.t('login.userName')} label={t('login.userName')}
label-style={{ color: 'black' }} label-style={{ color: 'black' }}
path='userName' path='userName'
> >
<NInput <NInput
type='text' type='text'
size='large' size='large'
v-model={[this.loginForm.userName, 'value']} v-model={[state.loginForm.userName, 'value']}
placeholder={this.t('login.userName_tips')} placeholder={t('login.userName_tips')}
autofocus autofocus
onKeydown={withKeys(this.handleLogin, ['enter'])} onKeydown={withKeys(handleLogin, ['enter'])}
/> />
</NFormItem> </NFormItem>
<NFormItem <NFormItem
label={this.t('login.userPassword')} label={t('login.userPassword')}
label-style={{ color: 'black' }} label-style={{ color: 'black' }}
path='userPassword' path='userPassword'
> >
<NInput <NInput
type='password' type='password'
size='large' size='large'
v-model={[this.loginForm.userPassword, 'value']} v-model={[state.loginForm.userPassword, 'value']}
placeholder={this.t('login.userPassword_tips')} placeholder={t('login.userPassword_tips')}
onKeydown={withKeys(this.handleLogin, ['enter'])} onKeydown={withKeys(handleLogin, ['enter'])}
/> />
</NFormItem> </NFormItem>
</NForm> </NForm>
@ -86,15 +81,14 @@ const login = defineComponent({
round round
type='info' type='info'
style={{ width: '100%' }} style={{ width: '100%' }}
onClick={this.handleLogin} onClick={handleLogin}
> >
{this.t('login.login')} {t('login.login')}
</NButton> </NButton>
</div> </div>
</div> </div>
</div> </div>
) )
}, }
})
export default login export default login

Loading…
Cancel
Save