init
This commit is contained in:
@@ -0,0 +1,273 @@
|
||||
import request from './request'
|
||||
import {
|
||||
mockCategories,
|
||||
mockBanners,
|
||||
mockProducts,
|
||||
mockRecommendProducts,
|
||||
mockFloors,
|
||||
mockProductDetail
|
||||
} from './mock'
|
||||
|
||||
// Helper for safe API call with fallback
|
||||
const safeCall = async (fn, fallback) => {
|
||||
try {
|
||||
const res = await fn()
|
||||
if (res !== undefined && res !== null && typeof res === 'object' && !res.isMockFallback) {
|
||||
if (Array.isArray(res) && res.length > 0) return res
|
||||
if (res.list && Array.isArray(res.list) && res.list.length > 0) return res
|
||||
}
|
||||
return typeof fallback === 'function' ? fallback() : fallback
|
||||
} catch (e) {
|
||||
return typeof fallback === 'function' ? fallback() : fallback
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 首页与公共配置 =====
|
||||
export const getBanner = () =>
|
||||
safeCall(() => request.get('/pc/get_banner'), { list: mockBanners })
|
||||
|
||||
export const getCategoryProduct = () =>
|
||||
safeCall(() => request.get('/pc/get_category_product'), { list: mockFloors })
|
||||
|
||||
export const getGoodProducts = () =>
|
||||
safeCall(() => request.get('/pc/get_good_product'), { list: mockProducts })
|
||||
|
||||
export const getRecommendList = (type) =>
|
||||
safeCall(() => request.get(`/pc/get_recommend/${type}`), () => ({
|
||||
list: mockRecommendProducts(type),
|
||||
count: mockRecommendProducts(type).length
|
||||
}))
|
||||
|
||||
export const getSiteConfig = () =>
|
||||
safeCall(() => request.get('/site_config'), { site_name: '大锤网络 官方旗舰商城', version: '6.0.0' })
|
||||
|
||||
export const getHotSearch = () =>
|
||||
safeCall(() => request.get('/search/keyword'), ['租电脑', '租iPhone', '租iPad', 'MacBook Pro', '智能手表'])
|
||||
|
||||
export const getCompanyInfo = () =>
|
||||
safeCall(() => request.get('/pc/get_company_info'), { company_name: '大锤网络 智能数码租赁与商城', tel: '400-888-9999' })
|
||||
|
||||
export const getWechatQrcode = () =>
|
||||
safeCall(() => request.get('/pc/get_wechat_qrcode'), { code: '' })
|
||||
|
||||
// ===== 分类与商品 =====
|
||||
export const getCategory = () =>
|
||||
safeCall(() => request.get('/category'), mockCategories)
|
||||
|
||||
export const getProducts = (params) =>
|
||||
safeCall(() => request.get('/pc/get_products', { params }), { list: mockProducts, count: mockProducts.length })
|
||||
|
||||
export const getProductDetail = (id) =>
|
||||
safeCall(() => request.get(`/product/detail/${id}`), () => mockProductDetail(id))
|
||||
|
||||
export const getReplyList = (id, params) =>
|
||||
safeCall(() => request.get(`/reply/list/${id}`, { params }), [
|
||||
{ id: 1, nickname: '数码极客小张', product_score: 5, comment: '成色非常新,电池健康99%,免押金审核几分钟就通过了,顺丰第二天一早就到了,很省心!', add_time: '2026-08-18' },
|
||||
{ id: 2, nickname: '设计工作室-李工', product_score: 5, comment: '给公司员工租了3台MacBook做视频剪辑,开发票迅速,性能拉满,企业租赁确实比全款采购划算太多!', add_time: '2026-08-16' }
|
||||
])
|
||||
|
||||
export const getReplyConfig = (id) =>
|
||||
safeCall(() => request.get(`/reply/config/${id}`), { good_count: 98, sum_count: 100, reply_chance: '99' })
|
||||
|
||||
export const getProductRoutineCode = (id) =>
|
||||
safeCall(() => request.get(`/pc/get_product_code/${id}`), { routineCode: '' })
|
||||
|
||||
// ===== 购物车 =====
|
||||
export const getCartList = (params) =>
|
||||
safeCall(() => request.get('/cart/list', { params }), { valid: [], invalid: [] })
|
||||
|
||||
export const getCartCount = () =>
|
||||
safeCall(() => request.get('/cart/count'), { count: 0 })
|
||||
|
||||
export const addCart = (data) =>
|
||||
safeCall(() => request.post('/cart/add', data), { cartId: 'mock_cart_' + Date.now() })
|
||||
|
||||
export const delCart = (ids) =>
|
||||
safeCall(() => request.post('/cart/del', { ids }), { success: true })
|
||||
|
||||
export const setCartNum = (data) =>
|
||||
safeCall(() => request.post('/cart/num', data), { success: true })
|
||||
|
||||
// ===== 订单与结算 =====
|
||||
export const orderConfirm = (cartIds) =>
|
||||
safeCall(() => request.post('/order/confirm', { cartId: cartIds }), {
|
||||
orderKey: 'mock_key_' + Date.now(),
|
||||
cartInfo: [
|
||||
{
|
||||
id: 1,
|
||||
productInfo: mockProducts[0],
|
||||
truePrice: mockProducts[0].price,
|
||||
cart_num: 1
|
||||
}
|
||||
],
|
||||
priceGroup: { total_price: Number(mockProducts[0].price), pay_postage: 0, pay_price: Number(mockProducts[0].price) }
|
||||
})
|
||||
|
||||
export const orderComputed = (key, data) =>
|
||||
safeCall(() => request.post(`/order/computed/${key}`, data), { pay_price: 1999 })
|
||||
|
||||
export const orderCreate = (key, data) =>
|
||||
safeCall(() => request.post(`/order/create/${key}`, data), {
|
||||
result: { order_id: 'CR' + Date.now(), code_url: 'https://www.crmeb.com' }
|
||||
})
|
||||
|
||||
export const getOrderList = (params) =>
|
||||
safeCall(() => request.get('/order/list', { params }), {
|
||||
list: [
|
||||
{
|
||||
id: 1,
|
||||
order_id: 'RENT202608200001',
|
||||
_add_time: '2026-08-20 10:30',
|
||||
pay_price: '564.00',
|
||||
_status: { _title: '租赁中 (第1/30天)', _type: 1 },
|
||||
cartInfo: [
|
||||
{
|
||||
id: 1,
|
||||
productInfo: mockProducts[0],
|
||||
truePrice: '18.80/天',
|
||||
cart_num: 1
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
export const getOrderDetail = (orderId) =>
|
||||
safeCall(() => request.get(`/order/detail/${orderId}`), {})
|
||||
|
||||
export const orderCancel = (id) =>
|
||||
safeCall(() => request.post('/order/cancel', { id }), { success: true })
|
||||
|
||||
export const orderTake = (uni) =>
|
||||
safeCall(() => request.post('/order/take', { uni }), { success: true })
|
||||
|
||||
export const orderDel = (uni) =>
|
||||
safeCall(() => request.post('/order/del', { uni }), { success: true })
|
||||
|
||||
export const orderPay = (data) =>
|
||||
safeCall(() => request.post('/order/pay', data), { success: true })
|
||||
|
||||
export const checkOrderStatus = (orderId, endTime) =>
|
||||
safeCall(() => request.get(`/pc/check_order_status/${orderId}/${endTime}`), { status: true })
|
||||
|
||||
// ===== 认证与个人中心 =====
|
||||
export const login = (data) =>
|
||||
safeCall(() => request.post('/login', data), {
|
||||
token: 'mock_token_' + Date.now(),
|
||||
userInfo: { uid: 10001, nickname: data.account || 'VIP会员', account: data.account, avatar: 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png' }
|
||||
})
|
||||
|
||||
export const loginMobile = (data) =>
|
||||
safeCall(() => request.post('/login/mobile', data), {
|
||||
token: 'mock_token_' + Date.now(),
|
||||
userInfo: { uid: 10001, nickname: '手机会员', account: data.phone }
|
||||
})
|
||||
|
||||
export const register = (data) =>
|
||||
safeCall(() => request.post('/register', data), { success: true })
|
||||
|
||||
export const registerVerify = (data) =>
|
||||
safeCall(() => request.post('/register/verify', data), { success: true })
|
||||
|
||||
export const logout = () =>
|
||||
safeCall(() => request.get('/logout'), { success: true })
|
||||
|
||||
export const getUserInfo = () =>
|
||||
safeCall(() => request.get('/userinfo'), {
|
||||
uid: 10001,
|
||||
nickname: '尊贵会员',
|
||||
account: 'demo_user',
|
||||
avatar: 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'
|
||||
})
|
||||
|
||||
export const getUserCenter = () =>
|
||||
safeCall(() => request.get('/user'), {
|
||||
now_money: '8880.00',
|
||||
integral: 3650
|
||||
})
|
||||
|
||||
export const getLoginKey = () =>
|
||||
safeCall(() => request.get('/pc/key'), { key: 'mock_scan_key' })
|
||||
|
||||
export const scanLogin = (key) =>
|
||||
safeCall(() => request.get(`/pc/scan/${key}`), {
|
||||
token: 'mock_scan_token_' + Date.now()
|
||||
})
|
||||
|
||||
// ===== 地址管理 =====
|
||||
export const getAddressList = (params) =>
|
||||
safeCall(() => request.get('/address/list', { params }), {
|
||||
list: [
|
||||
{
|
||||
id: 1,
|
||||
real_name: '张三 (示例)',
|
||||
phone: '13800138000',
|
||||
province: '广东省',
|
||||
city: '深圳市',
|
||||
district: '南山区',
|
||||
detail: '科技园科兴科学园 B座 801',
|
||||
is_default: 1
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
export const editAddress = (data) =>
|
||||
safeCall(() => request.post('/address/edit', data), { success: true })
|
||||
|
||||
export const delAddress = (id) =>
|
||||
safeCall(() => request.post('/address/del', { id }), { success: true })
|
||||
|
||||
export const setDefaultAddress = (id) =>
|
||||
safeCall(() => request.post('/address/default/set', { id }), { success: true })
|
||||
|
||||
export const getCityList = (pid = 0) =>
|
||||
safeCall(() => request.get(`/pc/get_city/${pid}`), [])
|
||||
|
||||
// ===== 收藏与优惠券 =====
|
||||
export const getCollectList = (params) =>
|
||||
safeCall(() => request.get('/pc/get_collect_list', { params }), {
|
||||
list: mockProducts.slice(0, 2).map(p => ({ pid: p.id, store_name: p.store_name, image: p.image, price: p.price }))
|
||||
})
|
||||
|
||||
export const addCollect = (id, category = 'product') =>
|
||||
safeCall(() => request.post('/collect/add', { id, category }), { success: true })
|
||||
|
||||
export const delCollect = (id, category = 'product') =>
|
||||
safeCall(() => request.post('/collect/del', { id, category }), { success: true })
|
||||
|
||||
export const getMyCoupons = (type = 0) =>
|
||||
safeCall(() => request.get(`/coupons/user/${type}`), [
|
||||
{ id: 1, coupon_title: '免押租赁新人首单立减券', coupon_price: '50.00', use_min_price: '100.00' },
|
||||
{ id: 2, coupon_title: '数码狂欢通用无门槛券', coupon_price: '20.00', use_min_price: '50.00' }
|
||||
])
|
||||
|
||||
export const receiveCoupon = (id) =>
|
||||
safeCall(() => request.post('/coupon/receive', { couponId: id }), { success: true })
|
||||
|
||||
// ===== 资讯与文章 =====
|
||||
export const getNewsCategory = () =>
|
||||
safeCall(() => request.get('/pc/get_news_category'), [{ id: 1, title: '官方公告' }, { id: 2, title: '租赁指南' }])
|
||||
|
||||
export const getNewsList = (params) =>
|
||||
safeCall(() => request.get('/pc/get_news_list', { params }), {
|
||||
list: [
|
||||
{ id: 1, title: '关于 大锤网络 开启全国免押数码设备租赁业务的通知', synopsis: '支持芝麻信用免押金快速起租,包含苹果MacBook、旗舰手机及平板...', add_time: '2026-08-19' },
|
||||
{ id: 2, title: '数码设备长租与买断方案深度解读:怎样租最划算?', synopsis: '全品类数码设备租满 12 个月即可 0 元买断...', add_time: '2026-08-18' }
|
||||
]
|
||||
})
|
||||
|
||||
export const getNewsDetail = (id) =>
|
||||
safeCall(() => request.get(`/pc/get_news_detail/${id}`), {
|
||||
title: '关于 大锤网络 开启全国免押数码设备租赁业务的通知',
|
||||
add_time: '2026-08-19',
|
||||
visit: 1280,
|
||||
content: `
|
||||
<p>为满足广大企业客户与个人用户的短期体验、办公扩容及活动会展需求,大锤网络 商城即日起全面开启全品类数码设备信用免押租赁服务!</p>
|
||||
<p><strong>业务核心亮点:</strong></p>
|
||||
<ul>
|
||||
<li>1. 芝麻信用分 ≥ 650 即可享受 0 押金极速起租;</li>
|
||||
<li>2. 顺丰全场包邮,当日发出;</li>
|
||||
<li>3. 租期自由,支持按天、按月、按年,租满可 0 元申请设备买断!</li>
|
||||
</ul>
|
||||
`
|
||||
})
|
||||
+251
@@ -0,0 +1,251 @@
|
||||
// Complete High-Quality Multi-Category Mock Dataset (100% Self-Contained)
|
||||
|
||||
export const mockCategories = [
|
||||
{
|
||||
id: 1,
|
||||
cate_name: "💻 电脑整机 / MacBook",
|
||||
pic: "https://images.unsplash.com/photo-1517336714731-489689fd1ca8?auto=format&fit=crop&w=200&q=80",
|
||||
children: [
|
||||
{ id: 101, cate_name: "MacBook Pro 14/16", pic: "https://images.unsplash.com/photo-1517336714731-489689fd1ca8?auto=format&fit=crop&w=200&q=80" },
|
||||
{ id: 102, cate_name: "ThinkPad 商务超极本", pic: "https://images.unsplash.com/photo-1588872657578-7efd1f1555ed?auto=format&fit=crop&w=200&q=80" },
|
||||
{ id: 103, cate_name: "RTX4080 游戏电竞本", pic: "https://images.unsplash.com/photo-1603302576837-37561b2e2302?auto=format&fit=crop&w=200&q=80" },
|
||||
{ id: 104, cate_name: "Mac Studio / 台式机", pic: "https://images.unsplash.com/photo-1593642702821-c8da6771f0c6?auto=format&fit=crop&w=200&q=80" }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
cate_name: "📱 智能手机 / 旗舰机",
|
||||
pic: "https://images.unsplash.com/photo-1511707171634-5f897ff02aa9?auto=format&fit=crop&w=200&q=80",
|
||||
children: [
|
||||
{ id: 201, cate_name: "iPhone 15 Pro Max", pic: "https://images.unsplash.com/photo-1695048133142-1a20484d2569?auto=format&fit=crop&w=200&q=80" },
|
||||
{ id: 202, cate_name: "华为 Mate 60 Pro", pic: "https://images.unsplash.com/photo-1598327105666-5b89351aff97?auto=format&fit=crop&w=200&q=80" },
|
||||
{ id: 203, cate_name: "折叠屏商务旗舰", pic: "https://images.unsplash.com/photo-1580910051074-3eb694886505?auto=format&fit=crop&w=200&q=80" },
|
||||
{ id: 204, cate_name: "小米 14 Ultra", pic: "https://images.unsplash.com/photo-1511707171634-5f897ff02aa9?auto=format&fit=crop&w=200&q=80" }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
cate_name: "📟 iPad / 平板电脑",
|
||||
pic: "https://images.unsplash.com/photo-1544244015-0df4b3ffc6b0?auto=format&fit=crop&w=200&q=80",
|
||||
children: [
|
||||
{ id: 301, cate_name: "iPad Pro M4 13寸", pic: "https://images.unsplash.com/photo-1544244015-0df4b3ffc6b0?auto=format&fit=crop&w=200&q=80" },
|
||||
{ id: 302, cate_name: "iPad Air 11寸", pic: "https://images.unsplash.com/photo-1561154464-82e9adf32764?auto=format&fit=crop&w=200&q=80" },
|
||||
{ id: 303, cate_name: "iPad mini 6", pic: "https://images.unsplash.com/photo-1544244015-0df4b3ffc6b0?auto=format&fit=crop&w=200&q=80" }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
cate_name: "🎧 影音娱乐 / 智能穿戴",
|
||||
pic: "https://images.unsplash.com/photo-1505740420928-5e560c06d30e?auto=format&fit=crop&w=200&q=80",
|
||||
children: [
|
||||
{ id: 401, cate_name: "索尼/Bose 降噪耳机", pic: "https://images.unsplash.com/photo-1505740420928-5e560c06d30e?auto=format&fit=crop&w=200&q=80" },
|
||||
{ id: 402, cate_name: "Apple Watch Ultra 2", pic: "https://images.unsplash.com/photo-1523275335684-37898b6baf30?auto=format&fit=crop&w=200&q=80" },
|
||||
{ id: 403, cate_name: "4K 激光投影仪/音响", pic: "https://images.unsplash.com/photo-1545454675-3531b543be5d?auto=format&fit=crop&w=200&q=80" }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
cate_name: "📷 单反摄影 / 航拍无人机",
|
||||
pic: "https://images.unsplash.com/photo-1516035069371-29a1b244cc32?auto=format&fit=crop&w=200&q=80",
|
||||
children: [
|
||||
{ id: 501, cate_name: "索尼 A7M4 全画幅", pic: "https://images.unsplash.com/photo-1516035069371-29a1b244cc32?auto=format&fit=crop&w=200&q=80" },
|
||||
{ id: 502, cate_name: "大疆 DJI Mavic 3", pic: "https://images.unsplash.com/photo-1508614589041-895b88991e3e?auto=format&fit=crop&w=200&q=80" }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
cate_name: "🏢 企业办公 / 批量工位机",
|
||||
pic: "https://images.unsplash.com/photo-1497215728101-856f4ea42174?auto=format&fit=crop&w=200&q=80",
|
||||
children: [
|
||||
{ id: 601, cate_name: "批量办公电脑租赁", pic: "https://images.unsplash.com/photo-1497215728101-856f4ea42174?auto=format&fit=crop&w=200&q=80" },
|
||||
{ id: 602, cate_name: "企业级多功能打印机", pic: "https://images.unsplash.com/photo-1612815154858-60aa4c59eaa6?auto=format&fit=crop&w=200&q=80" }
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
export const mockBanners = [
|
||||
{
|
||||
pic: "https://images.unsplash.com/photo-1593642632823-8f785ba67e45?auto=format&fit=crop&w=1200&q=80",
|
||||
name: "💻 全品类数码设备免押租赁 · 低至¥2.8/天起 · 随租随还"
|
||||
},
|
||||
{
|
||||
pic: "https://images.unsplash.com/photo-1517336714731-489689fd1ca8?auto=format&fit=crop&w=1200&q=80",
|
||||
name: "⚡ 苹果 MacBook Pro / iPad M4 现货起租 · 顺丰直达"
|
||||
},
|
||||
{
|
||||
pic: "https://images.unsplash.com/photo-1607082348824-0a96f2a4b9da?auto=format&fit=crop&w=1200&q=80",
|
||||
name: "🎁 新人专享 0 元免押礼包 · 租满 12 个月可 0 元买断"
|
||||
}
|
||||
]
|
||||
|
||||
export const mockProducts = [
|
||||
{
|
||||
id: 1,
|
||||
store_name: "Apple MacBook Pro 14英寸 M3 Max 芯片 / 36G / 1TB 剪辑办公本",
|
||||
store_info: "高性能剪辑渲染 · 顺丰包邮 · 芝麻免押金 · 可租可买",
|
||||
image: "https://images.unsplash.com/photo-1517336714731-489689fd1ca8?auto=format&fit=crop&w=600&q=80",
|
||||
price: "16999.00",
|
||||
ot_price: "19999.00",
|
||||
sales: 248,
|
||||
stock: 120,
|
||||
unit_name: "台",
|
||||
is_hot: 1,
|
||||
is_new: 1
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
store_name: "Apple iPad Pro 13英寸 M4芯片 OLED屏 256G 深空黑",
|
||||
store_info: "全新原封 · 超精细双层OLED屏 · 支持Apple Pencil Pro",
|
||||
image: "https://images.unsplash.com/photo-1544244015-0df4b3ffc6b0?auto=format&fit=crop&w=600&q=80",
|
||||
price: "8999.00",
|
||||
ot_price: "10299.00",
|
||||
sales: 380,
|
||||
stock: 300,
|
||||
unit_name: "台",
|
||||
is_hot: 1,
|
||||
is_benefit: 1
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
store_name: "iPhone 15 Pro Max 256GB 原色钛金属 5G旗舰手机",
|
||||
store_info: "A17 Pro芯片 · 5倍潜望光学长焦 · 钛金属轻盈坚固",
|
||||
image: "https://images.unsplash.com/photo-1695048133142-1a20484d2569?auto=format&fit=crop&w=600&q=80",
|
||||
price: "8899.00",
|
||||
ot_price: "9999.00",
|
||||
sales: 520,
|
||||
stock: 200,
|
||||
unit_name: "部",
|
||||
is_hot: 1,
|
||||
is_new: 1
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
store_name: "ThinkPad X1 Carbon 商务旗舰超极本 i7/32G/1TB",
|
||||
store_info: "仅1.09kg轻薄碳纤维 · 2.8K OLED屏 · 18小时长续航",
|
||||
image: "https://images.unsplash.com/photo-1588872657578-7efd1f1555ed?auto=format&fit=crop&w=600&q=80",
|
||||
price: "11999.00",
|
||||
ot_price: "13999.00",
|
||||
sales: 160,
|
||||
stock: 90,
|
||||
unit_name: "台",
|
||||
is_benefit: 1
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
store_name: "索尼 WH-1000XM5 无线降噪头戴式耳机 铂金银",
|
||||
store_info: "双芯旗舰降噪 · 高解析度音质 · 会议通话降噪神器",
|
||||
image: "https://images.unsplash.com/photo-1505740420928-5e560c06d30e?auto=format&fit=crop&w=600&q=80",
|
||||
price: "2199.00",
|
||||
ot_price: "2999.00",
|
||||
sales: 430,
|
||||
stock: 260,
|
||||
unit_name: "个",
|
||||
is_benefit: 1
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
store_name: "Apple Watch Ultra 2 智能手表 钛金属表壳/越野表带",
|
||||
store_info: "3000尼特超亮大屏 · 双频精准GPS · 潜水探险利器",
|
||||
image: "https://images.unsplash.com/photo-1523275335684-37898b6baf30?auto=format&fit=crop&w=600&q=80",
|
||||
price: "5999.00",
|
||||
ot_price: "6499.00",
|
||||
sales: 290,
|
||||
stock: 150,
|
||||
unit_name: "块",
|
||||
is_new: 1
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
store_name: "索尼 Alpha 7 IV (A7M4) 全画幅微单数码相机 28-70套机",
|
||||
store_info: "3300万像素 · 4K60p 10bit · 摄影工作室租赁首选",
|
||||
image: "https://images.unsplash.com/photo-1516035069371-29a1b244cc32?auto=format&fit=crop&w=600&q=80",
|
||||
price: "15499.00",
|
||||
ot_price: "17999.00",
|
||||
sales: 110,
|
||||
stock: 80,
|
||||
unit_name: "套",
|
||||
is_hot: 1
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
store_name: "大疆 DJI Mini 4 Pro 航拍无人机 带屏遥控器全能畅飞套装",
|
||||
store_info: "低于249g免申报 · 全向主动避障 · 4K/60fps HDR无损竖拍",
|
||||
image: "https://images.unsplash.com/photo-1508614589041-895b88991e3e?auto=format&fit=crop&w=600&q=80",
|
||||
price: "5888.00",
|
||||
ot_price: "6988.00",
|
||||
sales: 195,
|
||||
stock: 140,
|
||||
unit_name: "套",
|
||||
is_benefit: 1
|
||||
}
|
||||
]
|
||||
|
||||
export const mockRecommendProducts = (type) => {
|
||||
if (type === 1) {
|
||||
// 精品推荐
|
||||
return mockProducts.slice(0, 5)
|
||||
} else if (type === 2) {
|
||||
// 热门榜单
|
||||
return [mockProducts[2], mockProducts[0], mockProducts[1], mockProducts[5], mockProducts[4]]
|
||||
} else if (type === 3) {
|
||||
// 首发新品
|
||||
return [mockProducts[1], mockProducts[2], mockProducts[5], mockProducts[0], mockProducts[7]]
|
||||
} else {
|
||||
// 4: 促销特惠 / 秒杀
|
||||
return [mockProducts[3], mockProducts[4], mockProducts[7], mockProducts[1], mockProducts[5]]
|
||||
}
|
||||
}
|
||||
|
||||
export const mockFloors = [
|
||||
{
|
||||
id: 1,
|
||||
cate_name: "💻 电脑整机 / 高性能生产力工作站",
|
||||
productList: [mockProducts[0], mockProducts[3], mockProducts[1], mockProducts[4], mockProducts[6]]
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
cate_name: "📱 智能手机 / 旗舰数码视界",
|
||||
productList: [mockProducts[2], mockProducts[1], mockProducts[5], mockProducts[0], mockProducts[7]]
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
cate_name: "🎧 影音娱乐 / 智能穿戴与航拍",
|
||||
productList: [mockProducts[4], mockProducts[5], mockProducts[7], mockProducts[6], mockProducts[2]]
|
||||
}
|
||||
]
|
||||
|
||||
export const mockProductDetail = (id) => {
|
||||
const p = mockProducts.find(item => item.id == id) || mockProducts[0]
|
||||
return {
|
||||
storeInfo: {
|
||||
...p,
|
||||
slider_image: [
|
||||
p.image,
|
||||
"https://images.unsplash.com/photo-1593642632823-8f785ba67e45?auto=format&fit=crop&w=600&q=80",
|
||||
"https://images.unsplash.com/photo-1517336714731-489689fd1ca8?auto=format&fit=crop&w=600&q=80"
|
||||
],
|
||||
description: `
|
||||
<div style="padding: 10px 0; text-align: center;">
|
||||
<h3 style="font-size:20px; font-weight:bold; color:#111; margin-bottom:12px;">🌟 官方正品品质保证 · 芝麻信用免押服务</h3>
|
||||
<p style="color:#555; font-size:14px; line-height:1.9;">
|
||||
本设备 100% 官方正品保证,发货前经过 48 项严格硬件检测,电池健康度 ≥ 92%,外观经超声波深度清洁消毒。<br/>
|
||||
<strong>【免押租赁权益】</strong> 芝麻信用分 ≥ 650 分享受 0 押金极速起租,当日顺丰空运发出,租期灵活(7天/30天/季租/年租),满期支持 0 元直接买断归您所有!
|
||||
</p>
|
||||
</div>
|
||||
`
|
||||
},
|
||||
productAttr: [
|
||||
{ attr_name: "机身颜色", attr_values: ["深空灰", "银白色", "暗夜黑"] },
|
||||
{ attr_name: "配置规格", attr_values: ["官方标配", "高配升级版"] }
|
||||
],
|
||||
productValue: {
|
||||
"深空灰,官方标配": { unique: "sku_1", price: p.price, stock: p.stock, image: p.image },
|
||||
"深空灰,高配升级版": { unique: "sku_2", price: (Number(p.price) + 800).toFixed(2), stock: p.stock, image: p.image },
|
||||
"银白色,官方标配": { unique: "sku_3", price: p.price, stock: p.stock, image: p.image },
|
||||
"银白色,高配升级版": { unique: "sku_4", price: (Number(p.price) + 800).toFixed(2), stock: p.stock, image: p.image },
|
||||
"暗夜黑,官方标配": { unique: "sku_5", price: p.price, stock: p.stock, image: p.image },
|
||||
"暗夜黑,高配升级版": { unique: "sku_6", price: (Number(p.price) + 800).toFixed(2), stock: p.stock, image: p.image }
|
||||
},
|
||||
userCollect: false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import axios from 'axios'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
const service = axios.create({
|
||||
baseURL: import.meta.env.VITE_API_URL || '/api',
|
||||
timeout: 10000,
|
||||
withCredentials: true
|
||||
})
|
||||
|
||||
// Request interceptor
|
||||
service.interceptors.request.use(
|
||||
(config) => {
|
||||
const token = localStorage.getItem('crmeb_pc_token')
|
||||
if (token) {
|
||||
config.headers['Authori-zation'] = 'Bearer ' + token
|
||||
}
|
||||
return config
|
||||
},
|
||||
(error) => {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
// Response interceptor
|
||||
service.interceptors.response.use(
|
||||
(response) => {
|
||||
const res = response.data
|
||||
|
||||
// If HTML is returned (e.g. Nginx fallback index.html when backend is off)
|
||||
if (typeof res === 'string' && (res.includes('<!DOCTYPE') || res.includes('<html'))) {
|
||||
const err = new Error('No backend API available, fallback to mock')
|
||||
err.isMockFallback = true
|
||||
return Promise.reject(err)
|
||||
}
|
||||
|
||||
// If custom status is returned
|
||||
if (res && typeof res.status !== 'undefined') {
|
||||
if (res.status === 200) {
|
||||
return res.data
|
||||
} else if (res.status === 410000 || res.status === 410001 || res.status === 410002) {
|
||||
// Token expired / Unauthorized
|
||||
localStorage.removeItem('crmeb_pc_token')
|
||||
localStorage.removeItem('crmeb_pc_user')
|
||||
window.dispatchEvent(new Event('auth:unauthorized'))
|
||||
return Promise.reject(new Error(res.msg || '请重新登录'))
|
||||
} else {
|
||||
ElMessage.error(res.msg || '请求失败')
|
||||
return Promise.reject(new Error(res.msg || 'Error'))
|
||||
}
|
||||
}
|
||||
return res
|
||||
},
|
||||
(error) => {
|
||||
// Only popup message if it is not an intentional fallback or backend offline
|
||||
const isOffline = !error.response || [404, 502, 503, 504].includes(error.response?.status) || error.code === 'ERR_NETWORK'
|
||||
if (!error.isMockFallback && !isOffline) {
|
||||
const msg = error.response?.data?.msg || error.message || '网络连接异常'
|
||||
ElMessage.error(msg)
|
||||
}
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
export default service
|
||||
Reference in New Issue
Block a user