Skip to content

Commit

Permalink
图片错误处理
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Feb 20, 2018
1 parent 4ed86f5 commit bf1e857
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/assets/website.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions src/pages/Navigation/Edit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react';
import classNames from 'classnames';
import styles from './Edit.less';
import websiteIcon from '../../assets/website.svg';
import website from '../../source/website.json';
import addIcon from '../../assets/add-icon.png';

Expand Down Expand Up @@ -78,7 +79,7 @@ export default class Edit extends Component {
return (
<div className={styles.navEdit} ref={node => this.warpper = node}>
<div className={styles.edit}>
<img alt="" src={edit.icon} />
<img alt="" onError={e => e.target.src = websiteIcon} src={edit.icon} />
<span className={styles.title}>{edit.label}</span>
<input className={styles.url} onChange={this.onChangeEdit.bind(this)} value={edit.value} type="text" placeholder="输入网址" />
<button className={styles.save} onClick={this.onClickAdd.bind(this, edit)}>确定</button>
Expand All @@ -105,7 +106,7 @@ export default class Edit extends Component {
>
{item.children.map((_item, _idx) => (
<span key={_idx} onClick={this.handleAddNav.bind(this, _item)}>
<img alt={_item.label} src={_item.icon} />
<img alt={_item.label} onError={e => e.target.src = websiteIcon} src={_item.icon} />
<p>{_item.label}</p>
</span>
))}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Navigation/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react';
import styles from './index.less';
import addIcon from '../../assets/add-icon.png';
import website from '../../assets/website.svg';
import Edit from './Edit';
// import Contextmenu from "../../component/Contextmenu";

Expand Down Expand Up @@ -107,7 +108,7 @@ export default class Navigation extends Component {
{navContent.map((item, idx) => {
return (
<a key={idx} href={item.value} target="_top">
<img alt={item.label} src={item.icon} />
<img alt={item.label} onError={e => e.target.src = website} src={item.icon} />
<p>{item.label}</p>
{optionDown && <i onClick={this.onKeyDownOption.bind(this, item)} className={styles.keyDown} />}
</a>
Expand Down
1 change: 1 addition & 0 deletions src/pages/Navigation/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
display: block;
filter: brightness(0.99);
transition: filter .3s;
background: #fff;
}
.keyDown {
height: 23px;
Expand Down
10 changes: 10 additions & 0 deletions src/source/website.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,21 @@
"value": "https://y.qq.com/",
"icon": "https://jaywcjlove.github.io/logo/yqq.png"
},
{
"label": "音悦Tai",
"value": "http://www.yinyuetai.com/",
"icon": "https://jaywcjlove.github.io/logo/yinyuetai.jpg"
},
{
"label": "豆瓣FM",
"value": "https://douban.fm/",
"icon": "https://jaywcjlove.github.io/logo/doubanfm.png"
},
{
"label": "喜马拉雅FM",
"value": "http://www.ximalaya.com/",
"icon": "https://jaywcjlove.github.io/logo/ximalaya.jpg"
},
{
"label": "蜻蜓FM",
"value": "http://www.qingting.fm/",
Expand Down

0 comments on commit bf1e857

Please sign in to comment.