| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- // 返回两个日期之间的月份
- export function getDiffDate(minDate, maxDate) {
- let startDate = new Date(minDate.replace(/-/g, '/'));
- let endDate = new Date(maxDate.replace(/-/g, '/'));
- let months = [];
- //把时间的天数都设置成当前月第一天
- startDate.setDate(1)
- endDate.setDate(1)
- // new Date(yyyy-MM-dd) 不知为何有时候小时是 08 有时候是00
- endDate.setHours(0)
- startDate.setHours(0)
- while (endDate.getTime() >= startDate.getTime()) {
- let year = startDate.getFullYear();
- let month = startDate.getMonth() + 1;
- //加一个月
- startDate.setMonth(month)
- if (month.toString().length == 1) {
- month = "0" + month;
- }
- months.push(year + "-" + month)
- }
- return months;
- }
- // 时间格式化
- export function times(date, ym) {
- date = new Date(date.replace(/-/g, '/'));
- var y = date.getFullYear();
- var m = date.getMonth() + 1;
- m = m < 10 ? "0" + m : m;
- var d = date.getDate();
- d = d < 10 ? "0" + d : d;
- var h = date.getHours();
- h = h < 10 ? "0" + h : h;
- var minute = date.getMinutes();
- minute = minute < 10 ? "0" + minute : minute;
- var second = date.getSeconds();
- second = second < 10 ? "0" + second : second;
- if (ym == "ym") {
- return y + "-" + m;
- }
- else if (ym == "ymd") {
- return y + "-" + m + "-" + d;
- }
- else if (ym == "ymds") {
- return y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + second;
- }
- }
- // 将rgb颜色转成hex
- export function RtoH(color) {
- var rgb = color.split(',');
- var r = parseInt(rgb[0].split('(')[1]);
- var g = parseInt(rgb[1]);
- var b = parseInt(rgb[2].split(')')[0]);
- var hex = "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
- return hex;
- }
- // 将hex颜色转成rgb
- export function HtoR(hex, opacity) {
- var RGBA = "rgba(" + parseInt("0x" + hex.slice(1, 3)) + "," + parseInt("0x" + hex.slice(3, 5)) + "," + parseInt("0x" + hex.slice(5, 7)) + "," + opacity + ")";
- // return { red: parseInt("0x" + hex.slice(1, 3)), green: parseInt("0x" + hex.slice(3, 5)), blue: parseInt("0x" + hex.slice(5, 7)), rgba: RGBA }
- return RGBA;
- }
- // 189 **** 0222
- export function phoneNumA(value) {
- if (value && value.length > 8) {
- return `${value.substring(0, 3)} ${"*".repeat(value.length - 7).replace(/(.{4})/g, "$1 ")}${value.length % 4 ? " " : ""}${value.slice(-4)}`;
- }
- return value;
- }
- // goto
- export function goto(url, json) {
- let params = "";
- if (json) {
- params = [];
- let da = Object.keys(json).map(function (key) {
- if (json[key]) return encodeURIComponent(key) + "=" + encodeURIComponent(json[key]);
- });
- da.forEach(e => {
- if (e) params.push(e)
- });
- params = params.join("&")
- }
- uni.navigateTo({
- url: url + '?' + params
- });
- }
- // tidyTpye
- export function tidyTpye(va) {
- switch (va) {
- case '1': return "零售专区";
- case '2': return "批发专区";
- case '3': return "精品优选";
- case '4': return "今日值得买";
- case '5': return "茶宝兑换";
- case '6': return "天天捡漏";
- default: return ""
- }
- }
|