From ef9e6c06dd80abf2c1c674974e29f95002820f04 Mon Sep 17 00:00:00 2001 From: fanxb Date: Mon, 30 Dec 2019 22:56:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E8=B7=B3=E8=BD=AC=E5=89=8D=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E6=98=AF=E5=90=A6=E6=9C=89http?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/src/components/Search/index.jsx | 55 ++++++++++++++++---- front/src/pages/manage/OverView/index.jsx | 63 ++++++++++++++++++----- 2 files changed, 93 insertions(+), 25 deletions(-) diff --git a/front/src/components/Search/index.jsx b/front/src/components/Search/index.jsx index 10aa5ae..0d4ebfd 100644 --- a/front/src/components/Search/index.jsx +++ b/front/src/components/Search/index.jsx @@ -63,21 +63,35 @@ class Search extends React.Component { this.setState({ resultList: [] }); return; } - httpUtil.get("/bookmark/searchUserBookmark?content=" + encodeURIComponent(content)).then(res => this.setState({ resultList: res })); + httpUtil + .get( + "/bookmark/searchUserBookmark?content=" + encodeURIComponent(content) + ) + .then(res => this.setState({ resultList: res })); } /** * 处理跳转到搜索引擎或者对应的书签 */ enter() { - const { currentIndex, currentOptionIndex, resultList, content } = this.state; + const { + currentIndex, + currentOptionIndex, + resultList, + content + } = this.state; if (currentOptionIndex === 0 && resultList.length > 0) { - window.open(resultList[currentIndex].url); + let url = resultList[currentIndex].url; + window.open(url.startsWith("http") ? url : "http://" + url); } if (currentOptionIndex === 1) { - window.open("https://www.baidu.com/s?ie=UTF-8&wd=" + encodeURIComponent(content)); + window.open( + "https://www.baidu.com/s?ie=UTF-8&wd=" + encodeURIComponent(content) + ); } else if (currentOptionIndex === 2) { - window.open("https://www.google.com/search?q=" + encodeURIComponent(content)); + window.open( + "https://www.google.com/search?q=" + encodeURIComponent(content) + ); } } @@ -123,7 +137,12 @@ class Search extends React.Component { * 渲染结果列表 */ renderResults() { - const { resultList, currentIndex, currentOptionIndex, isFocus } = this.state; + const { + resultList, + currentIndex, + currentOptionIndex, + isFocus + } = this.state; if (currentOptionIndex !== 0 || !isFocus) { return; } @@ -132,25 +151,37 @@ class Search extends React.Component {
{resultList.map((item, index) => (
window.open(item.url)} > {item.name}  - {item.url} + + {item.url} +
))}
); } else { - return ; + return ( + + ); } } render() { const { content, options, currentOptionIndex } = this.state; const prefix = ( - {options.map((item, index) => ( {item} @@ -171,7 +202,9 @@ class Search extends React.Component { onChange={this.contentChange.bind(this)} onKeyDown={this.keyUp.bind(this)} onFocus={() => this.setState({ isFocus: true })} - onBlur={() => setTimeout(() => this.setState({ isFocus: false }), 600)} + onBlur={() => + setTimeout(() => this.setState({ isFocus: false }), 600) + } /> {this.renderResults()} diff --git a/front/src/pages/manage/OverView/index.jsx b/front/src/pages/manage/OverView/index.jsx index aaf0258..52c2a8a 100644 --- a/front/src/pages/manage/OverView/index.jsx +++ b/front/src/pages/manage/OverView/index.jsx @@ -22,9 +22,11 @@ function mapDispatchToProps(dispatch) { addNode: (item, e) => dispatch(action.addNode(item, e)), editNode: (item, e) => dispatch(action.editNode(item, e)), changeIsInit: value => dispatch(action.changeIsInit(value)), - changeCheckedKeys: (keys, nodes) => dispatch(action.changeCheckedKeys(keys, nodes)), + changeCheckedKeys: (keys, nodes) => + dispatch(action.changeCheckedKeys(keys, nodes)), changeExpandedKeys: keys => dispatch(action.changeExpandedKeys(keys)), - changeCurrentClickItem: item => dispatch(action.changeCurrentClickItem(item)), + changeCurrentClickItem: item => + dispatch(action.changeCurrentClickItem(item)), changeLoadedKeys: keys => dispatch(action.changeLoadedKeys(keys)) }; } @@ -78,7 +80,9 @@ class OverView extends React.Component { const { expandedKeys, changeExpandedKeys } = this.props; const item = e.node.props.dataRef; if (item.type === 0) { - window.open(item.url); + window.open( + item.url.startsWith("http") ? item.url : "http://" + item.url + ); } else { const id = item.bookmarkId.toString(); const index = expandedKeys.indexOf(id); @@ -88,7 +92,16 @@ class OverView extends React.Component { } render() { - const { isEdit, setIsEdit, treeData, addNode, isInit, expandedKeys, checkedKeys, loadedKeys } = this.props; + const { + isEdit, + setIsEdit, + treeData, + addNode, + isInit, + expandedKeys, + checkedKeys, + loadedKeys + } = this.props; const { isLoading } = this.state; const { changeExpandedKeys } = this.props; return ( @@ -98,23 +111,46 @@ class OverView extends React.Component {
我的书签树 - ) : null} - 使用帮助 + + 使用帮助 +
{isEdit ? ( - ) : null} -
@@ -136,7 +172,9 @@ class OverView extends React.Component { > {renderTreeNodes.call(this, treeData)} - {isInit && treeData.length === 0 ? : null} + {isInit && treeData.length === 0 ? ( + + ) : null}
@@ -145,7 +183,4 @@ class OverView extends React.Component { } } -export default connect( - mapStateToProps, - mapDispatchToProps -)(OverView); +export default connect(mapStateToProps, mapDispatchToProps)(OverView);