myfun.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // 返回两个日期之间的月份
  2. export function getDiffDate(minDate, maxDate) {
  3. let startDate = new Date(minDate.replace(/-/g, '/'));
  4. let endDate = new Date(maxDate.replace(/-/g, '/'));
  5. let months = [];
  6. //把时间的天数都设置成当前月第一天
  7. startDate.setDate(1)
  8. endDate.setDate(1)
  9. // new Date(yyyy-MM-dd) 不知为何有时候小时是 08 有时候是00
  10. endDate.setHours(0)
  11. startDate.setHours(0)
  12. while (endDate.getTime() >= startDate.getTime()) {
  13. let year = startDate.getFullYear();
  14. let month = startDate.getMonth() + 1;
  15. //加一个月
  16. startDate.setMonth(month)
  17. if (month.toString().length == 1) {
  18. month = "0" + month;
  19. }
  20. months.push(year + "-" + month)
  21. }
  22. return months;
  23. }
  24. // 将rgb颜色转成hex
  25. export function RtoH(color) {
  26. var rgb = color.split(',');
  27. var r = parseInt(rgb[0].split('(')[1]);
  28. var g = parseInt(rgb[1]);
  29. var b = parseInt(rgb[2].split(')')[0]);
  30. var hex = "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
  31. return hex;
  32. }
  33. // 将hex颜色转成rgb
  34. export function HtoR(hex, opacity) {
  35. var RGBA = "rgba(" + parseInt("0x" + hex.slice(1, 3)) + "," + parseInt("0x" + hex.slice(3, 5)) + "," + parseInt("0x" + hex.slice(5, 7)) + "," + opacity + ")";
  36. // return { red: parseInt("0x" + hex.slice(1, 3)), green: parseInt("0x" + hex.slice(3, 5)), blue: parseInt("0x" + hex.slice(5, 7)), rgba: RGBA }
  37. return RGBA;
  38. }
  39. // 189 **** 0222
  40. export function phoneNumA(value) {
  41. if (value && value.length > 8) {
  42. return `${value.substring(0, 3)} ${"*".repeat(value.length - 7).replace(/(.{4})/g, "$1 ")}${value.length % 4 ? " " : ""}${value.slice(-4)}`;
  43. }
  44. return value;
  45. }
  46. // goto
  47. export function goto(url, json) {
  48. let params = "";
  49. if (json) {
  50. params = [];
  51. let da = Object.keys(json).map(function (key) {
  52. if (json[key]) return encodeURIComponent(key) + "=" + encodeURIComponent(json[key]);
  53. });
  54. da.forEach(e => {
  55. if (e) params.push(e)
  56. });
  57. params = params.join("&")
  58. }
  59. uni.navigateTo({
  60. url: url + '?' + params
  61. });
  62. }
  63. // tidyTpye
  64. export function tidyTpye(va) {
  65. switch (va) {
  66. case '1': return "零售专区";
  67. case '2': return "批发专区";
  68. case '3': return "精品优选";
  69. case '4': return "甄选好物";
  70. case '5': return "茶宝兑换";
  71. case '6': return "天天捡漏";
  72. default: return ""
  73. }
  74. }