Skip to content

Commit 971b231

Browse files
BinaryHBsdjcw
authored andcommitted
feat: 创建工单时增加文档检索功能
在「新建工单」页面,用户输入标题时,对标题文字,通过 algolia 执行文档检索,返回关联的文档结果。
1 parent 02a52c3 commit 971b231

5 files changed

Lines changed: 164 additions & 11 deletions

File tree

modules/NewTicket.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
/*global $*/
1+
/*global $, ALGOLIA_API_KEY*/
22
import React from 'react'
33
import PropTypes from 'prop-types'
44
import {FormGroup, ControlLabel, FormControl, Button, Tooltip, OverlayTrigger} from 'react-bootstrap'
55
import AV from 'leancloud-storage/live-query'
6+
import docsearch from 'docsearch.js'
67

78
import {uploadFiles, getTinyCategoryInfo} from './common'
89
import {defaultLeanCloudRegion, getLeanCloudRegionText} from '../lib/common'
@@ -24,6 +25,13 @@ export default class NewTicket extends React.Component {
2425
}
2526

2627
componentDidMount() {
28+
docsearch({
29+
apiKey: ALGOLIA_API_KEY,
30+
indexName: 'leancloud',
31+
inputSelector: '.docsearch-input',
32+
debug: false // Set debug to true if you want to inspect the dropdown
33+
})
34+
2735
this.contentTextarea.addEventListener('paste', this.pasteEventListener.bind(this))
2836
AV.Cloud.run('checkPermission')
2937
.then(() => {
@@ -165,7 +173,8 @@ export default class NewTicket extends React.Component {
165173
<form onSubmit={this.handleSubmit.bind(this)}>
166174
<FormGroup>
167175
<ControlLabel>标题</ControlLabel>
168-
<input type="text" className="form-control" value={this.state.title} onChange={this.handleTitleChange.bind(this)} />
176+
<input type="text" className="form-control docsearch-input" value={this.state.title}
177+
onChange={this.handleTitleChange.bind(this)} />
169178
</FormGroup>
170179
<FormGroup>
171180
<ControlLabel>

package-lock.json

Lines changed: 142 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"color": "^1.0.3",
3333
"compression": "^1.6.2",
3434
"css-loader": "^0.28.4",
35+
"docsearch.js": "^2.5.2",
3536
"express": "^4.14.0",
3637
"extract-text-webpack-plugin": "^1.0.1",
3738
"highlight.js": "^9.10.0",

public/css/docsearch-override.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
span.algolia-autocomplete {
2+
display: block!important;
3+
}
4+
.algolia-autocomplete .ds-dropdown-menu {
5+
max-width: 100%;
6+
min-width: 100%;
7+
}

server.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ const getIndexPage = (uuid) => {
4141
<link rel="stylesheet" href="/css/leancloud-base.css">
4242
<link rel="stylesheet" href="/css/react-datepicker.css">
4343
<link rel="stylesheet" href="/index.css">
44+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.css" />
4445
<link rel="stylesheet" href="${process.env.WEBPACK_DEV_SERVER || ''}/app.css">
46+
<link rel="stylesheet" href="/css/docsearch-override.css">
4547
<script src="/js/jquery.min.js"></script>
4648
<script src="/js/bootstrap.min.js"></script>
4749
<div id=app></div>
@@ -54,6 +56,7 @@ const getIndexPage = (uuid) => {
5456
UUID = '${uuid}'
5557
ORG_NAME = '${orgName}'
5658
USE_OAUTH = '${!!process.env.OAUTH_KEY}'
59+
ALGOLIA_API_KEY = '${process.env.ALGOLIA_API_KEY}'
5760
</script>
5861
<script src='${process.env.WEBPACK_DEV_SERVER || ''}/bundle.js'></script>
5962
<script>

0 commit comments

Comments
 (0)