index.js
989 Bytes
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
function formatNumber(n) {
const str = n.toString()
return str[1] ? str : `0${str}`
}
export function formatTime(date) {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
const t1 = [year, month, day].map(formatNumber).join('/')
const t2 = [hour, minute, second].map(formatNumber).join(':')
return `${t1} ${t2}`
}
export function formatPrice(price) {
return (price / 100).toFixed(2)
}
export function startWith(src, str) {
const reg = new RegExp('^' + str)
return reg.test(src)
}
export function endWith(src, str) {
const reg = new RegExp(str + '$')
return reg.test(src)
}
export const host = 'http://linjiashop-mobile-api.microapp.store/'
export const fileMgrUrl = host + 'file/getImgStream?idFile='
export default {
formatNumber,
formatTime,
formatPrice,
startWith,
endWith,
host,
fileMgrUrl
}