| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- /**
- * 判断是否是外部链接
- * @param {string} path 路径
- * @returns {boolean}
- */
- export function isExternal(path) {
- return /^(https?:|mailto:|tel:)/.test(path);
- }
- /**
- * 格式化时间
- * @param {Date|string|number} time 时间
- * @param {string} format 格式
- * @returns {string}
- */
- export function formatDate(time, format = "YYYY-MM-DD HH:mm:ss") {
- if (!time) {
- return "";
- }
- const date = new Date(time);
- const year = date.getFullYear();
- const month = date.getMonth() + 1;
- const day = date.getDate();
- const hour = date.getHours();
- const minute = date.getMinutes();
- const second = date.getSeconds();
- const formatMap = {
- YYYY: year.toString(),
- MM: month.toString().padStart(2, "0"),
- DD: day.toString().padStart(2, "0"),
- HH: hour.toString().padStart(2, "0"),
- mm: minute.toString().padStart(2, "0"),
- ss: second.toString().padStart(2, "0"),
- };
- return format.replace(/(YYYY|MM|DD|HH|mm|ss)/g, (match) => formatMap[match]);
- }
- /**
- * 深拷贝
- * @param {Object} obj 要拷贝的对象
- * @returns {Object}
- */
- export function deepClone(obj) {
- if (obj === null || typeof obj !== "object") {
- return obj;
- }
- const result = Array.isArray(obj) ? [] : {};
- for (const key in obj) {
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
- result[key] = deepClone(obj[key]);
- }
- }
- return result;
- }
|