|
@@ -0,0 +1,158 @@
|
|
|
+import React, { useCallback, useEffect, useState } from 'react'
|
|
|
+import styles from './index.module.scss'
|
|
|
+import BtnRight from '@/components/BtnRight'
|
|
|
+import store from '@/store'
|
|
|
+import { baseURL } from '@/utils/http'
|
|
|
+import { API_getCode, API_getMsgList, API_msgSave } from '@/store/action/all'
|
|
|
+import { Input, TextArea, Toast } from 'antd-mobile'
|
|
|
+import { ReloadOutlined } from '@ant-design/icons'
|
|
|
+
|
|
|
+type ListType = {
|
|
|
+ content: string
|
|
|
+ createTime: string
|
|
|
+ creatorId?: any
|
|
|
+ creatorName: string
|
|
|
+ id: number
|
|
|
+ name: string
|
|
|
+ status: number
|
|
|
+ updateTime: string
|
|
|
+}
|
|
|
+
|
|
|
+function Zmsg() {
|
|
|
+ const [list, setList] = useState<ListType[]>([])
|
|
|
+ const [loding, setLoding] = useState(false)
|
|
|
+
|
|
|
+ const getListFu = useCallback(async () => {
|
|
|
+ const res = await API_getMsgList()
|
|
|
+ if (res.code === 0) {
|
|
|
+ setLoding(true)
|
|
|
+ setList(res.data.records || [])
|
|
|
+ }
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ // 获取验证码
|
|
|
+ const getCodeFu = useCallback(async () => {
|
|
|
+ const res: any = await API_getCode()
|
|
|
+ const reader = new FileReader()
|
|
|
+ reader.readAsDataURL(res)
|
|
|
+ reader.onload = () => {
|
|
|
+ setCodeImg(reader.result)
|
|
|
+ }
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ getListFu()
|
|
|
+ getCodeFu()
|
|
|
+ }, [getCodeFu, getListFu])
|
|
|
+
|
|
|
+ // 文本信息
|
|
|
+ const [content, setContent] = useState('')
|
|
|
+ const [name, setName] = useState('')
|
|
|
+ const [randCode, setRandCode] = useState('')
|
|
|
+ const [codeImg, setCodeImg] = useState<any>('')
|
|
|
+
|
|
|
+ // 消息提示
|
|
|
+ const msgTit = useCallback((val: string) => {
|
|
|
+ Toast.show({
|
|
|
+ icon: 'fail',
|
|
|
+ content: val
|
|
|
+ })
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ // 点击提交
|
|
|
+ const btnOk = useCallback(async () => {
|
|
|
+ const contentRes = content.trim()
|
|
|
+ if (!contentRes) return msgTit('请输入内容')
|
|
|
+ if (contentRes.length < 5) return msgTit('内容最少5个字符')
|
|
|
+ if (!name) return msgTit('请输入称呼')
|
|
|
+ if (!randCode || randCode.length < 5) return msgTit('请输入5位验证码')
|
|
|
+
|
|
|
+ const obj = {
|
|
|
+ content,
|
|
|
+ name,
|
|
|
+ randCode
|
|
|
+ }
|
|
|
+ const res: any = await API_msgSave(obj)
|
|
|
+
|
|
|
+ if (res.code === 0) {
|
|
|
+ Toast.show({
|
|
|
+ icon: 'success',
|
|
|
+ content: '提交成功,等待管理员审核'
|
|
|
+ })
|
|
|
+ setContent('')
|
|
|
+ setName('')
|
|
|
+ setRandCode('')
|
|
|
+ getCodeFu()
|
|
|
+ }
|
|
|
+ }, [content, getCodeFu, msgTit, name, randCode])
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div id='HotOpCss' className={styles.Zmsg}>
|
|
|
+ <div className='ZmMain'>
|
|
|
+ <div className='ZmMainll'>
|
|
|
+ <h1>留言板</h1>
|
|
|
+ {list.length ? (
|
|
|
+ <div className='ZmMainll1 mySorrl'>
|
|
|
+ {list.map(item => (
|
|
|
+ <div className='ZmRow' key={item.id}>
|
|
|
+ <p className='ZmRow1'>{item.createTime}</p>
|
|
|
+ <p>{item.name}:</p>
|
|
|
+ <p>{item.content}</p>
|
|
|
+ </div>
|
|
|
+ ))}
|
|
|
+ </div>
|
|
|
+ ) : null}
|
|
|
+
|
|
|
+ {list.length <= 0 && loding ? <div className='ZmNull'>暂无留言</div> : null}
|
|
|
+ </div>
|
|
|
+ <div
|
|
|
+ className='ZmMainrr'
|
|
|
+ style={{ backgroundImage: `url(${baseURL}home/leftBtn/msgBj.png)` }}
|
|
|
+ >
|
|
|
+ <h1>评论</h1>
|
|
|
+ <TextArea
|
|
|
+ value={content}
|
|
|
+ onChange={val => setContent(val)}
|
|
|
+ maxLength={500}
|
|
|
+ showCount
|
|
|
+ placeholder='请输入内容,5-500字'
|
|
|
+ />
|
|
|
+
|
|
|
+ <Input
|
|
|
+ placeholder='请输入称呼(必填,1-6个字)'
|
|
|
+ maxLength={6}
|
|
|
+ value={name}
|
|
|
+ onChange={val => setName(val.trim())}
|
|
|
+ />
|
|
|
+ <div className='ZmMainrrCode'>
|
|
|
+ <Input
|
|
|
+ placeholder='请输入图形验证码'
|
|
|
+ maxLength={5}
|
|
|
+ value={randCode}
|
|
|
+ onChange={val => setRandCode(val.trim())}
|
|
|
+ />
|
|
|
+
|
|
|
+ <img src={codeImg} alt='' />
|
|
|
+
|
|
|
+ <ReloadOutlined rev={undefined} onClick={getCodeFu} />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div className='Zmbtn'>
|
|
|
+ <div onClick={btnOk}>提交</div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 右下角的返回按钮 */}
|
|
|
+ <BtnRight
|
|
|
+ imgName='back'
|
|
|
+ clickSon={() => store.dispatch({ type: 'layout/msgShow', payload: false })}
|
|
|
+ title='返回'
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+const MemoZmsg = React.memo(Zmsg)
|
|
|
+
|
|
|
+export default MemoZmsg
|