| | |
| | | import moment from 'moment'; |
| | | import Taro from '@tarojs/taro'; |
| | | |
| | | moment.locale('zh-cn'); |
| | | |
| | | export class Tools { |
| | | /** |
| | | * 显示消息 |
| | |
| | | * @return {string} |
| | | */ |
| | | static createGUID() { |
| | | return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { |
| | | return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { |
| | | let r = (Math.random() * 16) | 0, |
| | | v = c === 'x' ? r : (r & 0x3) | 0x8; |
| | | return v.toString(16); |
| | |
| | | /** |
| | | * 数值转换为金钱格式 |
| | | * @param {Number|String} number |
| | | * @param {String} [forRead=''] 便于阅读财务金额模式 |
| | | * @return {string} |
| | | */ |
| | | static moneyFormat(number) { |
| | | static moneyFormat(number, forRead = '') { |
| | | if (!number && typeof number !== 'number' && typeof number !== 'string') { |
| | | return ''; |
| | | } |
| | | if (typeof number === 'string') { |
| | | number = Number(number) || 0; |
| | | } |
| | | return number.toFixed(2); |
| | | if (forRead === 'forRead') { |
| | | return number.toLocaleString('zh-cn', { |
| | | minimumFractionDigits: 2, |
| | | maximumFractionDigits: 2, |
| | | }); |
| | | } else { |
| | | return number.toFixed(2); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return {String} |
| | | */ |
| | | static transWeekIndexToDate(year, week, weekDay) { |
| | | const yearStart = moment([year, 0, 1]); |
| | | const dayLong = 24 * 60 * 60 * 1000; |
| | | const firstWeekLong = (7 - yearStart.day()) * dayLong; |
| | | const weeksLong = (week - 1) * 7 * dayLong; |
| | | const weekDayLong = weekDay * dayLong; |
| | | const dayTimestamp = yearStart.valueOf() + firstWeekLong + weeksLong + weekDayLong; |
| | | return moment(dayTimestamp).format('YYYY-MM-DD'); |
| | | if (weekDay < 1 && weekDay > 7) { |
| | | return ''; |
| | | } |
| | | const weekDate = moment(year + '-' + week, 'YYYY-WW'); |
| | | const firstDay = weekDate.startOf('week'); |
| | | return firstDay.add(weekDay - 1, 'day').format('YYYY-MM-DD'); |
| | | } |
| | | |
| | | /** |
| | |
| | | console.info(Math.round(px) + 'px'); |
| | | }; |
| | | } |
| | | |