diff --git a/package.json b/package.json index 48fe6dc..2574e35 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,8 @@ "scripts": { "start": "node scripts/start.js", "build": "node scripts/build.js", - "test": "node scripts/test.js" + "test": "node scripts/test.js", + "deploy:dev": "npm run build && scp -r ./build/* testDev:/home/ceshi/pzy/nft9527" }, "eslintConfig": { "extends": [ diff --git a/src/api/index.ts b/src/api/index.ts index d4844a8..22e7ae3 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -156,3 +156,15 @@ export const un_shelves_nft = (id: number) => export const no_user_info = (id: number) => request({ url: "/v1/showAccount", data: { id } }); + +/** + * @description 清除消息提醒 + */ + +export const clear_msg = () => request({ url: "/v1/clearMessage" }); + +/** + * @description 設置所有消息已讀 + */ + +export const read_all_msg = () => request({ url: "/v1/readMessage" }); \ No newline at end of file diff --git a/src/assets/avatar.png b/src/assets/avatar.png deleted file mode 100644 index efde823..0000000 Binary files a/src/assets/avatar.png and /dev/null differ diff --git a/src/assets/buy-success.png b/src/assets/buy-success.png index 915a643..e26543c 100644 Binary files a/src/assets/buy-success.png and b/src/assets/buy-success.png differ diff --git a/src/assets/cover.png b/src/assets/cover.png deleted file mode 100644 index 2d52c2a..0000000 Binary files a/src/assets/cover.png and /dev/null differ diff --git a/src/assets/nft/dragon.jpg b/src/assets/nft/dragon.jpg deleted file mode 100644 index f11e676..0000000 Binary files a/src/assets/nft/dragon.jpg and /dev/null differ diff --git a/src/assets/nft/兔.jpg b/src/assets/nft/兔.jpg deleted file mode 100644 index 89380dc..0000000 Binary files a/src/assets/nft/兔.jpg and /dev/null differ diff --git a/src/assets/nft/牛.jpg b/src/assets/nft/牛.jpg deleted file mode 100644 index 32b9c0f..0000000 Binary files a/src/assets/nft/牛.jpg and /dev/null differ diff --git a/src/assets/nft/狗.jpg b/src/assets/nft/狗.jpg deleted file mode 100644 index c8dc62a..0000000 Binary files a/src/assets/nft/狗.jpg and /dev/null differ diff --git a/src/assets/nft/猪.jpg b/src/assets/nft/猪.jpg deleted file mode 100644 index 8a4f003..0000000 Binary files a/src/assets/nft/猪.jpg and /dev/null differ diff --git a/src/assets/nft/猴.jpg b/src/assets/nft/猴.jpg deleted file mode 100644 index e90edc0..0000000 Binary files a/src/assets/nft/猴.jpg and /dev/null differ diff --git a/src/assets/nft/羊.jpg b/src/assets/nft/羊.jpg deleted file mode 100644 index 755c642..0000000 Binary files a/src/assets/nft/羊.jpg and /dev/null differ diff --git a/src/assets/nft/虎.jpg b/src/assets/nft/虎.jpg deleted file mode 100644 index 14adcac..0000000 Binary files a/src/assets/nft/虎.jpg and /dev/null differ diff --git a/src/assets/nft/蛇.jpg b/src/assets/nft/蛇.jpg deleted file mode 100644 index c78c78d..0000000 Binary files a/src/assets/nft/蛇.jpg and /dev/null differ diff --git a/src/assets/nft/马.jpg b/src/assets/nft/马.jpg deleted file mode 100644 index e42efe0..0000000 Binary files a/src/assets/nft/马.jpg and /dev/null differ diff --git a/src/assets/nft/鸡.jpg b/src/assets/nft/鸡.jpg deleted file mode 100644 index fae05dd..0000000 Binary files a/src/assets/nft/鸡.jpg and /dev/null differ diff --git a/src/assets/nft/鼠.jpg b/src/assets/nft/鼠.jpg deleted file mode 100644 index b95f8c4..0000000 Binary files a/src/assets/nft/鼠.jpg and /dev/null differ diff --git a/src/assets/personal.png b/src/assets/personal.png index e5605cf..d7afa16 100644 Binary files a/src/assets/personal.png and b/src/assets/personal.png differ diff --git a/src/hooks/useNotify.ts b/src/hooks/useNotify.ts new file mode 100644 index 0000000..9d8ab34 --- /dev/null +++ b/src/hooks/useNotify.ts @@ -0,0 +1,91 @@ +import { useRef, useState } from "react"; +import { Toast } from "react-vant"; +import { clear_msg, read_all_msg } from "~/api"; +import { MessageType } from "~/types/store"; +import signGenerator from "~/utils/sign/sign"; + +const useNotify = (path: string, isNotity: boolean) => { + console.log(isNotity); + + const baseUrl = `${process.env.REACT_APP_WS_URL}/api/v1/${path}`; + const ws = useRef(null); + const filterMessage = useRef([] as MessageType[]); + const [messages, setMessages] = useState([] as MessageType[]); + + const connect = (token: string) => { + let timestamp = Date.now(); + let signData = { + uri: `/api/v1/${path}`, + timestamp: timestamp, + args: "", + }; + const sign = signGenerator(signData); + ws.current = new WebSocket( + `${baseUrl}?Token=${token}&sign=${sign}×tamp=${timestamp}` + ); + + ws.current.onmessage = (event: any) => { + if ( + event && + event.data && + event.origin === process.env.REACT_APP_WS_URL + ) { + let message = JSON.parse(event.data) as MessageType; + let item = filterMessage.current.find((v) => v.id === message.id); + if (item) return; + filterMessage.current.push(message); + setMessages((_) => [...filterMessage.current]); + // 如果打開了消息列表,則推送直接設置為已讀 + if (isNotity) { + readAllMsg(); + } + } + }; + }; + + // 斷開連接 + const disconnect = () => { + ws.current && ws.current.close(); + ws.current = null; + resetMessages(); + }; + + // 重置消息列表 + const resetMessages = () => { + filterMessage.current = []; + setMessages([]); + }; + + // 刪除所有消息 + const deleteAllMsg = async () => { + if (messages.length <= 0) return; + const res: any = await clear_msg(); + if (res && res.code === 0) { + Toast.success("清除成功"); + resetMessages(); + } + }; + + // 設置所有消息為已讀 + const readAllMsg = async () => { + const res: any = await read_all_msg(); + if (res && res.code === 0) { + // 把消息改爲已讀 + filterMessage.current.forEach((item) => { + item.status = 2; + }); + setMessages([...filterMessage.current]); + } + }; + + return { + connect, + disconnect, + messages, + resetMessages, + readAllMsg, + deleteAllMsg, + }; +}; + +export default useNotify; diff --git a/src/hooks/useWs.ts b/src/hooks/useWs.ts deleted file mode 100644 index 8763471..0000000 --- a/src/hooks/useWs.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { useRef } from "react"; -import signGenerator from "~/utils/sign/sign"; - -const useWs = (path: string) => { - const baseUrl = `ws://14.29.101.215:30307/api/v1/${path}`; - // const baseUrl = `ws://192.168.124.52:8083/api/v1/${path}`; - const ws = useRef(null); - - const connect = (token: string) => { - let timestamp = Date.now(); - let signData = { - uri: `/api/v1/${path}`, - timestamp: timestamp, - args: "", - }; - const sign = signGenerator(signData); - ws.current = new WebSocket( - `${baseUrl}?Token=${token}&sign=${sign}×tamp=${timestamp}` - ); - - ws.current.onMessage = (data: any) => { - console.log(data); - }; - }; - - const disconnect = () => { - ws.current && ws.current.close(); - ws.current = null; - }; - - return { - connect, - disconnect, - }; -}; - -export default useWs; diff --git a/src/router/layout/Navbar.tsx b/src/router/layout/Navbar.tsx index 85e63e0..fb682af 100644 --- a/src/router/layout/Navbar.tsx +++ b/src/router/layout/Navbar.tsx @@ -1,24 +1,43 @@ +import { useMemo } from 'react' import { useRouter } from '~/hooks/useRouter' +import store from '~/store' import '~/styles/layout.scss' +import { MessageType } from '~/types/store' import ConnectButton from './ConnectButton' interface NavbarProps { pathname: string, - setVisible: Function + setVisible: Function, + token: string, + messages: MessageType[], + readAllMsg: Function } const Navbar = (props: NavbarProps) => { - const { pathname, setVisible } = props + const { pathname, setVisible, token, messages, readAllMsg } = props const { push } = useRouter() + const msgCount = useMemo(() => { + // status 1.未讀 2.已讀 + let list = messages.filter(v => v.status === 1) + console.log(list); + return list.length + }, [messages]) + const isBlue = () => { if (pathname === '/share') return 'header-bg-color' if (pathname === '/noShare') return 'header-bg-color' return '' } + const openMsg = () => { + if (!token) return store.setVisibleUnLogin(true) + readAllMsg() + setVisible(true) + } + return (
@@ -34,8 +53,8 @@ const Navbar = (props: NavbarProps) => { {/*
首页
*/}
-
setVisible(true)}> -
+
+ {msgCount > 0 &&
}
diff --git a/src/router/layout/Notify.tsx b/src/router/layout/Notify.tsx index 76f63b0..1948169 100644 --- a/src/router/layout/Notify.tsx +++ b/src/router/layout/Notify.tsx @@ -1,66 +1,84 @@ import '~/styles/layout.scss' -import { Button, Divider, Popup } from "react-vant" +import { Button, Dialog, Divider, Popup } from "react-vant" +import { MessageType } from '~/types/store' interface NotifyProps { visible: boolean, - setVisible: Function + setVisible: Function, + messages: MessageType[], + deleteAllMsg: Function } const Notify = (props: NotifyProps) => { - const { visible, setVisible } = props + const { visible, setVisible, messages, deleteAllMsg } = props - const data = [ - { title: '提醒', color: '#F96900', imgName: 'register-success', desc: '您挂单的“生肖唐彩-狗”NFT, @Miner 出价 4,153.00 USDT,您挂单的“生肖唐彩-狗”NFT, @Miner 出价 4,153.00 USDT,您挂单的“生肖唐彩-狗”NFT, @Miner 出价 4,153.00 USDT' }, - { title: '注册成功', color: '#11C0CB', imgName: 'warn', desc: '恭喜,您已成功注册,9527NFT数字交易平台.' }, - ] + const confirmDelete = async () => { + if (messages.length <= 0) return + Dialog.alert({ + showCancelButton: true, + showConfirmButton: true, + title: '提示', + message: '確定清除所有歷史消息嗎?', + confirmButtonText: '確定', + confirmButtonColor: '#0FC6D4', + onConfirm: () => deleteAllMsg() + }) + } return ( - setVisible(false)} - position='right' - style={{ - height: '100%', - width: '70%', - borderTopLeftRadius: 20, - borderBottomLeftRadius: 20, - boxShadow: '8px 8px 20px 0px rgba(0, 0, 0, 0.1)' - }} - overlayStyle={{ backgroundColor: 'rgba(0,0,0,0.05)' }} - > -
-
消息提醒
- -
- { - data.map((item, index) => ( -
- -
-
{item.title}
-
{item.desc}
+ <> + setVisible(false)} + position='right' + style={{ + height: '100%', + width: '70%', + borderTopLeftRadius: 20, + borderBottomLeftRadius: 20, + boxShadow: '8px 8px 20px 0px rgba(0, 0, 0, 0.1)' + }} + overlayStyle={{ backgroundColor: 'rgba(0,0,0,0.05)' }} + > +
+
+
+
消息提醒
+
+
+
+ { + messages.map((item) => ( +
+ +
+
{item.title}
+
{item.message}
+
-
- )) - } -
-
- -
+ )) + } -
- setVisible(false)}> +
+ +
+
+
+ setVisible(false)}> +
-
- + + + ) } diff --git a/src/router/layout/index.tsx b/src/router/layout/index.tsx index a4bee4f..1527042 100644 --- a/src/router/layout/index.tsx +++ b/src/router/layout/index.tsx @@ -8,7 +8,7 @@ import Navbar from './Navbar'; import Tabbar from './Tabbar'; import { observer } from 'mobx-react'; import store from '~/store'; -import useWs from '~/hooks/useWs'; +import useNotify from '~/hooks/useNotify'; import { ethers } from 'ethers'; import { bind_rmd } from '~/api'; import { AlreadyBind, BindRmd, BindSuccess, DefaultBind, UnLogin, VaildLink } from './ui'; @@ -16,9 +16,9 @@ import { AlreadyBind, BindRmd, BindSuccess, DefaultBind, UnLogin, VaildLink } fr const LayoutRouter = () => { const { location, push } = useRouter() - const messageWs = useWs('getMessage') - const { token, walletAddress, userInfo, visibleUnLogin } = store.state const [visible, setVisible] = useState(false) + const messageWs = useNotify('getMessage', visible) + const { token, walletAddress, userInfo, visibleUnLogin } = store.state const [visibleVaildLink, setVisibleVaildLink] = useState(false) //无效的链接 const [visibleAlreadyBind, setVisibleAlreadyBind] = useState(false) //已绑定 @@ -55,8 +55,8 @@ const LayoutRouter = () => { store.resetNft("myNft") } - // token && messageWs.connect(token) - // !token && messageWs.disconnect() + token && messageWs.connect(token) + !token && messageWs.disconnect() }, [token]) useEffect(() => { @@ -102,6 +102,9 @@ const LayoutRouter = () => {
@@ -118,7 +121,12 @@ const LayoutRouter = () => { /> ) } - +
{/* 無效鏈接 */} diff --git a/src/styles/home.scss b/src/styles/home.scss index 0e8c1ab..af09baa 100644 --- a/src/styles/home.scss +++ b/src/styles/home.scss @@ -5,7 +5,6 @@ width: 100%; border-radius: 30px; overflow: hidden; - background-color: $primary; position: relative; img{ diff --git a/src/styles/layout.scss b/src/styles/layout.scss index 15718cd..e736b6f 100644 --- a/src/styles/layout.scss +++ b/src/styles/layout.scss @@ -99,24 +99,43 @@ display: none; } -.notify-box{ - padding: 10px 20px; - border: 1px solid #eeeeee; - box-shadow: 8px 8px 20px 0px rgba(0, 0, 0, 0.1); - border-radius: 10px; - - .img{ - @include img-size(32px,32px) - } -} - -.rv-popup{ +.notify{ + width: 100%; + height: 100%; position: relative; + + .header{ + height: 50px; + width: 100%; + display: flex; + align-items: center; + border-bottom: 1px solid #eee; + } .close{ position: absolute; top: 49%; - left: 0; + left: -4px; + } + + .notify-box{ + + height: calc(100% - 51px); + overflow: hidden; + overflow-y: scroll; + padding: 0px 20px; + + .notify-item-box{ + padding: 10px 20px; + border: 1px solid #eeeeee; + box-shadow: 8px 8px 20px 0px rgba(0, 0, 0, 0.1); + border-radius: 10px; + overflow: hidden; + + .img{ + @include img-size(32px,32px) + } + } } } diff --git a/src/types/store.d.ts b/src/types/store.d.ts index acfbe20..7526b42 100644 --- a/src/types/store.d.ts +++ b/src/types/store.d.ts @@ -76,10 +76,20 @@ interface InviteRecordData { id: number; } +interface MessageType { + id: number; + url: string; + status: number; + title: string; + message: string; + color: string; +} + export { StoreLocalStorageKey, UserInfo, CoinList, MarketNFTData, InviteRecordData, + MessageType, };