From b7f713f2c3d0ae431986293701d3483accbe0e05 Mon Sep 17 00:00:00 2001 From: Ximu-Luya <794876939@qq.com> Date: Sun, 24 Mar 2024 19:17:13 +0800 Subject: [PATCH 1/8] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E5=88=A9?= =?UTF-8?q?=E6=B6=A6=E8=AE=A1=E7=AE=97=E8=A7=84=E5=88=99=E5=AE=9E=E6=97=B6?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/City.vue | 15 +++++---------- components/Price.vue | 4 ++-- layouts/default.vue | 8 ++++---- stores/latest.ts | 8 +++++--- stores/settings.ts | 32 ++++++++++++++++++-------------- utils/log.ts | 2 +- 6 files changed, 35 insertions(+), 34 deletions(-) diff --git a/components/City.vue b/components/City.vue index 8b097d9..e63789f 100644 --- a/components/City.vue +++ b/components/City.vue @@ -65,19 +65,14 @@ const sortCitesByProfit = ( !latestLog || Date.now() - new Date(latestLog.uploadedAt).valueOf() > 1 * 24 * 60 * 60 * 1000 || !sourceCityPrice - ) return { cityName: city.name, profit: -9999 }; - // 如果最新交易记录无效,排名在有效记录之后,且按顺序排列 - else if (isLogValid(latestLog)) + ) return { cityName: city.name, profit: -99999 }; + else { + const profit = settingStore.getProfitWithRule(latestLog.price, sourceCityPrice); return { cityName: city.name, - profit: Math.round(latestLog.price * 1.2 * 0.98 - sourceCityPrice * 0.8 * 1.08) - 9000 - }; - // 如果最新交易记录有效,按利润高低排名 - else - return { - cityName: city.name, - profit: Math.round(latestLog.price * 1.2 * 0.98 - sourceCityPrice * 0.8 * 1.08) + profit: profit - (isLogValid(latestLog) ? 0 : 9999) // 如果最新交易记录无效,排名在有效记录之后,且按顺序排列 }; + } }) .forEach((cityProfit) => (citiesProfitMap[cityProfit.cityName] = cityProfit.profit)); diff --git a/components/Price.vue b/components/Price.vue index 8f8c694..09c7b86 100644 --- a/components/Price.vue +++ b/components/Price.vue @@ -26,7 +26,7 @@ const reportDialogVisible = ref(false); const isOutdated = computed(() => { if (!props.log) return true; props.timestamp; - return isLogValid(props.log); + return !isLogValid(props.log); }); // 单位利润 @@ -39,7 +39,7 @@ const profit = computed(() => { props.log.sourceCity ); if (sourceCityLatestLog) { - return Math.round(props.log.price * 1.2 * 0.98 - sourceCityLatestLog.price * 0.8 * 1.08); + return settingStore.getProfitWithRule(props.log.price, sourceCityLatestLog.price); } else { return undefined; } diff --git a/layouts/default.vue b/layouts/default.vue index 9fd4174..a5c75e2 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -155,14 +155,14 @@ const settingStore = useSettingStore();
最大砍价抬价
@@ -170,14 +170,14 @@ const settingStore = useSettingStore();
不砍价不抬价
diff --git a/stores/latest.ts b/stores/latest.ts index 1518ff2..e2c3a21 100644 --- a/stores/latest.ts +++ b/stores/latest.ts @@ -22,11 +22,13 @@ export const useLatestLogs = defineStore('latest_logs', () => { }); }; + const getLatestLog = (sourceCity: string, productName: string, targetCity: string) => { + return transactionMap.value.get(`${productName}-from${sourceCity}to${targetCity}`); + }; + return { logs, - getLatestLog(sourceCity: string, productName: string, targetCity: string) { - return transactionMap.value.get(`${productName}-from${sourceCity}to${targetCity}`); - }, + getLatestLog, fetch, startGetData }; diff --git a/stores/settings.ts b/stores/settings.ts index 8fb5c61..29e0de2 100644 --- a/stores/settings.ts +++ b/stores/settings.ts @@ -1,16 +1,15 @@ // import { umami } from '~analytics/umami'; export type ListSortMode = 'byCity' | 'byProfit'; -export type ProfitComputeRule = 'maxPriceChange' | 'noChange'; export type DataDisplayItems = 'profit' | 'perTicketProfit'; export const useSettingStore = defineStore('setting', () => { // const listSortMode = useStorage('listSortMode', 'byCity') - // const profitComputeRule = useStorage('profitComputeRule', 'noChange') const listSortMode = ref('byCity'); const dataDisplayItems = ref(['profit', 'perTicketProfit']); - const profitComputeRule = ref('maxPriceChange'); + const taxRate = ref(0.08); + const priceChangeRate = ref(0.2); // 切换列表排序模式 const switchListSortModeTo = (targetMode: ListSortMode) => { @@ -19,11 +18,18 @@ export const useSettingStore = defineStore('setting', () => { // umami?.track(`switch list mode to ${targetMode}`).catch(() => {}); }; - // 切换利润计算规则 - const switchProfitComputeRuleTo = (targetRule: ProfitComputeRule) => { - profitComputeRule.value = targetRule; - - // umami?.track(`switch profit compute rule to ${targetRule}`).catch(() => {}); + /** + * 根据设置中的配置计算利润 + * @param sourceCityPrice 买入价格 + * @param targetCityPrice 卖出价格 + * @returns + */ + const getProfitWithRule = (sourceCityPrice: number | undefined, targetCityPrice: number) => { + // 买入价格不存在时,返回-9999 + if (!sourceCityPrice) return -9999; + const finalSourceCityPrice = sourceCityPrice * (1 - priceChangeRate.value) * (1 + taxRate.value); + const finalTargetCityPrice = targetCityPrice * (1 + priceChangeRate.value) * (1 - taxRate.value); + return Math.round(finalTargetCityPrice - finalSourceCityPrice); }; // 切换数据显示项 @@ -37,13 +43,11 @@ export const useSettingStore = defineStore('setting', () => { return { listSortMode: listSortMode, - // listSortMode: skipHydrate(listSortMode), switchListSortModeTo, - profitComputeRule: profitComputeRule, - // profitComputeRule: skipHydrate(profitComputeRule), - switchProfitComputeRuleTo, - dataDisplayItems: dataDisplayItems, - // dataDisplayItems: skipHydrate(dataDisplayItems), + taxRate, + priceChangeRate, + getProfitWithRule, + dataDisplayItems, switchDataDisplayItems }; }); diff --git a/utils/log.ts b/utils/log.ts index 2b12765..92858b5 100644 --- a/utils/log.ts +++ b/utils/log.ts @@ -4,5 +4,5 @@ export function isLogValid(log: Log | undefined | null) { if (!log) return false; const uploadedAt = log.uploadedAt.getTime(); // 60 分钟 - return new Date().getTime() - uploadedAt > 3600 * 1000; + return new Date().getTime() - uploadedAt < 3600 * 1000; } From cc5ce7fee2f335b7c59059f0b575a1b0faca2f77 Mon Sep 17 00:00:00 2001 From: Ximu-Luya <794876939@qq.com> Date: Sun, 24 Mar 2024 22:16:14 +0800 Subject: [PATCH 2/8] =?UTF-8?q?feat:=20=E5=B0=86=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E9=80=BB=E8=BE=91=E8=BF=81=E7=A7=BB=E8=87=B3?= =?UTF-8?q?=E6=A0=B9=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.vue | 4 ++++ pages/index.vue | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app.vue b/app.vue index c9ac810..dedcd5c 100644 --- a/app.vue +++ b/app.vue @@ -1,6 +1,10 @@