myutil.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import Vue from 'vue'
  2. import * as api from '@/api/api'
  3. import {
  4. isURL
  5. } from '@/utils/validate'
  6. import {
  7. ACCESS_TOKEN
  8. } from '@/store/mutation-types'
  9. import onlineCommons from '@jeecg/antd-online-mini'
  10. /**
  11. * 时间格式化
  12. * @param value
  13. * @param fmt
  14. * @returns {*}
  15. */
  16. export function myFormatDate(date, fmt) {
  17. var o = {
  18. "M+": date.getMonth() + 1, //月份
  19. "d+": date.getDate(), //日
  20. "h+": date.getHours(), //小时
  21. "m+": date.getMinutes(), //分
  22. "s+": date.getSeconds(), //秒
  23. "q+": Math.floor((date.getMonth() + 3) / 3), //季度
  24. "S": date.getMilliseconds() //毫秒
  25. };
  26. if (/(y+)/.test(fmt)) {
  27. fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
  28. }
  29. for (var k in o) {
  30. if (new RegExp("(" + k + ")").test(fmt)) {
  31. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  32. }
  33. }
  34. return fmt;
  35. }
  36. /**
  37. * 获取小数点配置:单价 4位,金额2位,重量 2位,体积 3位。
  38. * 成衣 整数,面料2位,辅料待确认。PCS整数,M/KG 2位
  39. * 件数/箱 整数?
  40. * masterMetering:单位
  41. */
  42. export function getDotConfig(masterMetering){
  43. var config = {
  44. price : 4, // 单价
  45. money : 2, // 金额
  46. weight : 2, // 重量
  47. volume : 3, // 体积
  48. quantity : 0 // 数量
  49. };
  50. if (masterMetering =="PCS"){
  51. config.quantity = 0;
  52. }else if (masterMetering =="M/KG"){
  53. config.quantity = 2;
  54. }
  55. return config;
  56. }
  57. /**
  58. * 获取小数点位数的正则表达式,支持0~4位小数
  59. * dot 小数点位数
  60. */
  61. export function getDotValidExpress(dot){
  62. if (dot == 0){
  63. return {pattern: /^[1-9]\d*$/, message: '请输入零以上的正整数' };
  64. } else if (dot == 1){
  65. return {pattern: /^\d+(\.\d{1})?$/, message: '小数点位数不能超过1位' };
  66. } else if (dot == 2){
  67. return {pattern: /^\d+(\.\d{1,2})?$/, message: '小数点位数不能超过2位' };
  68. } else if (dot == 3){
  69. return {pattern: /^\d+(\.\d{1,3})?$/, message: '小数点位数不能超过3位' };
  70. } else if (dot == 4){
  71. return {pattern: /^\d+(\.\d{1,4})?$/, message: '小数点位数不能超过4位' };
  72. }
  73. return {};
  74. }