From 941549ff04bfd5017caaae64328c4b51fcdf7a6d Mon Sep 17 00:00:00 2001 From: archer <545436317@qq.com> Date: Tue, 6 Jun 2023 15:44:58 +0800 Subject: [PATCH] perf: user info framwork --- .github/workflows/image.yml | 19 +- docs/deploy/fastgpt/docker-compose.yml | 1 + src/components/Icon/icons/promotion.svg | 1 - src/components/Icon/index.tsx | 1 - src/components/Layout/navbar.tsx | 6 - src/components/WxConcat/index.tsx | 9 +- src/pages/api/plugins/kb/data/getDataList.ts | 1 + src/pages/login/index.tsx | 6 +- src/pages/number/components/BillTable.tsx | 13 +- .../number/components/PayRecordTable.tsx | 95 +++---- .../number/components/PromotionTable.tsx | 54 ++++ src/pages/number/index.tsx | 233 +++++++++++++----- src/pages/openapi/index.tsx | 1 + src/pages/promotion/index.tsx | 179 -------------- src/pages/tools/index.tsx | 5 - src/service/pg.ts | 1 - 16 files changed, 286 insertions(+), 339 deletions(-) delete mode 100644 src/components/Icon/icons/promotion.svg create mode 100644 src/pages/number/components/PromotionTable.tsx delete mode 100644 src/pages/promotion/index.tsx diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index fe5ba0fe9..92517eff0 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -62,9 +62,22 @@ jobs: with: username: ${{ secrets.DOCKER_HUB_NAME }} password: ${{ secrets.DOCKER_HUB_PASSWORD }} + - name: Set DOCKER_REPO_TAGGED based on branch or tag + run: | + if [[ "${{ github.ref_name }}" == "main" ]]; then + echo "IMAGE_TAG=latest" >> $GITHUB_ENV + else + echo "IMAGE_TAG=${{ github.ref_name }}" >> $GITHUB_ENV + fi - name: Pull image from GitHub Container Registry - run: docker pull ghcr.io/${{ github.repository_owner }}/fastgpt:${{ github.ref_name }} + env: + IMAGE_TAG: ${{ env.IMAGE_TAG }} + run: docker pull ghcr.io/${{ github.repository_owner }}/fastgpt:${ IMAGE_TAG } - name: Tag image with Docker Hub repository name and version tag - run: docker tag ghcr.io/${{ github.repository_owner }}/fastgpt:${{ github.ref_name }} ${{ secrets.DOCKER_IMAGE_NAME }}:${{ github.ref_name }} + env: + IMAGE_TAG: ${{ env.IMAGE_TAG }} + run: docker tag ghcr.io/${{ github.repository_owner }}/fastgpt:${ IMAGE_TAG } ${{ secrets.DOCKER_IMAGE_NAME }}:${ IMAGE_TAG } - name: Push image to Docker Hub - run: docker push ${{ secrets.DOCKER_IMAGE_NAME }}:${{ github.ref_name }} + env: + IMAGE_TAG: ${{ env.IMAGE_TAG }} + run: docker push ${{ secrets.DOCKER_IMAGE_NAME }}:${ IMAGE_TAG } diff --git a/docs/deploy/fastgpt/docker-compose.yml b/docs/deploy/fastgpt/docker-compose.yml index cab8ff616..de0f27774 100644 --- a/docs/deploy/fastgpt/docker-compose.yml +++ b/docs/deploy/fastgpt/docker-compose.yml @@ -19,6 +19,7 @@ services: - /etc/localtime:/etc/localtime:ro mongodb: image: mongo:5.0.18 + # image : registry.cn-hangzhou.aliyuncs.com/fastgpt/mongo:5.0.18 # 阿里云 container_name: mongo restart: always ports: diff --git a/src/components/Icon/icons/promotion.svg b/src/components/Icon/icons/promotion.svg deleted file mode 100644 index b71596c89..000000000 --- a/src/components/Icon/icons/promotion.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/components/Icon/index.tsx b/src/components/Icon/index.tsx index 34a8e8b55..3ebb82146 100644 --- a/src/components/Icon/index.tsx +++ b/src/components/Icon/index.tsx @@ -8,7 +8,6 @@ const map = { chatSend: require('./icons/chatSend.svg').default, develop: require('./icons/develop.svg').default, user: require('./icons/user.svg').default, - promotion: require('./icons/promotion.svg').default, delete: require('./icons/delete.svg').default, withdraw: require('./icons/withdraw.svg').default, stop: require('./icons/stop.svg').default, diff --git a/src/components/Layout/navbar.tsx b/src/components/Layout/navbar.tsx index 96142e8f1..e37c1c8a7 100644 --- a/src/components/Layout/navbar.tsx +++ b/src/components/Layout/navbar.tsx @@ -42,12 +42,6 @@ const Navbar = () => { link: '/model/share', activeLink: ['/model/share'] }, - { - label: '邀请', - icon: 'promotion', - link: '/promotion', - activeLink: ['/promotion'] - }, { label: '开发', icon: 'develop', diff --git a/src/components/WxConcat/index.tsx b/src/components/WxConcat/index.tsx index 291500f92..ff9a4341a 100644 --- a/src/components/WxConcat/index.tsx +++ b/src/components/WxConcat/index.tsx @@ -9,7 +9,6 @@ import { ModalFooter, ModalBody, ModalCloseButton, - useColorModeValue, Image } from '@chakra-ui/react'; @@ -18,7 +17,7 @@ const WxConcat = ({ onClose }: { onClose: () => void }) => { - wx交流群 + 联系方式-wx void }) => { height={'200px'} alt="" /> - - 微信号: - - YNyiqi - - diff --git a/src/pages/api/plugins/kb/data/getDataList.ts b/src/pages/api/plugins/kb/data/getDataList.ts index f2a4c0061..921c0b598 100644 --- a/src/pages/api/plugins/kb/data/getDataList.ts +++ b/src/pages/api/plugins/kb/data/getDataList.ts @@ -43,6 +43,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< PgClient.select('modelData', { fields: ['id', 'q', 'a', 'source'], where, + order: [{ field: 'id', mode: 'DESC' }], limit: pageSize, offset: pageSize * (pageNum - 1) }), diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx index 16af48ea8..b906a84f3 100644 --- a/src/pages/login/index.tsx +++ b/src/pages/login/index.tsx @@ -17,7 +17,7 @@ const Login = () => { const { lastRoute = '' } = router.query as { lastRoute: string }; const { isPc } = useGlobalStore(); const [pageType, setPageType] = useState<`${PageTypeEnum}`>(PageTypeEnum.login); - const { setUserInfo, setLastModelId, loadMyModels } = useUserStore(); + const { setUserInfo, setLastModelId, loadMyModels, loadKbList, setLastKbId } = useUserStore(); const { setLastChatId, setLastChatModelId, loadHistory } = useChatStore(); const loginSuccess = useCallback( @@ -26,7 +26,9 @@ const Login = () => { setLastChatId(''); setLastModelId(''); setLastChatModelId(''); + setLastKbId(''); loadMyModels(true); + loadKbList(true); loadHistory({ pageNum: 1, init: true }); setUserInfo(res.user); @@ -37,10 +39,12 @@ const Login = () => { [ lastRoute, loadHistory, + loadKbList, loadMyModels, router, setLastChatId, setLastChatModelId, + setLastKbId, setLastModelId, setUserInfo ] diff --git a/src/pages/number/components/BillTable.tsx b/src/pages/number/components/BillTable.tsx index d7bdc9b33..e7d9182ca 100644 --- a/src/pages/number/components/BillTable.tsx +++ b/src/pages/number/components/BillTable.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { Card, Box, Table, Thead, Tbody, Tr, Th, Td, TableContainer, Flex } from '@chakra-ui/react'; +import { Table, Thead, Tbody, Tr, Th, Td, TableContainer, Flex } from '@chakra-ui/react'; import { BillTypeMap } from '@/constants/user'; import { getUserBills } from '@/api/user'; import type { UserBillType } from '@/types/user'; @@ -19,11 +19,8 @@ const BillTable = () => { }); return ( - - - 使用记录 - - + <> + @@ -51,10 +48,10 @@ const BillTable = () => { - + - + ); }; diff --git a/src/pages/number/components/PayRecordTable.tsx b/src/pages/number/components/PayRecordTable.tsx index 6d6548fb6..14fc34f28 100644 --- a/src/pages/number/components/PayRecordTable.tsx +++ b/src/pages/number/components/PayRecordTable.tsx @@ -1,29 +1,14 @@ import React, { useState, useCallback } from 'react'; -import { - Card, - Box, - Flex, - Button, - Table, - Thead, - Tbody, - Tr, - Th, - Td, - TableContainer, - useDisclosure -} from '@chakra-ui/react'; +import { Button, Table, Thead, Tbody, Tr, Th, Td, TableContainer } from '@chakra-ui/react'; import { getPayOrders, checkPayResult } from '@/api/user'; import { PaySchema } from '@/types/mongoSchema'; import dayjs from 'dayjs'; import { useQuery } from '@tanstack/react-query'; import { formatPrice } from '@/utils/user'; -import WxConcat from '@/components/WxConcat'; import { useGlobalStore } from '@/store/global'; import { useToast } from '@/hooks/useToast'; const PayRecordTable = () => { - const { isOpen: isOpenWx, onOpen: onOpenWx, onClose: onCloseWx } = useDisclosure(); const [payOrders, setPayOrders] = useState([]); const { setLoading } = useGlobalStore(); const { toast } = useToast(); @@ -60,52 +45,38 @@ const PayRecordTable = () => { }); return ( - <> - - - - 充值记录 - - - - -
- - - - - - - - - - - {payOrders.map((item) => ( - - - - - - - - ))} - -
订单号时间金额状态
{item.orderId} - {item.createTime ? dayjs(item.createTime).format('YYYY/MM/DD HH:mm:ss') : '-'} - {formatPrice(item.price)}元{item.status} - {item.status === 'NOTPAY' && ( - - )} -
-
-
- {/* wx 联系 */} - {isOpenWx && } - + + + + + + + + + + + + + {payOrders.map((item) => ( + + + + + + + + ))} + +
订单号时间金额状态
{item.orderId} + {item.createTime ? dayjs(item.createTime).format('YYYY/MM/DD HH:mm:ss') : '-'} + {formatPrice(item.price)}元{item.status} + {item.status === 'NOTPAY' && ( + + )} +
+
); }; diff --git a/src/pages/number/components/PromotionTable.tsx b/src/pages/number/components/PromotionTable.tsx new file mode 100644 index 000000000..2ddcb0f70 --- /dev/null +++ b/src/pages/number/components/PromotionTable.tsx @@ -0,0 +1,54 @@ +import React from 'react'; +import { Flex, Table, Thead, Tbody, Tr, Th, Td, TableContainer } from '@chakra-ui/react'; +import { useLoading } from '@/hooks/useLoading'; +import dayjs from 'dayjs'; +import { getPromotionRecords } from '@/api/user'; +import { usePagination } from '@/hooks/usePagination'; +import { PromotionRecordType } from '@/api/response/user'; +import { PromotionTypeMap } from '@/constants/user'; + +const OpenApi = () => { + const { Loading } = useLoading(); + + const { + data: promotionRecords, + isLoading, + Pagination + } = usePagination({ + api: getPromotionRecords + }); + + return ( + <> + + + + + + + + + + + {promotionRecords.map((item) => ( + + + + + + ))} + +
时间类型金额
+ {item.createTime ? dayjs(item.createTime).format('YYYY/MM/DD HH:mm:ss') : '-'} + {PromotionTypeMap[item.type]}{item.amount}
+ + +
+ + + + + ); +}; + +export default OpenApi; diff --git a/src/pages/number/index.tsx b/src/pages/number/index.tsx index 872f1af1e..ed670488f 100644 --- a/src/pages/number/index.tsx +++ b/src/pages/number/index.tsx @@ -1,8 +1,21 @@ -import React, { useCallback, useState } from 'react'; -import { Card, Box, Flex, Button, Input } from '@chakra-ui/react'; +import React, { useCallback, useRef, useState } from 'react'; +import { + Card, + Box, + Flex, + Button, + Input, + Grid, + useDisclosure, + Tabs, + TabList, + TabPanels, + Tab, + TabPanel +} from '@chakra-ui/react'; import { useForm } from 'react-hook-form'; import { UserUpdateParams } from '@/types/user'; -import { putUserInfo } from '@/api/user'; +import { putUserInfo, getPromotionInitData } from '@/api/user'; import { useToast } from '@/hooks/useToast'; import { useGlobalStore } from '@/store/global'; import { useUserStore } from '@/store/user'; @@ -13,8 +26,10 @@ import { useQuery } from '@tanstack/react-query'; import dynamic from 'next/dynamic'; import { useSelectFile } from '@/hooks/useSelectFile'; import { compressImg } from '@/utils/file'; +import { useCopyData } from '@/utils/tools'; import Loading from '@/components/Loading'; import Avatar from '@/components/Avatar'; +import MyIcon from '@/components/Icon'; const PayRecordTable = dynamic(() => import('./components/PayRecordTable'), { loading: () => , @@ -24,20 +39,49 @@ const BilTable = dynamic(() => import('./components/BillTable'), { loading: () => , ssr: false }); +const PromotionTable = dynamic(() => import('./components/PromotionTable'), { + loading: () => , + ssr: false +}); const PayModal = dynamic(() => import('./components/PayModal'), { loading: () => , ssr: false }); +const WxConcat = dynamic(() => import('@/components/WxConcat'), { + loading: () => , + ssr: false +}); + +enum TableEnum { + 'bill' = 'bill', + 'pay' = 'pay', + 'promotion' = 'promotion' +} const NumberSetting = () => { + const tableType = useRef([ + { label: '账单详情', value: TableEnum.bill, Component: BilTable }, + { label: '充值记录', value: TableEnum.pay, Component: PayRecordTable }, + { label: '佣金记录', value: TableEnum.pay, Component: PromotionTable } + ]); const router = useRouter(); + const { copyData } = useCopyData(); const { userInfo, updateUserInfo, initUserInfo, setUserInfo } = useUserStore(); const { setLoading } = useGlobalStore(); const { register, handleSubmit, reset } = useForm({ defaultValues: userInfo as UserType }); - const [showPay, setShowPay] = useState(false); const { toast } = useToast(); + const { + isOpen: isOpenPayModal, + onClose: onClosePayModal, + onOpen: onOpenPayModal + } = useDisclosure(); + const { + isOpen: isOpenWxConcat, + onClose: onCloseWxConcat, + onOpen: onOpenWxConcat + } = useDisclosure(); const { File, onOpen: onOpenSelectFile } = useSelectFile({ fileType: '.jpg,.png', @@ -92,76 +136,137 @@ const NumberSetting = () => { }, [router, setUserInfo]); useQuery(['init'], initUserInfo); + const { data: { invitedAmount = 0, historyAmount = 0, residueAmount = 0 } = {} } = useQuery( + ['getPromotionInitData'], + getPromotionInitData + ); return ( - {/* 核心信息 */} - - - - 账号信息 - - - - - 头像: - - - - 账号: - {userInfo?.username} - - - - 余额: - - {userInfo?.balance} 元 + + + + + 账号信息 - - - 如果填写了自己的 openai 账号,网页上 openai 模型对话不会计费。 + + 头像: + + + + 账号: + {userInfo?.username} + + + + 余额: + + {userInfo?.balance} 元 + + + + + 如果填写了自己的 openai 账号,网页上 openai 模型对话不会计费。 + - - - openaiKey: - { - if (e.keyCode === 13) { - handleSubmit(onclickSave)(); - } - }} - > - + + openaiKey: + { + if (e.keyCode === 13) { + handleSubmit(onclickSave)(); + } + }} + > + + + + + 我的邀请 + + {[ + { label: '佣金比例', value: `${userInfo?.promotion.rate || 15}%` }, + { label: '已注册用户数', value: `${invitedAmount}人` }, + { label: '累计佣金', value: `¥${historyAmount}` } + ].map((item) => ( + + {item.label} + {item.value} + + ))} + + + + + + + + + {tableType.current.map((item) => ( + + {item.label} + + ))} + + + {tableType.current.map((Item) => ( + + + + ))} + + + {isOpenPayModal && } + {isOpenWxConcat && } - {/* 充值记录 */} - - {/* 账单表 */} - - {showPay && setShowPay(false)} />} ); }; diff --git a/src/pages/openapi/index.tsx b/src/pages/openapi/index.tsx index 549083713..d1ce020ed 100644 --- a/src/pages/openapi/index.tsx +++ b/src/pages/openapi/index.tsx @@ -61,6 +61,7 @@ const OpenApi = () => { 的形式接入到自己的应用中,例如:飞书、企业微信、客服助手。请注意保管你的 Api Key,不要泄露! + 使用 Fast Api 功能仅能使用平台余额。 { - const { Loading } = useLoading(); - const { userInfo, initUserInfo } = useUserStore(); - const { copyData } = useCopyData(); - const { - isOpen: isOpenWithdraw, - onClose: onCloseWithdraw, - onOpen: onOpenWithdraw - } = useDisclosure(); - - useQuery(['init'], initUserInfo); - const { data: { invitedAmount = 0, historyAmount = 0, residueAmount = 0 } = {} } = useQuery( - ['getPromotionInitData'], - getPromotionInitData - ); - - const { - data: promotionRecords, - isLoading, - Pagination, - total - } = usePagination({ - api: getPromotionRecords - }); - - return ( - - - - 我的邀请 - - - 你可以通过邀请链接邀请好友注册 FastGpt 账号。好友在 FastGpt - 平台的每次充值,你都会获得一定比例的佣金。 - - - 当前剩余佣金: ¥ - - {residueAmount} - - - - - - - - - - 佣金比例 - {userInfo?.promotion.rate || 15}% - - - 已注册用户数 - {invitedAmount}人 - - - 累计佣金 - ¥ {historyAmount} - - - - - 佣金记录 ({total}) - - - - - - - - - - - - {promotionRecords.map((item) => ( - - - - - - ))} - -
时间类型金额
- {item.createTime ? dayjs(item.createTime).format('YYYY/MM/DD HH:mm:ss') : '-'} - {PromotionTypeMap[item.type]}{item.amount}
- - -
- - - -
- - - - 提现联系 - - - - - 微信号: - - YNyiqi - - - 发送你的邀请链接和需要提现的金额 - - - - - - - -
- ); -}; - -export default OpenApi; diff --git a/src/pages/tools/index.tsx b/src/pages/tools/index.tsx index f8fcda6fc..96bf6f9e1 100644 --- a/src/pages/tools/index.tsx +++ b/src/pages/tools/index.tsx @@ -15,11 +15,6 @@ const list = [ label: 'AI应用市场', link: '/model/share' }, - { - icon: 'promotion', - label: '邀请好友', - link: '/promotion' - }, { icon: 'develop', label: '开发', diff --git a/src/service/pg.ts b/src/service/pg.ts index af4c62af8..23bcedcac 100644 --- a/src/service/pg.ts +++ b/src/service/pg.ts @@ -108,7 +108,6 @@ class Pg { } LIMIT ${props.limit || 10} OFFSET ${props.offset || 0} `; - const pg = await connectPg(); return pg.query(sql); }