Skip to content

Commit

Permalink
Improve BOM UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Tnze committed Dec 28, 2024
1 parent cd2d318 commit 9595e41
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use serde::Serialize;

mod db;
use db::{
collectables_shop_refine, craft_types, item_action, item_food, item_food_effect,
item_with_amount, items, prelude::*, recipe_level_tables, recipes,
craft_types, item_action, item_food, item_food_effect, item_with_amount, items, prelude::*,
recipe_level_tables, recipes,
};

type Result<T> = std::result::Result<T, StatusError>;
Expand Down
19 changes: 15 additions & 4 deletions src/components/bom/Selector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@ const settingStore = useSettingStore();

const search = ref('');
const recipeList = ref<RecipeInfo[]>([]);
const isLoading = ref(false);

async function update() {
const source = await settingStore.getDataSource;
const recipeTable = await source.recipeTable(1, search.value);
recipeList.value = recipeTable.results;
try {
isLoading.value = true;
const source = await settingStore.getDataSource;
const recipeTable = await source.recipeTable(1, search.value);
recipeList.value = recipeTable.results;
} finally {
isLoading.value = false;
}
}

watch(search, () => update(), { immediate: true });
Expand All @@ -49,7 +55,12 @@ async function selectItem(recipe: RecipeInfo) {
</script>

<template>
<el-table :data="recipeList" @row-click="selectItem" max-height="300">
<el-table
:data="recipeList"
@row-click="selectItem"
max-height="300"
v-tnze-loading="isLoading"
>
<el-table-column prop="job" :label="$t('craft-type')" width="150" />
<el-table-column prop="item_name" :label="$t('name')">
<template #header>
Expand Down
3 changes: 2 additions & 1 deletion src/datasource/beta-xivapi-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class BetaXivApiRecipeSource {
jobLevelMax?: number,
): Promise<RecipesSourceResult> {
const params: Record<string, string> = {
fields: 'Icon,ItemResult.Name,CraftType.Name,DifficultyFactor,DurabilityFactor,QualityFactor,MaterialQualityFactor,RecipeLevelTable@as(raw),RequiredCraftsmanship,RequiredControl,CanHq',
fields: 'Icon,ItemResult.Name,AmountResult,CraftType.Name,DifficultyFactor,DurabilityFactor,QualityFactor,MaterialQualityFactor,RecipeLevelTable@as(raw),RequiredCraftsmanship,RequiredControl,CanHq',
// 'limit': "100",
};
const query = new URLSearchParams(params);
Expand Down Expand Up @@ -130,6 +130,7 @@ export class BetaXivApiRecipeSource {
rlv: assert(v?.fields['RecipeLevelTable@as(raw)'], 'rlv'),
item_id: assert(v?.fields?.ItemResult.row_id, 'item_id'),
item_name: assert(v?.fields?.ItemResult?.fields.Name, 'item_name'),
item_amount: v?.fields?.AmountResult,
job: assert(v?.fields?.CraftType?.fields?.Name, 'job'),

difficulty_factor: assert(
Expand Down
42 changes: 36 additions & 6 deletions src/pages/Bom.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import {
ElDialog,
ElButton,
ElAlert,
ElMessage,
MessageHandler,
ElIcon,
ElText,
} from 'element-plus';
import { Plus, Delete } from '@element-plus/icons-vue';
import { Plus, Delete, Loading, Refresh } from '@element-plus/icons-vue';

import BomItem from '@/components/bom/Item.vue';
import Selector from '@/components/bom/Selector.vue';
Expand All @@ -43,6 +43,7 @@ const { $t } = useFluent();
const store = useStore();
const selectorOpen = ref(false);
const errMsg = ref<string>();
const calculating = ref(false);

const groupedIngs = computed(() => {
if (store.ingredients.length == 0) {
Expand All @@ -68,13 +69,24 @@ function clearSelection() {
updateBom();
}

let alertHandle: MessageHandler | undefined = undefined;
let runningProcess: Promise<void> | undefined = undefined;
let outdated = false;
async function updateBom() {
let p;
try {
errMsg.value = undefined;
await store.updateBom();
calculating.value = true;

p = store.updateBom();
runningProcess = p;
await p;
} catch (e: any) {
errMsg.value = String(e);
} finally {
if (p == runningProcess) {
runningProcess = undefined;
calculating.value = false;
}
}
}
</script>
Expand Down Expand Up @@ -130,7 +142,24 @@ async function updateBom() {
</div>
</TransitionGroup>
</el-scrollbar>
<el-divider content-position="left">{{ $t('ings') }}</el-divider>
<el-divider content-position="left">
<el-text>
<template v-if="calculating">
{{ $t('calculating') }}
<el-icon class="is-loading">
<Loading />
</el-icon>
</template>
<template v-else>
{{ $t('ings') }}
<el-button link @click="updateBom()">
<el-icon>
<Refresh />
</el-icon>
</el-button>
</template>
</el-text>
</el-divider>
<el-alert v-if="errMsg" type="error" show-icon :closable="false">
{{ errMsg }}
</el-alert>
Expand Down Expand Up @@ -208,6 +237,7 @@ async function updateBom() {

<fluent locale="zh-CN">
ings = 材料
calculating = 计算中
add = 添加
clear = 清空
</fluent>
Expand Down
16 changes: 15 additions & 1 deletion src/stores/bom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default defineStore('bom', {

recipeCache: new Map<ItemID, RecipeInfo[]>(),
ingredientsCache: new Map<RecipeID, ItemWithAmount[]>(),
itemInfoCache: new Map<ItemID, Item>(),
ingredients: <Slot[]>[],
}),

Expand Down Expand Up @@ -114,7 +115,8 @@ export default defineStore('bom', {
for (const subIng of subIngs) {
let slot = ings.get(subIng.ingredient_id);
if (slot == undefined) {
const itemInfo = await ds.itemInfo(
const itemInfo = await this.fetchItemInfo(
ds,
subIng.ingredient_id,
);
slot = new Slot(itemInfo);
Expand Down Expand Up @@ -256,5 +258,17 @@ export default defineStore('bom', {
}
return result.filter(v => v.ingredient_id >= 20); // 过滤偏属性水晶
},

async fetchItemInfo(
dataSource: DataSource,
itemId: ItemID,
): Promise<Item> {
let result = this.itemInfoCache.get(itemId);
if (result == undefined) {
result = await dataSource.itemInfo(itemId);
this.itemInfoCache.set(itemId, result);
}
return result;
},
},
});

0 comments on commit 9595e41

Please sign in to comment.