Przeglądaj źródła

首页金刚区交由数据库管理

wangwenju 3 tygodni temu
rodzic
commit
37d984c103

+ 46 - 66
LiangZhiYUMao/pages/index/index.vue

@@ -262,15 +262,7 @@
 				noticeList: [],
 
 				// 功能入口
-				functionList: [
-					{ id: 1, name: '星命测算', icon: '💖', path: '/pages/astrology/index', bgColor: '#FF6B9D', iconColor: '#FFFFFF', gradient: 'linear-gradient(135deg, #FF6B9D 0%, #FF8EAB 100%)' },
-					{ id: 2, name: '红娘列表', icon: '👤', path: '/pages/matchmakers/list', bgColor: '#6BC5F8', iconColor: '#FFFFFF', gradient: 'linear-gradient(135deg, #6BC5F8 0%, #87CEEB 100%)' },
-					// { id: 3, name: '加入红娘', icon: '💕', path: '/pages/part-time-matchmaker/index', bgColor: '#9B7EDE', iconColor: '#FFFFFF', gradient: 'linear-gradient(135deg, #9B7EDE 0%, #B19CD9 100%)' },
-					// { id: 3, name: '加入红娘', icon: '💕', path: '/pages/part-time-matchmaker/index', bgColor: '#9B7EDE', iconColor: '#FFFFFF', gradient: 'linear-gradient(135deg, #9B7EDE 0%, #B19CD9 100%)' },
-					{ id: 4, name: '精品课程', icon: '📚', path: '/pages/courses/list', bgColor: '#FF8C42', iconColor: '#FFFFFF', gradient: 'linear-gradient(135deg, #FF8C42 0%, #FFA366 100%)' },
-					{ id: 5, name: '今日缘分', icon: '💝', path: '/pages/recommend/index', bgColor: '#FF69B4', iconColor: '#FFFFFF', gradient: 'linear-gradient(135deg, #FF69B4 0%, #FF8CC8 100%)', needLogin: true },
-					// { id: 6, name: '专属定制', icon: '🎁', path: '/pages/customize/index', bgColor: '#FFA500', iconColor: '#FFFFFF', gradient: 'linear-gradient(135deg, #FFA500 0%, #FFB84D 100%)' }
-				],
+			functionList: [],
 
 				// 热门活动
 				hotActivities: [],
@@ -322,6 +314,7 @@
 			this.loadUserInfo()
 			this.loadBannerData()
 			this.loadNoticeData()
+			this.loadFunctionGridData()
 			// this.loadTodayRecommend()
 			this.loadCharmIndex()
 			this.loadHotActivities()
@@ -499,6 +492,47 @@
 					// 使用默认数据
 				}
 			},
+			
+			// 加载金刚区功能列表
+			async loadFunctionGridData() {
+				try {
+					// 调用 API 获取金刚区功能数据
+					const data = await api.home.getFunctionGrid()
+					if (data && data.length > 0) {
+						// 处理金刚区数据,确保字段格式正确
+						this.functionList = data.map(item => ({
+							...item,
+							// 确保渐变背景色格式正确
+							gradient: item.gradient || `linear-gradient(135deg, ${item.bgColor} 0%, ${this.lightenColor(item.bgColor, 10)} 100%)`
+						}))
+					}
+				} catch (error) {
+					console.error('获取金刚区功能列表失败:', error)
+					// 使用默认数据作为降级方案
+					this.functionList = [
+						{ id: 1, name: '星命测算', icon: '💖', path: '/pages/astrology/index', bgColor: '#FF6B9D', iconColor: '#FFFFFF', gradient: 'linear-gradient(135deg, #FF6B9D 0%, #FF8EAB 100%)' },
+						{ id: 2, name: '红娘列表', icon: '👤', path: '/pages/matchmakers/list', bgColor: '#6BC5F8', iconColor: '#FFFFFF', gradient: 'linear-gradient(135deg, #6BC5F8 0%, #87CEEB 100%)' },
+						{ id: 4, name: '精品课程', icon: '📚', path: '/pages/courses/list', bgColor: '#FF8C42', iconColor: '#FFFFFF', gradient: 'linear-gradient(135deg, #FF8C42 0%, #FFA366 100%)' },
+						{ id: 5, name: '今日缘分', icon: '💝', path: '/pages/recommend/index', bgColor: '#FF69B4', iconColor: '#FFFFFF', gradient: 'linear-gradient(135deg, #FF69B4 0%, #FF8CC8 100%)', needLogin: true }
+					]
+				}
+			},
+			
+			// 颜色提亮函数(用于生成渐变背景色)
+			lightenColor(color, percent) {
+				// 移除#号
+				color = color.replace('#', '')
+				// 转换为RGB
+				let r = parseInt(color.substring(0, 2), 16)
+				let g = parseInt(color.substring(2, 4), 16)
+				let b = parseInt(color.substring(4, 6), 16)
+				// 提亮颜色
+				r = Math.min(255, Math.round(r + (255 - r) * percent / 100))
+				g = Math.min(255, Math.round(g + (255 - g) * percent / 100))
+				b = Math.min(255, Math.round(b + (255 - b) * percent / 100))
+				// 转换回十六进制
+				return '#' + ((r << 16) | (g << 8) | b).toString(16).padStart(6, '0')
+			},
 
 			// 加载公告数据
 			async loadNoticeData() {
@@ -622,46 +656,10 @@
 							endTime: activity.endTime || activity.end_time || activity.endDate || '',
 							status: activity.status || 0
 						}})
-					} else {
-						// 使用默认活动数据
-						this.hotActivities = [
-						]
-					}
+					} 
 				} catch (error) {
 					console.error('获取热门活动失败:', error)
-					// 使用默认数据
-					this.hotActivities = [
-						{
-							id: 1,
-							name: '七夕单身派对',
-							description: '浪漫七夕夜,遇见更好的ta',
-							coverImage: DEFAULT_IMAGES.activity || 'https://images.unsplash.com/photo-1511632765486-a01980e01a18?w=750&h=400&fit=crop',
-							startTime: '2024-02-14 19:00:00',
-							location: '杭州西湖文化广场',
-							price: 99,
-							status: 1
-						},
-						{
-							id: 2,
-							name: '情人节主题聚会',
-							description: '高端单身聚会,品味生活',
-							coverImage: DEFAULT_IMAGES.banner || 'https://images.unsplash.com/photo-1522673607200-164d1b6ce486?w=750&h=360&fit=crop',
-							startTime: '2024-02-14 20:00:00',
-							location: '上海外滩茶餐厅',
-							price: 128,
-							status: 1
-						},
-						{
-							id: 3,
-							name: '春日户外踏青',
-							description: '拥抱春天,邂逅美好',
-							coverImage: DEFAULT_IMAGES.couple || 'https://images.unsplash.com/photo-1516589178581-6cd7833ae3b2?w=520&h=360&fit=crop',
-							startTime: '2024-03-20 14:00:00',
-							location: '苏州园林博物馆',
-							price: 68,
-							status: 1
-						}
-					]
+
 				}
 			},
 
@@ -717,25 +715,7 @@
 					}
 				} catch (error) {
 					console.error('获取成功案例失败:', error)
-					// 使用默认数据
-					this.successCases = [
-						{
-							caseNo: 'CASE001',
-							maleUserNickname: '张先生',
-							femaleUserNickname: '李女士',
-							imageUrl: DEFAULT_IMAGES.couple,
-							quote: '从第一次咖啡约会到领证,只用了90天',
-							marriageDate: '2024-08-20'
-						},
-						{
-							caseNo: 'CASE002',
-							maleUserNickname: '王先生',
-							femaleUserNickname: '赵女士',
-							imageUrl: DEFAULT_IMAGES.couple,
-							quote: '感谢红娘的专业服务,让我们相遇相知',
-							marriageDate: '2024-09-15'
-						}
-					]
+					
 				}
 			},
 

+ 6 - 44
LiangZhiYUMao/pages/message/chat.vue

@@ -464,23 +464,6 @@ export default {
   },
 
   methods: {
-    /**
-     * 根据语音时长计算语音气泡宽度
-     */
-    getVoiceWidth(duration) {
-      // 基础宽度 + 时长比例计算的宽度
-      // 例如:60px 基础宽度 + 每秒钟 2px 的宽度增量
-      const baseWidth = 60;
-      const perSecondWidth = 2;
-      const maxWidth = 180;
-      
-      // 确保时长是数字类型
-      const durationNum = parseInt(duration) || 0;
-      
-      // 计算宽度并限制最大宽度
-      const width = Math.min(baseWidth + durationNum * perSecondWidth, maxWidth);
-      return width + 'px';
-    },
     /**
      * 红娘入口:根据当前登录用户ID获取红娘资料并设置头像
      */
@@ -1303,11 +1286,11 @@ export default {
       try {
         console.log('🔄 同步消息到MySQL...', timMessage.ID);
         
-        // 构建同步参数(V2版本,支持红娘消息)
+        // 构建同步参数
         const syncData = {
           messageId: timMessage.ID,
-          fromTimUserId: String(timMessage.from),  // 保持字符串格式,支持 m_xxx
-          toTimUserId: String(timMessage.to),      // 保持字符串格式,支持 m_xxx
+          fromUserId: timMessage.from,
+          toUserId: timMessage.to,
           messageType: this.getMessageType(timMessage),
           content: this.getMessageContent(timMessage),
           sendTime: timMessage.time  // TIM返回的是秒级时间戳
@@ -1341,9 +1324,9 @@ export default {
           }
         }
         
-        // 调用后端同步接口(V2版本,支持红娘消息)
+        // 调用后端同步接口
         const res = await uni.request({
-          url: 'http://localhost:8083/api/chat/syncTIMMessageV2',
+          url: 'http://localhost:8083/api/chat/syncTIMMessage',
           method: 'POST',
           data: syncData,
           header: {
@@ -1352,8 +1335,7 @@ export default {
         });
         
         if (res[1].data.code === 200) {
-          const msgType = res[1].data.type === 'matchmaker' ? '红娘消息' : '用户消息';
-          console.log(`✅ 消息已同步到MySQL (${msgType}):`, timMessage.ID);
+          console.log('✅ 消息已同步到MySQL:', timMessage.ID);
         } else {
           console.warn('⚠️ 消息同步失败:', res[1].data.message);
         }
@@ -1421,26 +1403,6 @@ export default {
       }
     },
     
-    /**
-     * 根据语音时长计算语音消息气泡宽度
-     * @param {number} duration 语音时长(秒)
-     * @returns {string} 宽度样式值
-     */
-    getVoiceWidth(duration) {
-      // 基础宽度 120rpx,每秒增加 10rpx,最大 300rpx
-      const baseWidth = 120;
-      const perSecondWidth = 10;
-      const maxWidth = 300;
-      const minWidth = 120;
-      
-      const seconds = parseInt(duration) || 0;
-      let width = baseWidth + seconds * perSecondWidth;
-      
-      // 限制在最小和最大范围内
-      width = Math.max(minWidth, Math.min(maxWidth, width));
-      
-      return width + 'rpx';
-    },
     
     /**
      * 滚动到底部

+ 3 - 0
LiangZhiYUMao/utils/api.js

@@ -190,6 +190,9 @@ export default {
     // 获取公告列表
     getNotices: () => request({ url: '/announcement/active' }),
     
+    // 获取首页金刚区功能列表
+    getFunctionGrid: () => request({ url: '/home/function-grid' }),
+    
     // 获取未读消息数
     getUnreadCount: () => request({ url: '/home/unread-count' })
   },

+ 21 - 0
service/homePage/src/main/java/com/zhentao/controller/HomeController.java

@@ -1,6 +1,8 @@
 package com.zhentao.controller;
 
 import com.zhentao.common.Result;
+import com.zhentao.service.HomeFunctionGridService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.*;
@@ -12,6 +14,9 @@ import java.util.*;
 @RequestMapping("/api/home")
 public class HomeController {
     
+    @Autowired
+    private HomeFunctionGridService homeFunctionGridService;
+    
     /**
      * 获取公告列表
      * 
@@ -60,6 +65,22 @@ public class HomeController {
             return Result.error("获取未读消息数失败:" + e.getMessage());
         }
     }
+    
+    /**
+     * 获取金刚区功能列表
+     * 
+     * @return 金刚区功能列表
+     */
+    @GetMapping("/function-grid")
+    public Result<List> getFunctionGrid() {
+        try {
+            // 从数据库获取启用的金刚区功能列表
+            return Result.success(homeFunctionGridService.getEnabledFunctionGrids());
+        } catch (Exception e) {
+            e.printStackTrace();
+            return Result.error("获取金刚区功能列表失败:" + e.getMessage());
+        }
+    }
 }
 
 

+ 210 - 0
service/homePage/src/main/java/com/zhentao/entity/HomeFunctionGrid.java

@@ -0,0 +1,210 @@
+package com.zhentao.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/**
+ * <p>
+ * 首页金刚区功能表
+ * </p>
+ *
+ * @author zhentao
+ * @since 2024-05-20
+ */
+@TableName("home_function_grid")
+public class HomeFunctionGrid implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键ID
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 功能名称
+     */
+    @TableField("name")
+    private String name;
+
+    /**
+     * 图标(emoji)
+     */
+    @TableField("icon")
+    private String icon;
+
+    /**
+     * 跳转路径
+     */
+    @TableField("path")
+    private String path;
+
+    /**
+     * 背景颜色
+     */
+    @TableField("bg_color")
+    private String bgColor;
+
+    /**
+     * 图标颜色
+     */
+    @TableField("icon_color")
+    private String iconColor;
+
+    /**
+     * 渐变背景
+     */
+    @TableField("gradient")
+    private String gradient;
+
+    /**
+     * 是否需要登录:0-不需要 1-需要
+     */
+    @TableField("need_login")
+    private Boolean needLogin;
+
+    /**
+     * 排序
+     */
+    @TableField("sort")
+    private Integer sort;
+
+    /**
+     * 状态:0-禁用 1-启用
+     */
+    @TableField("status")
+    private Boolean status;
+
+    /**
+     * 创建时间
+     */
+    @TableField("create_time")
+    private LocalDateTime createTime;
+
+    /**
+     * 更新时间
+     */
+    @TableField("update_time")
+    private LocalDateTime updateTime;
+
+    // getter和setter方法
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getIcon() {
+        return icon;
+    }
+
+    public void setIcon(String icon) {
+        this.icon = icon;
+    }
+
+    public String getPath() {
+        return path;
+    }
+
+    public void setPath(String path) {
+        this.path = path;
+    }
+
+    public String getBgColor() {
+        return bgColor;
+    }
+
+    public void setBgColor(String bgColor) {
+        this.bgColor = bgColor;
+    }
+
+    public String getIconColor() {
+        return iconColor;
+    }
+
+    public void setIconColor(String iconColor) {
+        this.iconColor = iconColor;
+    }
+
+    public String getGradient() {
+        return gradient;
+    }
+
+    public void setGradient(String gradient) {
+        this.gradient = gradient;
+    }
+
+    public Boolean getNeedLogin() {
+        return needLogin;
+    }
+
+    public void setNeedLogin(Boolean needLogin) {
+        this.needLogin = needLogin;
+    }
+
+    public Integer getSort() {
+        return sort;
+    }
+
+    public void setSort(Integer sort) {
+        this.sort = sort;
+    }
+
+    public Boolean getStatus() {
+        return status;
+    }
+
+    public void setStatus(Boolean status) {
+        this.status = status;
+    }
+
+    public LocalDateTime getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(LocalDateTime createTime) {
+        this.createTime = createTime;
+    }
+
+    public LocalDateTime getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setUpdateTime(LocalDateTime updateTime) {
+        this.updateTime = updateTime;
+    }
+
+    @Override
+    public String toString() {
+        return "HomeFunctionGrid{" +
+                "id=" + id +
+                ", name='" + name + '\'' +
+                ", icon='" + icon + '\'' +
+                ", path='" + path + '\'' +
+                ", bgColor='" + bgColor + '\'' +
+                ", iconColor='" + iconColor + '\'' +
+                ", gradient='" + gradient + '\'' +
+                ", needLogin=" + needLogin +
+                ", sort=" + sort +
+                ", status=" + status +
+                ", createTime=" + createTime +
+                ", updateTime=" + updateTime +
+                '}';
+    }
+}

+ 18 - 0
service/homePage/src/main/java/com/zhentao/mapper/HomeFunctionGridMapper.java

@@ -0,0 +1,18 @@
+package com.zhentao.mapper;
+
+import com.zhentao.entity.HomeFunctionGrid;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * <p>
+ * 首页金刚区功能表 Mapper 接口
+ * </p>
+ *
+ * @author zhentao
+ * @since 2024-05-20
+ */
+@Mapper
+public interface HomeFunctionGridMapper extends BaseMapper<HomeFunctionGrid> {
+
+}

+ 22 - 0
service/homePage/src/main/java/com/zhentao/service/HomeFunctionGridService.java

@@ -0,0 +1,22 @@
+package com.zhentao.service;
+
+import com.zhentao.entity.HomeFunctionGrid;
+import com.baomidou.mybatisplus.extension.service.IService;
+import java.util.List;
+
+/**
+ * <p>
+ * 首页金刚区功能表 服务类
+ * </p>
+ *
+ * @author zhentao
+ * @since 2024-05-20
+ */
+public interface HomeFunctionGridService extends IService<HomeFunctionGrid> {
+
+    /**
+     * 获取启用的金刚区功能列表,按排序排序
+     * @return 金刚区功能列表
+     */
+    List<HomeFunctionGrid> getEnabledFunctionGrids();
+}

+ 30 - 0
service/homePage/src/main/java/com/zhentao/service/impl/HomeFunctionGridServiceImpl.java

@@ -0,0 +1,30 @@
+package com.zhentao.service.impl;
+
+import com.zhentao.entity.HomeFunctionGrid;
+import com.zhentao.mapper.HomeFunctionGridMapper;
+import com.zhentao.service.HomeFunctionGridService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import org.springframework.stereotype.Service;
+import java.util.List;
+
+/**
+ * <p>
+ * 首页金刚区功能表 服务实现类
+ * </p>
+ *
+ * @author zhentao
+ * @since 2024-05-20
+ */
+@Service
+public class HomeFunctionGridServiceImpl extends ServiceImpl<HomeFunctionGridMapper, HomeFunctionGrid> implements HomeFunctionGridService {
+
+    @Override
+    public List<HomeFunctionGrid> getEnabledFunctionGrids() {
+        // 查询启用的金刚区功能,按排序字段升序排列
+        return baseMapper.selectList(new LambdaQueryWrapper<HomeFunctionGrid>()
+                .eq(HomeFunctionGrid::getStatus, true)
+                .orderByAsc(HomeFunctionGrid::getSort)
+        );
+    }
+}

+ 24 - 0
service/homePage/src/main/resources/sql/home_function_grid.sql

@@ -0,0 +1,24 @@
+-- 金刚区功能表
+CREATE TABLE IF NOT EXISTS `home_function_grid` (
+  `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
+  `name` VARCHAR(50) NOT NULL COMMENT '功能名称',
+  `icon` VARCHAR(20) NOT NULL COMMENT '图标(emoji)',
+  `path` VARCHAR(255) NOT NULL COMMENT '跳转路径',
+  `bg_color` VARCHAR(50) NULL COMMENT '背景颜色',
+  `icon_color` VARCHAR(50) NULL COMMENT '图标颜色',
+  `gradient` VARCHAR(255) NULL COMMENT '渐变背景',
+  `need_login` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否需要登录:0-不需要 1-需要',
+  `sort` INT NOT NULL DEFAULT 0 COMMENT '排序',
+  `status` TINYINT(1) NOT NULL DEFAULT 1 COMMENT '状态:0-禁用 1-启用',
+  `create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+  `update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
+  PRIMARY KEY (`id`),
+  KEY `idx_status_sort` (`status`, `sort`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='首页金刚区功能表';
+
+-- 插入初始数据
+INSERT INTO `home_function_grid` (`name`, `icon`, `path`, `bg_color`, `icon_color`, `gradient`, `need_login`, `sort`, `status`) VALUES
+('星命测算', '💖', '/pages/astrology/index', '#FF6B9D', '#FFFFFF', 'linear-gradient(135deg, #FF6B9D 0%, #FF8EAB 100%)', 0, 1, 1),
+('红娘列表', '👤', '/pages/matchmakers/list', '#6BC5F8', '#FFFFFF', 'linear-gradient(135deg, #6BC5F8 0%, #87CEEB 100%)', 0, 2, 1),
+('精品课程', '📚', '/pages/courses/list', '#FF8C42', '#FFFFFF', 'linear-gradient(135deg, #FF8C42 0%, #FFA366 100%)', 0, 3, 1),
+('今日缘分', '💝', '/pages/recommend/index', '#FF69B4', '#FFFFFF', 'linear-gradient(135deg, #FF69B4 0%, #FF8CC8 100%)', 1, 4, 1);