shaogen1995 2 tuần trước cách đây
mục cha
commit
2b36d066b1

+ 34 - 0
src/pages/A3answers/data.ts

@@ -0,0 +1,34 @@
+export type A3tableType = {
+  answer: string
+  createTime: string
+  creatorId?: any
+  creatorName?: any
+  id: number
+  phone: string
+  question: string
+  suggest: string
+  type: string
+  updateTime: string
+  userName: string
+}
+export type A3fromDataType = {
+  searchKey: string
+  type: string
+  pageNum: number
+  pageSize: number
+}
+
+export const A3fromDataBase: A3fromDataType = {
+  searchKey: '',
+  type: '',
+  pageNum: 1,
+  pageSize: 10
+}
+
+export const A3Select = [
+  { value: '回答不相关', label: '回答不相关' },
+  { value: '回答不完整', label: '回答不完整' },
+  { value: '答案错误', label: '答案错误' },
+  { value: '无法回答问题', label: '无法回答问题' },
+  { value: '其他', label: '其他' }
+]

+ 10 - 0
src/pages/A3answers/index.module.scss

@@ -0,0 +1,10 @@
+.A3answers {
+  :global {
+    .A3top {
+      display: flex;
+      align-items: center;
+      width: 600px;
+      padding: 20px;
+    }
+  }
+}

+ 102 - 0
src/pages/A3answers/index.tsx

@@ -0,0 +1,102 @@
+import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
+import styles from './index.module.scss'
+import { Input, Select } from 'antd'
+import { useDispatch, useSelector } from 'react-redux'
+import { A3fromDataBase, A3Select, A3tableType } from './data'
+import { A3_APIdel, A3_APIgetList } from '@/store/action/A3answers'
+import { RootState } from '@/store'
+import { MessageFu } from '@/utils/message'
+import MyPopconfirm from '@/components/MyPopconfirm'
+import MyTable from '@/components/MyTable'
+import { A3tableC } from '@/utils/tableData'
+function A3answers() {
+  const dispatch = useDispatch()
+  const [formData, setFormData] = useState(A3fromDataBase)
+
+  const getListFu = useCallback(() => {
+    dispatch(A3_APIgetList(formData))
+  }, [dispatch, formData])
+
+  useEffect(() => {
+    getListFu()
+  }, [getListFu])
+
+  // 输入框改变
+  const timeRef = useRef(-1)
+  const txtChangeFu = useCallback(
+    (e: React.ChangeEvent<HTMLInputElement>, key: 'searchKey') => {
+      clearTimeout(timeRef.current)
+      timeRef.current = window.setTimeout(() => {
+        setFormData({
+          ...formData,
+          [key]: e.target.value,
+          pageNum: 1
+        })
+      }, 500)
+    },
+    [formData]
+  )
+
+  // 从仓库拿数据
+  const tableInfo = useSelector((state: RootState) => state.A3answers.tableInfo)
+  // 点击删除
+  const delTableFu = useCallback(
+    async (id: number) => {
+      const res: any = await A3_APIdel([id])
+      if (res.code === 0) {
+        MessageFu.success('删除成功!')
+        getListFu()
+      }
+    },
+    [getListFu]
+  )
+
+  const tableLastBtn = useMemo(() => {
+    return [
+      {
+        title: '操作',
+        render: (item: A3tableType) => (
+          <MyPopconfirm txtK='删除' onConfirm={() => delTableFu(item.id)} />
+        )
+      }
+    ]
+  }, [delTableFu])
+
+  return (
+    <div className={styles.A3answers}>
+      <div className='A3top'>
+        <Select
+          allowClear
+          placeholder='反馈类型'
+          style={{ width: 300 }}
+          options={A3Select}
+          value={formData.type || null}
+          onChange={e => setFormData({ ...formData, type: e, pageNum: 1 })}
+        />
+        &emsp;
+        <Input
+          placeholder='请输入问题或回答'
+          maxLength={50}
+          showCount
+          allowClear
+          onChange={e => txtChangeFu(e, 'searchKey')}
+        />
+      </div>
+      <MyTable
+        yHeight={620}
+        list={tableInfo.list}
+        columnsTemp={A3tableC}
+        lastBtn={tableLastBtn}
+        pageNum={formData.pageNum}
+        pageSize={formData.pageSize}
+        total={tableInfo.total}
+        onChange={(pageNum, pageSize) => setFormData({ ...formData, pageNum, pageSize })}
+        // widthSet={{ answer: 300, suggest: 300 }}
+      />
+    </div>
+  )
+}
+
+const MemoA3answers = React.memo(A3answers)
+
+export default MemoA3answers

+ 6 - 0
src/pages/Layout/data.ts

@@ -9,6 +9,12 @@ const tabLeftArr: RouterType[] = [
     Com: React.lazy(() => import('../A1atlas'))
   },
   {
+    id: 3,
+    name: 'AI问答',
+    path: '/answers',
+    Com: React.lazy(() => import('../A3answers'))
+  },
+  {
     id: 2,
     name: '视频管理',
     path: '/video',

+ 1 - 1
src/pages/Layout/index.tsx

@@ -34,7 +34,7 @@ function Layout() {
   const getUserAuthFu = useCallback(async () => {
     const userInfo = getTokenInfo().user
 
-    const isOkIdArr: number[] = [1, 2]
+    const isOkIdArr: number[] = [1, 2, 3]
 
     // 是管理员
     if (userInfo.isAdmin === 1) {

+ 25 - 0
src/store/action/A3answers.ts

@@ -0,0 +1,25 @@
+import http from '@/utils/http'
+import { AppDispatch } from '..'
+/**
+ * AI问答 获取列表
+ */
+export const A3_APIgetList = (data: any): any => {
+  return async (dispatch: AppDispatch) => {
+    const res = await http.post('cms/aiQuestion/pageList', data)
+    if (res.code === 0) {
+      const obj = {
+        list: res.data.records,
+        total: res.data.total
+      }
+
+      dispatch({ type: 'A3/getList', payload: obj })
+    }
+  }
+}
+
+/**
+ * AI问答 删除
+ */
+export const A3_APIdel = (ids: number[]) => {
+  return http.post(`cms/aiQuestion/removes`, ids)
+}

+ 28 - 0
src/store/reducer/A3answers.ts

@@ -0,0 +1,28 @@
+import { A3tableType } from '@/pages/A3answers/data'
+
+// 初始化状态
+const initState = {
+  // 列表数据
+  tableInfo: {
+    list: [] as A3tableType[],
+    total: 0
+  }
+}
+
+// 定义 action 类型
+type Props = {
+  type: 'A3/getList'
+  payload: { list: A3tableType[]; total: number }
+}
+
+// reducer
+export default function userReducer(state = initState, action: Props) {
+  switch (action.type) {
+    // 获取列表数据
+    case 'A3/getList':
+      return { ...state, tableInfo: action.payload }
+
+    default:
+      return state
+  }
+}

+ 2 - 0
src/store/reducer/index.ts

@@ -5,6 +5,7 @@ import { combineReducers } from 'redux'
 import A0Layout from './layout'
 import A1atlas from './A1atlas'
 import A2video from './A2video'
+import A3answers from './A3answers'
 import Z1user from './Z1user'
 
 // 合并 reducer
@@ -12,6 +13,7 @@ const rootReducer = combineReducers({
   A0Layout,
   A1atlas,
   A2video,
+  A3answers,
   Z1user
 })
 

+ 10 - 0
src/utils/tableData.ts

@@ -14,6 +14,16 @@
 //     ["text", "创建日期",'description', 50,A],
 //   ];
 
+export const A3tableC = [
+  ['txt', '提交时间', 'createTime'],
+  ['txt', '反馈类型', 'type'],
+  ['text', '原问题', 'question', 50],
+  ['text', '原回答', 'answer', 50],
+  ['text', '反馈建议', 'suggest', 50],
+  ['txt', '提交人', 'userName'],
+  ['txt', '联系方式', 'phone']
+]
+
 export const Z1tableC = [
   ['txt', '用户名', 'userName'],
   ['txt', '角色', 'roleName'],