Authored by baoss

添加个人中心多个接口请求

... ... @@ -20,7 +20,7 @@ import scroll from './components/scroll';
import { createNamespacedHelpers } from 'vuex';
const {mapState} = createNamespacedHelpers('home/mine');
const {mapState, mapActions} = createNamespacedHelpers('home/mine');
export default {
data() {
return {
... ... @@ -36,9 +36,24 @@ export default {
}
},
computed:{
...mapState({
username: state => state.username
})
...mapState([
'favoriteNum',
'buyNum'
])
},
created() {
this.fetchResource()
this.fetchFavoriteNum()
this.fetchOrderSummary().then(data => {
console.log(data)
})
this.fetchSellerOrder()
this.fetchAssets().then(data => {
console.log(data)
})
},
methods: {
...mapActions(['fetchFavoriteNum','fetchResource','fetchSellerOrder','fetchOrderSummary', 'fetchAssets'])
},
components: {
tabItem,
... ...
import { parseAssetList, maskAccount } from '../../utils/mine-handler';
import { get, set } from 'lodash';
import { getImgUrl } from '../../common/utils';
const uid = '600046428';
const MINE_RESOURCE_CODE1 = '11a73219a63b50067d88e75c0fe04d10';
const MINE_RESOURCE_CODE2 = 'dc2731fbbebcba6329c74a379e9c41ec';
export default function() {
return {
namespaced: true,
state: {
animate: false,
rollNoticeList: [],
orderSum: {
sellerNum: 0,
readyNum: 0,
sentNum: 0,
finishNum: 0,
failNum: 0
},
favoriteNum: 0,
buyNum: 0,
assetData: {
list: [],
currentPage: 1,
endReached: false,
compensateIncome: 0,
goodsIncome: 0,
totalIncome: 0
},
resource1: {},
resource2: {}
},
mutations: {
addList(state, { list }) {
... ... @@ -16,6 +42,47 @@ export default function() {
state.rollNoticeList.push(state.rollNoticeList[0]);
state.rollNoticeList.shift();
state.animate = false;
},
addSellerOrder(state, { orderSumList }) {
let orderSum = {};
orderSumList.forEach((item) => {
switch (item.listType) {
case 1:
orderSum.sellerNum = item.sum;
break;
case 2:
orderSum.readyNum = item.sum;
break;
case 3:
orderSum.sentNum = item.sum;
break;
case 5:
orderSum.finishNum = item.sum;
break;
case 6:
orderSum.failNum = item.sum;
break;
default:
break;
}
});
state.orderSum = Object.assign({}, state.orderSum, orderSum);
},
addFavoriteNum(state, {count}) {
state.favoriteNum = count;
},
addOrderSummary(state, {count}) {
state.buyNum = count;
},
addAssets(state, assetData) {
state.assetData = Object.assign({}, state.assetData, assetData);
},
addResource(state, {resource1 = {}, resource2 = {}}) {
state.resource1 = Object.assign({}, state.resource1, resource1);
state.resource2 = Object.assign({}, state.resource1, resource2);
}
},
actions: {
... ... @@ -33,6 +100,65 @@ export default function() {
commit('animateHandler');
}, 500);
},
async fetchResource({commit}) {
const result = await this.$api.get('/api/ufo/mine/resource', {
content_code: MINE_RESOURCE_CODE1,
uid
});
const result1 = await this.$api.get('/api/ufo/mine/resource', {
content_code: MINE_RESOURCE_CODE2,
uid
});
if (result.code === 200) {
let src = getImgUrl(get(result, 'data[0].data[0].src') || '', 1000, 1000);
set(result, 'data[0].data[0].src', src);
commit('addResource', {resource1: result.data[0]});
}
if (result1.code === 200) {
let src = getImgUrl(get(result1, 'data[0].data[0].src') || '', 1000, 1000);
set(result1, 'data[0].data[0].src', src);
commit('addResource', {resource2: result1.data[0]});
}
},
async fetchSellerOrder({ commit }) {
const result = await this.$api.get('/api/ufo/mine/seller/orderSummary', {uid, debug: 'XYZ'});
if (result.code === 200) {
commit('addSellerOrder', { orderSumList: result.data });
}
return result.data || [];
},
async fetchFavoriteNum({ commit }) {
const result = await this.$api.get('/api/ufo/mine/favoriteNum', {uid});
if (result.code === 200) {
commit('addFavoriteNum', { count: result.data.product_favorite_total });
}
return result.data || [];
},
async fetchOrderSummary({ commit }) {
const result = await this.$api.get('/api/ufo/mine/order/summary', {uid, debug: 'XYZ'});
if (result.code === 200) {
commit('addOrderSummary', { count: result.data.buyCount });
}
return result.data || [];
},
async fetchAssets({ commit }) {
const result = await this.$api.get('/api/ufo/mine/assets', {page: 1, limit: 20, uid, debug: 'XYZ'});
if (result.code === 200) {
let assetData = parseAssetList(result.data);
commit('addAssets', assetData);
}
return result.data || [];
},
},
};
}
... ...
import moment from 'moment';
export function parseAssetList(json) {
let {
data,
page,
pagetotal,
summary
} = json;
let parsedList = data ? data.map((item) => {
let price = '';
if (item.amount !== null) {
if (item.incomeOutcome === 2) {
if (item.amount > 0) {
price = '-' + Number(Math.abs(item.amount)).toFixed(2);
} else {
price = '+' + Number(Math.abs(item.amount)).toFixed(2);
}
} else {
if (item.amount > 0) {
price += '+' + Number(Math.abs(item.amount)).toFixed(2);
} else {
price += '-' + Number(Math.abs(item.amount)).toFixed(2);
}
}
}
return {
title: item.tradeTypeDesc + '(订单号:' + item.orderCode + ')',
price: price,
tradeTypeDesc: item.tradeTypeDesc,
type: item.tradeType,
productName: item.productName,
sizeName: item.sizeName,
time: moment(new Date(item.createTime * 1000)).format('YYYY.MM.DD HH:mm'),
normalFlag: item.normalFlag,
};
}) : [];
summary = summary ? summary : {};
let endReached = parsedList.length === 0 || page === pagetotal;
return {
currentPage: page,
list: parsedList,
endReached,
compensateIncome: summary.compensateIncome,
goodsIncome: summary.goodsIncome,
totalIncome: summary.totalIncome,
};
}
export function formatNumber(number) {
return parseFloat(number) < 0 ? '-¥' + Math.abs(parseFloat(number)).toFixed(2) : '¥' + Math.abs(parseFloat(number)).toFixed(2);
}
export function maskAccount(string) {
if (/^1[3|4|5|7|8][0-9]{9}$/.test(string)) {
return string.substring(0, 3) + '****' + string.substring(7);
} else if (/^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test(string.toLowerCase())) {
if (string.indexOf('@') > 3) {
return string.substring(0, 3) + '****' + string.substring(string.lastIndexOf('@'));
} else {
return '****' + string.substring(string.lastIndexOf('@'));
}
} else if (string.length > 2) {
return string.substring(0, 1) + '****' + string.substring(string.length - 1);
}
return string.substring(0, 1) + '****';
}
... ...
... ... @@ -4,24 +4,50 @@ module.exports = {
api: 'ufo.users.rollNoticeList',
params: {}
},
'/api/ufo/mine/orderSummary': {
'/api/ufo/mine/seller/orderSummary': {
ufo: true,
api: 'ufo.seller.orderSummary',
params: {}
params: {
uid: {type: Number}
}
},
'/api/ufo/mine/favoriteNum': {
ufo: true,
api: 'ufo.user.favoriteNum',
params: {}
params: {
uid: {type: Number}
}
},
'/api/ufo/mine/depositNum': {
ufo: true,
api: 'ufo.deposit.queryUserStorageCount',
params: {}
params: {
uid: {type: Number}
}
},
'/api/ufo/mine/asssets': {
'/api/ufo/mine/assets': {
ufo: true,
api: 'ufo.asssets.details',
params: {}
params: {
uid: {type: Number},
limit: {type: Number},
page: {type: Number}
}
},
'/api/ufo/mine/order/summary': {
ufo: true,
url: '/shopping',
api: 'ufo.order.summary',
params: {
uid: {type: Number}
}
},
'/api/ufo/mine/resource': {
ufo: true,
api: 'ufo.resource.get',
params: {
content_code: { type: String },
uid: { type: Number },
}
},
};
... ...
... ... @@ -51,6 +51,7 @@
"knex": "^0.16.3",
"lodash": "^4.17.11",
"lottie-web": "^5.4.2",
"moment": "^2.24.0",
"mysql": "^2.16.0",
"nodemon": "^1.19.1",
"passport": "^0.4.0",
... ...