myfun.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. if (!url) {
  49. return this.$toast('该功能暂未开放,敬请期待!');
  50. }
  51. let params = "";
  52. if (json) {
  53. params = [];
  54. let da = Object.keys(json).map(function (key) {
  55. if (json[key]) return encodeURIComponent(key) + "=" + encodeURIComponent(json[key]);
  56. });
  57. da.forEach(e => {
  58. if (e) params.push(e)
  59. });
  60. params = params.join("&")
  61. }
  62. uni.navigateTo({ url: url + '?' + params });
  63. }
  64. // tidyTpye
  65. export function tidyTpye(va) {
  66. let a = Number(va)
  67. switch (a) {
  68. case 1: return "数智云店";
  69. case 2: return "批发专区";
  70. case 3: return "云宝货易";
  71. case 4: return "享好物";//消费券电商
  72. case 5: return "贡献值兑换";
  73. case 6: return "天天捡漏";
  74. case 7: return "消费券兑换";
  75. case 8: return "OE兑换";
  76. default: return ""
  77. }
  78. }
  79. export function hotelStarf(va) {
  80. switch (va) {
  81. case 1: return "一星级";
  82. case 2: return "二星级";
  83. case 3: return "三星级";
  84. case 4: return "四星级";
  85. case 5: return "五星级";
  86. case 6: return "经济型";
  87. case 7: return "舒适型";
  88. case 8: return "高档型";
  89. case 9: return "豪华型";
  90. default: return ""
  91. }
  92. }
  93. // json对象数组按照某个属性排序:降序排列
  94. let compareDesc = (propertyName) => {
  95. return function (object1, object2) {
  96. var value1 = object1[propertyName];
  97. var value2 = object2[propertyName];
  98. if (value2 < value1) {
  99. return -1;
  100. } else if (value2 > value1) {
  101. return 1;
  102. } else {
  103. return 0;
  104. }
  105. }
  106. }
  107. // json对象数组按照某个属性排序:升序排列
  108. let compareAsc = (propertyName) => {
  109. return function (object1, object2) {
  110. var value1 = object1[propertyName];
  111. var value2 = object2[propertyName];
  112. if (value2 < value1) {
  113. return 1;
  114. } else if (value2 > value1) {
  115. return -1;
  116. } else {
  117. return 0;
  118. }
  119. }
  120. }
  121. // json排序
  122. export function Desc(arr = [], key = "id") {
  123. return arr.sort(compareDesc(key));
  124. }
  125. export function Asc(arr = [], key = "id") {
  126. return arr.sort(compareAsc(key));
  127. }
  128. // 判断今明后天
  129. export function getThatDay(d) {
  130. var td = new Date();
  131. td = new Date(td.getFullYear(), td.getMonth(), td.getDate());
  132. var od = new Date(d);
  133. od = new Date(od.getFullYear(), od.getMonth(), od.getDate());
  134. var xc = (od - td) / 1000 / 60 / 60 / 24;
  135. if (xc == 0) {
  136. return "今天";
  137. } else if (xc < 2) {
  138. return "明天";
  139. } else if (xc < 3) {
  140. return "后天";
  141. } else {
  142. return "";
  143. }
  144. }
  145. // 计算两个日期之间的天数
  146. export function getDaysBetween(dateString1, dateString2) {
  147. var startDate = Date.parse(dateString1);
  148. var endDate = Date.parse(dateString2);
  149. if (startDate > endDate) {
  150. return 0;
  151. }
  152. if (startDate == endDate) {
  153. return 1;
  154. }
  155. var days = (endDate - startDate) / (1 * 24 * 60 * 60 * 1000);
  156. return days;
  157. }
  158. // 轻提示
  159. export function toast(msg, duration) {
  160. uni.showToast({
  161. title: msg,
  162. icon: "none",
  163. duration: duration ? duration : 1500,
  164. });
  165. }
  166. export const showModal = ({ content, showCancel = true, confirmText = '确定' }) => {
  167. return new Promise((resolve, reject) => {
  168. uni.showModal({
  169. title: '提示',
  170. content: content,
  171. showCancel,
  172. confirmText,
  173. success: (res) => {
  174. resolve(res)
  175. },
  176. fail: (err) => {
  177. reject(err)
  178. }
  179. })
  180. })
  181. }
  182. export const showLoading = ({ title }) => {
  183. return uni.showLoading({
  184. title,
  185. mask: true
  186. })
  187. }