Skip to content

Commit

Permalink
✨ show '1.11' as '+1.11'
Browse files Browse the repository at this point in the history
  • Loading branch information
shawjia committed Oct 28, 2018
1 parent e3c590c commit b1f00e1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
11 changes: 0 additions & 11 deletions src/app/pages/add/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,6 @@ Page({
hasTextErr: false,
},

onLoad() {
wx.cloud.callFunction({ name: 'funds' })
.then((res) => {
app.globalData.funds = res.result.funds || [];
})
.catch((err) => {
console.error(err);
throw (err);
});
},

onChange(e) {
const name = e.target.id;
const input = e.detail.trim();
Expand Down
14 changes: 9 additions & 5 deletions src/app/pages/index/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// https://developers.weixin.qq.com/miniprogram/dev/framework/app-service/page.html

import { formatPrice } from '../../utils/util';

const api = require('../../api');


const app = getApp();
let prices = {};

Expand Down Expand Up @@ -90,8 +93,9 @@ Page({
return item;
});

latestProfit = latestProfit.toFixed(2);
allProfit = allProfit.toFixed(2);
latestProfit = formatPrice(latestProfit.toFixed(2));
allProfit = formatPrice(allProfit.toFixed(2));

const latestProfitColor = latestProfit.includes('-') ? 'lose' : 'win';
const allProfitColor = allProfit.includes('-') ? 'lose' : 'win';

Expand Down Expand Up @@ -126,9 +130,9 @@ Page({
oriProfit = current - yesterday;
oriTotalProfit = current - start;

profit = oriProfit.toFixed(2);
totalProfit = oriTotalProfit.toFixed(2);
current = current.toFixed(2);
profit = formatPrice(oriProfit.toFixed(2));
totalProfit = formatPrice(oriTotalProfit.toFixed(2));
current = formatPrice(current.toFixed(2));
}

return {
Expand Down
2 changes: 2 additions & 0 deletions src/app/utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ const request = (url, data = {}, opts = {}) => new Promise((resolve, reject) =>
});

const isNumber = n => !Number.isNaN(+n);
const formatPrice = str => (str.includes('-') ? str : `+${str}`);

module.exports = {
request,
isNumber,
formatPrice,
};

0 comments on commit b1f00e1

Please sign in to comment.