Skip to content

Let's use AI to Earn!

feat: 商品任务展示

牛文政1c28e2609c4d
diff --git a/.env b/.env
index 9fed23af..970fedac 100644
--- a/.env
+++ b/.env
@@ -1,3 +1,4 @@
-# VITE_APP_URL = 'http://127.0.0.1:3000/api'
-VITE_APP_URL = 'https://attapi.yikart.cn/api'
-VITE_APP_HOT_URL = 'https://atthot.yikart.cn/api'
+VITE_APP_URL = 'http://127.0.0.1:3000/api'
+# VITE_APP_URL = 'https://attapi.yikart.cn/api'
+VITE_APP_HOT_URL = 'https://atthot.yikart.cn/api'
+VITE_APP_FILE_HOST = 'https://yika-bj.oss-cn-beijing.aliyuncs.com/'
diff --git a/commont/types/task.ts b/commont/types/task.ts
index a25c6565..bd7ec0e2 100644
--- a/commont/types/task.ts
+++ b/commont/types/task.ts
@@ -31,11 +31,25 @@ export const TaskStatusName = new Map([
[TaskStatus.CANCELLED, '取消'],
]);
-export interface Task extends TimeTemp {
+interface TaskData {
+ title: string;
+ desc?: string;
+}
+export interface TaskVideo extends TaskData {
+ videoUrl: string;
+}
+export interface TaskPromotion extends TaskData {}
+export interface TaskProduct extends TaskData {
+ price: number;
+ sales?: number;
+}
+export interface Task<T extends TaskProduct | TaskPromotion | TaskVideo>
+ extends TimeTemp {
id: string;
title: string;
description: string;
type: TaskType;
+ dataInfo: T;
imageUrl: string;
keepTime: number; // 保持时间(秒)
requiresShoppingCart: boolean; // 是否需要挂购物车
diff --git a/src/views/task/carTask.module.css b/src/views/task/carTask.module.css
new file mode 100644
index 00000000..551ed48e
--- /dev/null
+++ b/src/views/task/carTask.module.css
@@ -0,0 +1,24 @@
+.task-list-container {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 16px; /* 卡片之间的间距 */
+}
+
+.task-card {
+ width: calc(33.33% - 16px); /* 默认每行3个,减去间距 */
+ box-sizing: border-box; /* 确保宽度计算包含边框和内边距 */
+}
+
+/* 响应式规则:屏幕宽度小于1200px时,每行显示2个 */
+@media (max-width: 1200px) {
+ .task-card {
+ width: calc(50% - 16px);
+ }
+}
+
+/* 响应式规则:屏幕宽度小于768px时,每行显示1个 */
+@media (max-width: 768px) {
+ .task-card {
+ width: 100%;
+ }
+}
\ No newline at end of file
diff --git a/src/views/task/carTask.tsx b/src/views/task/carTask.tsx
index 866f2d60..01a22573 100644
--- a/src/views/task/carTask.tsx
+++ b/src/views/task/carTask.tsx
@@ -5,14 +5,16 @@
* @LastEditors: nevin
* @Description: 任务
*/
-import { Button } from 'antd';
+import { Button, Card, Col, Row } from 'antd';
import { useState, useEffect, useRef } from 'react';
-import { Task, TaskType } from '@@/types/task';
+import { Task, TaskProduct, TaskType } from '@@/types/task';
import { taskApi } from '@/api/task';
import { TaskInfoRef } from './components/popInfo';
import TaskInfo from './components/carInfo';
+const FILE_BASE_URL = import.meta.env.VITE_APP_FILE_HOST;
+
export default function Page() {
- const [taskList, setTaskList] = useState<Task[]>([]);
+ const [taskList, setTaskList] = useState<Task<TaskProduct>[]>([]);
const [pageInfo, setPageInfo] = useState({
pageSize: 10,
pageNo: 1,
@@ -34,20 +36,54 @@ export default function Page() {
}, []);
return (
- <div>
+ <div className="p-4">
<TaskInfo ref={Ref_TaskInfo} />
- <div>
+ <div className="flex flex-wrap gap-4">
{taskList.map((v) => {
return (
- <div key={v.id}>
- {v.title}
- <Button
- type="primary"
- onClick={() => Ref_TaskInfo.current?.init(v)}
- >
- 查看
- </Button>
- </div>
+ <Card
+ key={v.id}
+ className="box-border w-full p-4 sm:w-1/2 md:w-1/3"
+ >
+ <Row>
+ <Col span={12}>
+ <div>
+ <img
+ src={`${FILE_BASE_URL}${v.imageUrl}`}
+ alt=""
+ className="w-full h-full"
+ />
+ </div>
+ </Col>
+ <Col span={12}>
+ <h3>{v.title}</h3>
+ <Row>
+ <Col span={12}>
+ {!v.dataInfo ? (
+ <div>暂无数据</div>
+ ) : (
+ <>
+ <p> {v.dataInfo.title}</p>
+ <p> {v.dataInfo.price}元</p>
+ <p>数量: {v.dataInfo.sales}</p>
+ </>
+ )}
+ </Col>
+ <Col span={12}>
+ <p>招募人数: {v.maxRecruits}</p>
+ </Col>
+ </Row>
+ </Col>
+ </Row>
+ <Row>
+ <Button
+ type="primary"
+ onClick={() => Ref_TaskInfo.current?.init(v)}
+ >
+ 查看
+ </Button>
+ </Row>
+ </Card>
);
})}
</div>