|
@@ -1,14 +1,181 @@
|
|
-import React from "react";
|
|
|
|
-import styles from "./index.module.scss";
|
|
|
|
- function A3recommend() {
|
|
|
|
|
|
+import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|
|
|
+import styles from './index.module.scss'
|
|
|
|
+import { Button, Input } from 'antd'
|
|
|
|
+import { useDispatch, useSelector } from 'react-redux'
|
|
|
|
+import { A3FromDataType } from './data'
|
|
|
|
+import { A3_APIdel, A3_APIgetList } from '@/store/action/A3recommend'
|
|
|
|
+import { RootState } from '@/store'
|
|
|
|
+import { MessageFu } from '@/utils/message'
|
|
|
|
+import { A3tableType } from '@/types'
|
|
|
|
+import MyPopconfirm from '@/components/MyPopconfirm'
|
|
|
|
+import MyTable from '@/components/MyTable'
|
|
|
|
+import { A3tableC } from '@/utils/tableData'
|
|
|
|
+import A3add from './A3add'
|
|
|
|
+
|
|
|
|
+const fromDataBase: A3FromDataType = {
|
|
|
|
+ type: 'index',
|
|
|
|
+ searchKey: '',
|
|
|
|
+ num: '',
|
|
|
|
+ pageNum: 1,
|
|
|
|
+ pageSize: 9999
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const topTypeArr: { name: string; key: 'index' | 'rank' }[] = [
|
|
|
|
+ {
|
|
|
|
+ name: '首页推荐',
|
|
|
|
+ key: 'index'
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ name: '排行榜推荐',
|
|
|
|
+ key: 'rank'
|
|
|
|
+ }
|
|
|
|
+]
|
|
|
|
+
|
|
|
|
+function A3recommend() {
|
|
|
|
+ const dispatch = useDispatch()
|
|
|
|
+
|
|
|
|
+ const [fromData, setFromData] = useState(fromDataBase)
|
|
|
|
+
|
|
|
|
+ const getListFu = useCallback(() => {
|
|
|
|
+ dispatch(A3_APIgetList(fromData))
|
|
|
|
+ }, [dispatch, fromData])
|
|
|
|
+
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ getListFu()
|
|
|
|
+ }, [getListFu])
|
|
|
|
+
|
|
|
|
+ const [inputKey, setInputKey] = useState(1)
|
|
|
|
+
|
|
|
|
+ // 输入框的输入
|
|
|
|
+ const timeRef = useRef(-1)
|
|
|
|
+ const txtChangeFu = useCallback(
|
|
|
|
+ (e: React.ChangeEvent<HTMLInputElement>, key: 'searchKey' | 'num') => {
|
|
|
|
+ clearTimeout(timeRef.current)
|
|
|
|
+ timeRef.current = window.setTimeout(() => {
|
|
|
|
+ setFromData({ ...fromData, [key]: e.target.value.replaceAll("'", ''), pageNum: 1 })
|
|
|
|
+ }, 500)
|
|
|
|
+ },
|
|
|
|
+ [fromData]
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ // 点击重置
|
|
|
|
+ const resetSelectFu = useCallback(() => {
|
|
|
|
+ setInputKey(Date.now())
|
|
|
|
+ setFromData({ ...fromDataBase, type: fromData.type })
|
|
|
|
+ }, [fromData.type])
|
|
|
|
+
|
|
|
|
+ const tableList = useSelector((state: RootState) => state.A3recommend.tableList)
|
|
|
|
+
|
|
|
|
+ const delTableFu = useCallback(
|
|
|
|
+ async (id: number) => {
|
|
|
|
+ const res = await A3_APIdel(id)
|
|
|
|
+ if (res.code === 0) {
|
|
|
|
+ MessageFu.success('删除成功!')
|
|
|
|
+ getListFu()
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ [getListFu]
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ const tableLastBtn = useMemo(() => {
|
|
|
|
+ return [
|
|
|
|
+ {
|
|
|
|
+ title: '操作',
|
|
|
|
+ render: (item: A3tableType) => (
|
|
|
|
+ <>
|
|
|
|
+ <Button size='small' type='text' onClick={() => setEditId(item.id)}>
|
|
|
|
+ 编辑
|
|
|
|
+ </Button>
|
|
|
|
+
|
|
|
|
+ <MyPopconfirm txtK='删除' onConfirm={() => delTableFu(item.id)} />
|
|
|
|
+ </>
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ }, [delTableFu])
|
|
|
|
+
|
|
|
|
+ // 点击编辑和新增
|
|
|
|
+ const [editId, setEditId] = useState(0)
|
|
|
|
|
|
return (
|
|
return (
|
|
<div className={styles.A3recommend}>
|
|
<div className={styles.A3recommend}>
|
|
- <h1>A3recommend</h1>
|
|
|
|
|
|
+ <div className='pageTitle'>图书推荐</div>
|
|
|
|
+ {/* 顶部筛选 */}
|
|
|
|
+ <div className='A3top'>
|
|
|
|
+ <div>
|
|
|
|
+ <div className='A3TopRow'>
|
|
|
|
+ {topTypeArr.map(v => (
|
|
|
|
+ <Button
|
|
|
|
+ type={v.key === fromData.type ? 'primary' : 'default'}
|
|
|
|
+ key={v.key}
|
|
|
|
+ onClick={() => setFromData({ ...fromData, type: v.key, pageNum: 1 })}
|
|
|
|
+ >
|
|
|
|
+ {v.name}
|
|
|
|
+ </Button>
|
|
|
|
+ ))}
|
|
|
|
+ </div>
|
|
|
|
+
|
|
|
|
+ <div className='A3TopRow'>
|
|
|
|
+ <span>搜索:</span>
|
|
|
|
+ <Input
|
|
|
|
+ key={inputKey}
|
|
|
|
+ maxLength={20}
|
|
|
|
+ style={{ width: 192 }}
|
|
|
|
+ placeholder='请输入书名/作者/出版社'
|
|
|
|
+ allowClear
|
|
|
|
+ onChange={e => txtChangeFu(e, 'searchKey')}
|
|
|
|
+ />
|
|
|
|
+
|
|
|
|
+ <Input
|
|
|
|
+ key={inputKey + 1}
|
|
|
|
+ maxLength={20}
|
|
|
|
+ style={{ width: 192 }}
|
|
|
|
+ placeholder='请输入完整ISBN编号'
|
|
|
|
+ allowClear
|
|
|
|
+ onChange={e => txtChangeFu(e, 'num')}
|
|
|
|
+ />
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ <div>
|
|
|
|
+ <Button onClick={resetSelectFu}>重置</Button> 
|
|
|
|
+ <Button
|
|
|
|
+ type='primary'
|
|
|
|
+ onClick={() => {
|
|
|
|
+ if (fromData.type === 'index' && tableList.length >= 30)
|
|
|
|
+ return MessageFu.warning('最多支持30本!')
|
|
|
|
+ if (fromData.type === 'rank' && tableList.length >= 10)
|
|
|
|
+ return MessageFu.warning('最多支持10本!')
|
|
|
|
+ setEditId(-1)
|
|
|
|
+ }}
|
|
|
|
+ >
|
|
|
|
+ 新增
|
|
|
|
+ </Button>
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+
|
|
|
|
+ {/* 表格主体 */}
|
|
|
|
+ <div className='A3tableBox'>
|
|
|
|
+ <MyTable
|
|
|
|
+ yHeight={678}
|
|
|
|
+ list={tableList}
|
|
|
|
+ columnsTemp={A3tableC}
|
|
|
|
+ lastBtn={tableLastBtn}
|
|
|
|
+ pagingInfo={false}
|
|
|
|
+ />
|
|
|
|
+ </div>
|
|
|
|
+
|
|
|
|
+ {editId ? (
|
|
|
|
+ <A3add
|
|
|
|
+ id={editId}
|
|
|
|
+ type={fromData.type}
|
|
|
|
+ closeFu={() => setEditId(0)}
|
|
|
|
+ addTableFu={resetSelectFu}
|
|
|
|
+ />
|
|
|
|
+ ) : null}
|
|
</div>
|
|
</div>
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
-const MemoA3recommend = React.memo(A3recommend);
|
|
|
|
|
|
+const MemoA3recommend = React.memo(A3recommend)
|
|
|
|
|
|
-export default MemoA3recommend;
|
|
|
|
|
|
+export default MemoA3recommend
|