Datepicker internationalisation
This commit is contained in:
@@ -1,5 +1,10 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
|
import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
|
||||||
|
import { useI18n } from '../composables/useI18n'
|
||||||
|
|
||||||
|
|
||||||
|
const { locale, setLocale, getTranslation ,t} = useI18n()
|
||||||
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
modelValue?: string | [string, string]
|
modelValue?: string | [string, string]
|
||||||
@@ -68,6 +73,10 @@ const formatDisplayDate = (dateStr: string) => {
|
|||||||
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`
|
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getMonth = (key: string): string => {
|
||||||
|
return getTranslation(key)
|
||||||
|
}
|
||||||
|
|
||||||
// 显示值
|
// 显示值
|
||||||
const displayValue = computed(() => {
|
const displayValue = computed(() => {
|
||||||
if (props.type === 'daterange') {
|
if (props.type === 'daterange') {
|
||||||
@@ -464,6 +473,7 @@ const yearList = computed(() => {
|
|||||||
return years
|
return years
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
// 月份名称
|
// 月份名称
|
||||||
const monthNames = [
|
const monthNames = [
|
||||||
'一月',
|
'一月',
|
||||||
@@ -480,6 +490,7 @@ const monthNames = [
|
|||||||
'十二月',
|
'十二月',
|
||||||
]
|
]
|
||||||
const weekDays = ['日', '一', '二', '三', '四', '五', '六']
|
const weekDays = ['日', '一', '二', '三', '四', '五', '六']
|
||||||
|
*/
|
||||||
|
|
||||||
// 生命周期
|
// 生命周期
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
@@ -736,7 +747,7 @@ const panelStyle = computed(() => {
|
|||||||
<<
|
<<
|
||||||
</button>
|
</button>
|
||||||
<span class="el-month-picker__header-label" @click="showYearSelector($event)">
|
<span class="el-month-picker__header-label" @click="showYearSelector($event)">
|
||||||
{{ currentYear }}年
|
{{ currentYear }}
|
||||||
</span>
|
</span>
|
||||||
<button type="button" class="el-picker-panel__icon-btn" @click="nextYear">
|
<button type="button" class="el-picker-panel__icon-btn" @click="nextYear">
|
||||||
>>
|
>>
|
||||||
@@ -744,7 +755,7 @@ const panelStyle = computed(() => {
|
|||||||
</div>
|
</div>
|
||||||
<div class="el-month-picker__content">
|
<div class="el-month-picker__content">
|
||||||
<div
|
<div
|
||||||
v-for="(monthName, index) in monthNames"
|
v-for="(monthName, index) in t.monthNames"
|
||||||
:key="index"
|
:key="index"
|
||||||
class="el-month-picker__item"
|
class="el-month-picker__item"
|
||||||
:class="{ 'is-current': index === currentMonth }"
|
:class="{ 'is-current': index === currentMonth }"
|
||||||
@@ -766,10 +777,10 @@ const panelStyle = computed(() => {
|
|||||||
</button>
|
</button>
|
||||||
<span class="el-date-picker__header-label">
|
<span class="el-date-picker__header-label">
|
||||||
<span class="el-date-picker__header-year" @click="showYearSelector($event)">
|
<span class="el-date-picker__header-year" @click="showYearSelector($event)">
|
||||||
{{ currentYear }}年
|
{{ currentYear }}
|
||||||
</span>
|
</span>
|
||||||
<span class="el-date-picker__header-month" @click="showMonthSelector($event)">
|
<span class="el-date-picker__header-month" @click="showMonthSelector($event)">
|
||||||
{{ monthNames[currentMonth] }}
|
{{ t.monthNames[currentMonth] }}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<button type="button" class="el-picker-panel__icon-btn" @click="nextMonth">
|
<button type="button" class="el-picker-panel__icon-btn" @click="nextMonth">
|
||||||
@@ -783,7 +794,7 @@ const panelStyle = computed(() => {
|
|||||||
<div class="el-date-picker__content">
|
<div class="el-date-picker__content">
|
||||||
<!-- 星期标题 -->
|
<!-- 星期标题 -->
|
||||||
<div class="el-date-table__header">
|
<div class="el-date-table__header">
|
||||||
<div v-for="day in weekDays" :key="day" class="el-date-table__header-cell">
|
<div v-for="day in t.weekDays" :key="day" class="el-date-table__header-cell">
|
||||||
{{ day }}
|
{{ day }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -39,6 +39,23 @@ const messages = {
|
|||||||
// 月份格式
|
// 月份格式
|
||||||
monthFormat: (month: number) => `${month}月`,
|
monthFormat: (month: number) => `${month}月`,
|
||||||
|
|
||||||
|
// 月份名称
|
||||||
|
monthNames: [
|
||||||
|
'一月',
|
||||||
|
'二月',
|
||||||
|
'三月',
|
||||||
|
'四月',
|
||||||
|
'五月',
|
||||||
|
'六月',
|
||||||
|
'七月',
|
||||||
|
'八月',
|
||||||
|
'九月',
|
||||||
|
'十月',
|
||||||
|
'十一月',
|
||||||
|
'十二月',
|
||||||
|
],
|
||||||
|
weekDays:['日', '一', '二', '三', '四', '五', '六'],
|
||||||
|
|
||||||
// 其他
|
// 其他
|
||||||
milestone: '里程碑',
|
milestone: '里程碑',
|
||||||
targetDate: '目标日期',
|
targetDate: '目标日期',
|
||||||
@@ -191,6 +208,22 @@ const messages = {
|
|||||||
// 月份格式
|
// 月份格式
|
||||||
monthFormat: (month: number) => `M${String(month).padStart(2, '0')}`,
|
monthFormat: (month: number) => `M${String(month).padStart(2, '0')}`,
|
||||||
|
|
||||||
|
// Month name
|
||||||
|
monthNames: [
|
||||||
|
'Jan',
|
||||||
|
'Feb',
|
||||||
|
'Mar',
|
||||||
|
'Apr',
|
||||||
|
'May',
|
||||||
|
'Jun',
|
||||||
|
'Jul',
|
||||||
|
'Aug',
|
||||||
|
'Sep',
|
||||||
|
'Oct',
|
||||||
|
'Nov',
|
||||||
|
'Dec',
|
||||||
|
],
|
||||||
|
weekDays:['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
||||||
// 其他
|
// 其他
|
||||||
milestone: 'Milestone',
|
milestone: 'Milestone',
|
||||||
targetDate: 'Target Date',
|
targetDate: 'Target Date',
|
||||||
|
|||||||
Reference in New Issue
Block a user