Compare commits
10 Commits
v1.1.2
...
d83ad11241
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d83ad11241 | ||
|
|
bce7e41adf | ||
| 2b77ea189b | |||
|
|
82bd8051d8 | ||
|
|
4e27d707ec | ||
|
|
32c08d96d4 | ||
|
|
1031630712 | ||
|
|
31c26e9636 | ||
|
|
333bd3f686 | ||
|
|
9201a819be |
121
README.md
121
README.md
@@ -1,5 +1,9 @@
|
||||
## TODO
|
||||
|
||||
- 导航栏
|
||||
- 账单页面
|
||||
- 实名认证响应
|
||||
|
||||
分离公共 api 接口 env 定义
|
||||
|
||||
统一前端基础库(类型,api)
|
||||
@@ -16,31 +20,114 @@
|
||||
|
||||
业务定制页面每月需求用量,可选项需要确认是否合理
|
||||
|
||||
页头高度降低
|
||||
|
||||
帮助中心文档优化
|
||||
|
||||
考虑重新组织导航栏
|
||||
- 产品购买
|
||||
- 提取 IP
|
||||
- 业务场景
|
||||
- 帮助中心
|
||||
- 大客户定制
|
||||
|
||||
购买与提取手机端优化,尽量一页展示全部
|
||||
|
||||
全部替换封装时间范围组件,检查结束时间字段手机端适配问题(需要尾部对齐)
|
||||
|
||||
迁移到 tanstack form
|
||||
|
||||
页尾链接完善跳转地址
|
||||
|
||||
树组件优化
|
||||
|
||||
### 架构改进
|
||||
## 目录结构
|
||||
|
||||
考虑使用 swr 或 react query 来代替直接的服务端 react cache 缓存以及客户端 zustand 缓存,以将服务端请求的数据能够水合到客户端,避免重复请求
|
||||
```
|
||||
├── node_modules/ # 项目依赖包
|
||||
├── public/ # 静态资源(如 favicon、图片等,可直接通过根路径访问)
|
||||
├── src/ # 源代码目录
|
||||
│ ├── actions/ # 服务端操作或 API 逻辑(如 Server Actions)
|
||||
│ ├── app/ # Next.js 13+ App Router 目录,存放页面、布局、路由等
|
||||
| | ├── (api)/ # API 路由目录
|
||||
| | ├── (auth)/ # 认证相关页面
|
||||
| | ├── (home)/ # 首页模块
|
||||
| | ├── admin/ # 管理后台模块
|
||||
| | ├── effects.tsx # 全局副作用/状态管理(如 Redux、SWR 初始化)
|
||||
| | ├── favicon.ico # 网站图标
|
||||
| | ├── globals.css # 全局样式
|
||||
| | └── layout.tsx # 根布局组件(所有页面共享的布局结构)
|
||||
| |
|
||||
│ ├── assets/ # 项目资源文件(如图片、字体、样式等)
|
||||
│ ├── components/ # 可复用的 React 组件
|
||||
│ ├── lib/ # 工具函数、配置、服务等
|
||||
│ ├── mdx-components.tsx # MDX 组件配置
|
||||
│ └── proxy.ts # 代理配置(如 API 代理)
|
||||
├── .dockerignore # Docker 忽略文件
|
||||
├── .env # 环境变量文件
|
||||
├── .gitignore # Git 忽略文件
|
||||
├── .npmrc # npm 配置
|
||||
├── bun.lock # Bun 包管理器锁文件
|
||||
├── components.json # 组件库配置(如 shadcn/ui)
|
||||
├── Dockerfile # Docker 构建配置
|
||||
├── eslint.config.mjs # ESLint 代码检查配置
|
||||
├── next-env.d.ts # Next.js 类型声明
|
||||
├── next.config.ts # Next.js 配置文件
|
||||
├── package.json # 项目依赖和脚本
|
||||
├── postcss.config.mjs # PostCSS 配置
|
||||
├── publish.ps1 # PowerShell 发布脚本
|
||||
├── README.md # 项目说明文档
|
||||
└── tsconfig.json # TypeScript 配置
|
||||
```
|
||||
|
||||
### 需要确认
|
||||
## 技术栈
|
||||
| 类别 | 场景/库名 | 推荐方案/用途 |
|
||||
| :--- | :--- | :--- |
|
||||
| **状态管理** | 简单跨组件通信 | React Context |
|
||||
| | 复杂全局状态 | Zustand + persist |
|
||||
| | 服务端状态 | TanStack Query |
|
||||
| | 表单状态 | React Hook Form |
|
||||
| | 路由状态 | Next.js 内置 (useSearchParams, useParams) |
|
||||
| **核心框架** | Next.js | 服务框架 (React 全栈框架) |
|
||||
| **UI / 样式体系** | shadcn/ui | UI 组件库 |
|
||||
| | Radix UI | 无样式基础 UI 组件原语 |
|
||||
| | Tailwind CSS | CSS 框架 (原子化 CSS) |
|
||||
| | lucide-react | 图标库 |
|
||||
| **表单与数据验证** | React Hook Form | 表单状态管理及验证 |
|
||||
| | Zod | 数据验证与类型推断 |
|
||||
| **数据管理与通信** | Zustand | 全局状态管理库 |
|
||||
| | TanStack Query | 服务端状态管理 (数据请求、缓存) |
|
||||
| | TanStack Table | 无头 UI 表格库 |
|
||||
| **图表可视化** | Recharts | 图表库 |
|
||||
| **工具库** | date-fns | 日期时间处理库 |
|
||||
| | qrcode | QR 码生成库 |
|
||||
|
||||
页面内操作是否需要关联到 url 上,以在使用后退功能时返回到上一次操作
|
||||
## 搭建开发环境
|
||||
|
||||
项目基于 bun 运行,bun 是一个 typescript 原生的运行时环境,用于代替 nodejs,可以带来更高的性能提升。
|
||||
|
||||
1. 拉取项目:`git clone https://43.226.58.254:53000/lanhu/web`
|
||||
2. 安装依赖包:`bun install`
|
||||
3. 创建环境变量文件 .env,复制 .env.example 中的内容到 .env,并根据实际情况修改
|
||||
4. 运行项目 `bun run dev`
|
||||
|
||||
## 构建项目 & 版本管理
|
||||
|
||||
1. 在 package.json 文件中修改版本号
|
||||
2. 构建并上传镜像, 终端运行 `./publish.ps1 <版本号>`
|
||||
3. 终端执行成功后在 `https://43.226.58.254:53000/lanhu/web` 发布最新版本
|
||||
|
||||
生产环境的项目部署通过单独的部署脚本进行管理,前端开发上线只需要构建以及发布版本,无需考虑部署问题。
|
||||
|
||||
## 开发规范 & 主要业务逻辑
|
||||
|
||||
原型图:https://lanhuapp.com/link/#/invite?sid=lxgnSyga
|
||||
|
||||
### 快速创建前台新页面
|
||||
|
||||
wrap.tsx :新页面间距复用组件
|
||||
page.tsx:新页面统一布局
|
||||
stores:共享状态组件
|
||||
|
||||
### 数据流与状态管理: 组件间通信方式
|
||||
|
||||
- 通信方式:Props 父传子 / 回调函数 子传父 / Context 跨组件 useContext() / Zustand Store 全局状态管理useStore() / URL 参数 页面间状态共享 useSearchParams()
|
||||
路由与导航: 路由使用的Next.js App Router 架构 Server Actions 实现。
|
||||
|
||||
### 认证与权限控制:登录流程-路由守卫(中间件)
|
||||
|
||||
### 支付流程实现: 支付二维码生成
|
||||
|
||||
### SSE 支付状态监听
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 图片使用 Next.js Image 组件自动优化
|
||||
- 动态导入 (next/dynamic) 实现纯客户端组件
|
||||
|
||||
3
bun.lock
3
bun.lock
@@ -45,6 +45,7 @@
|
||||
"sonner": "^2.0.7",
|
||||
"tailwind-merge": "^3.4.0",
|
||||
"tailwindcss-animate": "^1.0.7",
|
||||
"vaul": "^1.1.2",
|
||||
"zod": "^3.25.76",
|
||||
"zustand": "^5.0.9",
|
||||
},
|
||||
@@ -1399,6 +1400,8 @@
|
||||
|
||||
"util-deprecate": ["util-deprecate@1.0.2", "https://registry.npmmirror.com/util-deprecate/-/util-deprecate-1.0.2.tgz", {}, "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="],
|
||||
|
||||
"vaul": ["vaul@1.1.2", "https://registry.npmmirror.com/vaul/-/vaul-1.1.2.tgz", { "dependencies": { "@radix-ui/react-dialog": "^1.1.1" }, "peerDependencies": { "react": "^16.8 || ^17.0 || ^18.0 || ^19.0.0 || ^19.0.0-rc", "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0.0 || ^19.0.0-rc" } }, "sha512-ZFkClGpWyI2WUQjdLJ/BaGuV6AVQiJ3uELGk3OYtP+B6yCO7Cmn9vPFXVJkRaGkOJu3m8bQMgtyzNHixULceQA=="],
|
||||
|
||||
"vfile": ["vfile@6.0.3", "https://registry.npmmirror.com/vfile/-/vfile-6.0.3.tgz", { "dependencies": { "@types/unist": "^3.0.0", "vfile-message": "^4.0.0" } }, "sha512-KzIbH/9tXat2u30jf+smMwFCsno4wHVdNmzFyL+T/L3UGqqk6JKfVqOFOZEpZSHADH1k40ab6NUIXZq422ov3Q=="],
|
||||
|
||||
"vfile-message": ["vfile-message@4.0.3", "https://registry.npmmirror.com/vfile-message/-/vfile-message-4.0.3.tgz", { "dependencies": { "@types/unist": "^3.0.0", "unist-util-stringify-position": "^4.0.0" } }, "sha512-QTHzsGd1EhbZs4AsQ20JX1rC3cOlt/IWJruk893DfLRr57lcnOeMaWG4K0JrRta4mIJZKth2Au3mM3u03/JWKw=="],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "lanhu-web",
|
||||
"version": "1.1.2",
|
||||
"version": "1.2.2",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev -H 0.0.0.0 --turbopack",
|
||||
@@ -51,6 +51,7 @@
|
||||
"sonner": "^2.0.7",
|
||||
"tailwind-merge": "^3.4.0",
|
||||
"tailwindcss-animate": "^1.0.7",
|
||||
"vaul": "^1.1.2",
|
||||
"zod": "^3.25.76",
|
||||
"zustand": "^5.0.9"
|
||||
},
|
||||
|
||||
@@ -141,7 +141,7 @@ export default function LoginCard() {
|
||||
<button
|
||||
type="button"
|
||||
tabIndex={-1}
|
||||
className="absolute right-2 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600"
|
||||
className="absolute right-2 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 cursor-pointer"
|
||||
onClick={() => setShowPwd(v => !v)}
|
||||
aria-label={showPwd ? '隐藏密码' : '显示密码'}
|
||||
>
|
||||
|
||||
@@ -28,7 +28,7 @@ export function HeroSection() {
|
||||
</div>
|
||||
|
||||
<FreeTrial className={[
|
||||
`mt-32 max-md:mt-20 w-96 max-md:w-full h-16 md:h-24 rounded-lg shadow-lg`,
|
||||
`mt-32 max-md:mt-20 w-96 max-md:w-full h-16 md:h-24 rounded-lg shadow-lg cursor-pointer`,
|
||||
`bg-linear-to-r from-blue-500 to-cyan-400 text-white text-xl lg:text-4xl`,
|
||||
].join(' ')}/>
|
||||
</Wrap>
|
||||
|
||||
@@ -2,15 +2,15 @@ import Wrap from '@/components/wrap'
|
||||
import {Children} from '@/lib/utils'
|
||||
import Sidebar from './sidebar'
|
||||
import HomePage from '@/components/home/page'
|
||||
import SidebarDrawer from './sidebar-drawer'
|
||||
|
||||
export default function DocsLayout(props: Children) {
|
||||
return (
|
||||
<HomePage path={[
|
||||
{label: '帮助中心', href: '/docs'},
|
||||
]}>
|
||||
<Wrap className="flex gap-3">
|
||||
<Sidebar/>
|
||||
<div className="flex-1 bg-white rounded-lg p-6 min-h-[420px]">
|
||||
<HomePage path={[{label: '帮助中心', href: '/docs'}]}>
|
||||
<Wrap className="flex gap-3 flex-col md:flex-row">
|
||||
<SidebarDrawer/>
|
||||
<Sidebar className="hidden md:block w-68"/>
|
||||
<div className="flex-1 bg-white rounded-lg p-4 md:p-6 min-h-[420px]">
|
||||
{props.children}
|
||||
</div>
|
||||
</Wrap>
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
export default function DocsIndexPage() {
|
||||
return (
|
||||
<div></div>
|
||||
<div className="text-center text-slate-500 py-12">
|
||||
<p className="text-lg">欢迎来到帮助中心</p>
|
||||
<p className="text-sm mt-2">请从左侧目录选择需要查看的文档</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
37
src/app/(home)/docs/sidebar-drawer.tsx
Normal file
37
src/app/(home)/docs/sidebar-drawer.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
'use client'
|
||||
import {useState} from 'react'
|
||||
import {Menu} from 'lucide-react'
|
||||
import {
|
||||
Drawer,
|
||||
DrawerContent,
|
||||
DrawerTrigger,
|
||||
} from '@/components/ui/drawer'
|
||||
import Sidebar from './sidebar'
|
||||
|
||||
export default function SidebarDrawer() {
|
||||
const [open, setOpen] = useState(false)
|
||||
|
||||
return (
|
||||
<div className="md:hidden flex items-center justify-between bg-white rounded-lg p-3">
|
||||
<span className="font-medium text-slate-900">帮助中心</span>
|
||||
<Drawer open={open} onOpenChange={setOpen}>
|
||||
<DrawerTrigger asChild>
|
||||
<button className="flex items-center gap-2 text-slate-600 hover:text-slate-900 p-1 cursor-pointer">
|
||||
<Menu size={20}/>
|
||||
<span className="text-sm">目录</span>
|
||||
</button>
|
||||
</DrawerTrigger>
|
||||
<DrawerContent>
|
||||
<div className="mx-auto w-full max-w-sm">
|
||||
<div className="px-4 py-3 border-b">
|
||||
<h3 className="text-lg font-semibold text-slate-900">帮助中心</h3>
|
||||
</div>
|
||||
<div className="px-2 py-2 max-h-[70vh] overflow-y-auto">
|
||||
<Sidebar onClose={() => setOpen(false)}/>
|
||||
</div>
|
||||
</div>
|
||||
</DrawerContent>
|
||||
</Drawer>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -3,10 +3,7 @@ import {useState, useMemo, useCallback} from 'react'
|
||||
import Link from 'next/link'
|
||||
import {usePathname} from 'next/navigation'
|
||||
import {ChevronRight} from 'lucide-react'
|
||||
|
||||
type Props = {
|
||||
collapsed?: boolean
|
||||
}
|
||||
import {merge} from '@/lib/utils'
|
||||
|
||||
// 菜单配置
|
||||
const MENU_ITEMS = [
|
||||
@@ -58,7 +55,12 @@ const MENU_ITEMS = [
|
||||
},
|
||||
]
|
||||
|
||||
export default function Sidebar({collapsed = false}: Props) {
|
||||
type Props = {
|
||||
className?: string
|
||||
onClose?: () => void
|
||||
}
|
||||
|
||||
export default function Sidebar({className, onClose}: Props) {
|
||||
const pathname = usePathname()
|
||||
|
||||
// 获取当前文档 key
|
||||
@@ -100,9 +102,7 @@ export default function Sidebar({collapsed = false}: Props) {
|
||||
|
||||
return (
|
||||
<aside
|
||||
className={`bg-white rounded-lg p-3 transition-all duration-200 shrink-0 ${
|
||||
collapsed ? 'w-20' : 'w-68'
|
||||
}`}
|
||||
className={merge(`bg-white rounded-lg p-3 transition-all duration-200 shrink-0`, className)}
|
||||
>
|
||||
<nav className="space-y-2">
|
||||
{MENU_ITEMS.map(section => (
|
||||
@@ -110,9 +110,7 @@ export default function Sidebar({collapsed = false}: Props) {
|
||||
<div
|
||||
onClick={() => toggleGroup(section.group)}
|
||||
className={`flex items-center gap-2 cursor-pointer px-3 py-2 rounded-sm transition-colors ${
|
||||
finalExpandedGroups[section.group] && !collapsed
|
||||
? 'bg-blue-50'
|
||||
: 'hover:bg-slate-50'
|
||||
finalExpandedGroups[section.group] && 'bg-blue-50'
|
||||
}`}
|
||||
>
|
||||
<div
|
||||
@@ -123,15 +121,13 @@ export default function Sidebar({collapsed = false}: Props) {
|
||||
<ChevronRight size={16}/>
|
||||
</div>
|
||||
|
||||
{!collapsed && (
|
||||
<div className="text-lg font-semibold text-slate-900">
|
||||
{section.group}
|
||||
</div>
|
||||
)}
|
||||
<div className="text-lg font-semibold text-slate-900">
|
||||
{section.group}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{finalExpandedGroups[section.group] && (
|
||||
<ul className={`mt-1 text-base ${collapsed ? 'hidden' : 'block'}`}>
|
||||
<ul className="mt-1 text-base">
|
||||
{section.items.map((item) => {
|
||||
const isActive = currentKey === item.key
|
||||
const href = getItemHref(item.key)
|
||||
@@ -140,6 +136,7 @@ export default function Sidebar({collapsed = false}: Props) {
|
||||
<li key={item.key}>
|
||||
<Link
|
||||
href={href}
|
||||
onClick={() => onClose?.()}
|
||||
className={`block pl-8 py-2 text-base cursor-pointer transition-colors ${
|
||||
isActive
|
||||
? 'bg-blue-50 font-semibold'
|
||||
|
||||
@@ -225,7 +225,7 @@ function MenuItem(props: {
|
||||
onPointerLeave={props.onPointerLeave}
|
||||
className={[
|
||||
`h-full px-4 flex gap-3 items-center cursor-pointer text-lg`,
|
||||
`transition-colors duration-200 ease-in-out`,
|
||||
`transition-colors duration-200 ease-in-out cursor-pointer`,
|
||||
props.active
|
||||
? `text-blue-500`
|
||||
: ``,
|
||||
|
||||
@@ -99,7 +99,7 @@ export default function BillsPage(props: BillsPageProps) {
|
||||
<SelectItem value="all">全部</SelectItem>
|
||||
<SelectItem value="3">充值</SelectItem>
|
||||
<SelectItem value="1">消费</SelectItem>
|
||||
<SelectItem value="2">退款</SelectItem>
|
||||
{/* <SelectItem value="2">退款</SelectItem> */}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)}
|
||||
@@ -284,13 +284,13 @@ export default function BillsPage(props: BillsPageProps) {
|
||||
format(new Date(row.original.created_at), 'yyyy-MM-dd HH:mm')
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'action', header: `操作`, cell: item => (
|
||||
<div className="flex gap-2">
|
||||
-
|
||||
</div>
|
||||
),
|
||||
},
|
||||
// {
|
||||
// accessorKey: 'action', header: `操作`, cell: item => (
|
||||
// <div className="flex gap-2">
|
||||
// -
|
||||
// </div>
|
||||
// ),
|
||||
// },
|
||||
]}
|
||||
/>
|
||||
</Page>
|
||||
|
||||
@@ -116,7 +116,14 @@ export function Header() {
|
||||
</div>
|
||||
|
||||
{/* right */}
|
||||
<div className="flex-none flex items-center justify-end pr-4">
|
||||
<div className="flex-none flex items-center justify-end pr-4 max-md:hidden gap-2">
|
||||
<Link
|
||||
href="/"
|
||||
className={merge(
|
||||
`flex-none h-16 flex items-center justify-center`,
|
||||
)}>
|
||||
返回首页
|
||||
</Link>
|
||||
<Suspense>
|
||||
<HeaderUserCenter/>
|
||||
</Suspense>
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 31 KiB |
@@ -5,8 +5,10 @@ import {Loader} from 'lucide-react'
|
||||
import {useState} from 'react'
|
||||
import Image from 'next/image'
|
||||
import {PaymentModalProps} from './payment-modal'
|
||||
import {getTradeMethodDecoration} from '@/lib/models/trade'
|
||||
|
||||
export function DesktopPayment(props: PaymentModalProps) {
|
||||
const decoration = getTradeMethodDecoration(props.method)
|
||||
const [loading, setLoading] = useState(false)
|
||||
|
||||
const onSubmit = async () => {
|
||||
@@ -19,10 +21,10 @@ export function DesktopPayment(props: PaymentModalProps) {
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex gap-2 items-center">
|
||||
{props.decoration.icon ? (
|
||||
{decoration.icon ? (
|
||||
<Image
|
||||
src={props.decoration.icon}
|
||||
alt={props.decoration.text}
|
||||
src={decoration.icon}
|
||||
alt={decoration.text}
|
||||
width={24}
|
||||
height={24}
|
||||
className="rounded-md"
|
||||
@@ -30,7 +32,7 @@ export function DesktopPayment(props: PaymentModalProps) {
|
||||
) : (
|
||||
<div className="w-6 h-6 bg-gray-200 rounded-full"/>
|
||||
)}
|
||||
<span>{props.decoration.text}</span>
|
||||
<span>{decoration.text}</span>
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
@@ -43,7 +45,7 @@ export function DesktopPayment(props: PaymentModalProps) {
|
||||
/>
|
||||
<p className="text-sm text-gray-600">
|
||||
请使用
|
||||
{props.decoration.text}
|
||||
{decoration.text}
|
||||
扫码支付
|
||||
</p>
|
||||
|
||||
|
||||
@@ -6,8 +6,10 @@ import {CreditCard, Loader} from 'lucide-react'
|
||||
import {useState} from 'react'
|
||||
import Image from 'next/image'
|
||||
import {PaymentModalProps} from './payment-modal'
|
||||
import {getTradeMethodDecoration} from '@/lib/models/trade'
|
||||
|
||||
export function MobilePayment(props: PaymentModalProps) {
|
||||
const decoration = getTradeMethodDecoration(props.method)
|
||||
const [loading, setLoading] = useState(false) // 加载状态
|
||||
const [paymentInitiated, setPaymentInitiated] = useState(false) // 是否已发起支付
|
||||
|
||||
@@ -54,16 +56,16 @@ export function MobilePayment(props: PaymentModalProps) {
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-600">支付方式</span>
|
||||
<div className="flex items-center gap-2">
|
||||
{props.decoration.icon && (
|
||||
{decoration.icon && (
|
||||
<Image
|
||||
src={props.decoration.icon}
|
||||
alt={props.decoration.text}
|
||||
src={decoration.icon}
|
||||
alt={decoration.text}
|
||||
width={28}
|
||||
height={28}
|
||||
className="rounded-md"
|
||||
/>
|
||||
)}
|
||||
<span>{props.decoration.text}</span>
|
||||
<span>{decoration.text}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
|
||||
@@ -6,7 +6,7 @@ import {Dialog} from '@/components/ui/dialog'
|
||||
import {PaymentProps} from './type'
|
||||
import {payClose} from '@/actions/resource'
|
||||
import {useEffect} from 'react'
|
||||
import {useRouter} from 'next/navigation'
|
||||
import {UniversalDesktopPayment} from './universal-desktop-payment'
|
||||
|
||||
export type PaymentModalProps = {
|
||||
onConfirm: (showFail: boolean) => Promise<void>
|
||||
@@ -61,17 +61,13 @@ export function PaymentModal(props: PaymentModalProps) {
|
||||
onOpenChange={(open) => {
|
||||
if (!open) handleClose()
|
||||
}}>
|
||||
{props.platform === TradePlatform.Mobile ? (
|
||||
<MobilePayment
|
||||
{...props}
|
||||
onClose={handleClose}
|
||||
/>
|
||||
) : (
|
||||
<DesktopPayment
|
||||
{...props}
|
||||
onClose={handleClose}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* {props.platform === TradePlatform.Mobile
|
||||
? <MobilePayment {...props} onClose={handleClose}/>
|
||||
: <DesktopPayment {...props} onClose={handleClose}/>
|
||||
} */}
|
||||
|
||||
<UniversalDesktopPayment {...props} onClose={handleClose}/>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -8,8 +8,4 @@ export type PaymentProps = {
|
||||
amount: number
|
||||
platform: TradePlatform
|
||||
method: TradeMethod
|
||||
decoration: {
|
||||
icon: StaticImageData
|
||||
text: string
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
'use client'
|
||||
import {DialogClose, DialogContent, DialogHeader, DialogTitle} from '@/components/ui/dialog'
|
||||
import {Button} from '@/components/ui/button'
|
||||
import {Loader} from 'lucide-react'
|
||||
import {useState} from 'react'
|
||||
import Image from 'next/image'
|
||||
import {PaymentModalProps} from './payment-modal'
|
||||
import {getTradeMethodDecoration, TradePlatform} from '@/lib/models/trade'
|
||||
|
||||
export function UniversalDesktopPayment(props: PaymentModalProps) {
|
||||
const decoration = getTradeMethodDecoration(props.method)
|
||||
const [loading, setLoading] = useState(false)
|
||||
|
||||
const onSubmit = async () => {
|
||||
setLoading(true)
|
||||
await props.onConfirm(true)
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex gap-2 items-center">
|
||||
{decoration.icon ? (
|
||||
<Image
|
||||
src={decoration.icon}
|
||||
alt={decoration.text}
|
||||
width={24}
|
||||
height={24}
|
||||
className="rounded-md"
|
||||
/>
|
||||
) : (
|
||||
<div className="w-6 h-6 bg-gray-200 rounded-full"/>
|
||||
)}
|
||||
<span>{decoration.text}</span>
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="flex flex-col items-center gap-4">
|
||||
<Image
|
||||
src={props.pay_url}
|
||||
width={208}
|
||||
height={208}
|
||||
alt="二维码"
|
||||
/>
|
||||
<div className="flex-none flex flex-col gap-1 items-center">
|
||||
<p className="text-sm text-gray-600">
|
||||
请使用 微信 或 支付宝 扫码支付
|
||||
</p>
|
||||
<p className="text-sm text-gray-600">
|
||||
手机端长按二维码下载并识图
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="w-full text-center space-y-2">
|
||||
<p className="text-sm font-medium">
|
||||
支付金额:
|
||||
<span className="text-accent">
|
||||
¥
|
||||
{props.amount?.toFixed(2) || '0.00'}
|
||||
</span>
|
||||
</p>
|
||||
<p className="text-xs text-gray-500">
|
||||
订单号:
|
||||
{props.inner_no}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-4 w-full justify-center">
|
||||
<Button onClick={onSubmit}>
|
||||
{loading && <Loader className="animate-spin mr-2"/>}
|
||||
已完成支付
|
||||
</Button>
|
||||
<DialogClose asChild>
|
||||
<Button theme="outline" onClick={() => props.onClose?.()}>
|
||||
关闭
|
||||
</Button>
|
||||
</DialogClose>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
'use client'
|
||||
import {createContext} from 'react'
|
||||
import {useForm, UseFormReturn} from 'react-hook-form'
|
||||
import {useForm} from 'react-hook-form'
|
||||
import Center from '@/components/composites/purchase/long/center'
|
||||
import Right from '@/components/composites/purchase/long/right'
|
||||
import {Form} from '@/components/ui/form'
|
||||
@@ -20,13 +19,6 @@ const schema = z.object({
|
||||
// 从架构中推断类型
|
||||
export type Schema = z.infer<typeof schema>
|
||||
|
||||
type PurchaseFormContextType = {
|
||||
form: UseFormReturn<Schema>
|
||||
onSubmit?: () => void
|
||||
}
|
||||
|
||||
export const LongFormContext = createContext<PurchaseFormContextType | undefined>(undefined)
|
||||
|
||||
export default function LongForm() {
|
||||
const form = useForm<Schema>({
|
||||
resolver: zodResolver(schema),
|
||||
@@ -36,16 +28,14 @@ export default function LongForm() {
|
||||
quota: 500,
|
||||
expire: '30', // 天
|
||||
daily_limit: 100,
|
||||
pay_type: 'balance', // 余额支付
|
||||
pay_type: 'wechat', // 余额支付
|
||||
},
|
||||
})
|
||||
|
||||
return (
|
||||
<Form form={form} className="flex flex-col lg:flex-row gap-4">
|
||||
<LongFormContext.Provider value={{form}}>
|
||||
<Center/>
|
||||
<Right/>
|
||||
</LongFormContext.Provider>
|
||||
<Center/>
|
||||
<Right/>
|
||||
</Form>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,15 +1,6 @@
|
||||
'use client'
|
||||
import {Suspense, use, useContext, useEffect, useMemo, useState} from 'react'
|
||||
import {PurchaseFormContext} from '@/components/composites/purchase/short/form'
|
||||
import {RadioGroup} from '@/components/ui/radio-group'
|
||||
import {FormField} from '@/components/ui/form'
|
||||
import FormOption from '@/components/composites/purchase/option'
|
||||
import Image from 'next/image'
|
||||
import alipay from '../_assets/alipay.svg'
|
||||
import wechat from '../_assets/wechat.svg'
|
||||
import balance from '../_assets/balance.svg'
|
||||
import {Suspense, use, useEffect, useState} from 'react'
|
||||
import {useProfileStore} from '@/components/stores/profile'
|
||||
import RechargeModal from '@/components/composites/recharge'
|
||||
import Pay from '@/components/composites/purchase/pay'
|
||||
import {buttonVariants} from '@/components/ui/button'
|
||||
import Link from 'next/link'
|
||||
@@ -17,8 +8,9 @@ import {merge} from '@/lib/utils'
|
||||
import {useFormContext, useWatch} from 'react-hook-form'
|
||||
import {Schema} from '@/components/composites/purchase/long/form'
|
||||
import {Card} from '@/components/ui/card'
|
||||
import {getPrice, CreateResourceReq} from '@/actions/resource'
|
||||
import {getPrice} from '@/actions/resource'
|
||||
import {ExtraResp} from '@/lib/api'
|
||||
import {FieldPayment} from '../shared/field-payment'
|
||||
|
||||
export default function Right() {
|
||||
const {control} = useFormContext<Schema>()
|
||||
@@ -164,52 +156,7 @@ function BalanceOrLogin(props: {
|
||||
const profile = use(useProfileStore(store => store.profile))
|
||||
return profile ? (
|
||||
<>
|
||||
<FormField name="pay_type" label="支付方式" className="flex flex-col gap-6">
|
||||
{({id, field}) => (
|
||||
<RadioGroup
|
||||
id={id}
|
||||
defaultValue={field.value}
|
||||
onValueChange={field.onChange}
|
||||
className="flex flex-col gap-3">
|
||||
|
||||
{/* <div className="w-full p-3 flex flex-col gap-4 bg-gray-100 rounded-md">
|
||||
<p className="flex items-center gap-3">
|
||||
<Image src={balance} alt="余额icon"/>
|
||||
<span className="text-sm text-gray-500">账户余额</span>
|
||||
</p>
|
||||
<p className="flex justify-between items-center">
|
||||
<span className="text-xl">{profile?.balance}</span>
|
||||
<RechargeModal/>
|
||||
</p>
|
||||
</div> */}
|
||||
|
||||
{/* <FormOption
|
||||
id={`${id}-balance`}
|
||||
value="balance"
|
||||
compare={field.value}
|
||||
className="p-3 w-full flex-row gap-2 justify-center">
|
||||
<Image src={balance} alt="余额 icon"/>
|
||||
<span>余额</span>
|
||||
</FormOption> */}
|
||||
<FormOption
|
||||
id={`${id}-wechat`}
|
||||
value="wechat"
|
||||
compare={field.value}
|
||||
className="p-3 w-full flex-row gap-2 justify-center">
|
||||
<Image src={wechat} alt="微信 logo"/>
|
||||
<span>微信</span>
|
||||
</FormOption>
|
||||
<FormOption
|
||||
id={`${id}-alipay`}
|
||||
value="alipay"
|
||||
compare={field.value}
|
||||
className="p-3 w-full flex-row gap-2 justify-center">
|
||||
<Image src={alipay} alt="支付宝 logo"/>
|
||||
<span>支付宝</span>
|
||||
</FormOption>
|
||||
</RadioGroup>
|
||||
)}
|
||||
</FormField>
|
||||
{/* <FieldPayment/> */}
|
||||
<Pay
|
||||
method={props.method}
|
||||
balance={profile.balance}
|
||||
|
||||
@@ -11,7 +11,7 @@ import {useRouter} from 'next/navigation'
|
||||
import {completeResource, createResource, CreateResourceReq, prepareResource} from '@/actions/resource'
|
||||
import {
|
||||
TradeMethod,
|
||||
TradeMethodDecoration,
|
||||
TradePlatform,
|
||||
} from '@/lib/models/trade'
|
||||
import {PaymentModal} from '@/components/composites/payment/payment-modal'
|
||||
import {PaymentProps} from '@/components/composites/payment/type'
|
||||
@@ -32,7 +32,7 @@ export default function Pay(props: PayProps) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [trade, setTrade] = useState<PaymentProps | null>(null)
|
||||
const router = useRouter()
|
||||
const platform = usePlatformType()
|
||||
// const platform = usePlatformType()
|
||||
|
||||
const onOpen = async () => {
|
||||
setOpen(true)
|
||||
@@ -45,7 +45,7 @@ export default function Pay(props: PayProps) {
|
||||
const req = {
|
||||
...props.resource,
|
||||
payment_method: method,
|
||||
payment_platform: platform,
|
||||
payment_platform: TradePlatform.Desktop,
|
||||
}
|
||||
|
||||
const resp = await prepareResource(req)
|
||||
@@ -60,9 +60,8 @@ export default function Pay(props: PayProps) {
|
||||
inner_no: resp.data.trade_no,
|
||||
pay_url: resp.data.pay_url,
|
||||
amount: Number(props.amount),
|
||||
platform: platform,
|
||||
platform: TradePlatform.Desktop,
|
||||
method: method,
|
||||
decoration: TradeMethodDecoration[props.method],
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
57
src/components/composites/purchase/shared/field-payment.tsx
Normal file
57
src/components/composites/purchase/shared/field-payment.tsx
Normal file
@@ -0,0 +1,57 @@
|
||||
import FormOption from '../option'
|
||||
import {RadioGroup} from '@/components/ui/radio-group'
|
||||
import {FormField} from '@/components/ui/form'
|
||||
import Image from 'next/image'
|
||||
import alipay from '../_assets/alipay.svg'
|
||||
import wechat from '../_assets/wechat.svg'
|
||||
|
||||
export function FieldPayment() {
|
||||
return (
|
||||
<FormField name="pay_type" label="支付方式" className="flex flex-col gap-6">
|
||||
{({id, field}) => (
|
||||
<RadioGroup
|
||||
id={id}
|
||||
defaultValue={field.value}
|
||||
onValueChange={field.onChange}
|
||||
className="flex flex-col gap-3">
|
||||
|
||||
{/* <div className="w-full p-3 flex flex-col gap-4 bg-gray-100 rounded-md">
|
||||
<p className="flex items-center gap-3">
|
||||
<Image src={balance} alt="余额icon"/>
|
||||
<span className="text-sm text-gray-500">账户余额</span>
|
||||
</p>
|
||||
<p className="flex justify-between items-center">
|
||||
<span className="text-xl">{profile.balance}</span>
|
||||
<RechargeModal/>
|
||||
</p>
|
||||
</div> */}
|
||||
|
||||
{/* <FormOption
|
||||
id={`${id}-balance`}
|
||||
value="balance"
|
||||
compare={field.value}
|
||||
className="p-3 w-full flex-row gap-2 justify-center">
|
||||
<Image src={balance} alt="余额 icon"/>
|
||||
<span>余额</span>
|
||||
</FormOption> */}
|
||||
<FormOption
|
||||
id={`${id}-wechat`}
|
||||
value="wechat"
|
||||
compare={field.value}
|
||||
className="p-3 w-full flex-row gap-2 justify-center">
|
||||
<Image src={wechat} alt="微信 logo"/>
|
||||
<span>微信</span>
|
||||
</FormOption>
|
||||
<FormOption
|
||||
id={`${id}-alipay`}
|
||||
value="alipay"
|
||||
compare={field.value}
|
||||
className="p-3 w-full flex-row gap-2 justify-center">
|
||||
<Image src={alipay} alt="支付宝 logo"/>
|
||||
<span>支付宝</span>
|
||||
</FormOption>
|
||||
</RadioGroup>
|
||||
)}
|
||||
</FormField>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
'use client'
|
||||
import {createContext} from 'react'
|
||||
import {useForm, UseFormReturn} from 'react-hook-form'
|
||||
import {useForm} from 'react-hook-form'
|
||||
import Center from '@/components/composites/purchase/short/center'
|
||||
import Right from '@/components/composites/purchase/short/right'
|
||||
import {Form} from '@/components/ui/form'
|
||||
@@ -20,16 +19,7 @@ const schema = z.object({
|
||||
// 从架构中推断类型
|
||||
export type Schema = z.infer<typeof schema>
|
||||
|
||||
type PurchaseFormContextType = {
|
||||
form: UseFormReturn<Schema>
|
||||
onSubmit?: () => void
|
||||
}
|
||||
|
||||
export const PurchaseFormContext = createContext<PurchaseFormContextType | undefined>(undefined)
|
||||
|
||||
export type PurchaseFormProps = {}
|
||||
|
||||
export default function PurchaseForm(props: PurchaseFormProps) {
|
||||
export default function ShortForm() {
|
||||
const form = useForm<Schema>({
|
||||
resolver: zodResolver(schema),
|
||||
defaultValues: {
|
||||
@@ -38,7 +28,7 @@ export default function PurchaseForm(props: PurchaseFormProps) {
|
||||
quota: 10_000, // >= 10000
|
||||
expire: '30', // 天
|
||||
daily_limit: 2_000, // >= 2000
|
||||
pay_type: 'balance', // 余额支付
|
||||
pay_type: 'wechat', // 余额支付
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -1,23 +1,16 @@
|
||||
'use client'
|
||||
import {Suspense, use, useEffect, useMemo, useState} from 'react'
|
||||
import {Suspense, use, useEffect, useState} from 'react'
|
||||
import {Schema} from '@/components/composites/purchase/short/form'
|
||||
import {RadioGroup} from '@/components/ui/radio-group'
|
||||
import {FormField} from '@/components/ui/form'
|
||||
import FormOption from '@/components/composites/purchase/option'
|
||||
import Image from 'next/image'
|
||||
import alipay from '../_assets/alipay.svg'
|
||||
import wechat from '../_assets/wechat.svg'
|
||||
import balance from '../_assets/balance.svg'
|
||||
import {useProfileStore} from '@/components/stores/profile'
|
||||
import RechargeModal from '@/components/composites/recharge'
|
||||
import {buttonVariants} from '@/components/ui/button'
|
||||
import Link from 'next/link'
|
||||
import {merge} from '@/lib/utils'
|
||||
import Pay from '@/components/composites/purchase/pay'
|
||||
import {useFormContext, useWatch} from 'react-hook-form'
|
||||
import {Card} from '@/components/ui/card'
|
||||
import {CreateResourceReq, getPrice} from '@/actions/resource'
|
||||
import {getPrice} from '@/actions/resource'
|
||||
import {ExtraResp} from '@/lib/api'
|
||||
import {FieldPayment} from '../shared/field-payment'
|
||||
|
||||
export default function Right() {
|
||||
const {control} = useFormContext<Schema>()
|
||||
@@ -165,52 +158,7 @@ function BalanceOrLogin(props: {
|
||||
const profile = use(useProfileStore(store => store.profile))
|
||||
return profile ? (
|
||||
<>
|
||||
<FormField name="pay_type" label="支付方式" className="flex flex-col gap-6">
|
||||
{({id, field}) => (
|
||||
<RadioGroup
|
||||
id={id}
|
||||
defaultValue={field.value}
|
||||
onValueChange={field.onChange}
|
||||
className="flex flex-col gap-3">
|
||||
|
||||
{/* <div className="w-full p-3 flex flex-col gap-4 bg-gray-100 rounded-md">
|
||||
<p className="flex items-center gap-3">
|
||||
<Image src={balance} alt="余额icon"/>
|
||||
<span className="text-sm text-gray-500">账户余额</span>
|
||||
</p>
|
||||
<p className="flex justify-between items-center">
|
||||
<span className="text-xl">{profile.balance}</span>
|
||||
<RechargeModal/>
|
||||
</p>
|
||||
</div> */}
|
||||
|
||||
{/* <FormOption
|
||||
id={`${id}-balance`}
|
||||
value="balance"
|
||||
compare={field.value}
|
||||
className="p-3 w-full flex-row gap-2 justify-center">
|
||||
<Image src={balance} alt="余额 icon"/>
|
||||
<span>余额</span>
|
||||
</FormOption> */}
|
||||
<FormOption
|
||||
id={`${id}-wechat`}
|
||||
value="wechat"
|
||||
compare={field.value}
|
||||
className="p-3 w-full flex-row gap-2 justify-center">
|
||||
<Image src={wechat} alt="微信 logo"/>
|
||||
<span>微信</span>
|
||||
</FormOption>
|
||||
<FormOption
|
||||
id={`${id}-alipay`}
|
||||
value="alipay"
|
||||
compare={field.value}
|
||||
className="p-3 w-full flex-row gap-2 justify-center">
|
||||
<Image src={alipay} alt="支付宝 logo"/>
|
||||
<span>支付宝</span>
|
||||
</FormOption>
|
||||
</RadioGroup>
|
||||
)}
|
||||
</FormField>
|
||||
{/* <FieldPayment/> */}
|
||||
<Pay
|
||||
method={props.method}
|
||||
balance={profile.balance}
|
||||
|
||||
@@ -21,7 +21,6 @@ import {merge} from '@/lib/utils'
|
||||
import {
|
||||
TradePlatform,
|
||||
TradeMethod,
|
||||
TradeMethodDecoration,
|
||||
} from '@/lib/models/trade'
|
||||
import {PaymentModal} from '@/components/composites/payment/payment-modal'
|
||||
import Image from 'next/image'
|
||||
@@ -77,7 +76,6 @@ export default function RechargeModal(props: RechargeModelProps) {
|
||||
amount: data.amount,
|
||||
platform: platform,
|
||||
method: method,
|
||||
decoration: TradeMethodDecoration[data.method],
|
||||
})
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -11,6 +11,7 @@ export const buttonVariants = cva(
|
||||
'aria-invalid:ring-fail/20 dark:aria-invalid:ring-fail/40 aria-invalid:border-fail', // 无效状态样式
|
||||
'inline-flex items-center justify-center gap-2', // 布局
|
||||
'[&_svg]:pointer-events-none [&_svg:not([class*="size-"])]:size-4 shrink-0 [&_svg]:shrink-0 ',
|
||||
'cursor-pointer',
|
||||
],
|
||||
{
|
||||
variants: {
|
||||
|
||||
135
src/components/ui/drawer.tsx
Normal file
135
src/components/ui/drawer.tsx
Normal file
@@ -0,0 +1,135 @@
|
||||
'use client'
|
||||
|
||||
import * as React from 'react'
|
||||
import {Drawer as DrawerPrimitive} from 'vaul'
|
||||
|
||||
import {merge} from '@/lib/utils/index'
|
||||
|
||||
function Drawer({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Root>) {
|
||||
return <DrawerPrimitive.Root data-slot="drawer" {...props}/>
|
||||
}
|
||||
|
||||
function DrawerTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Trigger>) {
|
||||
return <DrawerPrimitive.Trigger data-slot="drawer-trigger" {...props}/>
|
||||
}
|
||||
|
||||
function DrawerPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Portal>) {
|
||||
return <DrawerPrimitive.Portal data-slot="drawer-portal" {...props}/>
|
||||
}
|
||||
|
||||
function DrawerClose({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Close>) {
|
||||
return <DrawerPrimitive.Close data-slot="drawer-close" {...props}/>
|
||||
}
|
||||
|
||||
function DrawerOverlay({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Overlay>) {
|
||||
return (
|
||||
<DrawerPrimitive.Overlay
|
||||
data-slot="drawer-overlay"
|
||||
className={merge(
|
||||
'fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DrawerContent({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Content>) {
|
||||
return (
|
||||
<DrawerPortal data-slot="drawer-portal">
|
||||
<DrawerOverlay/>
|
||||
<DrawerPrimitive.Content
|
||||
data-slot="drawer-content"
|
||||
className={merge(
|
||||
'group/drawer-content fixed z-50 flex h-auto flex-col bg-background',
|
||||
'data-[vaul-drawer-direction=top]:inset-x-0 data-[vaul-drawer-direction=top]:top-0 data-[vaul-drawer-direction=top]:mb-24 data-[vaul-drawer-direction=top]:max-h-[80vh] data-[vaul-drawer-direction=top]:rounded-b-lg data-[vaul-drawer-direction=top]:border-b',
|
||||
'data-[vaul-drawer-direction=bottom]:inset-x-0 data-[vaul-drawer-direction=bottom]:bottom-0 data-[vaul-drawer-direction=bottom]:mt-24 data-[vaul-drawer-direction=bottom]:max-h-[80vh] data-[vaul-drawer-direction=bottom]:rounded-t-lg data-[vaul-drawer-direction=bottom]:border-t',
|
||||
'data-[vaul-drawer-direction=right]:inset-y-0 data-[vaul-drawer-direction=right]:right-0 data-[vaul-drawer-direction=right]:w-3/4 data-[vaul-drawer-direction=right]:border-l data-[vaul-drawer-direction=right]:sm:max-w-sm',
|
||||
'data-[vaul-drawer-direction=left]:inset-y-0 data-[vaul-drawer-direction=left]:left-0 data-[vaul-drawer-direction=left]:w-3/4 data-[vaul-drawer-direction=left]:border-r data-[vaul-drawer-direction=left]:sm:max-w-sm',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<div className="mx-auto mt-4 hidden h-2 w-[100px] shrink-0 rounded-full bg-muted group-data-[vaul-drawer-direction=bottom]/drawer-content:block"/>
|
||||
{children}
|
||||
</DrawerPrimitive.Content>
|
||||
</DrawerPortal>
|
||||
)
|
||||
}
|
||||
|
||||
function DrawerHeader({className, ...props}: React.ComponentProps<'div'>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="drawer-header"
|
||||
className={merge(
|
||||
'flex flex-col gap-0.5 p-4 group-data-[vaul-drawer-direction=bottom]/drawer-content:text-center group-data-[vaul-drawer-direction=top]/drawer-content:text-center md:gap-1.5 md:text-left',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DrawerFooter({className, ...props}: React.ComponentProps<'div'>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="drawer-footer"
|
||||
className={merge('mt-auto flex flex-col gap-2 p-4', className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DrawerTitle({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Title>) {
|
||||
return (
|
||||
<DrawerPrimitive.Title
|
||||
data-slot="drawer-title"
|
||||
className={merge('font-semibold text-foreground', className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DrawerDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Description>) {
|
||||
return (
|
||||
<DrawerPrimitive.Description
|
||||
data-slot="drawer-description"
|
||||
className={merge('text-sm text-muted-foreground', className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Drawer,
|
||||
DrawerPortal,
|
||||
DrawerOverlay,
|
||||
DrawerTrigger,
|
||||
DrawerClose,
|
||||
DrawerContent,
|
||||
DrawerHeader,
|
||||
DrawerFooter,
|
||||
DrawerTitle,
|
||||
DrawerDescription,
|
||||
}
|
||||
@@ -1,16 +1,26 @@
|
||||
import {StaticImageData} from 'next/image'
|
||||
import wechat from '@/components/composites/purchase/_assets/wechat.svg'
|
||||
import alipay from '@/components/composites/purchase/_assets/alipay.svg'
|
||||
import balance from '@/components/composites/purchase/_assets/balance.svg'
|
||||
|
||||
export const TradeMethodDecoration = {
|
||||
alipay: {
|
||||
text: '支付宝',
|
||||
icon: alipay,
|
||||
},
|
||||
wechat: {
|
||||
text: '微信支付',
|
||||
icon: wechat,
|
||||
},
|
||||
export function getTradeMethodDecoration(method: TradeMethod) {
|
||||
switch (method) {
|
||||
case TradeMethod.Alipay:
|
||||
return {
|
||||
text: '支付宝',
|
||||
icon: alipay,
|
||||
}
|
||||
case TradeMethod.Wechat:
|
||||
return {
|
||||
text: '微信支付',
|
||||
icon: wechat,
|
||||
}
|
||||
default:
|
||||
return {
|
||||
text: '扫码支付',
|
||||
icon: balance,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 支付方法枚举
|
||||
|
||||
Reference in New Issue
Block a user