import Vue from 'vue' import * as api from '@/api/api' import { isURL } from '@/utils/validate' import { ACCESS_TOKEN } from '@/store/mutation-types' import onlineCommons from '@jeecg/antd-online-mini' /** * 时间格式化 * @param value * @param fmt * @returns {*} */ export function myFormatDate(date, fmt) { var o = { "M+": date.getMonth() + 1, //月份 "d+": date.getDate(), //日 "h+": date.getHours(), //小时 "m+": date.getMinutes(), //分 "s+": date.getSeconds(), //秒 "q+": Math.floor((date.getMonth() + 3) / 3), //季度 "S": date.getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length)); } for (var k in o) { if (new RegExp("(" + k + ")").test(fmt)) { fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); } } return fmt; } /** * 获取小数点配置:单价 4位,金额2位,重量 2位,体积 3位。 * 成衣 整数,面料2位,辅料待确认。PCS整数,M/KG 2位 * 件数/箱 整数? * masterMetering:单位 */ export function getDotConfig(masterMetering){ var config = { price : 4, // 单价 money : 2, // 金额 weight : 2, // 重量 volume : 3, // 体积 quantity : 0 // 数量 }; if (masterMetering =="PCS"){ config.quantity = 0; }else if (masterMetering =="M/KG"){ config.quantity = 2; } return config; } /** * 获取小数点位数的正则表达式,支持0~4位小数 * dot 小数点位数 */ export function getDotValidExpress(dot){ if (dot == 0){ return {pattern: /^[1-9]\d*$/, message: '请输入零以上的正整数' }; } else if (dot == 1){ return {pattern: /^\d+(\.\d{1})?$/, message: '小数点位数不能超过1位' }; } else if (dot == 2){ return {pattern: /^\d+(\.\d{1,2})?$/, message: '小数点位数不能超过2位' }; } else if (dot == 3){ return {pattern: /^\d+(\.\d{1,3})?$/, message: '小数点位数不能超过3位' }; } else if (dot == 4){ return {pattern: /^\d+(\.\d{1,4})?$/, message: '小数点位数不能超过4位' }; } return {}; }