123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- import dayjs from 'dayjs'
- import duration from 'dayjs/plugin/duration'
- dayjs.extend(duration);
- const systemInfo = uni.getSystemInfoSync();
- const Language = systemInfo.language == 'zh_CN' ? 'zh' : 'en'
- const 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();
- return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(
- ':');
- };
- const getLocation = async () => {
- let res = await uni.getLocation({
- type: 'wgs84',
-
-
-
-
- });
- return res[1]
- }
- const msg = (str) => {
- uni.showToast({
- title: str,
- icon:'none'
- })
- }
- function getRemainingTime(startTime, endTime,type = 0) {
-
- const start = dayjs(startTime);
- const end = dayjs(endTime);
-
- const diff = dayjs.duration(end.diff(start));
-
- if (diff.asMinutes() < 1) {
- return '<小于1分钟';
- }
-
- const days = diff.days();
- const hours = diff.hours();
- const minutes = diff.minutes();
- if(type){
- return {
- days,
- hours,
- minutes,
- }
- }
-
- return `${days}天${hours}小时${minutes}分`;
- }
- function fenToYuan(fen) {
- const roundedFen = Math.round(Number(fen));
- return Number((roundedFen / 100).toFixed(2));
- }
- const strJoin = (str) => {
- if (!str) return []
- return JSON.parse(str)
- }
- const formatNumber = (n) => {
- n = n.toString();
- return n[1] ? n : '0' + n;
- };
- function isEmail(email) {
- if(!email) return false
-
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
- return emailRegex.test(email);
- }
- module.exports = {
- Language,
- isEmail,
- formatTime: formatTime,
- getLocation,
- msg,
- strJoin,
- fenToYuan,
- getRemainingTime
- };
|