mirror of https://github.com/msgbyte/tailchat
feat: add genshin plugin
parent
536b7dec5c
commit
46e635cd14
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"label": "原神工具箱插件",
|
||||||
|
"name": "com.msgbyte.genshin",
|
||||||
|
"url": "/plugins/com.msgbyte.genshin/index.js",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"author": "msgbyte",
|
||||||
|
"description": "为Tailchat增加原神相关的娱乐能力",
|
||||||
|
"requireRestart": true
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"name": "@plugins/com.msgbyte.genshin",
|
||||||
|
"main": "src/index.ts",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"genshin-gacha-kit": "^1.1.0"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
import { useAsync } from '@capital/common';
|
||||||
|
import { Divider } from '@capital/component';
|
||||||
|
import React from 'react';
|
||||||
|
import { OfficialGachaPoolItem, util } from 'genshin-gacha-kit';
|
||||||
|
|
||||||
|
const GachaPoolItem: React.FC<{
|
||||||
|
items: OfficialGachaPoolItem[];
|
||||||
|
}> = React.memo((props) => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{props.items.map((i) => (
|
||||||
|
<div key={i.item_id}>
|
||||||
|
<img src={i.item_img} />
|
||||||
|
|
||||||
|
<div>{i.item_name}</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
GachaPoolItem.displayName = 'GachaPoolItem';
|
||||||
|
|
||||||
|
export const GachaPool: React.FC<{
|
||||||
|
gachaId: string;
|
||||||
|
}> = React.memo((props) => {
|
||||||
|
const { value: poolData } = useAsync(() => {
|
||||||
|
return util.getGachaData(props.gachaId);
|
||||||
|
}, [props.gachaId]);
|
||||||
|
|
||||||
|
if (!poolData) {
|
||||||
|
return <div>Loading...</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div>{poolData.banner}</div>
|
||||||
|
|
||||||
|
<div>{poolData.date_range}</div>
|
||||||
|
<div className="gacha-pool">
|
||||||
|
<GachaPoolItem items={poolData.r5_up_items ?? []} />
|
||||||
|
<GachaPoolItem items={poolData.r4_up_items ?? []} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Divider />
|
||||||
|
|
||||||
|
<div>{poolData.content}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
GachaPool.displayName = 'GachaPool';
|
@ -0,0 +1,23 @@
|
|||||||
|
.plugin-genshin-panel {
|
||||||
|
width: 100%;
|
||||||
|
padding: 10px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
.gacha-title {
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 22px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gacha-pool {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
|
||||||
|
> div {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Translate } from '../translate';
|
||||||
|
import { util } from 'genshin-gacha-kit';
|
||||||
|
import { useAsync } from '@capital/common';
|
||||||
|
import { PillTabs, PillTabPane } from '@capital/component';
|
||||||
|
import './index.less';
|
||||||
|
import { GachaPool } from './GachaPool';
|
||||||
|
|
||||||
|
const GenshinPanel: React.FC = React.memo(() => {
|
||||||
|
const { value: gachaList } = useAsync(() => {
|
||||||
|
return util.getGachaIndex();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="plugin-genshin-panel">
|
||||||
|
<div className="gacha-title">
|
||||||
|
{Translate.genshin} - {Translate.gacha}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<PillTabs>
|
||||||
|
{(gachaList ?? []).map((item) => (
|
||||||
|
<PillTabPane
|
||||||
|
key={item.gacha_id}
|
||||||
|
tab={`${item.gacha_name}(${item.begin_time} - ${item.end_time})`}
|
||||||
|
>
|
||||||
|
<GachaPool gachaId={item.gacha_id} />
|
||||||
|
</PillTabPane>
|
||||||
|
))}
|
||||||
|
</PillTabs>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
GenshinPanel.displayName = 'GenshinPanel';
|
||||||
|
|
||||||
|
export default GenshinPanel;
|
@ -0,0 +1,10 @@
|
|||||||
|
import { regCustomPanel, Loadable } from '@capital/common';
|
||||||
|
import { Translate } from './translate';
|
||||||
|
|
||||||
|
regCustomPanel({
|
||||||
|
position: 'personal',
|
||||||
|
icon: 'akar-icons:game-controller',
|
||||||
|
name: 'com.msgbyte.genshin/genshinPanel',
|
||||||
|
label: Translate.genshin,
|
||||||
|
render: Loadable(() => import('./GenshinPanel')),
|
||||||
|
});
|
@ -0,0 +1,6 @@
|
|||||||
|
import { localTrans } from '@capital/common';
|
||||||
|
|
||||||
|
export const Translate = {
|
||||||
|
genshin: localTrans({ 'zh-CN': '原神', 'en-US': 'Genshin' }),
|
||||||
|
gacha: localTrans({ 'zh-CN': '抽卡', 'en-US': 'Gacha' }),
|
||||||
|
};
|
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"baseUrl": "./src",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"jsx": "react",
|
||||||
|
"paths": {
|
||||||
|
"@capital/*": ["../../../src/plugin/*"],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue