广州市综治平台前端
xusd
2025-06-07 ee685c9f350ec9241107d4e8a05799768a0bce9a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
import React, { useEffect, useState, useRef } from 'react';
import NewTableSearch from '@/components/NewTableSearch';
import * as $$ from '@/utils/utility';
import { Form, Space } from 'antd';
import { Divider, Pagination, Spin, Tree, Tooltip } from '@arco-design/web-react';
import { IconDown, IconClose } from '@arco-design/web-react/icon';
import { useNavigate, useLocation } from 'react-router-dom';
import { Scrollbars } from "react-custom-scrollbars";
import { getOffset, getSize } from '@/utils/utility';
 
const TreeNode = Tree.Node;
 
//判决列表
function getPageQuery(data) {
  return $$.ax.request({ url: 'cpwsCaseInfo/pageQuery', type: 'get', data, service: 'know' });
}
 
//判决统计
function getJudgmentCount(data) {
  return $$.ax.request({ url: 'cpwsCaseInfo/categoryCount', type: 'get', data, service: 'know' });
}
 
//调解案例列表
function getCasePageQuery(data) {
  return $$.ax.request({ url: 'dyhCaseInfo/pageQuery', type: 'get', data, service: 'know' });
}
 
//调解案统计
function getCategoryCount(data) {
  return $$.ax.request({ url: 'dyhCaseInfo/categoryCount', type: 'get', data, service: 'know' });
}
 
//统计判决案例和调解案例数量
function getTypeCount(data) {
  return $$.ax.request({ url: 'cpwsCaseInfo/typeCount', type: 'get', data, service: 'know' });
}
 
export default function KnowledgeBase(props) {
  const [form] = Form.useForm();
  const navigate = useNavigate();
  let location = useLocation();
  const scrollRef = useRef(null);
  const dict = {
    '发生时间': 'judgmentTime',
    '纠纷发生地': 'courtName',
    'judgmentTime': '发生时间',
    'keyword': '关键词',
    'dyhCauseId': '纠纷类型',
    'courtName': '纠纷发生地'
  }
 
  const [knowSearchList, setKnowSearchList] = useState([]);//左侧知识库分类
  const [tableList, setTableList] = useState([])//列表
  const [searchData, setSearchData] = useState({});//查询数据
  const [pageData, setPageData] = useState({
    page: 1,
    size: 10,
  });//页码
  const [total, setTotal] = useState(0);//列表总数
  const [loading, setLoading] = useState(false);//表格请求
  const [height, setHeight] = useState(500);//滚动高度
  const [exampleList, setExampleList] = useState([]);//案例类型列表
  const [example, setExample] = useState('判决文书');//案例类型选中
  const [leftLoading, setLeftLoading] = useState(false);//左侧loading
 
  useEffect(() => {
    getTypeCountData()
 
    //缓存处理
    let returnRouteData = $$.getSessionStorage(location.pathname);
    if (returnRouteData && returnRouteData.mediateTab === '2') {
      getCount(returnRouteData.example, true)
      let obj = { ...returnRouteData.searchData };
      form.setFieldsValue(obj)
      setSearchData(returnRouteData.searchData)
      setPageData(returnRouteData.pageData)
      setExample(returnRouteData.example)
      getTableData(returnRouteData.example, { ...returnRouteData.searchData }, returnRouteData.pageData)
      $$.clearSessionStorage(location.pathname);
    } else {
      getCount(example)
    }
 
    onWindowResize()
    window.addEventListener("resize", onWindowResize);
    // 返回一个函数,该函数会在组件卸载前执行  
    return () => {
      // 组件销毁时执行  
      window.removeEventListener("resize", onWindowResize);
    };
  }, [])
 
  const onWindowResize = () => {
    let offsetTop = 0;
    if (scrollRef.current.container) {
      offsetTop = getOffset(scrollRef.current.container).top;
    }
    setHeight(getSize().windowH - offsetTop - 72)
  };
 
  //重置表格请求
  const handleTableReset = (name) => {
    form.resetFields()
    setSearchData({})
    setPageData({
      ...pageData,
      page: 1,
    })
    getTableData(name || example, {}, { page: 1, size: 10 })
  }
 
  //获取统计
  const getCount = async (name, flag) => {
    !flag && handleTableReset(name)
    setLeftLoading(true)
    const getPageData = name == '判决文书' ? getJudgmentCount : getCategoryCount;
    const res = await getPageData()
    if (res.type) {
      setKnowSearchList(res.data)
      setLeftLoading(false)
    }
  }
 
  //获取统计判决案例和调解案例数量
  const getTypeCountData = async () => {
    const res = await getTypeCount()
    if (res.type) {
      setExampleList(res.data)
    }
  }
 
  //获取数据
  const getTableData = async (name, searchData, pageData) => {
    const getPageData = name == '判决文书' ? getPageQuery : getCasePageQuery;
    setLoading(true)
    searchData.dyhCauseId = searchData.dyhCauseId?.length > 0 ? searchData.dyhCauseId[1] : '';
    $$.changeTimNeweFormat(searchData, 'judgmentTime', 'judgmentStart', 'judgmentEnd');
    const res = await getPageData({
      ...searchData,
      ...pageData
    })
    if (res.type) {
      setLoading(false)
      setTableList(res.data.content)
      setTotal(res.data.totalElements)
    }
  }
 
  //命中词条高亮
  const handleText = (text) => {
    let keyword = searchData.keyword || ''
    // 如果没有关键字,则直接渲染文本
    if (!keyword) {
      return <span>{text}</span>;
    }
 
    // 使用正则表达式查找所有匹配的关键字(不区分大小写)
    const regex = new RegExp(`(${keyword})`, 'gi');
 
    // 使用一个数组来存储片段
    const parts = [];
    let lastIndex = 0;
    let match;
 
    // 遍历所有匹配项,并将文本拆分为片段
    while ((match = regex.exec(text)) !== null) {
      // 添加非匹配文本到片段数组
      if (match.index > lastIndex) {
        parts.push(text.slice(lastIndex, match.index));
      }
      // 添加匹配文本(带有高亮样式)到片段数组
      parts.push(
        <span style={{ color: '#1A6FB8' }}>
          {match[0]}
        </span>
      );
      lastIndex = regex.lastIndex;
    }
 
    // 添加剩余的文本(如果有)
    if (lastIndex < text.length) {
      parts.push(text.slice(lastIndex));
    }
 
    // 返回包含所有片段的 JSX 元素
    return <span>{parts}</span>;
  }
 
  //左侧查询
  const searchTotal = (data, children) => {
    const name = dict[data.name];
    let newData = searchData;
    if (name == 'judgmentTime') {
      newData[name] = [children[0] + '-01-01', children[0] + '-12-31']
      setSearchData({
        ...newData
      })
      getTableData(example, { ...newData }, pageData)
    } else {
      //获取层级
      const courtLevel = findLevelInTree(data, children[0])
      const leftSearch = {
        ...newData,
        [name]: children[0],
        courtLevel: courtLevel
      }
      setSearchData(leftSearch)
      getTableData(example, { ...leftSearch }, pageData)
    }
  }
 
  //获取层级
  const findLevelInTree = (root, name) => {
    // 定义一个辅助函数来进行递归搜索
    function search(node, level) {
      // 如果当前节点的名字匹配,则返回当前层级
      if (node.name === name) {
        return level;
      }
 
      // 遍历当前节点的所有子节点
      if (node.children && node.children.length != 0) {
        for (let child of node.children) {
          // 递归调用 search 函数,层级加 1
          let result = search(child, level + 1);
          // 如果找到了匹配的节点,则返回结果
          if (result !== undefined) {
            return result;
          }
        }
      }
 
      // 如果没有找到匹配的节点,则返回 undefined
      return undefined;
    }
 
    // 从根节点开始搜索,初始层级为 0
    return search(root, 0);
  }
 
  //查询
  const handleSearch = () => {
    let values = form.getFieldsValue(true);
    let filterValues = {...values}
    Object.keys(values).map(item => {
      if (values[item] === '' || values[item] === undefined) {
        delete filterValues[item]
      }
    })
    const search = {
      ...searchData,
      ...filterValues
    }
    const pData = {
      ...pageData,
      page: 1
    }
    setSearchData(search)
    setPageData(pData)
    getTableData(example, { ...search }, { ...pData })
  };
 
  //数据 转换
  const handleMapData = (tree) => {
    return tree?.map(item => {
      const text = item.name + '(' + item.count + ')'
      return <TreeNode
        title={<Tooltip trigger='hover' content={text}>
          {text}
        </Tooltip>}
        key={item.name}
      >
        {(item.children && item.children.length != 0) && handleMapData(item.children)}
      </TreeNode>
    })
  }
 
  //点击切换案例类型
  const changeType = (data) => {
    getCount(data.name)
    setExample(data.name)
  }
 
  //缓存
  const handleCache = () => {
    $$.setSessionStorage(location.pathname, {
      searchData: searchData,
      pageData: pageData,
      mediateTab: props.mediateTab,
      example: example
    });
  }
 
  //根据id递归查找联级树
  const loopName = (data, id) => {
    for (const node of data) {
      if (node.value === id) {
        return node.label;
      }
      if (node.children) {
        const result = loopName(node.children, id);
        if (result) {
          return result;
        }
      }
    }
    return '';
  }
 
  return (
    <div>
      <div className="myMediation-search" style={{ marginTop: '15px' }}>
        <div style={{ fontSize: '16px', marginBottom: '10px' }}>查询条件</div>
        <NewTableSearch
          exportButtonShow={false}
          labelLength={4}
          rowNum={2}
          form={form}
          itemData={[
            { type: 'Input', name: 'keyword', label: '关键词' },
            { type: 'Cascader', name: 'dyhCauseId', label: '纠纷类型', placeholder: '请选择', span: 8, changeSelect: true, allowClear: false, treedata: $$.caseTypeSelect.caseTypeSelect },
            { type: 'RangePicker', name: 'judgmentTime', label: '判决时间', shortcutsPlacementLeft: true, shortcuts: $$.shortcutsList(), span: 8 },
          ]}
          handleReset={() => {
            form.resetFields()
            const newSearch = searchData
            const resetList = ['keyword', 'judgmentStart', 'judgmentEnd', 'dyhCauseId']
            resetList.forEach(key => {
              delete newSearch[key];
            });
            setSearchData({
              ...newSearch
            })
            setPageData({
              ...pageData,
              page: 1
            })
            getTableData(example, { ...newSearch }, { ...pageData, page: 1 })
          }}
          handleSearch={() => { handleSearch() }}
        />
      </div>
      <div className='knowledgeBase'>
        <div className='knowLeft'>
          <Spin loading={leftLoading} style={{ width: '100%', height: '100%' }}>
            <Scrollbars style={{ height: height + 68 + 'px' }} autoHide ref={scrollRef}>
              <div
                style={{
                  padding: '8px',
                  background: '#fff',
                  marginBottom: '12px'
                }}
              >
                <div className='knowTitle'>案例类型</div>
                <Divider />
                {exampleList?.map((res, index) => {
                  return <div
                    className='knowList'
                    key={index}
                    onClick={() => { changeType(res) }}
                    style={{ color: example == res.name ? '#1A6FB8' : '' }}
                  >{res.name + '(' + res.count + ')'}</div>
                })}
              </div>
              {knowSearchList?.map((item, index) => {
                return <div
                  style={{
                    padding: '8px',
                    background: '#fff',
                    marginBottom: knowSearchList.length - 1 === index ? '0' : '12px'
                  }}
                  key={index}
                  className={item.name != '纠纷发生地' ? 'treeFeel' : ''}
                >
                  <div className='knowTitle'>{item.name}</div>
                  <Divider />
                  <Tree
                    onSelect={(keys) => { searchTotal(item, keys) }}
                    autoExpandParent={false}
                    selectedKeys={item.name != '纠纷发生地' ? [searchData.judgmentTime ? searchData.judgmentTime[0].slice(0, 4) : ''] : [searchData.courtName]}
                  >
                    {handleMapData(item.children)}
                  </Tree>
                </div>
              })}
            </Scrollbars>
          </Spin>
        </div>
        <div className='knowRight'>
          <Spin loading={loading} style={{ width: '100%', height: '100%' }}>
            <Scrollbars style={{ height: height + 'px' }} autoHide ref={scrollRef}>
              <div style={{ fontSize: "16px" }}>查询结果</div>
              {Object.keys(searchData).length !== 0 && <>
                <div className='rightSearch'>
                  查询条件:{Object.keys(searchData).filter(item => item != 'courtLevel').length}项 &nbsp;&nbsp;
                  <span onClick={() => {
                    handleTableReset()
                  }}>清空条件</span>
                </div>
                <div className='rightTag'>
                  {Object.keys(searchData).map(item => {
                    let keyName = dict[item]
                    let value = searchData[item]
                    if (item == 'judgmentTime') {
                      //时间
                      value = searchData[item][0] + ' ~ ' + searchData[item][1]
                    }
                    if (item == 'dyhCauseId') {
                      //纠纷类型
                      let id = value[value.length - 1]
                      value = loopName($$.caseTypeSelect.caseTypeSelect, id)
                    }
                    if (item == 'courtLevel') {
                      return
                    }
                    return <div>{keyName}:{value}&nbsp;&nbsp;
                      <IconClose
                        style={{ cursor: 'pointer' }}
                        onClick={() => {
                          let newData = { ...searchData }
                          delete newData[item]
                          form.setFieldValue(item, undefined)
                          setSearchData({
                            ...newData
                          })
                          getTableData(example, { ...newData }, pageData)
                        }}
                      />
                    </div>
                  })}
                </div>
              </>}
              <div>
                {tableList.map((item, index) => {
                  return <div key={item.id || item.cpwsCaseInfoId}>
                    <div className='knowTableList'>
                      <div className='knowData'>
                        <div
                          className='knowTopTitle'
                          onClick={() => {
                            handleCache()
                            navigate(`/mediate/knowledgeBase/caseDetail/${item.cpwsCaseTextId || item.id}/${example}/${searchData.keyword}`)
                          }}
                        >{handleText(item.caseName || item.caseTitle || '无')}</div>
                        <div style={{ lineHeight: '18px', marginTop: '5px' }}>{`判决时间:${$$.dateFormat(item.judgmentDate || item.occurTime) || '无'} | 判决地点:${item.court || item.addr || '无'} | 纠纷类型:${item.caseReason || item.caseTypeName || '无'} | 案例类型:${example}`}</div>
                      </div>
                      <div className='knowAction'>
                        <Space style={{ color: '#1A6FB8' }}>
                          <div className='pointer' onClick={() => {
                            handleCache()
                            navigate(`/mediate/knowledgeBase/caseDetail/${item.cpwsCaseTextId || item.id}/${example}/${searchData.keyword}`)
                          }}>详情</div>
                          <div className='pointer' style={{ color: '#ccc' }} onClick={() => { }}>修改</div>
                          <div className='pointer' style={{ color: '#ccc' }} onClick={() => { }}>删除</div>
                        </Space>
                      </div>
                    </div>
                    <Divider />
                  </div>
                })}
                {tableList.length === 0 && <div style={{ textAlign: 'center', marginTop: '50px' }}>{$$.MyNewEmpty({ description: '暂无数据' })}</div>}
              </div>
            </Scrollbars>
            <Pagination
              showTotal
              total={total}
              showJumper
              sizeCanChange
              style={{ margin: '12px 12px 0 12px', justifyContent: 'end' }}
              current={pageData.page}
              pageSize={pageData.size}
              onChange={(page, size) => {
                setPageData({ page, size });
                getTableData(example, {...searchData}, { page, size })
              }}
            />
          </Spin>
        </div>
      </div>
    </div>
  )
}