From 814405709fa9cc44542f95b5e795e60992d9e319 Mon Sep 17 00:00:00 2001 From: silenceqi Date: Tue, 22 Dec 2020 15:20:34 +0800 Subject: [PATCH] rewrite pro dict page --- api/index_management/index.go | 147 ++++- api/init.go | 12 +- main.go | 1 + model/dict.go | 67 +- model/page_result.go | 6 + search-center.yml | 2 +- ui.go | 12 +- web/config/config.js | 7 + web/config/router.config.js | 2 +- web/mock/search/dict.js | 36 ++ web/src/pages/SearchManage/dict/Pro.js | 333 ++++++++++ web/src/pages/SearchManage/dict/Pro.less | 26 + .../pages/SearchManage/dict/Professional.js | 606 ------------------ .../pages/SearchManage/dict/Professional.less | 227 ------- web/src/pages/SearchManage/models/dict.js | 147 +++++ web/src/pages/SearchManage/models/logstash.js | 49 -- web/src/services/search.js | 35 + 17 files changed, 786 insertions(+), 929 deletions(-) create mode 100644 model/page_result.go create mode 100644 web/mock/search/dict.js create mode 100644 web/src/pages/SearchManage/dict/Pro.js create mode 100644 web/src/pages/SearchManage/dict/Pro.less delete mode 100644 web/src/pages/SearchManage/dict/Professional.js delete mode 100644 web/src/pages/SearchManage/dict/Professional.less create mode 100644 web/src/pages/SearchManage/models/dict.js delete mode 100644 web/src/pages/SearchManage/models/logstash.js create mode 100644 web/src/services/search.js diff --git a/api/index_management/index.go b/api/index_management/index.go index 3e0525d7..e8061231 100644 --- a/api/index_management/index.go +++ b/api/index_management/index.go @@ -1,72 +1,156 @@ package index_management import ( - "fmt" + "net/http" + "strconv" + "strings" + "time" + "infini.sh/framework/core/api" httprouter "infini.sh/framework/core/api/router" "infini.sh/framework/core/orm" "infini.sh/framework/core/util" model2 "infini.sh/search-center/model" - "net/http" ) - type APIHandler struct { api.Handler } +func (handler APIHandler) GetDictListAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { + var ( + fromStr = handler.GetParameterOrDefault(req, "from", "0") + sizeStr = handler.GetParameterOrDefault(req, "size", "6") + tag = handler.GetParameterOrDefault(req, "tags", "") + name = handler.GetParameterOrDefault(req, "name", "") + from, _ = strconv.Atoi(fromStr) + size, _ = strconv.Atoi(sizeStr) + tags = strings.Split(tag, ",") + ) + if len(tags) > 3 { + tags = tags[0:3] + } + rel, err := model2.GetDictList(from, size, name, tags) + if err != nil { + handler.Error(w, err) + } + resp := map[string]interface{}{ + "errno": "0", + "errmsg": "", + "data": rel, + } + handler.WriteJSON(w, resp, http.StatusOK) +} -func (handler APIHandler)CreateDictItemAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { +func (handler APIHandler) CreateDictItemAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { //id := ps.ByName("id") - dict:=model2.Dict{} - dict.ID = util.GetUUID() + jq, err := handler.GetJSON(req) + if err != nil { + handler.Error(w, err) + return + } + name, err := jq.String("name") + if err != nil { + handler.Error(w, err) + return + } + tags, err := jq.ArrayOfStrings("tags") + if err != nil { + handler.Error(w, err) + return + } - err := orm.Save(dict) - if err!=nil{ + content, err := jq.String("content") + if err != nil { + handler.Error(w, err) + return + } + createdAt := time.Now() + + dict := model2.Dict{ + ID: util.GetUUID(), + Name: name, + Tags: tags, + Content: []byte(content), + CreatedAt: createdAt, + UpdatedAt: createdAt, + } + + err = orm.Save(dict) + if err != nil { panic(err) } + handler.WriteJSON(w, map[string]interface{}{ + "payload": dict, + "errno": "0", + "errmsg": "", + }, http.StatusOK) } func (handler APIHandler) DeleteDictItemAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { id := ps.ByName("id") - dict:=model2.Dict{} + dict := model2.Dict{} dict.ID = id - err := orm.Delete(dict) - if err!=nil{ + if err != nil { panic(err) } + handler.WriteJSON(w, map[string]interface{}{ + "errno": "0", + "errmsg": "", + }, http.StatusOK) } -func (handler APIHandler) DeleteDictItemAction2(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { - - field:=handler.GetParameterOrDefault(req,"help","help message") - fmt.Println(field) - - json,err:=handler.GetJSON(req) - if err!=nil{ - handler.Error(w,err) +func (handler APIHandler) UpdateDictItemAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { + jq, err := handler.GetJSON(req) + if err != nil { + handler.Error(w, err) + return + } + id, err := jq.String("id") + if err != nil { + handler.Error(w, err) + return + } + name, err := jq.String("name") + if err != nil { + handler.Error(w, err) + return + } + tags, err := jq.ArrayOfStrings("tags") + if err != nil { + handler.Error(w, err) return } - id,err:=json.String("id") - if err!=nil{ - handler.Error(w,err) + content, err := jq.String("content") + if err != nil { + handler.Error(w, err) return } - dict:=model2.Dict{} - dict.ID = id + updatedAt := time.Now() - - err = orm.Delete(dict) - if err!=nil{ - handler.Error(w,err) + dict := model2.Dict{ + ID: id, + Name: name, + Tags: tags, + Content: []byte(content), + UpdatedAt: updatedAt, } + + err = orm.Update(dict) + if err != nil { + panic(err) + } + handler.WriteJSON(w, map[string]interface{}{ + "payload": dict, + "errno": "0", + "errmsg": "", + }, http.StatusOK) + } - - // TaskAction handle task creation and return task list which support parameter: `from`, `size` and `host`, eg: //curl -XGET http://127.0.0.1:8001/task?from=100&size=10&host=elasticsearch.cn func (handler APIHandler) TaskAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { @@ -91,5 +175,4 @@ func (handler APIHandler) TaskAction(w http.ResponseWriter, req *http.Request, p // handler.Error(w, err) //} else { // handler.WriteJSONListResult(w, total, tasks, http.StatusOK) - } - +} diff --git a/api/init.go b/api/init.go index fecc5284..518c6ed3 100644 --- a/api/init.go +++ b/api/init.go @@ -6,11 +6,13 @@ import ( "infini.sh/search-center/api/index_management" ) -func Init() { - handler:=index_management.APIHandler{} +func Init() { + handler := index_management.APIHandler{} //ui.HandleUIMethod(api.POST, "/api/get_indices",index_management.API1) - ui.HandleUIMethod(api.POST, "/api/dict/_create",handler.CreateDictItemAction) + ui.HandleUIMethod(api.GET, "/api/dict/_search", handler.GetDictListAction) + ui.HandleUIMethod(api.POST, "/api/dict/_create", handler.CreateDictItemAction) //ui.HandleUIMethod(api.GET, "/api/dict/:id",handler.GetDictItemAction) - ui.HandleUIMethod(api.DELETE, "/api/dict/:id",handler.DeleteDictItemAction) - ui.HandleUIMethod(api.DELETE, "/api/dict/",handler.DeleteDictItemAction2) + ui.HandleUIMethod(api.DELETE, "/api/dict/:id", handler.DeleteDictItemAction) + //ui.HandleUIMethod(api.DELETE, "/api/dict/", handler.DeleteDictItemAction2) + ui.HandleUIMethod(api.POST, "/api/dict/_update", handler.UpdateDictItemAction) } diff --git a/main.go b/main.go index 5722b2aa..bcacfae7 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "errors" _ "expvar" + "infini.sh/framework" "infini.sh/framework/core/env" "infini.sh/framework/core/module" diff --git a/model/dict.go b/model/dict.go index 5bc21f7e..e0afeffc 100644 --- a/model/dict.go +++ b/model/dict.go @@ -1,6 +1,69 @@ package model +import ( + "fmt" + "strings" + "time" + + "infini.sh/framework/core/orm" +) + +//Dict model type Dict struct { - ID string `json:"id" elastic_meta:"_id"` - Url string `json:"title,omitempty"` + ID string `json:"id" elastic_meta:"_id"` + Name string `json:"name,omitempty" elastic_mapping:"name:{type:text}"` + Tags []string `json:"tags" elastic_mapping:"tags:{type:text}"` + Content []byte `json:"content" elastic_mapping:"content:{type:binary}"` + CreatedAt time.Time `json:"created_at" elastic_mapping:"created_at:{type:date}"` + UpdatedAt time.Time `json:"updated_at" elastic_mapping:"updated_at:{type:date}"` +} + +func GetDictList(from, size int, name string, tags []string) (orm.Result, error) { + //sort := []orm.Sort{} + //sort = append(sort, orm.Sort{Field: "created_at", SortType: orm.DESC}) + var ( + sort = `[{ + "created_at": { + "order": "desc" + }}]` + query = `{ + "bool": { + "must": [ + %s + ], + "should": [ + %s + ], + "minimum_should_match": %d + } + }` + should = "" + must = "" + minShould = 0 + ) + if name = strings.Trim(name, " "); name != "" { + must = fmt.Sprintf(`{"match":{"name": "%s"}}`, name) + } + for i, tag := range tags { + if tag == "" { + continue + } + should += fmt.Sprintf(`{"match":{"tags":"%s"}}`, tag) + if i != len(tags)-1 { + should += "," + } + minShould = 1 + } + query = fmt.Sprintf(query, must, should, minShould) + rq := fmt.Sprintf(`{"from":%d, "size":%d, "sort": %s, "query": %s}`, from, size, sort, query) + //fmt.Println(rq) + q := &orm.Query{ + //From: from, + //Size: size, + //Sort: &sort, + RawQuery: []byte(rq), + } + //var dictList = []Dict{} + err, sr := orm.Search(Dict{}, nil, q) + return sr, err } diff --git a/model/page_result.go b/model/page_result.go new file mode 100644 index 00000000..2af4a2ef --- /dev/null +++ b/model/page_result.go @@ -0,0 +1,6 @@ +package model + +type PageResult struct { + Total int `json:"total"` + Data interface{} `json:"data"` +} diff --git a/search-center.yml b/search-center.yml index 3f575a8b..c9438bd1 100644 --- a/search-center.yml +++ b/search-center.yml @@ -1,7 +1,7 @@ elasticsearch: - name: default enabled: true - endpoint: https://192.168.3.98:9200 + endpoint: http://localhost:9200 index_prefix: infini- basic_auth: username: elastic diff --git a/ui.go b/ui.go index 7d6b5f32..44673adf 100644 --- a/ui.go +++ b/ui.go @@ -2,15 +2,15 @@ package main import ( "fmt" + "net/http" + log "github.com/cihub/seelog" "infini.sh/framework/core/api" "infini.sh/framework/core/ui" "infini.sh/framework/core/util" "infini.sh/framework/core/vfs" - "infini.sh/search-center/.public" uiapi "infini.sh/search-center/api" "infini.sh/search-center/config" - "net/http" ) type UI struct { @@ -20,22 +20,22 @@ type UI struct { func (h UI) InitUI() { - vfs.RegisterFS(public.StaticFS{StaticFolder: h.config.UILocalPath, TrimLeftPath: h.config.UILocalPath , CheckLocalFirst: h.config.UILocalEnabled, SkipVFS: !h.config.UIVFSEnabled}) + // vfs.RegisterFS(public.StaticFS{StaticFolder: h.config.UILocalPath, TrimLeftPath: h.config.UILocalPath , CheckLocalFirst: h.config.UILocalEnabled, SkipVFS: !h.config.UIVFSEnabled}) ui.HandleUI("/", vfs.FileServer(vfs.VFS())) uiapi.Init() ui.HandleUIFunc("/api/", func(w http.ResponseWriter, req *http.Request) { - log.Warn("api: ",req.URL," not implemented") + log.Warn("api: ", req.URL, " not implemented") request, err := h.GetRawBody(req) if err != nil { fmt.Println(err) return } - response:=map[string]interface{}{} - response["request"]=string(request) + response := map[string]interface{}{} + response["request"] = string(request) w.Write(util.ToJSONBytes(request)) }) diff --git a/web/config/config.js b/web/config/config.js index a225972e..b8fb6de6 100644 --- a/web/config/config.js +++ b/web/config/config.js @@ -67,6 +67,13 @@ export default { // pathRewrite: { '^/server': '' }, // }, // }, + proxy: { + '/api/': { + target: 'http://localhost:2900', + changeOrigin: true, + // pathRewrite: { '^/server': '' }, + }, + }, ignoreMomentLocale: true, lessLoaderOptions: { javascriptEnabled: true, diff --git a/web/config/router.config.js b/web/config/router.config.js index 83acfffa..da6519f2 100644 --- a/web/config/router.config.js +++ b/web/config/router.config.js @@ -188,7 +188,7 @@ export default [ }, { path: '/search/dict/professional', - component: './SearchManage/dict/Professional', + component: './SearchManage/dict/Pro', }, { path: '/search/dict/common', diff --git a/web/mock/search/dict.js b/web/mock/search/dict.js new file mode 100644 index 00000000..c0e4a167 --- /dev/null +++ b/web/mock/search/dict.js @@ -0,0 +1,36 @@ +import { func } from "prop-types"; + +let dictList = [{ + name: '道路词汇大全', + content: '晨明、作业段、作业标志、左开道岔、左港、遵义南、遵义北、俎上之肉、组合辙叉、阻工、走马岭、纵向间距、纵向轨枕、纵向标线、纵梁桥、纵断面高程、总监代表处、总监办、总概算汇总', + tags: ['铁路'] +},{ + name: '铁路词汇', + content: '晨明、作业段、作业标志、左开道岔、左港、遵义南、遵义北、俎上之肉、组合辙叉、阻工、走马岭、纵向间距、纵向轨枕、纵向标线、纵梁桥、纵断面高程、总监代表处、总监办、总概算汇总', + tags: ['铁路'] +},{ + name: '中国国道省道高速公路名录', + content: '' +},{ + name: '民用航空', + content: '' +},{ + name: '铁路常用词', + content: '' +},{ + name: '铁路词汇', + content: '' +},{ + name: '铁路工务', + content: '' +},]; + + +export default { + 'post /search/dictlist': function(req, res){ + res.send(dictList); + }, + // 'post /api/dict/_create': function(req, res){ + + // } +} \ No newline at end of file diff --git a/web/src/pages/SearchManage/dict/Pro.js b/web/src/pages/SearchManage/dict/Pro.js new file mode 100644 index 00000000..5487e314 --- /dev/null +++ b/web/src/pages/SearchManage/dict/Pro.js @@ -0,0 +1,333 @@ +import React from 'react'; +import {Form, Row, Col, Select,Input, Button, Card,List,Avatar, Modal} from 'antd'; +import Link from 'umi/link'; +import {connect} from 'dva' +import moment from 'moment'; + +const {Option} = Select; +import styles from './Pro.less'; + + +const UpdateForm = Form.create()(props => { + const { handleUpdateModalVisible, handleUpdate,values,form, title} = props; + + const okHandle = () => { + form.validateFields((err, fieldsValue) => { + if (err) return; + form.resetFields(); + let upVals = Object.assign(values, fieldsValue); + handleUpdate(upVals); + }); + }; + + return ( + handleUpdateModalVisible()} + > + + {form.getFieldDecorator('name', { + initialValue: values.name, + rules: [{ required: true, message: '请输入至少五个字符的名称!' }], + })()} + + + {form.getFieldDecorator('tags', { + initialValue: values.tags, + rules: [{ required: false }], + })()} + + + {form.getFieldDecorator('content', { + initialValue: values.content, + rules: [{ required: true }], + })()} + + + ); +}); + +@connect(({dict})=>({ + dict +})) +@Form.create() +class Pro extends React.Component { + constructor(props){ + super(props); + this.handleUpdate = this.handleUpdate.bind(this); + } + state = { + updateFormValues: null, + currentFormOp: null, + data: [], + search: { + size: 6, + name: "", + tags: "", + pageIndex: 1, + } + } + componentDidMount(){ + this.fetchData(); + } + + handleReset = ()=>{ + const {form} = this.props; + form.resetFields(); + this.setState({ + search: { + size: 6, + name: "", + tags: "", + pageIndex: 1, + } + },()=>{ + this.fetchData(); + }); + } + + handleSearch = ()=>{ + const {form} = this.props; + let me = this; + form.validateFields((err, fieldsValue) => { + if (err) return; + me.setState({search:{ + ...me.state.search, + pageIndex: 1, + name: fieldsValue.name, + tags: fieldsValue.tags.join(',') + }},()=>{ + me.fetchData(); + }) + }) + } + + renderForm() { + const { + form: { getFieldDecorator }, + } = this.props; + const formItemLayout = { + labelCol: { span: 10 }, + wrapperCol: { span: 14 }, + style: {marginBottom: 0} + }; + return ( +
+ + + + {getFieldDecorator('tags', { + // rules: [{ required: true, message: '请选择词典标签' }], + })( + + )} + + + + + {getFieldDecorator('name')()} + + + +
+ + +
+ +
+
+ ); + } + handleNewClick = () => { + this.setState({ + currentFormOp: 'NEW', + updateFormValues: {}, + formTitle: '添加词典' + }) + } + + handleDelete = (item) =>{ + const {dispatch} = this.props; + Modal.confirm({ + title: '删除Pipeline', + content: '确定删除该Pipeline吗?', + okText: '确认', + cancelText: '取消', + onOk: () => { + dispatch({ + type: 'dict/deleteDictItem', + payload: { + id: item.id, + } + }) + }, + }); + + } + + handleModifyClick = (item)=>{ + this.setState({ + updateFormValues: item, + formTitle: '修改词典', + currentFormOp: 'UPDATE', + }) + } + + handleUpdate(values){ + let {currentFormOp, data} = this.state; + const {dispatch} = this.props; + let me = this; + switch(currentFormOp){ + case "NEW": + dispatch({ + type: 'dict/addDictItem', + payload: values, + callback: ()=>{ + me.setState({ + updateFormValues: null, + currentFormOp: null + }); + } + }); + break; + case "UPDATE": + dispatch({ + type: 'dict/updateDictItem', + payload: values, + callback: ()=>{ + me.setState({ + updateFormValues: null, + currentFormOp: null + }); + } + }); + } + } + + fetchData = ()=>{ + const {dispatch} = this.props; + let {size, pageIndex} = this.state.search; + let me = this; + dispatch({ + type: 'dict/fetchDictList', + payload: { + from: (pageIndex - 1) * size, + ...this.state.search + }, + callback: ()=>{ + } + }); + } + + handlePageChange = (p)=>{ + this.setState({ + search: { + ...this.state.search, + pageIndex: p, + } + },()=>{ + this.fetchData(); + }) + } + + render(){ + let data = this.props.dict ? this.props.dict.dictList : []; + let total = this.props.dict ? this.props.dict.total: 0; + let updateFormValues = this.state.updateFormValues; + let size = this.state.search.size; + const updateMethods = { + handleUpdate: this.handleUpdate, + handleUpdateModalVisible: ()=>{ + this.setState({ + updateFormValues: null, + currentFormOp: null, + }) + } + }; + console.log('render'); + return ( +
+ + {this.renderForm()} + +
} + bordered={false}> + ( + +
+ + {item.name} +
+
词条样例:{item.content} +
+
+ + 更新时间: {moment(item.updated_at).format("YYYY-MM-DD HH:mm") } + +
+
+ + + + +
+
+ )}> + +
+ + {updateFormValues ? ( + + ) : null} + + ) + } +} + +export default Pro; \ No newline at end of file diff --git a/web/src/pages/SearchManage/dict/Pro.less b/web/src/pages/SearchManage/dict/Pro.less new file mode 100644 index 00000000..c03693b8 --- /dev/null +++ b/web/src/pages/SearchManage/dict/Pro.less @@ -0,0 +1,26 @@ +.list-item{ + padding: 24px; + border: 0; + border-radius: 0; + box-shadow: 1px 0 0 0 #e8e8e8, 0 1px 0 0 #e8e8e8, 1px 1px 0 0 #e8e8e8, 1px 0 0 0 #e8e8e8 inset, 0 1px 0 0 #e8e8e8 inset; + transition: all 0.3s; + padding-top: 24px !important; + padding-bottom: 24px !important; + margin-bottom: 0 !important; +} + +.list-item:hover { z-index: 1; box-shadow: rgba(0, 0, 0, 0.15) 0px 2px 8px; } + +.list-item .desc { + color: rgba(0, 0, 0, 0.45); + height: 44px; + line-height: 22px; + overflow: hidden; + margin:5px auto; + font-size: 12px; +} +.list-item .datetime{ + color: rgba(0, 0, 0, 0.25); + font-size: 12px; +} + diff --git a/web/src/pages/SearchManage/dict/Professional.js b/web/src/pages/SearchManage/dict/Professional.js deleted file mode 100644 index ef27d106..00000000 --- a/web/src/pages/SearchManage/dict/Professional.js +++ /dev/null @@ -1,606 +0,0 @@ -import React, { PureComponent, Fragment } from 'react'; -import { connect } from 'dva'; -import { - Row, - Col, - Card, - Form, - Input, - Button, - Modal, - message, - Divider, - Icon, - DatePicker, - TimePicker, - Select, - Popover, - Avatar -} from 'antd'; -import Link from 'umi/link'; -import StandardTable from '@/components/StandardTable'; -import PageHeaderWrapper from '@/components/PageHeaderWrapper'; - -import styles from './Professional.less'; - -const FormItem = Form.Item; -const { TextArea } = Input; -const fieldLabels = { - keyword_type: '词典标签' - -}; -const CreateForm = Form.create()(props => { - const { modalVisible, form, handleAdd, handleModalVisible } = props; - const okHandle = () => { - form.validateFields((err, fieldsValue) => { - if (err) return; - form.resetFields(); - handleAdd(fieldsValue); - }); - }; - return ( - handleModalVisible()}> - - {form.getFieldDecorator('name', { - rules: [{ required: true, message: '请输入至少一个字符的名称!', min: 1 }], - })()} - - - {form.getFieldDecorator('keyword_type', { - rules: [{ required: true, message: '请选择关键词类型' }], - })( - -)} - - -); -}); - -const UpdateForm = Form.create()(props => { - const { updateModalVisible, handleUpdateModalVisible, handleUpdate,values,form } = props; - - const okHandle = () => { - form.validateFields((err, fieldsValue) => { - if (err) return; - form.resetFields(); - handleUpdate(fieldsValue); - }); - }; - - return ( - handleUpdateModalVisible()}> - - - {form.getFieldDecorator('keyword', { - initialValue: values.keyword, - rules: [{ required: true, message: '请输入至少一个字符的名称!', min: 1 }], - })()} - - - - {form.getFieldDecorator('keyword_type', { - initialValue: values.value, - rules: [{ required: true, message: '请选择关键词类型' }], - })( - - )} - - -); -}); - -/* eslint react/no-multi-comp:0 */ -@connect(({ pipeline, loading }) => ({ - pipeline, - loading: loading.models.pipeline, -})) -@Form.create() -class Professional extends PureComponent { - state = { - modalVisible: false, - updateModalVisible: false, - expandForm: false, - selectedRows: [], - formValues: {}, - updateFormValues: {}, - }; - datasource = ` - [ - { - "keyword" : "验收标准", - "type" : "客运", - "value": "keyun" - }, - { - "keyword" : "桥梁施工技术规范", - "type" : "客运", - "value": "keyun" - },{ - "keyword" : "路规", - "type" : "客运", - "value": "keyun" - },{ - "keyword" : "遂规", - "type" : "客运", - "value": "keyun" - }, - { - "keyword" : "铁路技术管理规则", - "type" : "客运", - "value": "keyun" - },{ - "keyword" : "行车组织规则", - "type" : "客运", - "value": "keyun" - }, - { - "keyword" : "铁路交通事故调查处理规则", - "type" : "客运", - "value": "keyun" - }]`; - - columns = [ - { - title: '关键词名称', - dataIndex: 'keyword', - }, - { - title: '关键词分类', - dataIndex: 'type', - }, - { - title: '操作', - render: (text, record) => ( - - this.handleUpdateModalVisible(true, record)}>修改 - - { - this.state.selectedRows.push(record); - this.handleDeleteClick(); - }}>删除 - - ), - }, - ]; - - componentDidMount() { - const { dispatch } = this.props; - // dispatch({ - // type: 'pipeline/fetch', - // }); - } - - handleStandardTableChange = (pagination, filtersArg, sorter) => { - const { dispatch } = this.props; - const { formValues } = this.state; - - const filters = Object.keys(filtersArg).reduce((obj, key) => { - const newObj = { ...obj }; - newObj[key] = getValue(filtersArg[key]); - return newObj; - }, {}); - - const params = { - currentPage: pagination.current, - pageSize: pagination.pageSize, - ...formValues, - ...filters, - }; - if (sorter.field) { - params.sorter = `${sorter.field}_${sorter.order}`; - } - - dispatch({ - type: 'pipeline/fetch', - payload: params, - }); - }; - - handleFormReset = () => { - const { form, dispatch } = this.props; - form.resetFields(); - this.setState({ - formValues: {}, - }); - dispatch({ - type: 'pipeline/fetch', - payload: {}, - }); - }; - - handleDeleteClick = e => { - const { dispatch } = this.props; - const { selectedRows } = this.state; - - if (!selectedRows) return; - dispatch({ - type: 'pipeline/delete', - payload: { - key: selectedRows.map(row => row.name), - }, - callback: () => { - this.setState({ - selectedRows: [], - }); - }, - }); - }; - - handleSelectRows = rows => { - this.setState({ - selectedRows: rows, - }); - }; - - handleSearch = e => { - e.preventDefault(); - - const { dispatch, form } = this.props; - - form.validateFields((err, fieldsValue) => { - if (err) return; - - const values = { - ...fieldsValue, - updatedAt: fieldsValue.updatedAt && fieldsValue.updatedAt.valueOf(), - }; - - this.setState({ - formValues: values, - }); - - dispatch({ - type: 'rule/fetch', - payload: values, - }); - }); - }; - - handleModalVisible = flag => { - this.setState({ - modalVisible: !!flag, - }); - }; - - handleUpdateModalVisible = (flag, record) => { - this.setState({ - updateModalVisible: !!flag, - updateFormValues: record || {}, - }); - }; - - handleAdd = fields => { - const { dispatch } = this.props; - dispatch({ - type: 'pipeline/add', - payload: { - name: fields.name, - desc: fields.desc, - processors: fields.processors, - }, - }); - - message.success('添加成功'); - this.handleModalVisible(); - }; - - handleUpdate = fields => { - const { dispatch } = this.props; - dispatch({ - type: 'pipeline/update', - payload: { - name: fields.name, - desc: fields.desc, - processors: fields.processors, - }, - }); - - message.success('修改成功'); - this.handleUpdateModalVisible(); - }; - - renderSimpleForm() { - const { - form: { getFieldDecorator }, - } = this.props; - return ( -
- - - - {getFieldDecorator('keyword_type', { - rules: [{ required: true, message: '请选择关键词类型' }], - })( - - )} - - - - - {getFieldDecorator('name')()} - - - - - - - - - -
- ); - } - - renderForm() { - return this.renderSimpleForm(); - } - - render() { - const data = { - list: JSON.parse(this.datasource), - pagination: { - pageSize: 5, - }, - }; - const { selectedRows, modalVisible, updateModalVisible, updateFormValues } = this.state; - const parentMethods = { - handleAdd: this.handleAdd, - handleModalVisible: this.handleModalVisible, - }; - const updateMethods = { - handleUpdateModalVisible: this.handleUpdateModalVisible, - handleUpdate: this.handleUpdate, - }; - - return ( - - -
{this.renderForm()}
-
- 全部词典} - bodyStyle={{ padding: 0 }} > - - - - - 道路词汇大全 - } - description="词条样例:晨明、作业段、作业标志、左开道岔、左港、遵义南、遵义北、俎上之肉、组合辙叉、阻工、走马岭、纵向间距、纵向轨枕、纵向标线、纵梁桥、纵断面高程、总监代表处、总监办、总概算汇总"/> -
- - 更新时间: 2009-12-28 19:34:26 - -
- - - - -
-
- - - - - - 中国国道省道高速公路名录 - } - description="中国国道省道高速公路名录词条样例:京福高速公路、同三高速公路、青银高速公路、日东高速公路、潍莱高速公路、威乌高速公路、济青高速公路、青红高速公路、京珠高速公路、济菏高速公路、沪瑞高速公路、赣粤高速公路、连霍高速公路、丹拉高速公路"/> -
- - 更新时间: 2009-12-28 19:34:26 - -
- - - - -
-
- - - - - 物流货运专业术语 - } - description="词条样例:物流、物流活动、物流作业、物流模数、物流技术、物流成本、物流管理、物流中心、物流网络、物流信息、物流企业、物流单证、物流联盟、供应物流、生产物流、销售物流、回收物流、废弃物物流、绿色物流"/> -
- - 更新时间: 2009-12-28 19:34:26 - -
- - - - -
-
- - - - - 铁路词汇 - } - description="铁路词汇词条样例:铁路、铁道、铁道部、铁路局、太原铁路局、北京铁路局、车务段、机务段、工务段、供电段、电务段、列车段、车辆段、铁通、车务、机务、工务、供电、电务"/> -
- - 更新时间: 2009-12-28 19:34:26 - - -
- - - - -
-
- - - - - 客运专线铁路 - } - description="词条样例:验收标准、验标、桥梁施工技术规范、桥规、路规、遂规、铁路技术管理规则、行车组织规则、铁路交通事故调查处理规则、运输组织、铁路安全管理规则、铁路行车操作规则、铁路运用组织规程、区段号、司机号、总重、辆数"/> -
- - 更新时间: 2009-12-28 19:34:26 - -
- - - - -
-
- - - - - 民用航空 - } - description="词条样例:晨明、作业段、作业标志、左开道岔、左港、遵义南、遵义北、俎上之肉、组合辙叉、阻工、走马岭、纵向间距、纵向轨枕、纵向标线、纵梁桥、纵断面高程、总监代表处、总监办、总概算汇总"/> -
- - 更新时间: 2009-12-28 19:34:26 - -
- - - - -
-
- - - - - 物流术语 - } - description="词条样例:晨明、作业段、作业标志、左开道岔、左港、遵义南、遵义北、俎上之肉、组合辙叉、阻工、走马岭、纵向间距、纵向轨枕、纵向标线、纵梁桥、纵断面高程、总监代表处、总监办、总概算汇总"/> -
- - 更新时间: 2009-12-28 19:34:26 - -
- - - - -
-
- - - - - - 民航业词库 - } - description="词条样例:晨明、作业段、作业标志、左开道岔、左港、遵义南、遵义北、俎上之肉、组合辙叉、阻工、走马岭、纵向间距、纵向轨枕、纵向标线、纵梁桥、纵断面高程、总监代表处、总监办、总概算汇总"/> -
- - 更新时间: 2009-12-28 19:34:26 - -
- - - - -
-
- - - - - - 港口列表 - } - description="词条样例:阿比让、阿布扎比、阿德莱德、阿尔及尔、阿卡胡特拉、阿拉木图、阿里卡、阿帕帕、阿什杜德、阿什哈巴特、阿特利斯科、埃德蒙顿、安科纳、安特卫普、敖德萨、奥胡斯、奥克兰、奥兰、巴尔的摩"/> -
- - 更新时间: 2009-12-28 19:34:26 - -
- - - - -
-
-
-
- ); - } -} - -export default Professional; diff --git a/web/src/pages/SearchManage/dict/Professional.less b/web/src/pages/SearchManage/dict/Professional.less deleted file mode 100644 index 03801711..00000000 --- a/web/src/pages/SearchManage/dict/Professional.less +++ /dev/null @@ -1,227 +0,0 @@ -@import '~antd/lib/style/themes/default.less'; -@import '~@/utils/utils.less'; - -.activitiesList { - padding: 0 24px 8px 24px; - .username { - color: @text-color; - } - .event { - font-weight: normal; - } -} - -.pageHeaderContent { - display: flex; - .avatar { - flex: 0 1 72px; - margin-bottom: 8px; - & > span { - border-radius: 72px; - display: block; - width: 72px; - height: 72px; - } - } - .content { - position: relative; - top: 4px; - margin-left: 24px; - flex: 1 1 auto; - color: @text-color-secondary; - line-height: 22px; - .contentTitle { - font-size: 20px; - line-height: 28px; - font-weight: 500; - color: @heading-color; - margin-bottom: 12px; - } - } -} - -.extraContent { - .clearfix(); - float: right; - white-space: nowrap; - .statItem { - padding: 0 32px; - position: relative; - display: inline-block; - > p:first-child { - color: @text-color-secondary; - font-size: @font-size-base; - line-height: 22px; - margin-bottom: 4px; - } - > p { - color: @heading-color; - font-size: 30px; - line-height: 38px; - margin: 0; - > span { - color: @text-color-secondary; - font-size: 20px; - } - } - &:after { - background-color: @border-color-split; - position: absolute; - top: 8px; - right: 0; - width: 1px; - height: 40px; - content: ''; - } - &:last-child { - padding-right: 0; - &:after { - display: none; - } - } - } -} - -.members { - a { - display: block; - margin: 12px 0; - height: 24px; - color: @text-color; - transition: all 0.3s; - .textOverflow(); - .member { - font-size: @font-size-base; - line-height: 24px; - vertical-align: top; - margin-left: 12px; - } - &:hover { - color: @primary-color; - } - } -} - -.projectList { - :global { - .ant-card-meta-description { - color: @text-color-secondary; - height: 44px; - line-height: 22px; - overflow: hidden; - } - } - .cardTitle { - font-size: 0; - a { - color: @heading-color; - margin-left: 12px; - line-height: 24px; - height: 24px; - display: inline-block; - vertical-align: top; - font-size: @font-size-base; - &:hover { - color: @primary-color; - } - } - } - .projectGrid { - width: 33.33%; - } - .projectItemContent { - display: flex; - margin-top: 8px; - overflow: hidden; - font-size: 12px; - height: 20px; - line-height: 20px; - .textOverflow(); - a { - color: @text-color-secondary; - display: inline-block; - flex: 1 1 0; - .textOverflow(); - &:hover { - color: @primary-color; - } - } - .datetime { - color: @disabled-color; - flex: 0 0 auto; - float: right; - } - } -} - -.datetime { - color: @disabled-color; -} - -@media screen and (max-width: @screen-xl) and (min-width: @screen-lg) { - .activeCard { - margin-bottom: 24px; - } - .members { - margin-bottom: 0; - } - .extraContent { - margin-left: -44px; - .statItem { - padding: 0 16px; - } - } -} - -@media screen and (max-width: @screen-lg) { - .activeCard { - margin-bottom: 24px; - } - .members { - margin-bottom: 0; - } - .extraContent { - float: none; - margin-right: 0; - .statItem { - padding: 0 16px; - text-align: left; - &:after { - display: none; - } - } - } -} - -@media screen and (max-width: @screen-md) { - .extraContent { - margin-left: -16px; - } - .projectList { - .projectGrid { - width: 50%; - } - } -} - -@media screen and (max-width: @screen-sm) { - .pageHeaderContent { - display: block; - .content { - margin-left: 0; - } - } - .extraContent { - .statItem { - float: none; - } - } -} - -@media screen and (max-width: @screen-xs) { - .projectList { - .projectGrid { - width: 100%; - } - } -} diff --git a/web/src/pages/SearchManage/models/dict.js b/web/src/pages/SearchManage/models/dict.js new file mode 100644 index 00000000..1df7e223 --- /dev/null +++ b/web/src/pages/SearchManage/models/dict.js @@ -0,0 +1,147 @@ +import { message } from 'antd'; +import { getDictList, addDict, deleteDict,updateDict } from '@/services/search'; + +const utf8 = { + encode: function (string) { + string = string.replace(/\r\n/g,"\n"); + var utftext = ""; + for (var n = 0; n < string.length; n++) { + var c = string.charCodeAt(n); + if (c < 128) { + utftext += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + utftext += String.fromCharCode((c >> 6) | 192); + utftext += String.fromCharCode((c & 63) | 128); + } else { + utftext += String.fromCharCode((c >> 12) | 224); + utftext += String.fromCharCode(((c >> 6) & 63) | 128); + utftext += String.fromCharCode((c & 63) | 128); + } + + } + return utftext; + } , + decode: function (utftext) { + var string = ""; + var i = 0; + var c1, c2,c3; + var c = c1 = c2 = 0; + while ( i < utftext.length ) { + c = utftext.charCodeAt(i); + if (c < 128) { + string += String.fromCharCode(c); + i++; + } else if((c > 191) && (c < 224)) { + c2 = utftext.charCodeAt(i+1); + string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); + i += 2; + } else { + c2 = utftext.charCodeAt(i+1); + c3 = utftext.charCodeAt(i+2); + string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); + i += 3; + } + } + return string; + } +} + +export default { + namespace: 'dict', + + state: { + }, + effects: { + *fetchDictList({payload, callback}, {call, put}){ + const resp = yield call(getDictList, payload); + if(resp.errno != "0" || !resp.data.Result){ + return + } + resp.data.Result = resp.data.Result.map((item)=>{ + item.content = utf8.decode(atob(item.content)) + return item; + }) + yield put({ + type: 'saveData', + payload: { + dictList: resp.data.Result, + total: resp.data.Total, + ...payload, + }, + }); + if(callback && typeof callback == 'function'){ + callback(resp); + } + //message.loading('数据加载完成', 'initdata'); + }, + *addDictItem({payload, callback}, {call, put}){ + const rel = yield call(addDict, payload); + if(rel.errno != "0"){ + message.warn('添加失败:'+ rel.errmsg) + return + } + rel.payload.content = utf8.decode(atob(rel.payload.content)); + yield put({ + type: 'addDict', + payload: rel.payload, + }) + if(callback && typeof callback == 'function'){ + callback(rel); + } + }, + *updateDictItem({payload, callback}, {call, put}){ + const rel = yield call(updateDict, payload); + if(rel.errno != "0"){ + message.warn('修改:'+ rel.errmsg) + return + } + yield put({ + type: 'updateDict', + payload: payload, + }) + if(callback && typeof callback == 'function'){ + callback(rel); + } + }, + *deleteDictItem({payload}, {call, put, select}){ + let rel = yield call(deleteDict, payload); + if(typeof rel !== 'object'){ + rel = JSON.parse(rel); + } + if(rel.errno != "0"){ + message.warn('删除失败:'+ rel.errmsg) + return + } + const state = yield select(state => state.dict) + yield put({ + type: 'fetchDictList', + payload: { + from: state.from, + size: state.size, + } + }) + } + }, + reducers: { + saveData(state, {payload}){ + return { + ...state, + ...payload + }; + }, + addDict(state, {payload}){ + let dictList = state.dictList || []; + dictList.unshift(payload); + state.dictList = dictList; + return state; + }, + updateDict(state, {payload}){ + let cdata = state.dictList; + let idx = cdata.findIndex((item)=>{ + return item.id == payload.id; + }) + idx > -1 && (cdata[idx] = values); + return state; + } + }, +}; diff --git a/web/src/pages/SearchManage/models/logstash.js b/web/src/pages/SearchManage/models/logstash.js deleted file mode 100644 index 112a61dd..00000000 --- a/web/src/pages/SearchManage/models/logstash.js +++ /dev/null @@ -1,49 +0,0 @@ -import { routerRedux } from 'dva/router'; -import { message } from 'antd'; -import { getLogstashConfig, saveLogstashConfig } from '@/services/datamanagement'; - -export default { - namespace: 'logstash', - - state: { - logstash: { - jdbc:{}, - kafka:{}, - } - }, - effects: { - *queryInitialLogstashConfig(_, {call, put}){ - const istate = yield call(getLogstashConfig); - yield put({ - type: 'initLogstashState', - payload: istate, - }); - message.loading('数据加载完成', 'initdata'); - }, - *submitLogstashConfig({payload}, {call, put}){ - console.log(payload); - const rel = yield call(saveLogstashConfig, payload); - if(rel.message == "Ok") { - message.success('提交成功'); - yield put({ - type: 'updateState', - payload: payload, - }); - } - } - }, - reducers: { - initLogstashState(state, { payload: istate }) { - return { - logstash: istate - } - }, - updateState(state, {payload: newState}){ - var obj = { - ...state, - logstash: Object.assign(state.logstash, newState), - }; - return obj; - }, - }, -}; diff --git a/web/src/services/search.js b/web/src/services/search.js new file mode 100644 index 00000000..f08b2300 --- /dev/null +++ b/web/src/services/search.js @@ -0,0 +1,35 @@ +import request from '@/utils/request'; + +export async function getDictList(payload){ + let url = `/api/dict/_search?from=${payload.from}&size=${payload.size}`; + payload.name && (url+= `&name=${payload.name}`); + payload.tags && (url+=`&tags=${payload.tags}`); + return request(url,{ + method: 'GET', + // body: payload, + expirys: 0, + }); +} + +export async function addDict(payload){ + return request('/api/dict/_create',{ + method: 'POST', + body: payload, + expirys: 0, + }); +} + +export async function deleteDict(payload){ + return request(`/api/dict/${payload.id}`,{ + method: 'DELETE', + expirys: 0, + }); +} + +export async function updateDict(payload){ + return request('/api/dict/_update',{ + method: 'POST', + body: payload, + expirys: 0, + }); +} \ No newline at end of file