code refactor

This commit is contained in:
MaysWind
2025-01-11 13:59:47 +08:00
parent 61f26e060e
commit 89b233e51b
25 changed files with 128 additions and 128 deletions
+10 -10
View File
@@ -29,14 +29,14 @@
</template>
<script setup lang="ts">
import { type Ref, ref, computed } from 'vue';
import { ref, computed } from 'vue';
import { useI18n } from '@/locales/helpers.ts';
import type { ColorValue, ColorInfo } from '@/core/color.ts';
import { arrayContainsFieldValue } from '@/lib/common.ts';
import { getColorsInRows } from '@/lib/color.ts';
import { scrollToSelectedItem } from '@/lib/ui/mobile.ts';
import { type Framework7Dom, scrollToSelectedItem } from '@/lib/ui/mobile.ts';
const props = defineProps<{
modelValue: ColorValue;
@@ -46,34 +46,34 @@ const props = defineProps<{
}>();
const emit = defineEmits<{
(e: 'update:modelValue', value: ColorValue): void
(e: 'update:show', value: boolean): void
(e: 'update:modelValue', value: ColorValue): void;
(e: 'update:show', value: boolean): void;
}>();
const { tt } = useI18n();
const currentValue: Ref<ColorValue> = ref(props.modelValue);
const itemPerRow: Ref<number> = ref(props.columnCount || 7);
const currentValue = ref<ColorValue>(props.modelValue);
const itemPerRow = ref<number>(props.columnCount || 7);
const allColorRows = computed<ColorInfo[][]>(() => {
return getColorsInRows(props.allColorInfos, itemPerRow.value);
});
function onColorClicked(colorInfo: ColorInfo) {
function onColorClicked(colorInfo: ColorInfo): void {
currentValue.value = colorInfo.color;
emit('update:modelValue', currentValue.value);
}
function hasSelectedIcon(row: ColorInfo[]) {
function hasSelectedIcon(row: ColorInfo[]): boolean {
return arrayContainsFieldValue(row, 'id', currentValue.value);
}
function onSheetOpen(event: { $el: HTMLElement }) {
function onSheetOpen(event: { $el: Framework7Dom }): void {
currentValue.value = props.modelValue;
scrollToSelectedItem(event.$el, '.page-content', '.row-has-selected-item');
}
function onSheetClosed() {
function onSheetClosed(): void {
emit('update:show', false);
}
</script>
+10 -10
View File
@@ -29,14 +29,14 @@
</template>
<script setup lang="ts">
import { type Ref, ref, computed } from 'vue';
import { ref, computed } from 'vue';
import { useI18n } from '@/locales/helpers.ts';
import type { IconInfo, IconInfoWithId } from '@/core/icon.ts';
import { arrayContainsFieldValue } from '@/lib/common.ts';
import { getIconsInRows } from '@/lib/icon.ts';
import { scrollToSelectedItem } from '@/lib/ui/mobile.ts';
import { type Framework7Dom, scrollToSelectedItem } from '@/lib/ui/mobile.ts';
const props = defineProps<{
modelValue: string;
@@ -47,14 +47,14 @@ const props = defineProps<{
}>();
const emit = defineEmits<{
(e: 'update:modelValue', value: string): void
(e: 'update:show', value: boolean): void
(e: 'update:modelValue', value: string): void;
(e: 'update:show', value: boolean): void;
}>();
const { tt } = useI18n();
const currentValue: Ref<string> = ref(props.modelValue);
const itemPerRow: Ref<number> = ref(props.columnCount || 7);
const currentValue = ref<string>(props.modelValue);
const itemPerRow = ref<number>(props.columnCount || 7);
const allIconRows = computed<IconInfoWithId[][]>(() => {
return getIconsInRows(props.allIconInfos, itemPerRow.value);
@@ -70,20 +70,20 @@ const heightClass = computed<string>(() => {
}
});
function onIconClicked(iconInfo: IconInfoWithId) {
function onIconClicked(iconInfo: IconInfoWithId): void {
currentValue.value = iconInfo.id;
emit('update:modelValue', currentValue.value);
}
function hasSelectedIcon(row: IconInfoWithId[]) {
function hasSelectedIcon(row: IconInfoWithId[]): boolean {
return arrayContainsFieldValue(row, 'id', currentValue.value);
}
function onSheetOpen(event: { $el: HTMLElement }) {
function onSheetOpen(event: { $el: Framework7Dom }): void {
scrollToSelectedItem(event.$el, '.page-content', '.row-has-selected-item');
}
function onSheetClosed() {
function onSheetClosed(): void {
emit('update:show', false);
}
</script>
+6 -6
View File
@@ -41,17 +41,17 @@ const props = defineProps<{
}>();
const emit = defineEmits<{
(e: 'update:show', value: boolean): void
(e: 'info:copied'): void
(e: 'update:show', value: boolean): void;
(e: 'info:copied'): void;
}>();
const { tt } = useI18n();
const iconCopyToClipboard = useTemplateRef('copyToClipboardIcon');
const iconCopyToClipboard = useTemplateRef<unknown>('copyToClipboardIcon');
let clipboardHolder: ClipboardHolder | null = null;
function makeCopyToClipboardClickable() {
function makeCopyToClipboardClickable(): void {
if (clipboardHolder) {
return;
}
@@ -67,11 +67,11 @@ function makeCopyToClipboardClickable() {
}
}
function close() {
function close(): void {
emit('update:show', false);
}
function onSheetClosed() {
function onSheetClosed(): void {
close();
}
+6 -6
View File
@@ -46,8 +46,8 @@ const props = defineProps<{
}>();
const emit = defineEmits<{
(e: 'update:modelValue', value: MapPosition | undefined): void,
(e: 'update:show', value: boolean): void
(e: 'update:modelValue', value: MapPosition | undefined): void;
(e: 'update:show', value: boolean): void;
}>();
const { tt } = useI18n();
@@ -63,21 +63,21 @@ const geoLocation = computed<MapPosition | undefined>({
}
});
function save() {
function save(): void {
emit('update:show', false);
}
function close() {
function close(): void {
emit('update:show', false);
}
function onSheetOpen() {
function onSheetOpen(): void {
if (map.value) {
map.value.initMapView();
}
}
function onSheetClosed() {
function onSheetClosed(): void {
close();
}
</script>
+6 -6
View File
@@ -66,7 +66,7 @@
</template>
<script setup lang="ts">
import { type Ref, ref, computed } from 'vue';
import { ref, computed } from 'vue';
import { useI18n } from '@/locales/helper.js';
import { useI18nUIComponents } from '@/lib/ui/mobile.ts';
@@ -95,13 +95,13 @@ const props = defineProps<{
}>();
const emit = defineEmits<{
(e: 'update:modelValue', value: number): void,
(e: 'update:show', value: boolean): void
(e: 'update:modelValue', value: number): void;
(e: 'update:show', value: boolean): void;
}>();
const previousValue: Ref<string> = ref('');
const currentSymbol: Ref<string> = ref('');
const currentValue: Ref<string> = ref(getStringValue(props.modelValue));
const previousValue = ref<string>('');
const currentSymbol = ref<string>('');
const currentValue = ref<string>(getStringValue(props.modelValue));
const decimalSeparator = computed<string>(() => getCurrentDecimalSeparator(userStore));
+10 -10
View File
@@ -37,7 +37,7 @@
</template>
<script setup lang="ts">
import { type Ref, ref } from 'vue';
import { ref } from 'vue';
import { useI18n } from '@/locales/helpers.ts';
@@ -51,16 +51,16 @@ const props = defineProps<{
}>();
const emit = defineEmits<{
(e: 'update:modelValue', value: string): void
(e: 'update:show', value: boolean): void
(e: 'passcode:confirm', value: string): void
(e: 'update:modelValue', value: string): void;
(e: 'update:show', value: boolean): void;
(e: 'passcode:confirm', value: string): void;
}>();
const { tt } = useI18n();
const currentPasscode: Ref<string> = ref('');
const currentPasscode = ref<string>('');
function confirm() {
function confirm(): void {
if (!currentPasscode.value || props.confirmDisabled) {
return;
}
@@ -69,19 +69,19 @@ function confirm() {
emit('passcode:confirm', currentPasscode.value);
}
function cancel() {
function cancel(): void {
close();
}
function close() {
function close(): void {
emit('update:show', false);
}
function onSheetOpen() {
function onSheetOpen(): void {
currentPasscode.value = '';
}
function onSheetClosed() {
function onSheetClosed(): void {
close();
}
</script>
+10 -10
View File
@@ -38,7 +38,7 @@
</template>
<script setup lang="ts">
import { type Ref, ref } from 'vue';
import { ref } from 'vue';
import { useI18n } from '@/locales/helpers.ts';
@@ -53,16 +53,16 @@ const props = defineProps<{
}>();
const emit = defineEmits<{
(e: 'update:modelValue', value: string): void
(e: 'update:show', value: boolean): void
(e: 'password:confirm', value: string): void
(e: 'update:modelValue', value: string): void;
(e: 'update:show', value: boolean): void;
(e: 'password:confirm', value: string): void;
}>();
const { tt } = useI18n();
const currentPassword: Ref<string> = ref('');
const currentPassword = ref<string>('');
function confirm() {
function confirm(): void {
if (!currentPassword.value || props.confirmDisabled) {
return;
}
@@ -71,19 +71,19 @@ function confirm() {
emit('password:confirm', currentPassword.value);
}
function cancel() {
function cancel(): void {
close();
}
function close() {
function close(): void {
emit('update:show', false);
}
function onSheetOpen() {
function onSheetOpen(): void {
currentPassword.value = '';
}
function onSheetClosed() {
function onSheetClosed(): void {
close();
}
</script>
+9 -9
View File
@@ -27,7 +27,7 @@
</template>
<script setup lang="ts">
import { type Ref, ref, computed } from 'vue';
import { ref, computed } from 'vue';
import { useI18n } from '@/locales/helpers.ts';
@@ -41,20 +41,20 @@ const props = defineProps<{
}>();
const emit = defineEmits<{
(e: 'update:modelValue', value: string): void
(e: 'update:show', value: boolean): void
(e: 'pincode:confirm', value: string): void
(e: 'update:modelValue', value: string): void;
(e: 'update:show', value: boolean): void;
(e: 'pincode:confirm', value: string): void;
}>();
const { tt } = useI18n();
const currentPinCode: Ref<string> = ref('');
const currentPinCode = ref<string>('');
const currentPinCodeValid = computed<boolean>(() => {
return currentPinCode.value?.length === 6 || false;
});
function confirm() {
function confirm(): void {
if (!currentPinCodeValid.value || props.confirmDisabled) {
return;
}
@@ -63,15 +63,15 @@ function confirm() {
emit('pincode:confirm', currentPinCode.value);
}
function cancel() {
function cancel(): void {
emit('update:show', false);
}
function onSheetOpen() {
function onSheetOpen(): void {
currentPinCode.value = '';
}
function onSheetClosed() {
function onSheetClosed(): void {
cancel();
}
</script>