mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 17:24:26 +08:00
migrate color/icon selection sheet to composition API and typescript
This commit is contained in:
@@ -28,50 +28,48 @@
|
|||||||
</f7-sheet>
|
</f7-sheet>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script setup lang="ts">
|
||||||
|
import { type Ref, ref, computed } from 'vue';
|
||||||
|
|
||||||
|
import type { ColorValue, ColorInfo } from '@/core/color.ts';
|
||||||
import { arrayContainsFieldValue } from '@/lib/common.ts';
|
import { arrayContainsFieldValue } from '@/lib/common.ts';
|
||||||
import { getColorsInRows } from '@/lib/color.ts';
|
import { getColorsInRows } from '@/lib/color.ts';
|
||||||
import { scrollToSelectedItem } from '@/lib/ui/mobile.js';
|
import { scrollToSelectedItem } from '@/lib/ui/mobile.js';
|
||||||
|
|
||||||
export default {
|
const props = defineProps<{
|
||||||
props: [
|
modelValue: ColorValue;
|
||||||
'modelValue',
|
show: boolean;
|
||||||
'columnCount',
|
columnCount?: number;
|
||||||
'show',
|
allColorInfos: ColorValue[];
|
||||||
'allColorInfos'
|
}>();
|
||||||
],
|
|
||||||
emits: [
|
|
||||||
'update:modelValue',
|
|
||||||
'update:show'
|
|
||||||
],
|
|
||||||
data() {
|
|
||||||
const self = this;
|
|
||||||
|
|
||||||
return {
|
const emit = defineEmits<{
|
||||||
currentValue: self.modelValue,
|
(e: 'update:modelValue', value: ColorValue): void
|
||||||
itemPerRow: self.columnCount || 7
|
(e: 'update:show', value: boolean): void
|
||||||
}
|
}>();
|
||||||
},
|
|
||||||
computed: {
|
const currentValue: Ref<ColorValue> = ref(props.modelValue);
|
||||||
allColorRows() {
|
const itemPerRow: Ref<number> = ref(props.columnCount || 7);
|
||||||
return getColorsInRows(this.allColorInfos, this.itemPerRow);
|
|
||||||
}
|
const allColorRows = computed<ColorInfo[][]>(() => {
|
||||||
},
|
return getColorsInRows(props.allColorInfos, itemPerRow.value);
|
||||||
methods: {
|
});
|
||||||
onColorClicked(colorInfo) {
|
|
||||||
this.currentValue = colorInfo.color;
|
function onColorClicked(colorInfo: ColorInfo) {
|
||||||
this.$emit('update:modelValue', this.currentValue);
|
currentValue.value = colorInfo.color;
|
||||||
},
|
emit('update:modelValue', currentValue.value);
|
||||||
onSheetOpen(event) {
|
}
|
||||||
this.currentValue = this.modelValue;
|
|
||||||
scrollToSelectedItem(event.$el, '.page-content', '.row-has-selected-item');
|
function hasSelectedIcon(row: ColorInfo[]) {
|
||||||
},
|
return arrayContainsFieldValue(row, 'id', currentValue.value);
|
||||||
onSheetClosed() {
|
}
|
||||||
this.$emit('update:show', false);
|
|
||||||
},
|
function onSheetOpen(event: { $el: HTMLElement }) {
|
||||||
hasSelectedIcon(row) {
|
currentValue.value = props.modelValue;
|
||||||
return arrayContainsFieldValue(row, 'id', this.currentValue);
|
scrollToSelectedItem(event.$el, '.page-content', '.row-has-selected-item');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
function onSheetClosed() {
|
||||||
|
emit('update:show', false);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -28,61 +28,59 @@
|
|||||||
</f7-sheet>
|
</f7-sheet>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script setup lang="ts">
|
||||||
|
import { type Ref, ref, computed } from 'vue';
|
||||||
|
|
||||||
|
import type { IconInfo, IconInfoWithId } from '@/core/icon.ts';
|
||||||
import { arrayContainsFieldValue } from '@/lib/common.ts';
|
import { arrayContainsFieldValue } from '@/lib/common.ts';
|
||||||
import { getIconsInRows } from '@/lib/icon.ts';
|
import { getIconsInRows } from '@/lib/icon.ts';
|
||||||
import { scrollToSelectedItem } from '@/lib/ui/mobile.js';
|
import { scrollToSelectedItem } from '@/lib/ui/mobile.js';
|
||||||
|
|
||||||
export default {
|
const props = defineProps<{
|
||||||
props: [
|
modelValue: string;
|
||||||
'modelValue',
|
show: boolean;
|
||||||
'color',
|
columnCount?: number;
|
||||||
'columnCount',
|
color: string;
|
||||||
'show',
|
allIconInfos: Record<string, IconInfo>;
|
||||||
'allIconInfos'
|
}>();
|
||||||
],
|
|
||||||
emits: [
|
|
||||||
'update:modelValue',
|
|
||||||
'update:show'
|
|
||||||
],
|
|
||||||
data() {
|
|
||||||
const self = this;
|
|
||||||
|
|
||||||
return {
|
const emit = defineEmits<{
|
||||||
currentValue: self.modelValue,
|
(e: 'update:modelValue', value: string): void
|
||||||
itemPerRow: self.columnCount || 7
|
(e: 'update:show', value: boolean): void
|
||||||
}
|
}>();
|
||||||
},
|
|
||||||
computed: {
|
const currentValue: Ref<string> = ref(props.modelValue);
|
||||||
allIconRows() {
|
const itemPerRow: Ref<number> = ref(props.columnCount || 7);
|
||||||
return getIconsInRows(this.allIconInfos, this.itemPerRow);
|
|
||||||
},
|
const allIconRows = computed<IconInfoWithId[][]>(() => {
|
||||||
heightClass() {
|
return getIconsInRows(props.allIconInfos, itemPerRow.value);
|
||||||
if (this.allIconRows.length > 10) {
|
});
|
||||||
return 'icon-selection-huge-sheet';
|
|
||||||
} else if (this.allIconRows.length > 6) {
|
const heightClass = computed<string>(() => {
|
||||||
return 'icon-selection-large-sheet';
|
if (allIconRows.value.length > 10) {
|
||||||
} else {
|
return 'icon-selection-huge-sheet';
|
||||||
return '';
|
} else if (allIconRows.value.length > 6) {
|
||||||
}
|
return 'icon-selection-large-sheet';
|
||||||
}
|
} else {
|
||||||
},
|
return '';
|
||||||
methods: {
|
|
||||||
onIconClicked(iconInfo) {
|
|
||||||
this.currentValue = iconInfo.id;
|
|
||||||
this.$emit('update:modelValue', this.currentValue);
|
|
||||||
},
|
|
||||||
onSheetOpen(event) {
|
|
||||||
this.currentValue = this.modelValue;
|
|
||||||
scrollToSelectedItem(event.$el, '.page-content', '.row-has-selected-item');
|
|
||||||
},
|
|
||||||
onSheetClosed() {
|
|
||||||
this.$emit('update:show', false);
|
|
||||||
},
|
|
||||||
hasSelectedIcon(row) {
|
|
||||||
return arrayContainsFieldValue(row, 'id', this.currentValue);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function onIconClicked(iconInfo: IconInfoWithId) {
|
||||||
|
currentValue.value = iconInfo.id;
|
||||||
|
emit('update:modelValue', currentValue.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasSelectedIcon(row: IconInfoWithId[]) {
|
||||||
|
return arrayContainsFieldValue(row, 'id', currentValue.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSheetOpen(event: { $el: HTMLElement }) {
|
||||||
|
scrollToSelectedItem(event.$el, '.page-content', '.row-has-selected-item');
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSheetClosed() {
|
||||||
|
emit('update:show', false);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user