-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
101 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"api": [ | ||
{ | ||
"url": "http://localhost:3400/api/clothes", | ||
"name": "recommendClothes", | ||
"description": "根据用户的心情,给用户推荐他有的衣服", | ||
"parameters": { | ||
"properties": { | ||
"mood": { | ||
"description": "用户当前的心情,可选值有:开心(happy), 难过(sad),生气 (anger),害怕(fear),惊喜( surprise),厌恶 (disgust)", | ||
"enums": ["happy", "sad", "anger", "fear", "surprise", "disgust"], | ||
"type": "string" | ||
}, | ||
"gender": { | ||
"type": "string", | ||
"enum": ["man", "woman"], | ||
"description": "对话用户的性别,需要询问用户后才知道这个信息" | ||
} | ||
}, | ||
"required": ["mood", "gender"], | ||
"type": "object" | ||
} | ||
} | ||
], | ||
"identifier": "plugin-identifier-standalone", | ||
"type": "standalone", | ||
"ui": { | ||
"url": "http://localhost:3400/iframe", | ||
"height": 200 | ||
}, | ||
"version": "1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
fetchPluginMessage, | ||
postToFillPluginContent, | ||
useOnStandalonePluginInit, | ||
} from '@lobehub/chat-plugin-sdk/client'; | ||
import { Button } from 'antd'; | ||
import { memo, useEffect, useState } from 'react'; | ||
import { Center } from 'react-layout-kit'; | ||
|
||
import Data from '@/components/Render'; | ||
import { fetchClothes } from '@/services/clothes'; | ||
import { ResponseData } from '@/type'; | ||
|
||
const Render = memo(() => { | ||
// 初始化渲染状态 | ||
const [data, setData] = useState<ResponseData>(); | ||
|
||
// 初始化时从主应用同步状态 | ||
useEffect(() => { | ||
fetchPluginMessage().then(setData); | ||
}, []); | ||
|
||
// 记录请求参数 | ||
const [payload, setPayload] = useState<any>(); | ||
|
||
useOnStandalonePluginInit<ResponseData>((payload) => { | ||
if (payload.func === 'recommendClothes') { | ||
setPayload(payload.args); | ||
} | ||
}); | ||
|
||
const fetchData = async () => { | ||
const data = await fetchClothes(payload); | ||
setData(data); | ||
postToFillPluginContent(data); | ||
}; | ||
|
||
return data ? ( | ||
<Data {...data}></Data> | ||
) : ( | ||
<Center style={{ height: 150 }}> | ||
<Button | ||
disabled={!payload} | ||
onClick={() => { | ||
fetchData(); | ||
}} | ||
type={'primary'} | ||
> | ||
查询衣物 | ||
</Button> | ||
</Center> | ||
); | ||
}); | ||
|
||
export default Render; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { RequestData } from '@/type'; | ||
|
||
export const fetchClothes = async (params: RequestData) => { | ||
const res = await fetch('/api/clothes', { | ||
body: JSON.stringify(params), | ||
method: 'POST', | ||
}); | ||
|
||
return res.json(); | ||
}; |