helper.js
3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
export async function wechatShareSetting(axios, store, shareConfig = {
title: `借条100`, // 分享标题
link: `https://www.51liuliang.cc/netiou`,
imgUrl: 'https://www.51liuliang.cc/netiou/logo1.png',
desc: '',
success: function () {},
cancel: function () {}
}) {
const u = navigator.userAgent
const isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
let {data} = await axios.post(`/wechatTicket`, {
userId: store.state.user.id,
href: isiOS ? store.state.firstUrl : window.location.href
})
if (data.success) {
window.wx.config({
debug: false,
appId: data.config.appId, // 必填,公众号的唯一标识
timestamp: data.config.timestamp, // 必填,生成签名的时间戳
nonceStr: data.config.nonceStr, // 必填,生成签名的随机串
signature: data.config.signature,// 必填,签名
jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage'] // 必填,需要使用的JS接口列表
})
window.wx.ready(() => {
window.wx.onMenuShareTimeline(shareConfig)
window.wx.onMenuShareAppMessage(shareConfig)
})
window.wx.error(function(res){
console.log(res)
})
}
}
export function testIOSVersion() {
const u = navigator.userAgent.toLowerCase()
const ver = u.match(/cpu iphone os (.*?) like mac os/)
if (!ver) {
return true
} else {
return (parseFloat(ver[1].replace(/_/g,".")) < 10 ? false : true)
}
}
/**
* 获取YYYY-MM-DD格式的字符串
* @param {string} source 日期字符串
*/
export function dateParse(source) {
let date = source ? new Date(source) : new Date()
const year = date.getFullYear()
let month = date.getMonth() + 1
let day = date.getDate()
month = month < 10 ? '0'+ month : month
day = day < 10 ? '0'+ day : day
return `${year}-${month}-${day}`
}
/**
* 利息计算(不含违约金)
* @param {float} amount 借款金额
* @param {float} rate 利率
* @param {string} start 借款起始日期 YYYY-MM-DD
* @param {string} end 借款结束日期 YYYY-MM-DD
*/
export function interest(amount, rate, start, end) {
if (!start || !end) return 0
start = new Date(start).getTime()
end = new Date(end).getTime()
let gap = Math.floor((end - start) / (1000 * 60 * 60 * 24))
gap = gap > 0 ? gap : 0
return Math.round(amount * rate / 365 * gap * 100) / 100
}
/**
* 利息计算(含违约金)
* @param {float} amount 借款金额
* @param {float} rate 利率
* @param {string} start 借款起始日期 YYYY-MM-DD
* @param {string} end 借款结束日期 YYYY-MM-DD
*/
export function interestWithDamage(amount, rate, start, end) {
if (!start || !end) return 0
let now = new Date().getTime()
start = new Date(start).getTime()
end = new Date(end).getTime()
let gap = (end - start) / (1000 * 60 * 60 * 24)
gap = gap > 0 ? gap : 0
let overdue
if (now <= end) {
overdue = 0
} else {
overdue = Math.floor((now - end) / (1000 * 60 * 60 * 24))
}
return Math.round((amount * rate / 365 * gap + amount * 0.24 / 365 * overdue) * 100) / 100
}