Browse Source

[Feature][UI Next][V1.0.0-Alpha] Timezone to support search (#8872)

* timezone to support search

* Update data after switching time zones

* add blank after scss
3.0.0/version-upgrade
Devosend 2 years ago committed by GitHub
parent
commit
3bbca9d101
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      dolphinscheduler-ui-next/src/layouts/content/components/timezone/index.module.scss
  2. 72
      dolphinscheduler-ui-next/src/layouts/content/components/timezone/index.tsx
  3. 15
      dolphinscheduler-ui-next/src/layouts/content/components/timezone/use-dropdown.ts
  4. 3
      dolphinscheduler-ui-next/src/locales/modules/en_US.ts
  5. 3
      dolphinscheduler-ui-next/src/locales/modules/zh_CN.ts

5
dolphinscheduler-ui-next/src/layouts/content/components/timezone/index.module.scss

@ -18,3 +18,8 @@
.icon { .icon {
margin: 0 12px; margin: 0 12px;
} }
.custom-select {
margin: 10px;
width: auto;
}

72
dolphinscheduler-ui-next/src/layouts/content/components/timezone/index.tsx

@ -15,8 +15,9 @@
* limitations under the License. * limitations under the License.
*/ */
import { defineComponent, ref, PropType } from 'vue' import { useI18n } from 'vue-i18n'
import { NIcon, NButton, NPopselect } from 'naive-ui' import { defineComponent, ref, PropType, computed, h, inject } from 'vue'
import { NIcon, NButton, NSelect, NDropdown, NTag } from 'naive-ui'
import styles from './index.module.scss' import styles from './index.module.scss'
import { DownOutlined } from '@vicons/antd' import { DownOutlined } from '@vicons/antd'
import { useDropDown } from './use-dropdown' import { useDropDown } from './use-dropdown'
@ -24,6 +25,7 @@ import { useTimezoneStore } from '@/store/timezone/timezone'
const Timezone = defineComponent({ const Timezone = defineComponent({
name: 'Timezone', name: 'Timezone',
inject: ['reload'],
props: { props: {
timezoneOptions: { timezoneOptions: {
type: Array as PropType<any>, type: Array as PropType<any>,
@ -31,6 +33,8 @@ const Timezone = defineComponent({
} }
}, },
setup(props) { setup(props) {
const { t } = useI18n()
const reload: any = inject('reload')
const timezoneStore = useTimezoneStore() const timezoneStore = useTimezoneStore()
const chooseVal = ref( const chooseVal = ref(
props.timezoneOptions.filter( props.timezoneOptions.filter(
@ -38,17 +42,65 @@ const Timezone = defineComponent({
)[0].label )[0].label
) )
const { handleSelect } = useDropDown(chooseVal) const currentTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
const options = [
{
label: currentTimeZone,
key: currentTimeZone
},
{
key: 'header-divider',
type: 'divider'
},
{
key: 'footer',
type: 'render',
render: () => (
<NSelect
class={styles['custom-select']}
filterable
size='small'
placeholder={t('profile.please_select_timezone')}
options={props.timezoneOptions}
onUpdateValue={handleSelect}
/>
)
}
]
const renderDropdownLabel = (option: any) => {
if (option.label === currentTimeZone) {
return h('div', null, [
h('span', null, option.label),
h(
NTag,
{ type: 'info', size: 'small', style: 'margin-left: 10px' },
{ default: () => 'Local' }
)
])
} else {
return option.label
}
}
const optionsVal = computed(() =>
currentTimeZone === chooseVal.value
? options
: [{ label: chooseVal.value, key: chooseVal.value }, ...options]
)
const { handleSelect } = useDropDown(chooseVal, reload)
return { handleSelect, chooseVal } return { handleSelect, chooseVal, optionsVal, renderDropdownLabel }
}, },
render() { render() {
return ( return (
<NPopselect <NDropdown
options={this.timezoneOptions} trigger='hover'
trigger='click' show-arrow
scrollable options={this.optionsVal}
onUpdateValue={this.handleSelect} on-select={this.handleSelect}
renderLabel={this.renderDropdownLabel}
> >
<NButton text> <NButton text>
{this.chooseVal} {this.chooseVal}
@ -56,7 +108,7 @@ const Timezone = defineComponent({
<DownOutlined /> <DownOutlined />
</NIcon> </NIcon>
</NButton> </NButton>
</NPopselect> </NDropdown>
) )
} }
}) })

15
dolphinscheduler-ui-next/src/layouts/content/components/timezone/use-dropdown.ts

@ -15,21 +15,18 @@
* limitations under the License. * limitations under the License.
*/ */
import { useI18n } from 'vue-i18n'
import { updateUser } from '@/service/modules/users' import { updateUser } from '@/service/modules/users'
import { useTimezoneStore } from '@/store/timezone/timezone' import { useTimezoneStore } from '@/store/timezone/timezone'
import { useUserStore } from '@/store/user/user' import { useUserStore } from '@/store/user/user'
import type { UserInfoRes } from '@/service/modules/users/types' import type { UserInfoRes } from '@/service/modules/users/types'
export function useDropDown(chooseVal: any) { export function useDropDown(chooseVal: any, reload: any) {
const { t } = useI18n()
const userStore = useUserStore() const userStore = useUserStore()
const timezoneStore = useTimezoneStore() const timezoneStore = useTimezoneStore()
const userInfo = userStore.userInfo as UserInfoRes const userInfo = userStore.userInfo as UserInfoRes
const handleSelect = (value: string) => { const handleSelect = (key: string) => {
updateUser({ updateUser({
userPassword: '', userPassword: '',
id: userInfo.id, id: userInfo.id,
@ -38,11 +35,11 @@ export function useDropDown(chooseVal: any) {
email: '', email: '',
phone: userInfo.phone, phone: userInfo.phone,
state: userInfo.state, state: userInfo.state,
timeZone: value timeZone: key
}).then(() => { }).then(() => {
chooseVal.value = value chooseVal.value = key
timezoneStore.setTimezone(value as string) timezoneStore.setTimezone(key as string)
window.$message.success(t('profile.timezone_success')) reload()
}) })
} }

3
dolphinscheduler-ui-next/src/locales/modules/en_US.ts

@ -137,7 +137,8 @@ const profile = {
state_tips: 'Please choose your state', state_tips: 'Please choose your state',
enable: 'Enable', enable: 'Enable',
disable: 'Disable', disable: 'Disable',
timezone_success: 'Time zone updated successful' timezone_success: 'Time zone updated successful',
please_select_timezone: 'Choose timeZone'
} }
const monitor = { const monitor = {

3
dolphinscheduler-ui-next/src/locales/modules/zh_CN.ts

@ -136,7 +136,8 @@ const profile = {
state_tips: '请选择状态', state_tips: '请选择状态',
enable: '启用', enable: '启用',
disable: '禁用', disable: '禁用',
timezone_success: '时区更新成功' timezone_success: '时区更新成功',
please_select_timezone: '请选择时区'
} }
const monitor = { const monitor = {

Loading…
Cancel
Save