migrate to typescript

This commit is contained in:
MaysWind
2024-12-29 14:24:37 +08:00
parent b638a73e4d
commit 2560a70e5e
171 changed files with 3402 additions and 2557 deletions
@@ -29,9 +29,9 @@
</template>
<script>
import { arrayContainsFieldValue } from '@/lib/common.js';
import { getColorsInRows } from '@/lib/color.js';
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
import { arrayContainsFieldValue } from '@/lib/common.ts';
import { getColorsInRows } from '@/lib/color.ts';
import { scrollToSelectedItem } from '@/lib/ui/mobile.js';
export default {
props: [
@@ -57,7 +57,7 @@ import { mapStores } from 'pinia';
import { useUserStore } from '@/stores/user.js';
import datetimeConstants from '@/consts/datetime.js';
import { arrangeArrayWithNewStartIndex } from '@/lib/common.js';
import { arrangeArrayWithNewStartIndex } from '@/lib/common.ts';
import {
getCurrentUnixTime,
getCurrentYear,
@@ -53,7 +53,7 @@ import { mapStores } from 'pinia';
import { useUserStore } from '@/stores/user.js';
import datetimeConstants from '@/consts/datetime.js';
import { arrangeArrayWithNewStartIndex } from '@/lib/common.js';
import { arrangeArrayWithNewStartIndex } from '@/lib/common.ts';
import {
getCurrentUnixTime,
getCurrentYear,
@@ -65,7 +65,7 @@ import {
getTimeValues,
getCombinedDateAndTimeValues
} from '@/lib/datetime.js';
import { createInlinePicker } from '@/lib/ui.mobile.js';
import { createInlinePicker } from '@/lib/ui/mobile.js';
export default {
props: [
+3 -3
View File
@@ -29,9 +29,9 @@
</template>
<script>
import { arrayContainsFieldValue } from '@/lib/common.js';
import { getIconsInRows } from '@/lib/icon.js';
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
import { arrayContainsFieldValue } from '@/lib/common.ts';
import { getIconsInRows } from '@/lib/icon.ts';
import { scrollToSelectedItem } from '@/lib/ui/mobile.js';
export default {
props: [
+3 -3
View File
@@ -25,7 +25,7 @@
</template>
<script>
import { makeButtonCopyToClipboard, changeClipboardObjectText } from '@/lib/misc.js';
import { ClipboardHolder } from '@/lib/clipboard.ts';
export default {
props: [
@@ -54,7 +54,7 @@ export default {
watch: {
'information': function (newValue) {
if (this.clipboardHolder) {
changeClipboardObjectText(this.clipboardHolder, newValue);
this.clipboardHolder.setClipboardText(newValue);
}
}
},
@@ -73,7 +73,7 @@ export default {
}
if (self.$refs.copyToClipboardIcon) {
self.clipboardHolder = makeButtonCopyToClipboard({
self.clipboardHolder = ClipboardHolder.create({
el: '#copy-to-clipboard-icon',
text: self.information,
successCallback: function () {
+12 -12
View File
@@ -5,9 +5,9 @@
</template>
<script>
import iconConstants from '@/consts/icon.js';
import colorConstants from '@/consts/color.js';
import { isNumber } from '@/lib/common.js';
import { ALL_ACCOUNT_ICONS, DEFAULT_ACCOUNT_ICON, ALL_CATEGORY_ICONS, DEFAULT_CATEGORY_ICON } from '@/consts/icon.ts';
import { DEFAULT_ICON_COLOR, DEFAULT_ACCOUNT_COLOR, DEFAULT_CATEGORY_COLOR } from '@/consts/color.ts';
import { isNumber } from '@/lib/common.ts';
export default {
props: [
@@ -58,25 +58,25 @@ export default {
iconId = iconId.toString();
}
if (!iconConstants.allAccountIcons[iconId]) {
return iconConstants.defaultAccountIcon.icon;
if (!ALL_ACCOUNT_ICONS[iconId]) {
return DEFAULT_ACCOUNT_ICON.icon;
}
return iconConstants.allAccountIcons[iconId].icon;
return ALL_ACCOUNT_ICONS[iconId].icon;
},
getCategoryIcon(iconId) {
if (isNumber(iconId)) {
iconId = iconId.toString();
}
if (!iconConstants.allCategoryIcons[iconId]) {
return iconConstants.defaultCategoryIcon.icon;
if (!ALL_CATEGORY_ICONS[iconId]) {
return DEFAULT_CATEGORY_ICON.icon;
}
return iconConstants.allCategoryIcons[iconId].icon;
return ALL_CATEGORY_ICONS[iconId].icon;
},
getAccountIconStyle(color, defaultColor, additionalColorAttr) {
if (color && color !== colorConstants.defaultAccountColor) {
if (color && color !== DEFAULT_ACCOUNT_COLOR) {
color = '#' + color;
} else {
color = defaultColor;
@@ -93,7 +93,7 @@ export default {
return ret;
},
getCategoryIconStyle(color, defaultColor, additionalColorAttr) {
if (color && color !== colorConstants.defaultCategoryColor) {
if (color && color !== DEFAULT_CATEGORY_COLOR) {
color = '#' + color;
} else {
color = defaultColor;
@@ -110,7 +110,7 @@ export default {
return ret;
},
getDefaultIconStyle(color, defaultColor, additionalColorAttr) {
if (color && color !== colorConstants.defaultColor) {
if (color && color !== DEFAULT_ICON_COLOR) {
color = '#' + color;
} else {
color = defaultColor;
@@ -32,7 +32,7 @@
</template>
<script>
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
import { scrollToSelectedItem } from '@/lib/ui/mobile.js';
export default {
props: [
+6 -6
View File
@@ -69,8 +69,8 @@
import { mapStores } from 'pinia';
import { useUserStore } from '@/stores/user.js';
import currencyConstants from '@/consts/currency.js';
import { isString, isNumber, removeAll } from '@/lib/common.js';
import { ALL_CURRENCIES } from '@/consts/currency.ts';
import { isString, isNumber, removeAll } from '@/lib/common.ts';
export default {
props: [
@@ -100,11 +100,11 @@ export default {
return this.$locale.getCurrentDecimalSeparator(this.userStore);
},
supportDecimalSeparator() {
if (!this.currency || !currencyConstants.all[this.currency] || !isNumber(currencyConstants.all[this.currency].fraction)) {
if (!this.currency || !ALL_CURRENCIES[this.currency] || !isNumber(ALL_CURRENCIES[this.currency].fraction)) {
return true;
}
return currencyConstants.all[this.currency].fraction > 0;
return ALL_CURRENCIES[this.currency].fraction > 0;
},
currentDisplay() {
const previousValue = this.$locale.appendDigitGroupingSymbol(this.userStore, this.previousValue);
@@ -160,8 +160,8 @@ export default {
return str;
}
let integer = str.substring(0, decimalSeparatorPos);
let decimals = str.substring(decimalSeparatorPos + 1, str.length);
const integer = str.substring(0, decimalSeparatorPos);
const decimals = str.substring(decimalSeparatorPos + 1, str.length);
let newDecimals = '';
for (let i = decimals.length - 1; i >= 0; i--) {
+3 -3
View File
@@ -81,7 +81,7 @@ import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.js';
import { useUserStore } from '@/stores/user.js';
import colorConstants from '@/consts/color.js';
import { DEFAULT_ICON_COLOR, DEFAULT_CHART_COLORS } from '@/consts/color.ts';
import { formatPercent } from '@/lib/numeral.js';
export default {
@@ -139,7 +139,7 @@ export default {
value: item[this.valueField],
percent: (item[this.percentField] > 0 || item[this.percentField] === 0 || item[this.percentField] === '0') ? item[this.percentField] : (item[this.valueField] / totalValidValue * 100),
actualPercent: item[this.valueField] / totalValidValue,
color: item[this.colorField] ? item[this.colorField] : colorConstants.defaultChartColors[validItems.length % colorConstants.defaultChartColors.length],
color: item[this.colorField] ? item[this.colorField] : DEFAULT_CHART_COLORS[validItems.length % DEFAULT_CHART_COLORS.length],
sourceItem: item
};
@@ -223,7 +223,7 @@ export default {
}
},
getColor: function (color) {
if (color && color !== colorConstants.defaultColor) {
if (color && color !== DEFAULT_ICON_COLOR) {
color = '#' + color;
} else {
color = 'var(--default-icon-color)';
@@ -68,9 +68,9 @@
import { mapStores } from 'pinia';
import { useUserStore } from '@/stores/user.js';
import templateConstants from '@/consts/template.js';
import { sortNumbersArray } from '@/lib/common.js';
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
import { ScheduledTemplateFrequencyType } from '@/core/template.ts';
import { sortNumbersArray } from '@/lib/common.ts';
import { scrollToSelectedItem } from '@/lib/ui/mobile.js';
export default {
props: [
@@ -100,7 +100,7 @@ export default {
return this.$locale.getAllTransactionScheduledFrequencyTypes();
},
allTemplateScheduledFrequencyTypes() {
return templateConstants.allTemplateScheduledFrequencyTypes;
return ScheduledTemplateFrequencyType.all();
},
allWeekDays() {
return this.$locale.getAllWeekDays(this.firstDayOfWeek);
@@ -134,9 +134,9 @@ export default {
if (this.currentFrequencyType !== value) {
this.currentFrequencyType = value;
if (value === templateConstants.allTemplateScheduledFrequencyTypes.Weekly.type) {
if (value === ScheduledTemplateFrequencyType.Weekly.type) {
this.currentFrequencyValue = [this.firstDayOfWeek];
} else if (value === templateConstants.allTemplateScheduledFrequencyTypes.Monthly.type) {
} else if (value === ScheduledTemplateFrequencyType.Monthly.type) {
this.currentFrequencyValue = [1];
} else {
this.currentFrequencyValue = [];
@@ -79,8 +79,8 @@
import { mapStores } from 'pinia';
import { useTransactionTagsStore } from '@/stores/transactionTag.js';
import { copyArrayTo } from '@/lib/common.js';
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
import { copyArrayTo } from '@/lib/common.ts';
import { scrollToSelectedItem } from '@/lib/ui/mobile.js';
export default {
props: [
@@ -41,8 +41,8 @@
</template>
<script>
import { isArray } from '@/lib/common.js';
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
import { isArray } from '@/lib/common.ts';
import { scrollToSelectedItem } from '@/lib/ui/mobile.js';
export default {
props: [
@@ -85,7 +85,7 @@ export default {
if (isArray(this.items)) {
count = this.items.length;
} else {
for (let field in this.items) {
for (const field in this.items) {
if (!Object.prototype.hasOwnProperty.call(this.items, field)) {
continue;
}
+4 -4
View File
@@ -93,10 +93,10 @@ import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.js';
import { useUserStore } from '@/stores/user.js';
import colorConstants from '@/consts/color.js';
import { DEFAULT_ICON_COLOR, DEFAULT_CHART_COLORS } from '@/consts/color.ts';
import datetimeConstants from '@/consts/datetime.js';
import statisticsConstants from '@/consts/statistics.js';
import { isNumber } from '@/lib/common.js';
import { isNumber } from '@/lib/common.ts';
import {
getYearMonthFirstUnixTime,
getYearMonthLastUnixTime,
@@ -154,7 +154,7 @@ export default {
const legend = {
id: id,
name: (this.nameField && item[this.nameField]) ? this.getItemName(item[this.nameField]) : id,
color: this.getColor(item[this.colorField] ? item[this.colorField] : colorConstants.defaultChartColors[i % colorConstants.defaultChartColors.length]),
color: this.getColor(item[this.colorField] ? item[this.colorField] : DEFAULT_CHART_COLORS[i % DEFAULT_CHART_COLORS.length]),
displayOrders: (this.displayOrdersField && item[this.displayOrdersField]) ? item[this.displayOrdersField] : [0]
};
@@ -322,7 +322,7 @@ export default {
}
},
getColor: function (color) {
if (color && color !== colorConstants.defaultColor) {
if (color && color !== DEFAULT_ICON_COLOR) {
color = '#' + color;
}
@@ -65,8 +65,8 @@
import {
getItemByKeyValue,
getPrimaryValueBySecondaryValue
} from '@/lib/common.js';
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
} from '@/lib/common.ts';
import { scrollToSelectedItem } from '@/lib/ui/mobile.js';
export default {
props: [