mirror of
https://github.com/dataease/dataease.git
synced 2026-05-23 13:58:26 +08:00
前端项目运行时的部分警告处理 (#2759)
* fix: 执行 eslint 命令, 修复代码 * fix(frontend): justify-content 不支持的值 start, end 改为 flex-start, flex-end * Update format-utils.js 去掉注释 Co-authored-by: 王嘉豪 <42510293+ziyujiahao@users.noreply.github.com>
This commit is contained in:
@@ -1,20 +1,19 @@
|
||||
const isBoolean = require("lodash.isboolean");
|
||||
const isEmpty = require("lodash.isempty");
|
||||
const isInteger = require("lodash.isinteger");
|
||||
const isNull = require("lodash.isnull");
|
||||
const isNumber = require("lodash.isnumber");
|
||||
const isObject = require("lodash.isobject");
|
||||
const isString = require("lodash.isstring");
|
||||
const isArray = Array.isArray;
|
||||
|
||||
const isBoolean = require('lodash.isboolean')
|
||||
const isEmpty = require('lodash.isempty')
|
||||
const isInteger = require('lodash.isinteger')
|
||||
const isNull = require('lodash.isnull')
|
||||
const isNumber = require('lodash.isnumber')
|
||||
const isObject = require('lodash.isobject')
|
||||
const isString = require('lodash.isstring')
|
||||
const isArray = Array.isArray
|
||||
|
||||
class Convert {
|
||||
constructor() {
|
||||
this._option = {
|
||||
$id: "http://example.com/root.json",
|
||||
$schema: "http://json-schema.org/draft-07/schema#",
|
||||
$id: 'http://example.com/root.json',
|
||||
$schema: 'http://json-schema.org/draft-07/schema#',
|
||||
}
|
||||
this._object = null;
|
||||
this._object = null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,22 +24,22 @@ class Convert {
|
||||
format(object, option = {}) {
|
||||
// 数据校验,确保传入的的object只能是对象或数组
|
||||
if (!isObject(object)) {
|
||||
throw new TypeError("传入参数只能是对象或数组");
|
||||
throw new TypeError('传入参数只能是对象或数组')
|
||||
}
|
||||
// 合并属性
|
||||
this._option = Object.assign(this._option, option);
|
||||
this._option = Object.assign(this._option, option)
|
||||
// 需要转换的对象
|
||||
this._object = object;
|
||||
let convertRes;
|
||||
this._object = object
|
||||
let convertRes
|
||||
// 数组类型和对象类型结构不一样
|
||||
if (isArray(object)) {
|
||||
convertRes = this._arrayToSchema();
|
||||
convertRes = this._arrayToSchema()
|
||||
} else {
|
||||
convertRes = this._objectToSchema();
|
||||
convertRes = this._objectToSchema()
|
||||
}
|
||||
// 释放
|
||||
this._object = null;
|
||||
return convertRes;
|
||||
this._object = null
|
||||
return convertRes
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,22 +47,22 @@ class Convert {
|
||||
*/
|
||||
_arrayToSchema() {
|
||||
// root节点基本信息
|
||||
let result = this._value2object(this._object, this._option.$id, "", true);
|
||||
const result = this._value2object(this._object, this._option.$id, '', true)
|
||||
if (this._object.length > 0) {
|
||||
let itemArr = [];
|
||||
const itemArr = []
|
||||
for (let index = 0; index < this._object.length; index++) {
|
||||
// 创建items对象的基本信息
|
||||
let objectItem = this._object[index]
|
||||
let item = this._value2object(objectItem, `#/items`, 'items');
|
||||
const objectItem = this._object[index]
|
||||
let item = this._value2object(objectItem, `#/items`, 'items')
|
||||
if (isObject(objectItem) && !isEmpty(objectItem)) {
|
||||
// 递归遍历
|
||||
let objectItemSchema = this._json2schema(objectItem, `#/items`);
|
||||
const objectItemSchema = this._json2schema(objectItem, `#/items`)
|
||||
// 合并对象
|
||||
item = Object.assign(item, objectItemSchema);
|
||||
item = Object.assign(item, objectItemSchema)
|
||||
}
|
||||
itemArr.push(item);
|
||||
itemArr.push(item)
|
||||
}
|
||||
result["items"] = itemArr;
|
||||
result['items'] = itemArr
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -72,8 +71,8 @@ class Convert {
|
||||
* 对象类型转换成JSONSCHEMA
|
||||
*/
|
||||
_objectToSchema() {
|
||||
let baseResult = this._value2object(this._object, this._option.$id, "", true)
|
||||
let objectSchema = this._json2schema(this._object)
|
||||
let baseResult = this._value2object(this._object, this._option.$id, '', true)
|
||||
const objectSchema = this._json2schema(this._object)
|
||||
baseResult = Object.assign(baseResult, objectSchema)
|
||||
return baseResult
|
||||
}
|
||||
@@ -83,69 +82,69 @@ class Convert {
|
||||
* @param {*} object 需要转换对象
|
||||
* @param {*} name $id值
|
||||
*/
|
||||
_json2schema(object, name = "") {
|
||||
_json2schema(object, name = '') {
|
||||
// 如果递归值不是对象,那么return掉
|
||||
if (!isObject(object)) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
// 处理当前路径$id
|
||||
if (name === "" || name == undefined) {
|
||||
name = "#"
|
||||
if (name === '' || name == undefined) {
|
||||
name = '#'
|
||||
}
|
||||
let result = {};
|
||||
const result = {}
|
||||
// 判断传入object是对象还是数组。
|
||||
if (isArray(object)) {
|
||||
result.items = {};
|
||||
result.items = {}
|
||||
} else {
|
||||
result.properties = {};
|
||||
result.properties = {}
|
||||
}
|
||||
// 遍历传入的对象
|
||||
for (const key in object) {
|
||||
if (object.hasOwnProperty(key)) {
|
||||
const element = object[key];
|
||||
const element = object[key]
|
||||
// 如果只是undefined。跳过
|
||||
if (element === undefined) {
|
||||
continue;
|
||||
continue
|
||||
}
|
||||
let $id = `${name}/properties/${key}`
|
||||
const $id = `${name}/properties/${key}`
|
||||
// 判断当前 element 的值 是否也是对象,如果是就继续递归,不是就赋值给result
|
||||
if(!result["properties"]){
|
||||
continue;
|
||||
if (!result['properties']) {
|
||||
continue
|
||||
}
|
||||
if (isObject(element)) {
|
||||
// 创建当前属性的基本信息
|
||||
result["properties"][key] = this._value2object(element, $id, key)
|
||||
result['properties'][key] = this._value2object(element, $id, key)
|
||||
if (isArray(element)) {
|
||||
// 针对空数组和有值的数组做不同处理
|
||||
if (element.length > 0) {
|
||||
// 是数组
|
||||
let itemArr = [];
|
||||
const itemArr = []
|
||||
for (let index = 0; index < element.length; index++) {
|
||||
let elementItem = element[index];
|
||||
const elementItem = element[index]
|
||||
// 创建items对象的基本信息
|
||||
let item = this._value2object(elementItem, `${$id}/items`, key + 'items');
|
||||
let item = this._value2object(elementItem, `${$id}/items`, key + 'items')
|
||||
// 判断第一项是否是对象,且对象属性不为空
|
||||
if (isObject(elementItem) && !isEmpty(elementItem)) {
|
||||
// 新增的properties才合并进来
|
||||
item = Object.assign(item, this._json2schema(elementItem, `${$id}/items`));
|
||||
item = Object.assign(item, this._json2schema(elementItem, `${$id}/items`))
|
||||
}
|
||||
itemArr.push(item);
|
||||
itemArr.push(item)
|
||||
}
|
||||
result["properties"][key]["items"] = itemArr;
|
||||
result['properties'][key]['items'] = itemArr
|
||||
}
|
||||
} else {
|
||||
// 不是数组,递归遍历获取,然后合并对象属性
|
||||
result["properties"][key] = Object.assign(result["properties"][key], this._json2schema(element, $id));
|
||||
result['properties'][key] = Object.assign(result['properties'][key], this._json2schema(element, $id))
|
||||
}
|
||||
} else {
|
||||
// 一般属性直接获取基本信息
|
||||
if (result["properties"]) {
|
||||
result["properties"][key] = this._value2object(element, $id, key);
|
||||
if (result['properties']) {
|
||||
result['properties'][key] = this._value2object(element, $id, key)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,39 +154,39 @@ class Convert {
|
||||
* @param {*} key
|
||||
*/
|
||||
_value2object(value, $id, key = '', root = false) {
|
||||
let objectTemplate = {
|
||||
const objectTemplate = {
|
||||
$id: $id,
|
||||
title: `The ${key} Schema`,
|
||||
mock: {
|
||||
"mock": value
|
||||
'mock': value
|
||||
},
|
||||
}
|
||||
|
||||
// 判断是否为初始化root数据
|
||||
if (root) {
|
||||
objectTemplate["$schema"] = this._option.$schema;
|
||||
objectTemplate["title"] = `The Root Schema`;
|
||||
objectTemplate["mock"] = undefined;
|
||||
objectTemplate['$schema'] = this._option.$schema
|
||||
objectTemplate['title'] = `The Root Schema`
|
||||
objectTemplate['mock'] = undefined
|
||||
}
|
||||
if (isBoolean(value)) {
|
||||
objectTemplate.type = "boolean";
|
||||
objectTemplate.type = 'boolean'
|
||||
} else if (isInteger(value)) {
|
||||
objectTemplate.type = "integer";
|
||||
objectTemplate.type = 'integer'
|
||||
} else if (isNumber(value)) {
|
||||
objectTemplate.type = "number";
|
||||
objectTemplate.type = 'number'
|
||||
} else if (isString(value)) {
|
||||
objectTemplate.type = "string";
|
||||
objectTemplate.type = 'string'
|
||||
} else if (isNull(value)) {
|
||||
objectTemplate.type = "null";
|
||||
objectTemplate.type = 'null'
|
||||
} else if (isArray(value)) {
|
||||
objectTemplate.type = "array";
|
||||
objectTemplate["mock"] = undefined;
|
||||
objectTemplate.type = 'array'
|
||||
objectTemplate['mock'] = undefined
|
||||
} else if (isObject(value)) {
|
||||
objectTemplate.type = "object"
|
||||
objectTemplate["mock"] = undefined;
|
||||
objectTemplate.type = 'object'
|
||||
objectTemplate['mock'] = undefined
|
||||
}
|
||||
|
||||
return objectTemplate;
|
||||
return objectTemplate
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user