You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.0 KiB
66 lines
2.0 KiB
// 货源管理模块使用示例
|
|
// 本文件展示如何在页面中使用SupplyManager类
|
|
|
|
const SupplyManager = require('./supply-manager.js');
|
|
|
|
// 页面实例示例
|
|
const pageInstance = {
|
|
data: {},
|
|
setData: function(data) {
|
|
this.data = { ...this.data, ...data };
|
|
console.log('页面数据更新:', this.data);
|
|
}
|
|
};
|
|
|
|
// 初始化货源管理器
|
|
const supplyManager = new SupplyManager(pageInstance);
|
|
|
|
// 使用示例
|
|
async function exampleUsage() {
|
|
console.log('===== 货源管理模块使用示例 =====');
|
|
|
|
try {
|
|
// 1. 加载货源列表
|
|
console.log('1. 加载货源列表...');
|
|
await supplyManager.loadSupplies();
|
|
console.log(' 加载完成,货源数量:', supplyManager.data.supplies.length);
|
|
|
|
// 2. 搜索货源
|
|
console.log('2. 搜索货源...');
|
|
supplyManager.data.searchKeyword = '罗曼粉';
|
|
supplyManager.searchSupplies();
|
|
console.log(' 搜索完成,结果数量:', supplyManager.data.publishedSupplies.length);
|
|
|
|
// 3. 添加新货源
|
|
console.log('3. 添加新货源...');
|
|
supplyManager.data.newSupply = {
|
|
name: '罗曼粉',
|
|
price: '10.5',
|
|
minOrder: '50',
|
|
yolk: '红心',
|
|
spec: '格子装',
|
|
region: '北京市 北京市 朝阳区',
|
|
imageUrls: []
|
|
};
|
|
// 注意:实际添加货源需要登录状态和网络请求
|
|
// await supplyManager.addSupply();
|
|
console.log(' 新货源准备完成,等待发布');
|
|
|
|
// 4. 处理图片
|
|
console.log('4. 处理图片URL...');
|
|
const processedImages = supplyManager.processImageUrls(['http://example.com/image1.jpg', 'placeholder://example']);
|
|
console.log(' 图片处理结果:', processedImages);
|
|
|
|
// 5. 格式化时间
|
|
console.log('5. 格式化时间...');
|
|
const formattedTime = supplyManager.formatCreateTime(new Date());
|
|
console.log(' 格式化后的时间:', formattedTime);
|
|
|
|
console.log('===== 示例运行完成 =====');
|
|
} catch (error) {
|
|
console.error('示例运行出错:', error);
|
|
}
|
|
}
|
|
|
|
// 运行示例
|
|
exampleUsage();
|
|
|