|
|
@@ -5,12 +5,12 @@ import { parseTime } from './ruoyi'
|
|
|
*/
|
|
|
export function formatDate(cellValue) {
|
|
|
if (cellValue == null || cellValue == "") return "";
|
|
|
- var date = new Date(cellValue)
|
|
|
+ var date = new Date(cellValue)
|
|
|
var year = date.getFullYear()
|
|
|
var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
|
|
|
- var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
|
|
|
- var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
|
|
|
- var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
|
|
|
+ var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
|
|
|
+ var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
|
|
|
+ var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
|
|
|
var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
|
|
|
return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
|
|
|
}
|
|
|
@@ -249,7 +249,27 @@ export function debounce(func, wait, immediate) {
|
|
|
return result
|
|
|
}
|
|
|
}
|
|
|
+function stringify(obj) {
|
|
|
+ return JSON.stringify(obj, (key, val) => {
|
|
|
+ if (typeof val === 'function') {
|
|
|
+ return `${val}`
|
|
|
+ }
|
|
|
+ return val
|
|
|
+ })
|
|
|
+}
|
|
|
|
|
|
+function parse(str) {
|
|
|
+ JSON.parse(str, (k, v) => {
|
|
|
+ if (v.indexOf && v.indexOf('function') > -1) {
|
|
|
+ return eval(`(${v})`)
|
|
|
+ }
|
|
|
+ return v
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+export function jsonClone(obj) {
|
|
|
+ return parse(stringify(obj))
|
|
|
+}
|
|
|
/**
|
|
|
* This is just a simple version of deep copy
|
|
|
* Has a lot of edge cases bug
|
|
|
@@ -257,20 +277,58 @@ export function debounce(func, wait, immediate) {
|
|
|
* @param {Object} source
|
|
|
* @returns {Object}
|
|
|
*/
|
|
|
-export function deepClone(source) {
|
|
|
- if (!source && typeof source !== 'object') {
|
|
|
- throw new Error('error arguments', 'deepClone')
|
|
|
+// 深拷贝对象
|
|
|
+// 深拷贝对象
|
|
|
+export function deepClone(obj) {
|
|
|
+ const _toString = Object.prototype.toString
|
|
|
+
|
|
|
+ // null, undefined, non-object, function
|
|
|
+ if (!obj || typeof obj !== 'object') {
|
|
|
+ return obj
|
|
|
}
|
|
|
- const targetObj = source.constructor === Array ? [] : {}
|
|
|
- Object.keys(source).forEach(keys => {
|
|
|
- if (source[keys] && typeof source[keys] === 'object') {
|
|
|
- targetObj[keys] = deepClone(source[keys])
|
|
|
- } else {
|
|
|
- targetObj[keys] = source[keys]
|
|
|
- }
|
|
|
- })
|
|
|
- return targetObj
|
|
|
+
|
|
|
+ // DOM Node
|
|
|
+ if (obj.nodeType && 'cloneNode' in obj) {
|
|
|
+ return obj.cloneNode(true)
|
|
|
+ }
|
|
|
+
|
|
|
+ // Date
|
|
|
+ if (_toString.call(obj) === '[object Date]') {
|
|
|
+ return new Date(obj.getTime())
|
|
|
+ }
|
|
|
+
|
|
|
+ // RegExp
|
|
|
+ if (_toString.call(obj) === '[object RegExp]') {
|
|
|
+ const flags = []
|
|
|
+ if (obj.global) { flags.push('g') }
|
|
|
+ if (obj.multiline) { flags.push('m') }
|
|
|
+ if (obj.ignoreCase) { flags.push('i') }
|
|
|
+
|
|
|
+ return new RegExp(obj.source, flags.join(''))
|
|
|
+ }
|
|
|
+
|
|
|
+ const result = Array.isArray(obj) ? [] : obj.constructor ? new obj.constructor() : {}
|
|
|
+
|
|
|
+ for (const key in obj) {
|
|
|
+ result[key] = deepClone(obj[key])
|
|
|
+ }
|
|
|
+
|
|
|
+ return result
|
|
|
}
|
|
|
+// export function deepClone(source) {
|
|
|
+// if (!source && typeof source !== 'object') {
|
|
|
+// throw new Error('error arguments', 'deepClone')
|
|
|
+// }
|
|
|
+// const targetObj = source.constructor === Array ? [] : {}
|
|
|
+// Object.keys(source).forEach(keys => {
|
|
|
+// if (source[keys] && typeof source[keys] === 'object') {
|
|
|
+// targetObj[keys] = deepClone(source[keys])
|
|
|
+// } else {
|
|
|
+// targetObj[keys] = source[keys]
|
|
|
+// }
|
|
|
+// })
|
|
|
+// return targetObj
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* @param {Array} arr
|
|
|
@@ -330,7 +388,7 @@ export function makeMap(str, expectsLowerCase) {
|
|
|
? val => map[val.toLowerCase()]
|
|
|
: val => map[val]
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
export const exportDefault = 'export default '
|
|
|
|
|
|
export const beautifierConf = {
|
|
|
@@ -373,6 +431,29 @@ export const beautifierConf = {
|
|
|
indent_empty_lines: true
|
|
|
}
|
|
|
}
|
|
|
+/**
|
|
|
+ * num 小于0,左缩进num*2个空格; 大于0,右缩进num*2个空格。
|
|
|
+ * @param {string} str 代码
|
|
|
+ * @param {number} num 缩进次数
|
|
|
+ * @param {number} len 【可选】缩进单位,空格数
|
|
|
+ */
|
|
|
+export function indent(str, num, len = 2) {
|
|
|
+ if (num === 0) return str
|
|
|
+ const isLeft = num < 0; const result = []; let reg; let
|
|
|
+ spaces = ''
|
|
|
+ if (isLeft) {
|
|
|
+ num *= -1
|
|
|
+ reg = new RegExp(`(^\\s{0,${num * len}})`, 'g')
|
|
|
+ } else {
|
|
|
+ for (let i = 0; i < num * len; i++) spaces += ' '
|
|
|
+ }
|
|
|
+
|
|
|
+ str.split('\n').forEach(line => {
|
|
|
+ line = isLeft ? line.replace(reg, '') : spaces + line
|
|
|
+ result.push(line)
|
|
|
+ })
|
|
|
+ return result.join('\n')
|
|
|
+}
|
|
|
|
|
|
// 首字母大小
|
|
|
export function titleCase(str) {
|
|
|
@@ -387,4 +468,17 @@ export function camelCase(str) {
|
|
|
export function isNumberStr(str) {
|
|
|
return /^[+-]?(0|([1-9]\d*))(\.\d+)?$/g.test(str)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+const toStr = Function.prototype.call.bind(Object.prototype.toString)
|
|
|
+export function isObjectObject(t) {
|
|
|
+ return toStr(t) === '[object Object]'
|
|
|
+}
|
|
|
+export function isObjectArray(t) {
|
|
|
+ return toStr(t) === '[object Array]'
|
|
|
+}
|
|
|
+export function isObjectNull(t) {
|
|
|
+ return toStr(t) === '[object Null]'
|
|
|
+}
|
|
|
+export function isObjectUnde(t) {
|
|
|
+ return toStr(t) === '[object Undefined]'
|
|
|
+}
|