每周更新

This commit is contained in:
2025-12-05 16:24:20 +08:00
parent 485226d9dc
commit cbefb964d4
21 changed files with 2546 additions and 700 deletions

View File

@@ -2,6 +2,7 @@
import { getProductById } from '../../utils/productService'
import { getMachineInfo, getPayTypes,getShopMachineList,addGoodsV2 } from '../../api/products'
import { truncateAmountByCoin, truncateTo6 } from '../../utils/amount'
import { getGoodsListV2 } from '../../api/shoppingCart'
export default {
name: 'ProductDetail',
@@ -162,218 +163,7 @@ export default {
this.machineType = savedType
}
}catch(e){/* noop */}
let arr={
"meta": {
"pageNum": 1, // 当前页码(后端分页用,可选)
"pageSize": 10, // 每页条数(后端分页用,可选)
"total": 123 // 总条数(后端分页用,可选)
},
"columns": [
{
"key": "model", // 列字段名:与 rows 中同名字段映射
"label": "型号", // 表头显示文本
"type": "text", // 列类型text/amount/hashrate/days
"fixed": "left", // 是否左固定列left/right/不传
"width": 100 // 列宽(可选)
},
{
"key": "price", // 价格列字段名
"label": "价格", // 表头显示文本
"type": "amount", // 金额类型:仅渲染数值;单位来自行级 priceList.coin
"width": 100 // 列宽(可选)
},
// 动态币种/算法算力列(示例:仅第一列带注释,其余同结构)
{
"key": "XTM", // 币种/算法代码作为列 key
"label": "XTM", // 表头显示名
"type": "hashrate", // 列类型:算力
"unit": "MH/s", // 单元格单位(表头不显示单位)
"icon": "https://cdn.xxx/coin/xtm.png", // 表头图标(可选)
},
{
"key": "NXNA",
"label": "NXNA",
"type": "hashrate",
"unit": "MH/s",
"icon": "https://cdn.xxx/coin/nxna.png"
},
{
"key": "CLORE",
"label": "CLORE",
"type": "hashrate",
"unit": "MH/s",
"icon": "https://cdn.xxx/coin/clore.png"
},
{
"key": "CFX",
"label": "CFX",
"type": "hashrate",
"unit": "MH/s",
"icon": "https://cdn.xxx/coin/cfx.png"
},
{
"key": "IRON",
"label": "IRON",
"type": "hashrate",
"unit": "MH/s",
"icon": "https://cdn.xxx/coin/iron.png"
},
{
"key": "NEXA",
"label": "NEXA",
"type": "hashrate",
"unit": "MH/s",
"icon": "https://cdn.xxx/coin/nexa.png"
},
{
"key": "KLS",
"label": "KLS",
"type": "hashrate",
"unit": "MH/s",
"icon": "https://cdn.xxx/coin/kls.png"
},
{
"key": "RVN",
"label": "RVN",
"type": "hashrate",
"unit": "MH/s",
"icon": "https://cdn.xxx/coin/rvn.png"
},
{
"key": "ERG",
"label": "ERG",
"type": "hashrate",
"unit": "MH/s",
"icon": "https://cdn.xxx/coin/erg.png"
},
{
"key": "XEL",
"label": "XEL",
"type": "hashrate",
"unit": "kH/s",
"icon": "https://cdn.xxx/coin/xel.png"
},
// 尾部汇总列
{
"key": "monthIncome",
"label": "最大月收益",
"type": "amount",
"currency": "USDT",//固定显示单位
"period": "month",
"width": 110
},
{
"key": "maxLeaseDays",
"label": "最大租赁天数",
"type": "days",
"width": 80
}
],
"rows": [
{
"id": "gpu_100_hbm3", // 唯一标识(加入购物车传 id
"model": "H100 80GB HBM3", // 型号,对应 columns.key = model
"price": 142160.54, // 行价格基准值(当无 priceList 时展示)
"priceList": [ // 价格列表:随支付方式变更价格与单位
{
"chain": "TRON", // 支付链
"coin": "USDT", // 币种(价格单位来源)
"price": 142160.54 // 该支付方式下的单价
},
{ "chain": "TRON", "coin": "NEXA", "price": 142050.00 },
{ "chain": "ETH", "coin": "USDT", "price": 142100.00 },
{ "chain": "ETH", "coin": "ETH", "price": 142000.00 }
],
"saleNumbers": 120, // 总机器数(仅 ASIC 展示,后端只读返回)
"saleOutNumbers": 18, // 已售数量(仅 ASIC 展示,后端只读返回)
"XTM": 255.0, // 对应列 key 的算力数值(可为 null
"NXNA": 255.0,
"CLORE": 343.0,
"CFX": null,
"IRON": null,
"NEXA": null,
"KLS": null,
"RVN": 255.0,
"ERG": 900.0,
"XEL": null,
"monthIncome": 425.01, // 最大月收益(列定义 currency=USDT固定以 USDT 展示)
"maxLeaseDays": 10368 // 最大租赁天数(单位:天)
},
{
"id": "gpu_rtx_5090",
"model": "RTX 5090",
"price": 14216.05,
"priceList": [
{ "chain": "TRON", "coin": "USDT", "price": 14216.05 },
{ "chain": "TRON", "coin": "NEXA", "price": 14199.00 },
{ "chain": "ETH", "coin": "USDT", "price": 14180.00 },
{ "chain": "ETH", "coin": "ETH", "price": 14150.00 }
],
"saleNumbers": 80,
"saleOutNumbers": 22,
"XTM": 28.7,
"NXNA": 100.5,
"CLORE": 100.5,
"CFX": 210.0,
"IRON": 133.5,
"NEXA": 450.0,
"KLS": 133.5,
"RVN": 100.5,
"ERG": 575.0,
"XEL": 120.0,
"monthIncome": 267.84,
"maxLeaseDays": 1645
},
{
"id": "gpu_rtx_4090",
"model": "RTX 4090",
"price": 12083.65,
"priceList": [
{ "chain": "TRON", "coin": "USDT", "price": 12083.65 },
{ "chain": "TRON", "coin": "NEXA", "price": 12050.00 },
{ "chain": "ETH", "coin": "USDT", "price": 12020.00 },
{ "chain": "ETH", "coin": "ETH", "price": 11999.00 }
],
"saleNumbers": 64,
"saleOutNumbers": 9,
"XTM": 16.6,
"NXNA": 65.0,
"CLORE": 65.0,
"CFX": 130.0,
"IRON": 82.5,
"NEXA": 320.0,
"KLS": 82.5,
"RVN": 65.0,
"ERG": 265.0,
"XEL": 40.6,
"monthIncome": 155.00,
"maxLeaseDays": 2418
}
]
}
// 模拟数据写入动态表格(仅演示)
try{
this.dynamicMeta = arr.meta || {}
this.dynamicColumns = Array.isArray(arr.columns) ? arr.columns : []
this.dynamicRows = (Array.isArray(arr.rows) ? arr.rows : []).map(r => ({
saleNumbers: 0,
saleOutNumbers: 0,
leaseTime: 1,
purchaseQuantity: 0,
...r
}))
// 根据价格列表设置默认支付方式,确保筛选框与价格展示一致
this.ensureDefaultPayFilterFromPrices()
}catch(e){/* noop */}
// 不再使用本地模拟数据,动态表格完全依赖后端返回的 columns/rows
// 仅当路由携带 shopId 时,才发起店铺商品请求
const routeShopId =
(this.$route && this.$route.params && (this.$route.params.shopId || this.$route.params.id)) ||
@@ -569,7 +359,17 @@ export default {
},
// 切换矿机种类0-ASIC1-GPU
handleMachineTypeChange(){
// 变更类型后,重新请求数据
// 切换前清空所有已勾选状态与确认弹窗
try {
if (Array.isArray(this.dynamicRows)) {
this.dynamicRows.forEach(r => { if (r) this.$set(r, '_selected', false) })
}
if (this.confirmAddDialog) {
this.confirmAddDialog.items = []
this.confirmAddDialog.visible = false
}
} catch (e) { /* noop */ }
// 变更类型后,重新请求数据与支付方式
this.fetchGetMachineInfo(this.buildQueryParams())
this.fetchPayTypes()
// 本地记住用户选择
@@ -690,19 +490,32 @@ export default {
this.productDetailLoading = true
// 改为使用店铺机器列表接口
const res = await getShopMachineList(params)
console.log(res)
if (res && res.code === 200) {
console.log(res.data, 'res.rows');
this.total = res.total||0;
if (res && (res.code === 200 || res.code === 0)) {
const root = (res && res.data) ? res.data : res
const columns = Array.isArray(root.columns) ? root.columns : (Array.isArray(res.columns) ? res.columns : [])
const rows = Array.isArray(root.rows) ? root.rows : (Array.isArray(res.rows) ? res.rows : [])
const total = Number(root.total != null ? root.total : (res.total != null ? res.total : 0))
this.total = Number.isFinite(total) ? total : 0
// 动态表格:列与行
this.dynamicColumns = columns
this.dynamicRows = rows.map(r => ({
saleNumbers: 0,
saleOutNumbers: 0,
leaseTime: 1,
purchaseQuantity: 1,
_selected: false,
...r
}))
// 根据 rows 的 priceList 设置默认支付方式
this.ensureDefaultPayFilterFromPrices()
// 若后端同步返回支付方式,刷新本地支付方式
try {
const payList = res && res.data && res.data.payConfigList
const payList = root && root.payConfigList
if (Array.isArray(payList) && payList.length) {
this.paymentMethodList = payList
this.ensureDefaultPayFilterSelection()
}
} catch (e) { /* noop */ }
// 动态表格数据(如后端有对应 rows/columns可在此接入
// 此处保留现有动态表格的模拟/替换逻辑,不再维护旧表格数据结构
}
this.productDetailLoading = false
@@ -742,7 +555,7 @@ export default {
},
//查询购物车列表
async fetchGetGoodsList(params) {
const res = await getGoodsList(params)
const res = await getGoodsListV2(params)
// 统计当前商品在购物车中已有的机器ID用于禁用和默认勾选
try {
const productId = this.params && this.params.id ? Number(this.params.id) : Number(this.$route.params.id)
@@ -862,6 +675,16 @@ export default {
this.$set(row, '_selected', false)
return
}
// 无价格:不可选择
try {
const hasPrice = (Array.isArray(row && row.priceList) && row.priceList.some(it => it && it.price !== null && it.price !== undefined))
|| (row && row.price !== null && row.price !== undefined && row.price !== '')
if (!hasPrice) {
this.$message.warning('该机器暂无价格,无法选择')
this.$set(row, '_selected', false)
return
}
} catch (e) { /* noop */ }
const key = parentRow.id
const list = (this.selectedMap[key] && [...this.selectedMap[key]]) || []
const idx = list.findIndex(it => it && it.id === row.id)
@@ -968,7 +791,7 @@ export default {
this.confirmAddDialog.items = picked.map(r => ({
...r,
leaseTime: Number(r.leaseTime || 1),
purchaseQuantity: Number(r.purchaseQuantity || 0)
purchaseQuantity: Number(r.purchaseQuantity || 1)
}))
this.confirmAddDialog.visible = true
},
@@ -992,11 +815,15 @@ export default {
return obj
})
const res = await addGoodsV2(payload)
if (!res || !(res.code === 0 || res.code === 200)) {
this.$message.error('部分商品加入购物车失败,请重试')
} else {
this.$message.success(`已加入 ${items.length} 台矿机到购物车`)
if (res && (res.code === 0 || res.code === 200)) {
this.$message({
message: `已加入 ${items.length} 台矿机到购物车`,
type: 'success',
duration: 3000,
showClose: true
})
}
this.confirmAddDialog.visible = false
// 清空勾选
try {