36 lines
729 B
TypeScript
36 lines
729 B
TypeScript
import http from '@/utils/http';
|
|
import { Mines, MineBasic } from '@/types/common';
|
|
import { loadMineList, storeMineList } from '@/utils/storage';
|
|
|
|
export async function getMineBasic(): Promise<MineBasic> {
|
|
const {
|
|
ok,
|
|
data,
|
|
msg,
|
|
} = await http.get<MineBasic>('/mine/basic');
|
|
if (ok && data) {
|
|
return data;
|
|
}
|
|
throw Error(msg);
|
|
}
|
|
|
|
export async function getMineList(refresh = false): Promise<Mines> {
|
|
if (!refresh) {
|
|
const dataCached = loadMineList();
|
|
if (dataCached && dataCached.length) {
|
|
return dataCached;
|
|
}
|
|
}
|
|
|
|
const {
|
|
ok,
|
|
data,
|
|
msg,
|
|
} = await http.get<Mines>('/mine/list');
|
|
if (ok && data) {
|
|
storeMineList(data);
|
|
return data;
|
|
}
|
|
throw Error(msg);
|
|
}
|