diff --git a/images/1.jpg b/images/1.jpg deleted file mode 100644 index c2e2413..0000000 Binary files a/images/1.jpg and /dev/null differ diff --git a/images/2.jpg b/images/2.jpg deleted file mode 100644 index 3258df8..0000000 Binary files a/images/2.jpg and /dev/null differ diff --git a/images/招商图片.jpg b/images/招商图片.jpg deleted file mode 100644 index 9f610a9..0000000 Binary files a/images/招商图片.jpg and /dev/null differ diff --git a/images/立即入驻导航图片.jpg b/images/立即入驻导航图片.jpg deleted file mode 100644 index 543d0f2..0000000 Binary files a/images/立即入驻导航图片.jpg and /dev/null differ diff --git a/images/首页分享照片.jpg b/images/首页分享照片.jpg deleted file mode 100644 index 4485aad..0000000 Binary files a/images/首页分享照片.jpg and /dev/null differ diff --git a/pages/cooperation/index.js b/pages/cooperation/index.js index d626757..fd02014 100644 --- a/pages/cooperation/index.js +++ b/pages/cooperation/index.js @@ -1,10 +1,14 @@ // pages/cooperation/index.js +const API = require('../../utils/api.js'); Page({ /** * 页面的初始数据 */ data: { - // 页面数据可以在这里定义 + // 招商图片URL + cooperationImageUrl: '/images/招商图片.jpg', + // 首页分享图片URL + shareImageUrl: '' }, /** @@ -13,6 +17,52 @@ Page({ onLoad: function (options) { // 页面加载时的初始化操作 console.log('招商合作页面加载'); + // 加载招商图片和分享图片 + this.loadCoverData(); + }, + + /** + * 加载封面图片数据 + */ + loadCoverData: function () { + API.getCovers().then(res => { + if (res.success && res.covers) { + // 查找招商图片(id为5) + const cooperationCover = res.covers.find(cover => cover.id === 5); + let cooperationImageUrl = '/images/招商图片.jpg'; // 默认图片 + if (cooperationCover) { + try { + const urls = JSON.parse(cooperationCover.coverurl); + if (Array.isArray(urls) && urls.length > 0) { + cooperationImageUrl = urls[0].replace(/[`\s]/g, ''); + } + } catch (err) { + console.error('解析招商图片URL失败:', err); + } + } + + // 查找首页分享图片(id为6) + const shareCover = res.covers.find(cover => cover.id === 6); + let shareImageUrl = ''; + if (shareCover) { + try { + const urls = JSON.parse(shareCover.coverurl); + if (Array.isArray(urls) && urls.length > 0) { + shareImageUrl = urls[0].replace(/[`\s]/g, ''); + } + } catch (err) { + console.error('解析分享图片URL失败:', err); + } + } + + this.setData({ + cooperationImageUrl: cooperationImageUrl, + shareImageUrl: shareImageUrl + }); + } + }).catch(err => { + console.error('加载封面图片数据失败:', err); + }); }, /** @@ -66,7 +116,7 @@ Page({ return { title: '招商合作 - 又鸟蛋平台', path: '/pages/cooperation/index', - imageUrl: '' + imageUrl: this.data.shareImageUrl }; }, @@ -77,7 +127,7 @@ Page({ return { title: '招商合作 - 又鸟蛋平台', query: '', - imageUrl: '' + imageUrl: this.data.shareImageUrl }; }, diff --git a/pages/cooperation/index.wxml b/pages/cooperation/index.wxml index bd8549b..9b8a16a 100644 --- a/pages/cooperation/index.wxml +++ b/pages/cooperation/index.wxml @@ -6,7 +6,7 @@ - + diff --git a/pages/index/index.js b/pages/index/index.js index 3166305..689ed7c 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -73,6 +73,8 @@ Page({ link: '' } ], + // 首页分享图片URL + shareImageUrl: '/images/首页分享照片.jpg', // 侧边栏相关 showSidebar: false, @@ -600,6 +602,7 @@ Page({ this.loadCategories() this.loadGoods() this.checkPhoneInPersonnel() + this.loadAdCarouselList() // 页面加载完成后检查视频是否在视口内 setTimeout(() => { @@ -1385,6 +1388,57 @@ Page({ } }, + // 加载广告轮播图数据 + loadAdCarouselList: function () { + API.getCovers().then(res => { + if (res.success && res.covers) { + // 过滤出轮播图数据(id为1和2) + const carouselCovers = res.covers.filter(cover => cover.id === 1 || cover.id === 2); + // 处理轮播图数据,解析coverurl字段 + const adCarouselList = carouselCovers.map(cover => { + // 解析coverurl字段,提取图片URL + let imageUrl = ''; + try { + // coverurl是JSON字符串,格式为["url"] + const urls = JSON.parse(cover.coverurl); + if (Array.isArray(urls) && urls.length > 0) { + // 移除字符串中的空格和反引号 + imageUrl = urls[0].replace(/[`\s]/g, ''); + } + } catch (err) { + console.error('解析轮播图URL失败:', err); + } + return { + id: cover.id, + imageUrl: imageUrl, + link: '' + }; + }); + + // 查找首页分享图片(id为6) + const shareCover = res.covers.find(cover => cover.id === 6); + let shareImageUrl = '/images/首页分享照片.jpg'; // 默认图片 + if (shareCover) { + try { + const urls = JSON.parse(shareCover.coverurl); + if (Array.isArray(urls) && urls.length > 0) { + shareImageUrl = urls[0].replace(/[`\s]/g, ''); + } + } catch (err) { + console.error('解析首页分享图片URL失败:', err); + } + } + + this.setData({ + adCarouselList: adCarouselList, + shareImageUrl: shareImageUrl + }); + } + }).catch(err => { + console.error('加载轮播图失败:', err); + }); + }, + // 加载商品分类列表 loadCategories: function () { API.getProductCategories().then(categories => { @@ -2777,7 +2831,7 @@ Page({ return { title: '鸡蛋贸易平台 - 专业的鸡蛋交易小程序', path: '/pages/index/index', - imageUrl: '/images/首页分享照片.jpg' + imageUrl: this.data.shareImageUrl } }, @@ -2786,7 +2840,7 @@ Page({ return { title: '鸡蛋贸易平台 - 专业的鸡蛋交易小程序', query: '', - imageUrl: '/images/首页分享照片.jpg' + imageUrl: this.data.shareImageUrl } }, diff --git a/pages/settlement/index.js b/pages/settlement/index.js index f5a5013..9568709 100644 --- a/pages/settlement/index.js +++ b/pages/settlement/index.js @@ -7,6 +7,11 @@ Page({ // 当前步骤 currentStep: 0, + // 封面图片 + guideImageUrl: '/images/立即入驻导航图片.jpg', + // 分享图片 + shareImageUrl: '/images/立即入驻7.jpg', + // 身份选择 collaborationid: '', // 合作商身份ID (原selectedIdentity) showIdentityError: false, @@ -64,6 +69,9 @@ Page({ onLoad(options) { console.log('settlement页面加载,options:', options); + // 加载封面图片数据 + this.loadCoverData(); + // 检查是否是分享链接,需要显示引导页 if (options.showGuide) { console.log('检测到showGuide参数,显示引导页'); @@ -151,6 +159,36 @@ Page({ } }, + // 加载封面图片数据 + loadCoverData: function () { + API.getCovers().then(res => { + if (res.success && res.covers) { + // 查找立即入驻导航图片(id为3) + const guideCover = res.covers.find(cover => cover.id === 3); + let guideImageUrl = '/images/立即入驻导航图片.jpg'; // 默认图片 + let shareImageUrl = '/images/立即入驻7.jpg'; // 默认分享图片 + if (guideCover) { + try { + const urls = JSON.parse(guideCover.coverurl); + if (Array.isArray(urls) && urls.length > 0) { + guideImageUrl = urls[0].replace(/[`\s]/g, ''); + shareImageUrl = guideImageUrl; // 分享图片使用与导航图片相同的图片 + } + } catch (err) { + console.error('解析立即入驻导航图片URL失败:', err); + } + } + + this.setData({ + guideImageUrl: guideImageUrl, + shareImageUrl: shareImageUrl + }); + } + }).catch(err => { + console.error('加载封面图片数据失败:', err); + }); + }, + // 加载入驻进度 loadSettlementProgress() { @@ -1599,7 +1637,7 @@ Page({ return { title: '合作入驻 - 又鸟蛋平台', path: '/pages/settlement/index?showGuide=1', - imageUrl: '/images/立即入驻7.jpg' + imageUrl: this.data.shareImageUrl }; }, @@ -1610,7 +1648,7 @@ Page({ return { title: '合作入驻 - 又鸟蛋平台', query: 'showGuide=1', - imageUrl: '/images/立即入驻7.jpg' + imageUrl: this.data.shareImageUrl }; } }); \ No newline at end of file diff --git a/pages/settlement/index.wxml b/pages/settlement/index.wxml index 8bacb34..d236135 100644 --- a/pages/settlement/index.wxml +++ b/pages/settlement/index.wxml @@ -4,7 +4,7 @@ - + 成为供应商 完成入驻后即可发布货源,开展鸡蛋贸易 diff --git a/server-example/server-mysql.js b/server-example/server-mysql.js index a7ceff6..6190c9d 100644 --- a/server-example/server-mysql.js +++ b/server-example/server-mysql.js @@ -125,6 +125,31 @@ app.post('/api/test/post', (req, res) => { }); }); +// 获取封面图片列表接口 +app.get('/api/cover', async (req, res) => { + try { + console.log('===== 获取封面图片列表接口被调用 ====='); + + // 从数据库获取所有封面数据 + const covers = await Cover.findAll(); + console.log('获取到封面数据:', covers.length, '条'); + + res.json({ + success: true, + covers: covers, + message: '获取封面图片列表成功', + timestamp: new Date().toISOString() + }); + } catch (error) { + console.error('获取封面图片列表失败:', error); + res.status(500).json({ + success: false, + message: '获取封面图片列表失败', + error: error.message + }); + } +}); + // 创建临时文件夹用于存储上传的文件 const uploadTempDir = path.join(__dirname, 'temp-uploads'); if (!fs.existsSync(uploadTempDir)) { @@ -1246,6 +1271,31 @@ Resources.init({ timestamps: false }); +// 封面模型 - 用于存储各种封面图片 +class Cover extends Model { } +Cover.init({ + id: { + type: DataTypes.INTEGER, + primaryKey: true, + allowNull: false + }, + coverurl: { + type: DataTypes.TEXT, + allowNull: false, + comment: '封面图片' + }, + description: { + type: DataTypes.STRING(255), + allowNull: true, + comment: '图片描述' + } +}, { + sequelize, + modelName: 'Cover', + tableName: 'cover', + timestamps: false +}); + // 定义模型之间的关联关系 // 用户和商品的一对多关系 (卖家发布商品) diff --git a/utils/api.js b/utils/api.js index 2bad893..ada928e 100644 --- a/utils/api.js +++ b/utils/api.js @@ -1192,6 +1192,12 @@ module.exports = { return this.uploadProductWithRecursiveImages(uploadData, imageUrls); }, + // 获取封面图片列表 + getCovers: function () { + console.log('API.getCovers - 获取封面图片列表'); + return request('/api/cover', 'GET', {}); + }, + // 添加聊天记录 - 为用户和客服创建双向聊天记录,避免重复创建 addChatRecord: function (user_phone, manager_phone, unread = 0) { console.log('API.addChatRecord - user_phone:', user_phone, 'manager_phone:', manager_phone, 'unread:', unread);