Skip to content

Commit

Permalink
chore: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Mar 21, 2024
1 parent 83beb5a commit 4f5c7fb
Show file tree
Hide file tree
Showing 15 changed files with 258 additions and 161 deletions.
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"antfu.unocss",
"vue.volar"
]
}
4 changes: 2 additions & 2 deletions app.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import '@/utils/info'
import { Toaster } from '@/components/ui/sonner'
import '@/utils/info';
import { Toaster } from '@/components/ui/sonner';
</script>

<template>
Expand Down
28 changes: 16 additions & 12 deletions components/BuyReportForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const changePricePercent = (type: 'add' | 'reduce') => {
} else {
form.setFieldValue('percent', [percent - 1]);
}
}
};
</script>

<template>
Expand Down Expand Up @@ -65,15 +65,15 @@ const changePricePercent = (type: 'add' | 'reduce') => {
<FormLabel>价位</FormLabel>
<FormControl>
<div class="flex items-center space-x-2">
<span class="i-icon-park-outline-reduce-one text-xl cursor-pointer" @click="changePricePercent('reduce')"></span>
<Slider
v-bind="componentField"
:default-value="[100]"
:max="130"
:min="70"
:step="1"
/>
<span class="i-icon-park-outline-add-one text-xl cursor-pointer" @click="changePricePercent('add')"></span>
<span
class="i-icon-park-outline-reduce-one text-xl cursor-pointer"
@click="changePricePercent('reduce')"
></span>
<Slider v-bind="componentField" :default-value="[100]" :max="130" :min="70" :step="1" />
<span
class="i-icon-park-outline-add-one text-xl cursor-pointer"
@click="changePricePercent('add')"
></span>
</div>
<FormDescription class="flex justify-between">
<span
Expand All @@ -95,15 +95,19 @@ const changePricePercent = (type: 'add' | 'reduce') => {
<FormItem class="flex items-center space-y-0">
<FormControl>
<RadioGroupItem value="up" />
<FormLabel class="flex items-center font-normal text-xl text-green pl-2 cursor-pointer">
<FormLabel
class="flex items-center font-normal text-xl text-green pl-2 cursor-pointer"
>
<span class="i-material-symbols-trending-up text-green"></span>
</FormLabel>
</FormControl>
</FormItem>
<FormItem class="flex items-center space-y-0">
<FormControl>
<RadioGroupItem value="down" />
<FormLabel class="flex items-center font-normal text-xl text-red pl-2 cursor-pointer">
<FormLabel
class="flex items-center font-normal text-xl text-red pl-2 cursor-pointer"
>
<span class="i-material-symbols-trending-down text-red"></span>
</FormLabel>
</FormControl>
Expand Down
112 changes: 63 additions & 49 deletions components/City.vue
Original file line number Diff line number Diff line change
@@ -1,76 +1,93 @@
<script setup lang="ts">
import {
Card,
CardContent,
CardHeader,
CardTitle
} from '@/components/ui/card'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow
} from '@/components/ui/table'
} from '@/components/ui/table';
import Price from './Price.vue'
import Price from './Price.vue';
const props = defineProps<{ city: CityInfo }>()
const props = defineProps<{ city: CityInfo }>();
const currentCity = props.city
const currentCity = props.city;
const timestamp = useTimestamp({ interval: 10 * 1000 })
const timestamp = useTimestamp({ interval: 10 * 1000 });
const logStore = useLatestLogs()
const logStore = useLatestLogs();
const settingStore = useSettingStore()
const settingStore = useSettingStore();
// 售出城市列表
const sellCities = computed(() => {
return cities.filter((c) => c.name !== currentCity.name)
})
return cities.filter((c) => c.name !== currentCity.name);
});
// 按设置排序后的城市列表
const sortCitesWithSetting = (filteredCities: CityInfo[], sourceCityName: string, productName: string) => {
const sortCitesWithSetting = (
filteredCities: CityInfo[],
sourceCityName: string,
productName: string
) => {
if (settingStore.listSortMode === 'byCity') {
return filteredCities
return filteredCities;
} else if (settingStore.listSortMode === 'byProfit') {
return sortCitesByProfit(filteredCities, sourceCityName, productName)
return sortCitesByProfit(filteredCities, sourceCityName, productName);
} else {
return filteredCities
return filteredCities;
}
}
};
// 按单位利润排序城市
const sortCitesByProfit = (filteredCities: CityInfo[], sourceCityName: string, productName: string) => {
const sourceCityPrice = logStore.getLatestLog(sourceCityName, productName, sourceCityName)?.price || 0
const sortCitesByProfit = (
filteredCities: CityInfo[],
sourceCityName: string,
productName: string
) => {
const sourceCityPrice =
logStore.getLatestLog(sourceCityName, productName, sourceCityName)?.price || 0;
// 计算各城市货物利润
let citiesProfitMap: {[key: string]: number} = {}
filteredCities.map(city => {
const latestLog = logStore.getLatestLog(sourceCityName, productName, city.name)
/**
* 如果满足以下条件之一,排名最后
* 1. 最新交易记录不存在
* 2. 最新交易记录距离现在超过 1 天
* 3. 原产地价格不存在
*/
if (
!latestLog ||
(Date.now() - new Date(latestLog.uploadedAt).valueOf()) > (1 * 24 * 60 * 60 * 1000) ||
!sourceCityPrice
) return { cityName: city.name, profit: -9999 }
// 如果最新交易记录无效,排名在有效记录之后,且按顺序排列
else if(Boolean(isLogValid(latestLog))) 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) }
}).forEach(cityProfit => citiesProfitMap[cityProfit.cityName] = cityProfit.profit)
let citiesProfitMap: { [key: string]: number } = {};
filteredCities
.map((city) => {
const latestLog = logStore.getLatestLog(sourceCityName, productName, city.name);
/**
* 如果满足以下条件之一,排名最后
* 1. 最新交易记录不存在
* 2. 最新交易记录距离现在超过 1 天
* 3. 原产地价格不存在
*/
if (
!latestLog ||
Date.now() - new Date(latestLog.uploadedAt).valueOf() > 1 * 24 * 60 * 60 * 1000 ||
!sourceCityPrice
)
return { cityName: city.name, profit: -9999 };
// 如果最新交易记录无效,排名在有效记录之后,且按顺序排列
else if (Boolean(isLogValid(latestLog)))
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)
};
})
.forEach((cityProfit) => (citiesProfitMap[cityProfit.cityName] = cityProfit.profit));
const sortedCities = filteredCities.toSorted((a, b) => citiesProfitMap[b.name] - citiesProfitMap[a.name])
return sortedCities
}
const sortedCities = filteredCities.toSorted(
(a, b) => citiesProfitMap[b.name] - citiesProfitMap[a.name]
);
return sortedCities;
};
</script>

<template>
Expand All @@ -86,10 +103,7 @@ const sortCitesByProfit = (filteredCities: CityInfo[], sourceCityName: string, p
<!-- 按城市维度排序 -->
<template v-if="settingStore.listSortMode === 'byCity'">
<TableHead class="border-r">{{ currentCity.name }}</TableHead>
<TableHead
v-for="city in sellCities"
:key="city.name"
>{{ city.name }}</TableHead>
<TableHead v-for="city in sellCities" :key="city.name">{{ city.name }}</TableHead>
</template>
<!-- 按利润排序 -->
<template v-else>
Expand Down
38 changes: 24 additions & 14 deletions components/CreateLog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import {
import type { ProductInfo } from '@/utils/types';
const props = defineProps<{
sourceCityName: string // 原产地城市
targetCityName?: string // 目标城市
product: ProductInfo // 货物信息
sourceCityName: string; // 原产地城市
targetCityName?: string; // 目标城市
product: ProductInfo; // 货物信息
}>();
const open = defineModel('open', {
Expand All @@ -58,7 +58,7 @@ watch(open, (open) => {
if (open) {
form.resetForm();
if (props.targetCityName) {
form.setFieldValue("targetCity", props.targetCityName)
form.setFieldValue('targetCity', props.targetCityName);
}
}
});
Expand All @@ -70,7 +70,7 @@ const changePricePercent = (type: 'add' | 'reduce') => {
} else {
form.setFieldValue('percent', [percent - 1]);
}
}
};
</script>

<template>
Expand All @@ -86,9 +86,9 @@ const changePricePercent = (type: 'add' | 'reduce') => {
<div class="space-x-2 text-sm">
<span class="text-right font-bold">商品</span>
<span class="text-base">
<span class="text-gray-400">{{ sourceCityName }}</span>
购买的
购买的
<span class="text-gray-400">{{ product.name }}</span>
</span>
</div>
Expand All @@ -112,9 +112,9 @@ const changePricePercent = (type: 'add' | 'reduce') => {
</Select>
<FormDescription>
{{
form.values.targetCity !== sourceCityName
? `出售 ${product.name} 到 ${form.values.targetCity ?? '--'}`
: `从 ${form.values.targetCity} 购买 ${product.name}`
form.values.targetCity !== sourceCityName
? `出售 ${product.name} 到 ${form.values.targetCity ?? '--'}`
: `从 ${form.values.targetCity} 购买 ${product.name}`
}}
</FormDescription>
<FormMessage />
Expand All @@ -141,15 +141,21 @@ const changePricePercent = (type: 'add' | 'reduce') => {
<FormLabel>价位百分比</FormLabel>
<FormControl>
<div class="flex items-center space-x-2">
<span class="i-icon-park-outline-reduce-one text-xl cursor-pointer" @click="changePricePercent('reduce')"></span>
<span
class="i-icon-park-outline-reduce-one text-xl cursor-pointer"
@click="changePricePercent('reduce')"
></span>
<Slider
v-bind="componentField"
:default-value="[100]"
:max="130"
:min="70"
:step="1"
/>
<span class="i-icon-park-outline-add-one text-xl cursor-pointer" @click="changePricePercent('add')"></span>
<span
class="i-icon-park-outline-add-one text-xl cursor-pointer"
@click="changePricePercent('add')"
></span>
</div>
<FormDescription class="flex justify-between">
<span>
Expand All @@ -171,15 +177,19 @@ const changePricePercent = (type: 'add' | 'reduce') => {
<FormItem class="flex items-center space-y-0">
<FormControl>
<RadioGroupItem value="up" />
<FormLabel class="flex items-center font-normal text-xl text-green pl-2 cursor-pointer">
<FormLabel
class="flex items-center font-normal text-xl text-green pl-2 cursor-pointer"
>
<span class="i-material-symbols-trending-up text-green"></span>
</FormLabel>
</FormControl>
</FormItem>
<FormItem class="flex items-center space-y-0">
<FormControl>
<RadioGroupItem value="down" />
<FormLabel class="flex items-center font-normal text-xl text-red pl-2 cursor-pointer">
<FormLabel
class="flex items-center font-normal text-xl text-red pl-2 cursor-pointer"
>
<span class="i-material-symbols-trending-down text-red"></span>
</FormLabel>
</FormControl>
Expand Down
Loading

0 comments on commit 4f5c7fb

Please sign in to comment.