广州市综治平台前端
liuwh
6 days ago bd4e6eb3d29de84c00f5e448f5839300873a6abe
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
import React, { useEffect, useState, useRef } from 'react';
import NewPage from '@/components/NewPage';
import MyTabsNew from '@/components/MyTabsNew';
import NewTableSearch from '@/components/NewTableSearch';
import * as $$ from '@/utils/utility';
import { Form, Space } from 'antd';
import { Divider, Pagination, Spin } 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';
import ClassicCase from './components/ClassicCase.jsx';
import './index.less';
 
//知识库统计类别
function getCategoryCount(data) {
  return $$.ax.request({ url: 'lawInfo/categoryCount', type: 'get', data, service: 'know' });
}
 
//知识库列表
function getPageQuery(data) {
  return $$.ax.request({ url: 'lawInfo/pageQuery', type: 'get', data, service: 'know' });
}
export default function KnowledgeBase() {
  const [form] = Form.useForm();
  const navigate = useNavigate();
  let location = useLocation();
  const scrollRef = useRef(null);
  const dict = {
    '法律制定机关': 'authority',
    '法律性质': 'lawNature',
    '法律时效性': 'validity',
    'keyword': '关键词',
    'authority': '法律制定机关',
    'lawNature': '法律性质',
    'validity': '法律时效性',
    'publishTime': '公布日期',
    'implementationTime': '实施日期',
  }
 
  const [mediateTab, setMediateTab] = useState('1');// tabs标签分页
  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 [leftLoading, setLeftLoading] = useState(false);//左侧loading
 
  useEffect(() => {
    getCount()
    //缓存处理
    let returnRouteData = $$.getSessionStorage(location.pathname);
    if (returnRouteData && returnRouteData.mediateTab) {
      setMediateTab(returnRouteData.mediateTab)
    }
    if (returnRouteData && returnRouteData.mediateTab === '1') {
      if (returnRouteData.pageData) {
        setPageData(returnRouteData.pageData)
      }
      if (returnRouteData.searchData) {
        form.setFieldsValue(returnRouteData.searchData)
        setSearchData(returnRouteData.searchData)
      }
      $$.clearSessionStorage(location.pathname);
    }
    onWindowResize()
    window.addEventListener("resize", onWindowResize);
    // 返回一个函数,该函数会在组件卸载前执行  
    return () => {
      // 组件销毁时执行  
      window.removeEventListener("resize", onWindowResize);
    };
  }, [])
 
  useEffect(() => {
    getTableData()
  }, [searchData, pageData])
 
  const onWindowResize = () => {
    let offsetTop = 0;
    if (scrollRef.current.container) {
      offsetTop = getOffset(scrollRef.current.container).top;
    }
    setHeight(getSize().windowH - offsetTop - 72)
  };
 
  //获取统计
  const getCount = async () => {
    setLeftLoading(true)
    const res = await getCategoryCount()
    if (res.type) {
      setKnowSearchList(res.data)
      setLeftLoading(false)
    }
  }
 
  //获取数据
  const getTableData = async () => {
    setLoading(true)
    const search = { ...searchData }
    $$.changeTimNeweFormat(search, 'publishTime', 'publishStart', 'publishEnd');
    $$.changeTimNeweFormat(search, 'implementationTime', 'implementationStart', 'implementationEnd');
    const res = await getPageQuery({
      ...search,
      ...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]
    const newSearch = searchData
    setSearchData({
      ...newSearch,
      [name]: children.value
    })
    setPageData({
      ...pageData,
      page: 1
    })
  }
 
  //查询
  const handleSearch = () => {
    let values = form.getFieldsValue(true);
    let filterValues = { ...values }
    Object.keys(values).map(item => {
      if (values[item] === '' || values[item] === undefined) {
        delete filterValues[item]
      }
    })
    setSearchData({
      ...searchData,
      ...filterValues
    })
    setPageData({
      ...pageData,
      page: 1
    })
  };
 
  //缓存
  const handleCache = () => {
    $$.setSessionStorage(location.pathname, {
      searchData: searchData,
      pageData: pageData,
      mediateTab: mediateTab,
    });
  }
 
  return (
    <NewPage pageHead={{ breadcrumbData: [{ title: '工作台' }, { title: '知识库' }], title: '知识库' }}>
      <div className="comprehensive">
        <div className="pageTabs" style={{ marginTop: '-15px' }}>
          <MyTabsNew
            tabs={[
              { key: '1', label: '法律法规' },
              { key: '2', label: '典型案例' },
            ]}
            activeKey={mediateTab}
            onChange={(activeKey) => {
              setMediateTab(activeKey);
            }}
          />
        </div>
        {mediateTab === '1' && <>
          <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: 'RangePicker', name: 'publishTime', label: '公布日期', shortcutsPlacementLeft: true, shortcuts: $$.shortcutsList(), span: 8 },
                { type: 'RangePicker', name: 'implementationTime', label: '实施日期', shortcutsPlacementLeft: true, shortcuts: $$.shortcutsList(), span: 8 },
              ]}
              handleReset={() => {
                form.resetFields()
                const newSearch = searchData
                const resetList = ['keyword', 'publishTime', 'implementationTime']
                resetList.forEach(key => {
                  delete newSearch[key];
                });
                setSearchData({
                  ...newSearch
                })
                setPageData({
                  ...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}>
                  {knowSearchList?.map((item, index) => {
                    return <div
                      style={{
                        padding: '8px',
                        background: '#fff',
                        marginBottom: knowSearchList.length - 1 === index ? '0' : '12px'
                      }}
                      key={item.code}
                    >
                      <div className='knowTitle'>{item.name}</div>
                      <Divider />
                      {item.children?.map(res => {
                        let lightList = Object.keys(searchData)
                        let lightKey = lightList.indexOf(dict[item.name])
                        let lightValue = lightList[lightKey]
                        return <div
                          className='knowList'
                          style={{ color: (lightKey != -1) && searchData[lightValue] === res.value ? '#1a6fb8' : '' }}
                          key={res.code}
                          onClick={() => { searchTotal(item, res) }}
                        >{res.name + '(' + res.count + ')'}</div>
                      })}
                    </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).length}项 &nbsp;&nbsp;
                      <span onClick={() => {
                        form.resetFields()
                        setSearchData({})
                        setPageData({
                          ...pageData,
                          page: 1
                        })
                      }}>清空条件</span>
                    </div>
                    <div className='rightTag'>
                      {Object.keys(searchData).map(item => {
                        let keyName = dict[item]
                        let value = searchData[item]
                        if (item == 'implementationTime' || item == 'publishTime') {
                          //时间
                          value = searchData[item][0] + ' ~ ' + searchData[item][1]
                        }
                        if (item == 'authority' || item == 'lawNature' || item == 'validity') {
                          //左侧,根据code获取name
                          let leftDataFind = knowSearchList.find(mdata => mdata.name == keyName) || {}
                          leftDataFind.children?.some(mdata => {
                            if (mdata.value == value) {
                              value = mdata.name
                              return true
                            }
                            return false
                          })
                        }
                        return <div key={item}>{keyName}:{value}&nbsp;&nbsp;
                          <IconClose
                            style={{ cursor: 'pointer' }}
                            onClick={() => {
                              let newData = { ...searchData }
                              delete newData[item]
                              form.resetFields([item])
                              setSearchData({
                                ...newData
                              })
                            }}
                          />
                        </div>
                      })}
                    </div>
                  </>}
                  <div>
                    {tableList.map((item, index) => {
                      return <div key={index}>
                        <div className='knowTableList'>
                          <div className='knowImg'>{item.title.charAt(7)}</div>
                          <div className='knowData'>
                            <div
                              className='knowTopTitle'
                              onClick={() => {
                                handleCache()
                                navigate(`/mediate/knowledgeBase/detail/${item.lawOriginalInfoId}/${searchData.keyword}`)
                              }}
                            >{handleText(item.title)}</div>
                            <div style={{ lineHeight: '18px', marginTop: '5px' }}>{`时效性:${item.validityName || '无'} | 法律效力位阶:${item.lawNatureName || '无'} | 制定机关:${item.authorityName || '无'} | 公布日期:${$$.dateFormat(item.publishTime)
                              } | 实施日期:${$$.dateFormat(item.implementationTime)}`}</div>
                          </div>
                          <div className='knowAction'>
                            <Space style={{ color: '#1A6FB8' }}>
                              <div className='pointer' onClick={() => {
                                handleCache()
                                navigate(`/mediate/knowledgeBase/detail/${item.lawOriginalInfoId}/${searchData.keyword}`)
                              }}>详情</div>
                              <div className='pointer' style={{ color: '#ccc' }} onClick={() => { }}>修改</div>
                              <div className='pointer' style={{ color: '#ccc' }} onClick={() => { }}>删除</div>
                            </Space>
                          </div>
                        </div>
                        {item.keywordProvisionList && <div className='knowDetailTxt'>
                          {item.keywordProvisionList.map((res, index) => {
                            if (index <= 4) {
                              return <div key={res.lawProvisionId} style={{ marginBottom: '5px' }}>
                                {res.provisionIndex}&nbsp;&nbsp;&nbsp;&nbsp;{handleText(res.provisionText)}
                              </div>
                            }
                          })}
                          {item.keywordProvisionList.length > 5 && <div
                            style={{ color: '#1A6FB8', cursor: 'pointer' }}
                            onClick={() => {
                              handleCache()
                              navigate(`/mediate/knowledgeBase/detail/${item.lawOriginalInfoId}/${searchData.keyword}`)
                            }}
                          >
                            查看更多&nbsp;&nbsp;<IconDown />
                          </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 });
                  }}
                />
              </Spin>
            </div>
          </div>
        </>}
        {mediateTab === '2' && <>
          <ClassicCase mediateTab={mediateTab} />
        </>}
      </div>
    </NewPage>
  )
}