解决多语言切换时部分组件文本未更新问题
This commit is contained in:
@@ -8,11 +8,11 @@ export class DayUts {
|
||||
private _date: Date;
|
||||
|
||||
constructor(date?: Date | string | number | null) {
|
||||
if (date === null) {
|
||||
if (date == null || date == "") {
|
||||
this._date = new Date();
|
||||
} else if (typeof date === "string") {
|
||||
} else if (typeof date == "string") {
|
||||
this._date = new Date(date);
|
||||
} else if (typeof date === "number") {
|
||||
} else if (typeof date == "number") {
|
||||
this._date = new Date(date);
|
||||
} else if (date instanceof Date) {
|
||||
this._date = new Date(date.getTime());
|
||||
@@ -74,7 +74,7 @@ export class DayUts {
|
||||
/**
|
||||
* 获取某个单位的开始时间
|
||||
*/
|
||||
startOf(unit: "month" | "day" | "year"): DayUts {
|
||||
startOf(unit: "month" | "day" | "year" | "week"): DayUts {
|
||||
const newDate = new Date(this._date.getTime());
|
||||
|
||||
switch (unit) {
|
||||
@@ -93,6 +93,13 @@ export class DayUts {
|
||||
newDate.setSeconds(0);
|
||||
newDate.setMilliseconds(0);
|
||||
break;
|
||||
case "week":
|
||||
newDate.setDate(newDate.getDate() - newDate.getDay());
|
||||
newDate.setHours(0);
|
||||
newDate.setMinutes(0);
|
||||
newDate.setSeconds(0);
|
||||
newDate.setMilliseconds(0);
|
||||
break;
|
||||
case "day":
|
||||
newDate.setHours(0);
|
||||
newDate.setMinutes(0);
|
||||
@@ -107,7 +114,7 @@ export class DayUts {
|
||||
/**
|
||||
* 获取某个单位的结束时间
|
||||
*/
|
||||
endOf(unit: "month" | "day" | "year"): DayUts {
|
||||
endOf(unit: "month" | "day" | "year" | "week"): DayUts {
|
||||
const newDate = new Date(this._date.getTime());
|
||||
|
||||
switch (unit) {
|
||||
@@ -120,7 +127,6 @@ export class DayUts {
|
||||
newDate.setMilliseconds(999);
|
||||
break;
|
||||
case "month":
|
||||
// 设置到下个月的第一天,然后减一天
|
||||
newDate.setMonth(newDate.getMonth() + 1);
|
||||
newDate.setDate(0);
|
||||
newDate.setHours(23);
|
||||
@@ -128,6 +134,13 @@ export class DayUts {
|
||||
newDate.setSeconds(59);
|
||||
newDate.setMilliseconds(999);
|
||||
break;
|
||||
case "week":
|
||||
newDate.setDate(newDate.getDate() + 7);
|
||||
newDate.setHours(23);
|
||||
newDate.setMinutes(59);
|
||||
newDate.setSeconds(59);
|
||||
newDate.setMilliseconds(999);
|
||||
break;
|
||||
case "day":
|
||||
newDate.setHours(23);
|
||||
newDate.setMinutes(59);
|
||||
@@ -160,7 +173,7 @@ export class DayUts {
|
||||
*/
|
||||
isSame(date: DayUts | Date | string | number): boolean {
|
||||
const compareDate = this._parseDate(date);
|
||||
return this._date.getTime() === compareDate.getTime();
|
||||
return this._date.getTime() == compareDate.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,9 +282,9 @@ export class DayUts {
|
||||
return date.toDate();
|
||||
} else if (date instanceof Date) {
|
||||
return date;
|
||||
} else if (typeof date === "string") {
|
||||
} else if (typeof date == "string") {
|
||||
return new Date(date);
|
||||
} else if (typeof date === "number") {
|
||||
} else if (typeof date == "number") {
|
||||
return new Date(date);
|
||||
} else {
|
||||
// 如果都不匹配,返回当前时间
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,13 +1,13 @@
|
||||
<template>
|
||||
<cl-page>
|
||||
<view class="p-3 overflow-visible">
|
||||
<demo-item label="单列排序">
|
||||
<demo-item :label="t('单列排序')">
|
||||
<cl-draggable v-model="list">
|
||||
<template #item="{ item, index }">
|
||||
<view
|
||||
class="flex flex-row items-center p-3 bg-surface-100 rounded-lg mb-2"
|
||||
class="flex flex-row items-center p-3 bg-surface-100 rounded-lg mb-2 dark:!bg-surface-700"
|
||||
:class="{
|
||||
'!bg-surface-300': item['disabled']
|
||||
'opacity-50': item['disabled']
|
||||
}"
|
||||
>
|
||||
<cl-text>{{ (item as UTSJSONObject).label }}</cl-text>
|
||||
@@ -16,7 +16,7 @@
|
||||
</cl-draggable>
|
||||
</demo-item>
|
||||
|
||||
<demo-item label="结合列表使用">
|
||||
<demo-item :label="t('结合列表使用')">
|
||||
<cl-list border>
|
||||
<cl-draggable v-model="list2">
|
||||
<template #item="{ item, index, dragging, dragIndex }">
|
||||
@@ -36,13 +36,13 @@
|
||||
</cl-list>
|
||||
</demo-item>
|
||||
|
||||
<demo-item label="多列排序">
|
||||
<demo-item :label="t('多列排序')">
|
||||
<cl-draggable v-model="list3" :columns="4">
|
||||
<template #item="{ item, index }">
|
||||
<view
|
||||
class="flex flex-row items-center justify-center p-3 bg-surface-100 rounded-lg m-1"
|
||||
class="flex flex-row items-center justify-center p-3 bg-surface-100 rounded-lg m-1 dark:!bg-surface-700"
|
||||
:class="{
|
||||
'!bg-surface-300': (item as UTSJSONObject).disabled
|
||||
'opacity-50': item['disabled']
|
||||
}"
|
||||
>
|
||||
<cl-text>{{ (item as UTSJSONObject).label }}</cl-text>
|
||||
@@ -51,7 +51,7 @@
|
||||
</cl-draggable>
|
||||
</demo-item>
|
||||
|
||||
<demo-item label="结合图片使用">
|
||||
<demo-item :label="t('结合图片使用')">
|
||||
<cl-draggable v-model="list4" :columns="4">
|
||||
<template #item="{ item, index }">
|
||||
<view class="p-[2px]">
|
||||
@@ -72,6 +72,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { t } from "@/locale";
|
||||
import DemoItem from "../components/item.uvue";
|
||||
import { ref } from "vue";
|
||||
|
||||
|
||||
@@ -30,9 +30,14 @@
|
||||
></cl-select-date>
|
||||
</demo-item>
|
||||
|
||||
<demo-item :label="t('范围选择')">
|
||||
<cl-text :pt="{ className: 'mb-3' }">{{ form.date5 }}</cl-text>
|
||||
<cl-select-date v-model:values="form.date5" type="date" rangeable></cl-select-date>
|
||||
</demo-item>
|
||||
|
||||
<demo-item :label="t('自定义')">
|
||||
<cl-select-date
|
||||
v-model="form.date5"
|
||||
v-model="form.date6"
|
||||
:type="type"
|
||||
:label-format="labelFormat"
|
||||
:disabled="isDisabled"
|
||||
@@ -44,27 +49,55 @@
|
||||
className: 'mt-3'
|
||||
}"
|
||||
>
|
||||
<cl-list-item :label="t('年')">
|
||||
<cl-list-item label="YYYY">
|
||||
<cl-switch v-model="isYear"></cl-switch>
|
||||
</cl-list-item>
|
||||
|
||||
<cl-list-item :label="t('年-月')">
|
||||
<cl-list-item label="YYYY-MM">
|
||||
<cl-switch v-model="isMonth"></cl-switch>
|
||||
</cl-list-item>
|
||||
|
||||
<cl-list-item :label="t('年-月-日')">
|
||||
<cl-list-item
|
||||
label="YYYY-MM-DD"
|
||||
:pt="{
|
||||
label: {
|
||||
className: 'flex-[2]'
|
||||
}
|
||||
}"
|
||||
>
|
||||
<cl-switch v-model="isDate"></cl-switch>
|
||||
</cl-list-item>
|
||||
|
||||
<cl-list-item :label="t('年-月-日 时')">
|
||||
<cl-list-item
|
||||
label="YYYY-MM-DD HH"
|
||||
:pt="{
|
||||
label: {
|
||||
className: 'flex-[2]'
|
||||
}
|
||||
}"
|
||||
>
|
||||
<cl-switch v-model="isHour"></cl-switch>
|
||||
</cl-list-item>
|
||||
|
||||
<cl-list-item :label="t('年-月-日 时:分')">
|
||||
<cl-list-item
|
||||
label="YYYY-MM-DD HH:mm"
|
||||
:pt="{
|
||||
label: {
|
||||
className: 'flex-[2]'
|
||||
}
|
||||
}"
|
||||
>
|
||||
<cl-switch v-model="isMinute"></cl-switch>
|
||||
</cl-list-item>
|
||||
|
||||
<cl-list-item :label="t('年-月-日 时:分:秒')">
|
||||
<cl-list-item
|
||||
label="YYYY-MM-DD HH:mm:ss"
|
||||
:pt="{
|
||||
label: {
|
||||
className: 'flex-[2]'
|
||||
}
|
||||
}"
|
||||
>
|
||||
<cl-switch v-model="isSecond"></cl-switch>
|
||||
</cl-list-item>
|
||||
|
||||
@@ -94,7 +127,8 @@ type Form = {
|
||||
date2: string;
|
||||
date3: string;
|
||||
date4: string;
|
||||
date5: string;
|
||||
date5: string[];
|
||||
date6: string;
|
||||
};
|
||||
|
||||
const form = reactive<Form>({
|
||||
@@ -102,7 +136,8 @@ const form = reactive<Form>({
|
||||
date2: "",
|
||||
date3: "",
|
||||
date4: "",
|
||||
date5: ""
|
||||
date5: [],
|
||||
date6: ""
|
||||
});
|
||||
|
||||
const isDisabled = ref(false);
|
||||
|
||||
@@ -383,7 +383,6 @@ onMounted(() => {
|
||||
&.is-transition {
|
||||
transition-property: transform;
|
||||
transition-duration: 0.3s;
|
||||
transition-timing-function: ease;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ const props = defineProps({
|
||||
*/
|
||||
title: {
|
||||
type: String,
|
||||
default: t("请选择")
|
||||
default: () => t("请选择")
|
||||
},
|
||||
/**
|
||||
* 选择器占位符文本
|
||||
@@ -140,7 +140,7 @@ const props = defineProps({
|
||||
*/
|
||||
placeholder: {
|
||||
type: String,
|
||||
default: t("请选择")
|
||||
default: () => t("请选择")
|
||||
},
|
||||
/**
|
||||
* 选项数据源,支持树形结构
|
||||
|
||||
@@ -380,7 +380,6 @@ function getItemStyle(index: number) {
|
||||
if (props.animation > 0 && !isCurrent) {
|
||||
style["transition-property"] = "transform";
|
||||
style["transition-duration"] = `${props.animation}ms`;
|
||||
style["transition-timing-function"] = "ease";
|
||||
}
|
||||
|
||||
// 拖拽状态下的样式处理
|
||||
|
||||
@@ -37,7 +37,7 @@ const props = defineProps({
|
||||
// 空状态文本
|
||||
text: {
|
||||
type: String,
|
||||
default: t("暂无数据")
|
||||
default: () => t("暂无数据")
|
||||
},
|
||||
// 空状态图标名称
|
||||
icon: {
|
||||
|
||||
@@ -140,7 +140,7 @@ const props = defineProps({
|
||||
// 占位符
|
||||
placeholder: {
|
||||
type: String,
|
||||
default: t("请输入")
|
||||
default: () => t("请输入")
|
||||
},
|
||||
// 占位符样式类
|
||||
placeholderClass: {
|
||||
|
||||
@@ -113,12 +113,12 @@ const props = defineProps({
|
||||
// 弹窗标题
|
||||
title: {
|
||||
type: String,
|
||||
default: t("车牌键盘")
|
||||
default: () => t("车牌键盘")
|
||||
},
|
||||
// 输入框占位符
|
||||
placeholder: {
|
||||
type: String,
|
||||
default: t("安全键盘,请放心输入")
|
||||
default: () => t("安全键盘,请放心输入")
|
||||
},
|
||||
// 最大输入长度
|
||||
maxlength: {
|
||||
|
||||
@@ -117,12 +117,12 @@ const props = defineProps({
|
||||
// 弹窗标题
|
||||
title: {
|
||||
type: String,
|
||||
default: t("数字键盘")
|
||||
default: () => t("数字键盘")
|
||||
},
|
||||
// 输入框占位符
|
||||
placeholder: {
|
||||
type: String,
|
||||
default: t("安全键盘,请放心输入")
|
||||
default: () => t("安全键盘,请放心输入")
|
||||
},
|
||||
// 最大输入长度
|
||||
maxlength: {
|
||||
@@ -132,7 +132,7 @@ const props = defineProps({
|
||||
// 确认按钮文本
|
||||
confirmText: {
|
||||
type: String,
|
||||
default: t("确定")
|
||||
default: () => t("确定")
|
||||
},
|
||||
// 是否显示输入值
|
||||
showValue: {
|
||||
|
||||
@@ -140,12 +140,12 @@ const props = defineProps({
|
||||
// 弹窗标题
|
||||
title: {
|
||||
type: String,
|
||||
default: t("密码键盘")
|
||||
default: () => t("密码键盘")
|
||||
},
|
||||
// 输入框占位符
|
||||
placeholder: {
|
||||
type: String,
|
||||
default: t("安全键盘,请放心输入")
|
||||
default: () => t("安全键盘,请放心输入")
|
||||
},
|
||||
// 最小输入长度
|
||||
minlength: {
|
||||
@@ -160,7 +160,7 @@ const props = defineProps({
|
||||
// 确认按钮文本
|
||||
confirmText: {
|
||||
type: String,
|
||||
default: t("确定")
|
||||
default: () => t("确定")
|
||||
},
|
||||
// 是否显示输入值
|
||||
showValue: {
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
}"
|
||||
@tap="onTap"
|
||||
>
|
||||
<view class="cl-list-item__inner w-" :class="[pt.inner?.className]">
|
||||
<view class="cl-list-item__inner" :class="[pt.inner?.className]">
|
||||
<cl-icon
|
||||
:name="icon"
|
||||
:size="pt.icon?.size ?? 36"
|
||||
|
||||
@@ -42,7 +42,7 @@ const props = defineProps({
|
||||
// 加载中显示内容
|
||||
loadingText: {
|
||||
type: String,
|
||||
default: t("加载中")
|
||||
default: () => t("加载中")
|
||||
},
|
||||
// 是否加载完成
|
||||
finish: {
|
||||
@@ -52,7 +52,7 @@ const props = defineProps({
|
||||
// 加载完成显示内容
|
||||
finishText: {
|
||||
type: String,
|
||||
default: t("没有更多了")
|
||||
default: () => t("没有更多了")
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<view class="cl-picker-view">
|
||||
<view class="cl-picker-view__header" v-if="headers.length > 0">
|
||||
<text
|
||||
class="cl-picker-view__header-item dark:text-white"
|
||||
class="cl-picker-view__header-item dark:!text-white"
|
||||
v-for="(label, index) in headers"
|
||||
:key="index"
|
||||
>{{ label }}</text
|
||||
@@ -140,8 +140,8 @@ const indicatorStyle = computed(() => {
|
||||
|
||||
// 深色模式
|
||||
if (isDark.value) {
|
||||
style.backgroundColor = "rgba(200, 200, 200, 0.04)";
|
||||
style.border = "1rpx solid rgba(255, 255, 255, 0.5)";
|
||||
style.backgroundColor = "rgba(0, 0, 0, 0.1)";
|
||||
style.border = "1rpx solid rgba(255, 255, 255, 0.3)";
|
||||
}
|
||||
|
||||
// 构建样式字符串
|
||||
|
||||
@@ -96,12 +96,12 @@ const props = defineProps({
|
||||
// 选择器标题
|
||||
title: {
|
||||
type: String,
|
||||
default: t("请选择")
|
||||
default: () => t("请选择")
|
||||
},
|
||||
// 选择器占位符
|
||||
placeholder: {
|
||||
type: String,
|
||||
default: t("请选择")
|
||||
default: () => t("请选择")
|
||||
},
|
||||
// 是否显示选择器触发器
|
||||
showTrigger: {
|
||||
@@ -116,7 +116,7 @@ const props = defineProps({
|
||||
// 确认按钮文本
|
||||
confirmText: {
|
||||
type: String,
|
||||
default: t("确定")
|
||||
default: () => t("确定")
|
||||
},
|
||||
// 是否显示确认按钮
|
||||
showConfirm: {
|
||||
@@ -126,7 +126,7 @@ const props = defineProps({
|
||||
// 取消按钮文本
|
||||
cancelText: {
|
||||
type: String,
|
||||
default: t("取消")
|
||||
default: () => t("取消")
|
||||
},
|
||||
// 是否显示取消按钮
|
||||
showCancel: {
|
||||
|
||||
@@ -73,7 +73,7 @@ const props = defineProps({
|
||||
// 占位符文本
|
||||
placeholder: {
|
||||
type: String,
|
||||
default: t("请选择")
|
||||
default: () => t("请选择")
|
||||
},
|
||||
// 箭头图标名称
|
||||
arrowIcon: {
|
||||
|
||||
@@ -91,12 +91,12 @@ const props = defineProps({
|
||||
// 选择器标题
|
||||
title: {
|
||||
type: String,
|
||||
default: t("请选择")
|
||||
default: () => t("请选择")
|
||||
},
|
||||
// 选择器占位符
|
||||
placeholder: {
|
||||
type: String,
|
||||
default: t("请选择")
|
||||
default: () => t("请选择")
|
||||
},
|
||||
// 选项数据,支持树形结构
|
||||
options: {
|
||||
@@ -126,7 +126,7 @@ const props = defineProps({
|
||||
// 确认按钮文本
|
||||
confirmText: {
|
||||
type: String,
|
||||
default: t("确定")
|
||||
default: () => t("确定")
|
||||
},
|
||||
// 是否显示确认按钮
|
||||
showConfirm: {
|
||||
@@ -136,7 +136,7 @@ const props = defineProps({
|
||||
// 取消按钮文本
|
||||
cancelText: {
|
||||
type: String,
|
||||
default: t("取消")
|
||||
default: () => t("取消")
|
||||
},
|
||||
// 是否显示取消按钮
|
||||
showCancel: {
|
||||
|
||||
@@ -108,7 +108,7 @@ const props = defineProps({
|
||||
// 上传按钮显示的文本
|
||||
text: {
|
||||
type: String,
|
||||
default: t("上传/拍摄")
|
||||
default: () => t("上传/拍摄")
|
||||
},
|
||||
// 图片压缩方式:original原图,compressed压缩图
|
||||
sizeType: {
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
type Config = {
|
||||
zIndex: number;
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
};
|
||||
|
||||
export const config: Config = {
|
||||
zIndex: 600
|
||||
zIndex: 600,
|
||||
startDate: "1950-01-01 00:00:00",
|
||||
endDate: "2050-12-31 23:59:59"
|
||||
};
|
||||
|
||||
7
uni_modules/cool-ui/types/component.d.ts
vendored
7
uni_modules/cool-ui/types/component.d.ts
vendored
@@ -26,6 +26,13 @@ declare type ClSelectComponentPublicInstance = {
|
||||
declare type ClSelectDateComponentPublicInstance = {
|
||||
open: (cb: ((value: string) => void) | null) => void;
|
||||
close: () => void;
|
||||
setValue: (value: string) => void;
|
||||
setValues: (values: string[]) => void;
|
||||
clear: () => void;
|
||||
setRange: (index: number) => void;
|
||||
setRangeValue: (value: string[], index: number) => void;
|
||||
toDate: () => string;
|
||||
confirm: () => void;
|
||||
};
|
||||
|
||||
declare type ClSelectTimeComponentPublicInstance = {
|
||||
|
||||
@@ -123,3 +123,8 @@ export type ClUploadItem = {
|
||||
url: string;
|
||||
progress: number;
|
||||
};
|
||||
|
||||
export type ClSelectDateShortcut = {
|
||||
label: string;
|
||||
value: string[];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user