export function parseTime(time, pattern) {
if (arguments.length === 0 || !time) {
const format = pattern || "{y}-{m}-{d} {h}:{i}:{s}";
if (typeof time === "object") {
if (typeof time === "string" && /^[0-9]+$/.test(time)) {
} else if (typeof time === "string") {
.replace(new RegExp(/-/gm), "/")
.replace(new RegExp(/\.[\d]{3}/gm), "");
if (typeof time === "number" && time.toString().length === 10) {
const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
let value = formatObj[key];
return ["日", "一", "二", "三", "四", "五", "六"][value];
if (result.length > 0 && value < 10) {
export function resetForm(refName) {
if (this.$refs[refName]) {
this.$refs[refName].resetFields();
export function addDateRange(params, dateRange, propName) {
typeof search.params === "object" &&
search.params !== null &&
!Array.isArray(search.params)
dateRange = Array.isArray(dateRange) ? dateRange : [];
if (typeof propName === "undefined") {
search.params["beginTime"] = dateRange[0];
search.params["endTime"] = dateRange[1];
search.params["begin" + propName] = dateRange[0];
search.params["end" + propName] = dateRange[1];
export function selectDictLabel(datas, value) {
if (value === undefined) {
Object.keys(datas).some((key) => {
if (datas[key].value == "" + value) {
actions.push(datas[key].label);
if (actions.length === 0) {
export function selectDictLabels(datas, value, separator) {
if (value === undefined) {
var currentSeparator = undefined === separator ? "," : separator;
var temp = value.split(currentSeparator);
Object.keys(value.split(currentSeparator)).some((val) => {
Object.keys(datas).some((key) => {
if (datas[key].value == "" + temp[val]) {
actions.push(datas[key].label + currentSeparator);
actions.push(temp[val] + currentSeparator);
return actions.join("").substring(0, actions.join("").length - 1);
export function sprintf(str) {
str = str.replace(/%s/g, function () {
if (typeof arg === "undefined") {
export function parseStrEmpty(str) {
if (!str || str == "undefined" || str == "null") {
export function mergeRecursive(source, target) {
if (target[p].constructor == Object) {
source[p] = mergeRecursive(source[p], target[p]);
export function handleTree(data, id, parentId, children) {
parentId: parentId || "parentId",
childrenList: children || "children",
var childrenListMap = {};
const parentId = d[config.parentId];
if (childrenListMap[parentId] == null) {
childrenListMap[parentId] = [];
nodeIds[d[config.id]] = d;
childrenListMap[parentId].push(d);
const parentId = d[config.parentId];
if (nodeIds[parentId] == null) {
function adaptToChildrenList(o) {
if (childrenListMap[o[config.id]] !== null) {
o[config.childrenList] = childrenListMap[o[config.id]];
if (o[config.childrenList]) {
for (const c of o[config.childrenList]) {
export function tansParams(params) {
for (const propName of Object.keys(params)) {
const value = params[propName];
var part = encodeURIComponent(propName) + "=";
if (value !== null && typeof value !== "undefined") {
if (typeof value === "object") {
for (const key of Object.keys(value)) {
if (value[key] !== null && typeof value[key] !== "undefined") {
const params = propName + "[" + key + "]";
var subPart = encodeURIComponent(params) + "=";
result += subPart + encodeURIComponent(value[key]) + "&";
result += part + encodeURIComponent(value) + "&";
export async function blobValidate(data) {
const text = await data.text();
export function changePostParam(param) {
return JSON.stringify(param)
export function addCommas(num) {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
export function getCurrentTime() {
function formatDate(value) {
return value < 10 ? `0${value}` : value;
const year = date.getFullYear();
const month = formatDate(date.getMonth() + 1);
const day = formatDate(date.getDate());
const hour = formatDate(date.getHours());
const minute = formatDate(date.getMinutes());
const second = formatDate(date.getSeconds());
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
export function getAWeek() {
const sevenDaysAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
const endDate = formatDate(now);
const startDate = formatDate(sevenDaysAgo);
function formatDate(date) {
const year = date.getFullYear();
const month = formatNumber(date.getMonth() + 1);
const day = formatNumber(date.getDate());
const hours = formatNumber(date.getHours());
const minutes = formatNumber(date.getMinutes());
const seconds = formatNumber(date.getSeconds());
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
function formatNumber(num) {
return num > 9 ? num : `0${num}`;
return [startDate, endDate];
export function throttleFun(fn, wait = 500) {
if (last && now - last < wait) {
fn.call(this, ...arguments);
export function debounceFun(fn, wait = 500) {
if (timer) clearTimeout(timer);
timer = setTimeout(() => {
import axios from "axios";
import { Loading, Message } from "element-ui";
import { getToken } from "./auth";
export function downloadPost(formData, url) {
let downloadLoadingInstance;
downloadLoadingInstance = Loading.service({
spinner: "el-icon-loading",
background: "rgba(0, 0, 0, 0.7)",
url: process.env.VUE_APP_BASE_API + url,
AuthorizationSys: getToken(),
"Content-Type": "application/json",
}).then(async (data) => {
const isLogin = await blobValidate(data.data);
data.headers["content-disposition"].split("filename=")[1];
var fileName = decodeURIComponent(fileNameEncode);
const blob = new Blob([data.data]);
const resText = await data.text();
const rspObj = JSON.parse(resText);
const errMsg = rspObj.message;
downloadLoadingInstance.close();
export function getLastNumDay(num, isDateTime = true) {
const sevenDaysAgo = new Date(now.getTime() - num * 24 * 60 * 60 * 1000);
const endDate = formatDate(now);
const startDate = formatDate(sevenDaysAgo);
function formatDate(date) {
const year = date.getFullYear();
const month = formatNumber(date.getMonth() + 1);
const day = formatNumber(date.getDate());
const hours = formatNumber(date.getHours());
const minutes = formatNumber(date.getMinutes());
const seconds = formatNumber(date.getSeconds());
? `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
: `${year}-${month}-${day}`;
function formatNumber(num) {
return num > 9 ? num : `0${num}`;
return [startDate, endDate];
export function getLastDay(num) {
var time = new Date().getTime() - num * 24 * 60 * 60 * 1000;
var yesterday = new Date(time);
var month = yesterday.getMonth();
var day = yesterday.getDate();
yesterday.getFullYear() +
(yesterday.getMonth() > 9
? yesterday.getMonth() + 1
: "0" + (yesterday.getMonth() + 1)) +
(yesterday.getDate() > 9 ? yesterday.getDate() : "0" + yesterday.getDate());
export function isEmptyObject(obj) {
return Object.keys(obj).length === 0 && obj.constructor === Object;