diff --git a/Cunkebao/src/pages/mobile/workspace/main/api.ts b/Cunkebao/src/pages/mobile/workspace/main/api.ts index c4c8952f..c667f790 100644 --- a/Cunkebao/src/pages/mobile/workspace/main/api.ts +++ b/Cunkebao/src/pages/mobile/workspace/main/api.ts @@ -10,5 +10,10 @@ export function getWechatStats() { return request("/v1/dashboard/wechat-stats", {}, "GET"); } +// 获取常用功能列表 +export function getCommonFunctions() { + return request("/v1/workbench/common-functions", {}, "GET"); +} + // 你可以根据需要继续添加其他接口 // 例如:场景获客统计、今日数据统计等 diff --git a/Cunkebao/src/pages/mobile/workspace/main/index.module.scss b/Cunkebao/src/pages/mobile/workspace/main/index.module.scss index e8537ed6..e6493456 100644 --- a/Cunkebao/src/pages/mobile/workspace/main/index.module.scss +++ b/Cunkebao/src/pages/mobile/workspace/main/index.module.scss @@ -52,8 +52,10 @@ margin-bottom: 12px; } -.icon { - font-size: 20px; +.iconImage { + width: 75%; + object-fit: contain; + border-radius: 8px; } .featureHeader { diff --git a/Cunkebao/src/pages/mobile/workspace/main/index.tsx b/Cunkebao/src/pages/mobile/workspace/main/index.tsx index 68f29f0b..befab16f 100644 --- a/Cunkebao/src/pages/mobile/workspace/main/index.tsx +++ b/Cunkebao/src/pages/mobile/workspace/main/index.tsx @@ -1,128 +1,137 @@ -import React from "react"; +import React, { useEffect, useState } from "react"; import { Link } from "react-router-dom"; -import { Card, Badge } from "antd-mobile"; -import { - LikeOutlined, - SendOutlined, - TeamOutlined, - LinkOutlined, - ClockCircleOutlined, - ContactsOutlined, - BookOutlined, - ApartmentOutlined, -} from "@ant-design/icons"; +import { Card, Badge, SpinLoading, Toast } from "antd-mobile"; import Layout from "@/components/Layout/Layout"; import MeauMobile from "@/components/MeauMobile/MeauMoible"; import styles from "./index.module.scss"; import NavCommon from "@/components/NavCommon"; +import { getCommonFunctions } from "./api"; + +// 功能key到默认配置的映射(用于降级,当API没有返回icon时使用) +const featureConfig: Record = { + "auto_like": { + bgColor: "#fff2f0", + path: "/workspace/auto-like", + }, + "moments_sync": { + bgColor: "#f9f0ff", + path: "/workspace/moments-sync", + }, + "group_push": { + bgColor: "#fff7e6", + path: "/workspace/group-push", + }, + "auto_group": { + bgColor: "#f6ffed", + path: "/workspace/auto-group", + }, + "group_create": { + bgColor: "#f6ffed", + path: "/workspace/group-create", + }, + "traffic_distribution": { + bgColor: "#e6f7ff", + path: "/workspace/traffic-distribution", + }, + "contact_import": { + bgColor: "#f9f0ff", + path: "/workspace/contact-import/list", + }, + "ai_knowledge": { + bgColor: "#fff7e6", + path: "/workspace/ai-knowledge", + }, + "distribution_management": { + bgColor: "#f9f0ff", + path: "/workspace/distribution-management", + }, +}; + +interface CommonFunction { + id: number; + key: string; + name: string; + description?: string; + icon: React.ReactNode | null; + iconUrl?: string | null; + path: string; + bgColor?: string; + isNew?: boolean; + [key: string]: any; +} + const Workspace: React.FC = () => { - // 常用功能 - const commonFeatures = [ - { - id: "auto-like", - name: "自动点赞", - description: "智能自动点赞互动", - icon: ( - - ), - path: "/workspace/auto-like", - bgColor: "#fff2f0", - isNew: true, - }, - { - id: "moments-sync", - name: "朋友圈同步", - description: "自动同步朋友圈内容", - icon: ( - - ), - path: "/workspace/moments-sync", - bgColor: "#f9f0ff", - }, - { - id: "group-push", - name: "群消息推送", - description: "智能群发助手", - icon: ( - - ), - path: "/workspace/group-push", - bgColor: "#fff7e6", - }, - { - id: "auto-group", - name: "自动建群", - description: "智能拉好友建群", - icon: ( - - ), - path: "/workspace/auto-group", - bgColor: "#f6ffed", - }, - { - id: "group-create", - name: "自动建群(新版)", - description: "智能拉好友建群", - icon: ( - - ), - path: "/workspace/group-create", - bgColor: "#f6ffed", - isNew: true, - }, - { - id: "traffic-distribution", - name: "流量分发", - description: "管理流量分发和分配", - icon: ( - - ), - path: "/workspace/traffic-distribution", - bgColor: "#e6f7ff", - }, - { - id: "contact-import", - name: "通讯录导入", - description: "批量导入通讯录联系人", - icon: ( - - ), - path: "/workspace/contact-import/list", - bgColor: "#f9f0ff", - isNew: true, - }, - { - id: "ai-knowledge", - name: "AI知识库", - description: "管理和配置内容", - icon: ( - - ), - path: "/workspace/ai-knowledge", - bgColor: "#fff7e6", - isNew: true, - }, - { - id: "distribution-management", - name: "分销管理", - description: "管理分销客户和渠道", - icon: ( - - ), - path: "/workspace/distribution-management", - bgColor: "#f9f0ff", - isNew: true, - }, - ]; + const [commonFeatures, setCommonFeatures] = useState([]); + const [loading, setLoading] = useState(true); + + // 从API获取常用功能 + useEffect(() => { + const fetchCommonFunctions = async () => { + try { + setLoading(true); + const res = await getCommonFunctions(); + // 处理API返回的数据,映射图标和样式 + const features = (res?.list || res || []).map((item: any) => { + const config = featureConfig[item.key]; + + // icon是远程图片URL,渲染为img标签 + const iconElement = item.icon ? ( + {item.title { + // 图片加载失败时,隐藏图片 + const target = e.target as HTMLImageElement; + target.style.display = 'none'; + }} + /> + ) : null; + + return { + id: item.id, + key: item.key, + name: item.title || item.name || "", + description: item.subtitle || item.description || item.desc || "", + icon: iconElement, + iconUrl: item.icon || null, // 保存原始URL + path: item.route || item.path || (config?.path) || `/workspace/${item.key?.replace(/_/g, '-')}`, + bgColor: item.iconColor || (config?.bgColor) || undefined, // iconColor可以为空 + isNew: item.isNew || item.is_new || false, + }; + }); + setCommonFeatures(features); + } catch (e: any) { + Toast.show({ + content: e?.message || "获取常用功能失败", + position: "top", + }); + // 如果接口失败,使用默认数据(从配置映射表生成) + const defaultFeatures = Object.keys(featureConfig).map((key, index) => { + const config = featureConfig[key]; + return { + id: index + 1, + key, + name: key.replace(/_/g, ' '), + description: "", + icon: null, // 默认没有图标 + iconUrl: null, + path: config.path, + bgColor: config.bgColor, + isNew: false, + }; + }); + setCommonFeatures(defaultFeatures); + } finally { + setLoading(false); + } + }; + + fetchCommonFunctions(); + }, []); return ( { {/* 常用功能 */}

常用功能

-
- {commonFeatures.map(feature => ( - - -
+ +
+ ) : ( +
+ {commonFeatures.length > 0 ? ( + commonFeatures.map(feature => ( + - {feature.icon} -
-
-
{feature.name}
- {feature.isNew && ( - - )} -
-
- {feature.description} -
-
- - ))} -
+ +
+ {feature.icon} +
+
+
{feature.name}
+ {feature.isNew && ( + + )} +
+
+ {feature.description} +
+
+ + )) + ) : ( +
+ 暂无常用功能 +
+ )} +
+ )} {/* AI智能助手 */} diff --git a/Server/application/cunkebao/config/route.php b/Server/application/cunkebao/config/route.php index d085bc3e..07a9e8f8 100644 --- a/Server/application/cunkebao/config/route.php +++ b/Server/application/cunkebao/config/route.php @@ -119,6 +119,7 @@ Route::group('v1/', function () { Route::get('group-push-stats', 'app\cunkebao\controller\workbench\WorkbenchController@getGroupPushStats'); // 获取群发统计数据 Route::get('group-push-history', 'app\cunkebao\controller\workbench\WorkbenchController@getGroupPushHistory'); // 获取推送历史记录列表 + Route::get('common-functions', 'app\cunkebao\controller\workbench\CommonFunctionsController@getList'); // 获取常用功能列表 }); // 内容库相关 @@ -162,11 +163,6 @@ Route::group('v1/', function () { Route::get('userInfoStats', 'app\cunkebao\controller\StatsController@userInfoStats'); }); - // 常用功能相关 - Route::group('common-functions', function () { - Route::get('list', 'app\cunkebao\controller\CommonFunctionsController@getList'); // 获取常用功能列表 - }); - // 算力相关 Route::group('tokens', function () { Route::get('list', 'app\cunkebao\controller\TokensController@getList'); diff --git a/Server/application/cunkebao/controller/CommonFunctionsController.php b/Server/application/cunkebao/controller/workbench/CommonFunctionsController.php similarity index 96% rename from Server/application/cunkebao/controller/CommonFunctionsController.php rename to Server/application/cunkebao/controller/workbench/CommonFunctionsController.php index 55c20713..d13d1dc0 100644 --- a/Server/application/cunkebao/controller/CommonFunctionsController.php +++ b/Server/application/cunkebao/controller/workbench/CommonFunctionsController.php @@ -1,6 +1,6 @@