Skip to content

Commit

Permalink
fix:物品价格 物价接口替换 #38
Browse files Browse the repository at this point in the history
  • Loading branch information
fifthThirteen committed Sep 3, 2024
1 parent 9c83247 commit 79f77ba
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 156 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@jx3box/jx3box-comment-ui": "^1.9.9",
"@jx3box/jx3box-common": "^8.2.24",
"@jx3box/jx3box-common-ui": "^8.9.16",
"@jx3box/jx3box-data": "^3.6.4",
"@jx3box/jx3box-data": "^3.6.5",
"@jx3box/jx3box-dict": "^2.1.1",
"@jx3box/jx3box-editor": "^2.2.15",
"@jx3box/jx3box-map": "^0.2.0",
Expand Down
110 changes: 37 additions & 73 deletions src/components/item/item-price-chart.vue
Original file line number Diff line number Diff line change
@@ -1,110 +1,76 @@
<template>
<div class="m-item-price-logs">
<!-- 今日价格 -->
<!--近30日价格-->
<el-row class="m-today" v-if="currentPrice">
<el-col :span="8">
<div class="u-label">
<i class="el-icon-right u-avg"></i> 今日均价
</div>
<div class="u-label"><i class="el-icon-right u-avg"></i> 近30日均价</div>
<div class="u-value u-avg">
<GamePrice :price="currentPrice.AvgPrice" />
<GamePrice :price="currentPrice.avg" />
</div>
</el-col>
<el-col :span="8">
<div class="u-label">
<i class="el-icon-bottom u-min"></i> 今日最低价
</div>
<div class="u-label"><i class="el-icon-bottom u-min"></i> 近30日最低价</div>
<div class="u-value u-min">
<GamePrice :price="currentPrice.LowestPrice" />
<GamePrice :price="currentPrice.lower" />
</div>
</el-col>
<el-col :span="8">
<div class="u-label">
<i class="el-icon-top u-max"></i> 今日最高价
</div>
<div class="u-label"><i class="el-icon-top u-max"></i> 近30日最高价</div>
<div class="u-value u-max">
<GamePrice :price="currentPrice.HighestPrice" />
<GamePrice :price="currentPrice.higher" />
</div>
</el-col>
</el-row>

<div v-show="!hidden" id="m-item-price-chart" />
<div v-show="!logs.length" style="text-align:center">🐖 暂无记录</div>
<div v-show="!logs.length" style="text-align: center">🐖 暂无记录</div>
</div>
</template>

<script>
import { Chart } from "@antv/g2";
import {
get_item_price_logs,
get_item_servers_price_logs,
} from "@/service/item";
import { get_item_prices } from "@/service/item";
import GamePrice from "@jx3box/jx3box-common-ui/src/wiki/GamePrice.vue";
import dayjs from "dayjs";
export default {
name: "ItemPriceChart",
props: ["item_id", "server"],
data() {
return {
today: null,
yesterday: null,
logs: [],
chart: null,
hidden: false,
currentPrice: {},
};
},
computed: {
currentPrice({ today, yesterday }) {
return today || yesterday || null
}
},
methods: {
get_data() {
if (this.item_id) {
if (this.server) {
get_item_price_logs(this.item_id, {
server: this.server,
}).then((data) => {
data = data.data;
let output = [];
for (let i in data.data.logs) {
let log = data.data.logs[i];
output.push({
date: log.Date,
price: log.AvgPrice,
type: "均价",
});
output.push({
date: log.Date,
price: log.LowestPrice,
type: "最低价",
});
output.push({
date: log.Date,
price: log.HighestPrice,
type: "最高价",
});
}
this.today = data.data.today;
this.yesterday = data.data.yesterday;
this.logs = output;
this.hidden = !(this.logs.length > 0);
});
} else {
get_item_servers_price_logs(this.item_id).then((data) => {
data = data.data;
this.today = null;
this.yesterday = null;
this.logs = (data.data?.logs || []).map((item)=>{
return {
server: item.Server,
price: item.AvgPrice,
date: item.Date
}
});
this.hidden = !(this.logs.length > 0);
get_item_prices({
item_id: this.item_id,
server: this.server,
aggregate_type: "daily",
}).then((res) => {
const data = res.data || [];
this.logs = data.map((item) => {
return {
type: "价格",
date: dayjs(item.date).format("YYYY-MM-DD"),
price: item.price,
};
});
}
const prices = this.logs.map((item) => item.price);
const len = prices.length;
this.currentPrice = {
avg:
prices.reduce((acc, cur) => {
return acc + cur;
}, 0) / len,
lower: Math.min(...prices),
higher: Math.max(...prices),
};
this.hidden = !len;
});
}
},
render() {
Expand All @@ -115,7 +81,7 @@ export default {
width: "100%",
height: 300,
});
}else{
} else {
this.chart.clear();
}
Expand All @@ -141,9 +107,7 @@ export default {
shared: true,
customItems: (items) => {
for (let index = 0; index < items.length; index++) {
items[index].value = this.$options.filters.item_price(
items[index].value
);
items[index].value = this.$options.filters.item_price(items[index].value);
}
return items;
},
Expand Down
24 changes: 11 additions & 13 deletions src/components/item/item-prices.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
<th>等级</th>
<th>上传时间</th>
<th>服务器</th>
<th style="text-align: right">一口价 (总价)</th>
<th style="text-align: right">一口价 (单价)</th>
<th style="text-align: right">一口价</th>
</tr>
<tr v-for="(price, key) in prices" :key="key">
<td>
Expand All @@ -25,10 +24,9 @@
></span>
</td>
<td v-text="item && item.RequireLevel ? item.RequireLevel : 1"></td>
<td v-text="dayjs(price.created*1000).format('YYYY-MM-DD HH:mm:ss')"></td>
<td v-text="price.hour + ''"></td>
<td v-text="price.server"></td>
<td style="text-align: right" v-text="item_price(price.n_money)"></td>
<td style="text-align: right" v-text="item_price(price.unit_price)"></td>
<td style="text-align: right" v-text="item_price(price.price)"></td>
</tr>
</table>

Expand All @@ -53,7 +51,7 @@ export default {
};
},
computed: {
client: function() {
client: function () {
return this.$store.state.client;
},
},
Expand All @@ -62,23 +60,23 @@ export default {
get_data() {
if (this.item_id) {
this.priceLoading = true;
get_item_prices(this.item_id, {
get_item_prices({
item_id: this.item_id,
server: this.server,
limit: 15,
}).then((data) => {
aggregate_type: "hourly",
}).then((res) => {
this.priceLoading = false;
data = data.data;
this.prices = data.data.prices.sort((a,b)=> a.created + b.created) || [];
const data = res.data || [];
this.prices = data;
});
// 获取物品信息
get_item(this.item_id).then((data) => {
data = data.data;
this.item = data.data.item;
});
}
},
icon_url: function(id) {
icon_url: function (id) {
return iconLink(id, this.client);
},
item_price,
Expand Down
83 changes: 34 additions & 49 deletions src/components/item/price-chart.vue
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<template>
<div class="m-item-price-logs">
<!-- 今日价格 -->
<el-row class="m-today" v-if="today">
<!--近30日价格-->
<el-row class="m-today" v-if="currentPrice">
<el-col :span="8">
<div class="u-label"><i class="el-icon-right u-avg"></i> 今日均价</div>
<div class="u-label"><i class="el-icon-right u-avg"></i> 近30日均价</div>
<div class="u-value u-avg">
<GamePrice :price="today.price" />
<GamePrice :price="currentPrice.avg" />
</div>
</el-col>
<el-col :span="8">
<div class="u-label"><i class="el-icon-bottom u-min"></i> 今日最低价</div>
<div class="u-label"><i class="el-icon-bottom u-min"></i> 近30日最低价</div>
<div class="u-value u-min">
<GamePrice :price="today.min_price" />
<GamePrice :price="currentPrice.lower" />
</div>
</el-col>
<el-col :span="8">
<div class="u-label"><i class="el-icon-top u-max"></i> 今日最高价</div>
<div class="u-label"><i class="el-icon-top u-max"></i> 近30日最高价</div>
<div class="u-value u-max">
<GamePrice :price="today.max_price" />
<GamePrice :price="currentPrice.higher" />
</div>
</el-col>
</el-row>
Expand Down Expand Up @@ -51,64 +51,49 @@

<script>
import { Chart } from "@antv/g2";
import { get_item_servers_price_logs } from "@/service/item";
import { get_item_prices } from "@/service/item";
import GamePrice from "@/components/game-price.vue";
import item_price from "@/utils/item-price.js";
import dayjs from "dayjs";
export default {
name: "ItemPriceChart",
props: ["item_id", "server"],
data() {
return {
today: null,
yesterday: null,
logs: [],
chart: null,
hidden: false,
currentPrice: {},
};
},
methods: {
get_data() {
if (this.item_id) {
get_item_servers_price_logs(this.item_id, {
get_item_prices({
item_id: this.item_id,
server: this.server,
}).then((data) => {
data = data.data;
let output = [];
if (this.server) {
for (let i in data.data.logs) {
let log = data.data.logs[i];
output.push({
date: log.Date,
price: log.AvgPrice,
type: "均价",
});
output.push({
date: log.Date,
price: log.LowestPrice,
type: "最低价",
});
output.push({
date: log.Date,
price: log.HighestPrice,
type: "最高价",
});
}
} else {
for (let i in data.data.logs) {
let log = data.data.logs[i];
output.push({
date: log.Date,
price: log.AvgPrice,
server: log.Server,
});
}
}
this.today = null;
this.yesterday = null;
this.logs = output;
aggregate_type: "daily",
}).then((res) => {
const data = res.data || [];
this.logs = data.map((item) => {
return {
type: "价格",
date: dayjs(item.date).format("YYYY-MM-DD"),
price: item.price,
};
});
const prices = this.logs.map((item) => item.price);
const len = prices.length;
this.currentPrice = {
avg:
prices.reduce((acc, cur) => {
return acc + cur;
}, 0) / len,
lower: Math.min(...prices),
higher: Math.max(...prices),
};
this.render();
this.hidden = !(this.logs.length > 0);
this.hidden = !len;
});
}
},
Expand Down
Loading

0 comments on commit 79f77ba

Please sign in to comment.