服务不可用提示

This commit is contained in:
天可 2019-08-22 19:25:32 +08:00
parent 31821e51e6
commit e912048168
3 changed files with 25 additions and 14 deletions

View File

@ -114,5 +114,7 @@ module.exports = {
'app.docs.components.icon.pic-searcher.title': 'Search by image',
'app.docs.components.icon.pic-searcher.placeholder':
'Click or drag or paste file to this area to upload',
'app.docs.components.icon.pic-searcher.server-error':
'Predict service is temporarily unavailable',
},
};

View File

@ -68,21 +68,29 @@ class PicSearcher extends Component<PicSearcherProps, PicSearcherState> {
};
predict = async (imageBase64: any) => {
const {
intl: { messages },
} = this.props;
this.setState(() => ({ loading: true }));
const res = await fetch(
'//1647796581073291.cn-shanghai.fc.aliyuncs.com/2016-08-15/proxy/cr-sh.cr-fc-predict__stable/cr-fc-predict/',
{
method: 'post',
body: JSON.stringify({
modelId: 'data_icon',
type: 'ic',
imageBase64,
}),
},
);
let icons = await res.json();
icons = icons.map((i: any) => ({ score: i.score, type: i.class_name.replace(/\s/g, '-') }));
this.setState(() => ({ icons, loading: false }));
try {
const res = await fetch(
'//1647796581073291.cn-shanghai.fc.aliyuncs.com/2016-08-15/proxy/cr-sh.cr-fc-predict__stable/cr-fc-predict/',
{
method: 'post',
body: JSON.stringify({
modelId: 'data_icon',
type: 'ic',
imageBase64,
}),
},
);
let icons = await res.json();
icons = icons.map((i: any) => ({ score: i.score, type: i.class_name.replace(/\s/g, '-') }));
this.setState(() => ({ icons, loading: false }));
} catch (err) {
message.error(messages['app.docs.components.icon.pic-searcher.server-error']);
this.setState(() => ({ loading: false }));
}
};
toggleModal = () => {

View File

@ -110,5 +110,6 @@ module.exports = {
'app.docs.components.icon.category.logo': '品牌和标识',
'app.docs.components.icon.pic-searcher.title': '按图片搜索',
'app.docs.components.icon.pic-searcher.placeholder': '点击/拖拽/粘贴上传',
'app.docs.components.icon.pic-searcher.server-error': '识别服务暂不可用',
},
};