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. 86
      dolphinscheduler-ui-next/src/layouts/content/components/sidebar/index.tsx
  2. 82
      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. 130
      dolphinscheduler-ui-next/src/views/login/index.tsx

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

@ -15,53 +15,51 @@
* 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: [],
},
isShowSide: {
type: Boolean as PropType<boolean>,
default: false,
},
},
setup() {
const collapsedRef = ref(false)
const defaultExpandedKeys = [
'workflow',
'udf-manage',
'service-manage',
'statistical-manage',
]
return { collapsedRef, defaultExpandedKeys } const Sidebar = (props: Props) => {
}, // console.log('props', JSON.stringify(props))
render() { const collapsedRef = ref(false)
return ( const defaultExpandedKeys = [
this.isShowSide && ( 'workflow',
<NLayoutSider 'udf-manage',
bordered 'service-manage',
nativeScrollbar={false} 'statistical-manage',
show-trigger='bar' ]
collapse-mode='width'
collapsed={this.collapsedRef} watch(useI18n().locale, () => {
onCollapse={() => (this.collapsedRef = true)} const languageStore = useLanguageStore()
onExpand={() => (this.collapsedRef = false)} refreshOptionsRef.value = props.sideMenuOptions
> // console.log(123, JSON.stringify(props))
<NMenu })
options={this.sideMenuOptions}
defaultExpandedKeys={this.defaultExpandedKeys} const refreshOptionsRef = ref()
/>
</NLayoutSider> return (
) <NLayoutSider style={{display: props.isShowSide ? 'block' : 'none'}}
) bordered
}, nativeScrollbar={false}
}) show-trigger='bar'
collapse-mode='width'
collapsed={collapsedRef.value}
onCollapse={() => (collapsedRef.value = true)}
onExpand={() => (collapsedRef.value = false)}
>
<NMenu
options={props.sideMenuOptions || refreshOptionsRef.value}
defaultExpandedKeys={defaultExpandedKeys}
/>
</NLayoutSider>
)
}
export default Sidebar export default Sidebar

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

@ -15,58 +15,54 @@
* 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 = defineComponent({ const Content = () => {
name: 'Content',
setup() {
const { state, getHeaderMenuOptions } = useDataList()
const headerMenuOptions = getHeaderMenuOptions(state.menuOptions) const { state, getHeaderMenuOptions } = useDataList()
const sideMenuOptions = ref() const headerMenuOptions = getHeaderMenuOptions(state.menuOptions)
const getSideMenuOptions = (item: any) => { const sideMenuOptions = ref()
sideMenuOptions.value = const languageStore = useLanguageStore()
state.menuOptions.filter((menu) => menu.key === item.key)[0].children ||
[]
state.isShowSide = sideMenuOptions.value.length !== 0
}
return { const getSideMenuOptions = (item: any) => {
...toRefs(state), // console.log('item', item)
headerMenuOptions, languageStore.setMenuKey(item.key)
getSideMenuOptions, sideMenuOptions.value =
sideMenuOptions, state.menuOptions.filter((menu) => menu.key === item.key)[0].children ||
} []
}, state.isShowSide = sideMenuOptions.value.length !== 0
render() { // console.log('sideMenuOptions.value', sideMenuOptions.value)
return ( // console.log('state.isShowSide', state.isShowSide)
<NLayout style='height: 100%;'> }
<NLayoutHeader style='height: 65px;'>
<NavBar return (
onHandleMenuClick={this.getSideMenuOptions} <NLayout style='height: 100%;'>
headerMenuOptions={this.headerMenuOptions} <NLayoutHeader style='height: 65px;'>
languageOptions={this.languageOptions} <NavBar
profileOptions={this.profileOptions} onHandleMenuClick={getSideMenuOptions}
/> headerMenuOptions={headerMenuOptions}
</NLayoutHeader> languageOptions={state.languageOptions}
<NLayout has-sider position='absolute' style='top: 65px;'> profileOptions={state.profileOptions}
<SideBar />
sideMenuOptions={this.sideMenuOptions} </NLayoutHeader>
isShowSide={this.isShowSide} <NLayout has-sider position='absolute' style='top: 65px;'>
/> <SideBar
<NLayoutContent native-scrollbar={false} style='padding: 16px 22px;'> sideMenuOptions={sideMenuOptions.value}
<router-view /> isShowSide={state.isShowSide}
</NLayoutContent> />
</NLayout> <NLayoutContent native-scrollbar={false} style='padding: 16px 22px;'>
<router-view />
</NLayoutContent>
</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

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

@ -15,86 +15,80 @@
* 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', const { state, t, locale } = useValidate()
setup() {
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) } return (
}, <div class={styles.container}>
render() { <div class={styles['language-switch']}>
return ( <NSwitch
<div class={styles.container}> onUpdateValue={handleChange}
<div class={styles['language-switch']}> checked-value='en_US'
<NSwitch unchecked-value='zh_CN'
onUpdateValue={this.handleChange} >
checked-value='en_US' {{
unchecked-value='zh_CN' checked: () => 'en_US',
> unchecked: () => 'zh_CN',
{{ }}
checked: () => 'en_US', </NSwitch>
unchecked: () => 'zh_CN', </div>
}} <div class={styles['login-model']}>
</NSwitch> <div class={styles.logo}>
<div class={styles['logo-img']} />
</div> </div>
<div class={styles['login-model']}> <div class={styles['form-model']}>
<div class={styles.logo}> <NForm rules={state.rules} ref='loginFormRef'>
<div class={styles['logo-img']} /> <NFormItem
</div> label={t('login.userName')}
<div class={styles['form-model']}> label-style={{ color: 'black' }}
<NForm rules={this.rules} ref='loginFormRef'> path='userName'
<NFormItem
label={this.t('login.userName')}
label-style={{ color: 'black' }}
path='userName'
>
<NInput
type='text'
size='large'
v-model={[this.loginForm.userName, 'value']}
placeholder={this.t('login.userName_tips')}
autofocus
onKeydown={withKeys(this.handleLogin, ['enter'])}
/>
</NFormItem>
<NFormItem
label={this.t('login.userPassword')}
label-style={{ color: 'black' }}
path='userPassword'
>
<NInput
type='password'
size='large'
v-model={[this.loginForm.userPassword, 'value']}
placeholder={this.t('login.userPassword_tips')}
onKeydown={withKeys(this.handleLogin, ['enter'])}
/>
</NFormItem>
</NForm>
<NButton
round
type='info'
style={{ width: '100%' }}
onClick={this.handleLogin}
> >
{this.t('login.login')} <NInput
</NButton> type='text'
</div> size='large'
v-model={[state.loginForm.userName, 'value']}
placeholder={t('login.userName_tips')}
autofocus
onKeydown={withKeys(handleLogin, ['enter'])}
/>
</NFormItem>
<NFormItem
label={t('login.userPassword')}
label-style={{ color: 'black' }}
path='userPassword'
>
<NInput
type='password'
size='large'
v-model={[state.loginForm.userPassword, 'value']}
placeholder={t('login.userPassword_tips')}
onKeydown={withKeys(handleLogin, ['enter'])}
/>
</NFormItem>
</NForm>
<NButton
round
type='info'
style={{ width: '100%' }}
onClick={handleLogin}
>
{t('login.login')}
</NButton>
</div> </div>
</div> </div>
) </div>
}, )
}) }
export default login export default login

Loading…
Cancel
Save