Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
wangjiahao 2022-08-02 13:41:18 +08:00
commit f6ba0642ea
14 changed files with 458 additions and 474 deletions

View File

@ -1,5 +1,5 @@
import request from '@/utils/request' import request from '@/utils/request'
import {validateDs} from "@/api/system/datasource"; import { validateDs } from '@/api/system/datasource'
export function engineMode() { export function engineMode() {
return request({ return request({

View File

@ -1,7 +1,5 @@
import request from '@/utils/request' import request from '@/utils/request'
import {validateDs} from "@/api/system/datasource"; import { validateDs } from '@/api/system/datasource'
export function validate(data) { export function validate(data) {
return request({ return request({
@ -37,8 +35,6 @@ export function deleteKettle(id) {
}) })
} }
export function pageList(url, data) { export function pageList(url, data) {
return request({ return request({
url: url, url: url,

View File

@ -166,7 +166,7 @@ export default {
border-radius: 3px; border-radius: 3px;
} }
> > > .el-popover { >>> .el-popover {
height: 200px; height: 200px;
overflow: auto; overflow: auto;
} }

View File

@ -2,57 +2,57 @@
import { attrsMap, styleAttrs } from '@/components/widget/DeWidget/serviceNameFn.js' import { attrsMap, styleAttrs } from '@/components/widget/DeWidget/serviceNameFn.js'
export default { export default {
data() { data() {
return { return {
attrsMap, attrsMap,
styleAttrs, styleAttrs,
// 过滤组件名css变量映射 // 过滤组件名css变量映射
refComNameMap: { refComNameMap: {
'de-date': ['--BgDateColor', '--DateColor', '--BrDateColor'], 'de-date': ['--BgDateColor', '--DateColor', '--BrDateColor'],
'de-select': ['--BgSelectColor', '--SelectColor', '--BrSelectColor'], 'de-select': ['--BgSelectColor', '--SelectColor', '--BrSelectColor'],
'de-select-tree': ['--BgSelectTreeColor', '--SelectTreeColor', '--BrSelectTreeColor'], 'de-select-tree': ['--BgSelectTreeColor', '--SelectTreeColor', '--BrSelectTreeColor'],
"de-input-search": ['--BgSearchColor', '--SearchColor', '--BrSearchColor'], 'de-input-search': ['--BgSearchColor', '--SearchColor', '--BrSearchColor'],
"de-number-range": ['--BgRangeColor', '--RangeColor', '--BrRangeColor'] 'de-number-range': ['--BgRangeColor', '--RangeColor', '--BrRangeColor']
} }
}
},
watch: {
cssArr: {
handler() {
if (['de-select', 'de-select-tree'].includes(this.element.component)) {
if (!this.element.options.attrs.multiple) {
return
}
this.handleElTagStyle()
};
},
deep: true
},
},
computed: {
cssArr() {
const { brColor, wordColor, innerBgColor } = this.element.style;
return { brColor, wordColor, innerBgColor }
}
},
mounted() {
this.handleCoustomStyle()
},
methods: {
typeTransform() {
let refNode = this.refComNameMap[this.element.component];
if (!refNode) return [];
return refNode
},
handleCoustomStyle() {
// 判断组件是否是在仪表板内部 否则css样式取默认值
const isPanelDe = this.$parent.handlerInputStyle;
const { brColor, wordColor, innerBgColor } = this.element.style;
const newValue = { brColor, wordColor, innerBgColor };
const cssVar = this.typeTransform();
this.styleAttrs.forEach((ele, index) => {
document.documentElement.style.setProperty(cssVar[index], !isPanelDe ? '' : newValue[ele])
})
},
} }
} },
watch: {
cssArr: {
handler() {
if (['de-select', 'de-select-tree'].includes(this.element.component)) {
if (!this.element.options.attrs.multiple) {
return
}
this.handleElTagStyle()
}
},
deep: true
},
},
computed: {
cssArr() {
const { brColor, wordColor, innerBgColor } = this.element.style
return { brColor, wordColor, innerBgColor }
}
},
mounted() {
this.handleCoustomStyle()
},
methods: {
typeTransform() {
const refNode = this.refComNameMap[this.element.component]
if (!refNode) return []
return refNode
},
handleCoustomStyle() {
// 判断组件是否是在仪表板内部 否则css样式取默认值
const isPanelDe = this.$parent.handlerInputStyle
const { brColor, wordColor, innerBgColor } = this.element.style
const newValue = { brColor, wordColor, innerBgColor }
const cssVar = this.typeTransform()
this.styleAttrs.forEach((ele, index) => {
document.documentElement.style.setProperty(cssVar[index], !isPanelDe ? '' : newValue[ele])
})
},
}
}

View File

@ -1,90 +1,90 @@
// 通过控制 js 控制过滤组件输入框样式 如需额外处理 声明组件serviceName同名函数处理 // 通过控制 js 控制过滤组件输入框样式 如需额外处理 声明组件serviceName同名函数处理
import { timeDateRangeWidget, textInputWidget, attrsMap, styleAttrs } from '@/components/widget/DeWidget/serviceNameFn.js' import { timeDateRangeWidget, textInputWidget, attrsMap, styleAttrs } from '@/components/widget/DeWidget/serviceNameFn.js'
export default { export default {
data() { data() {
return { return {
attrsMap, attrsMap,
styleAttrs, styleAttrs,
// 过滤组件名ref映射 // 过滤组件名ref映射
refComNameMap: { refComNameMap: {
'de-date': 'dateRef', 'de-date': 'dateRef',
'de-select-grid': 'de-select-grid', 'de-select-grid': 'de-select-grid',
'de-select': 'deSelect', 'de-select': 'deSelect',
'de-select-tree': 'deSelectTree', 'de-select-tree': 'deSelectTree',
"de-input-search": "de-input-search", 'de-input-search': 'de-input-search',
"de-number-range": ['de-number-range-min', 'de-number-range-max'] 'de-number-range': ['de-number-range-min', 'de-number-range-max']
} }
}
},
watch: {
cssArr: {
handler(newValue) {
if (!this.isFilterComponent) return;
this.typeTransform().forEach(ele => {
this.handlerInputStyle(ele, newValue)
})
},
deep: true
},
multiple: {
handler() {
if (!['de-select-tree', 'de-select'].includes(this.element.component)) return;
const time = setTimeout(() => {
clearTimeout(time)
this.typeTransform().forEach(ele => {
this.handlerInputStyle(ele, this.cssArr)
})
}, 100)
},
deep: true
}
},
computed: {
cssArr() {
const { brColor, wordColor, innerBgColor } = this.element.style;
return { brColor, wordColor, innerBgColor }
},
multiple() {
const { multiple = false } = this.element.options.attrs
return multiple;
}
},
mounted() {
if (!this.isFilterComponent) return;
this.typeTransform().forEach(item => {
const nodeCache = this.$refs.deOutWidget.$refs[item].$el.querySelector('.el-input__inner') || this.$refs.deOutWidget.$refs[item].$el
this.styleAttrs.forEach(ele => {
nodeCache.style[this.attrsMap[ele]] = this.element.style[ele];
this[this.element.serviceName] && this[this.element.serviceName](this.selectRange(item), ele, this.element.style[ele])
})
})
},
methods: {
handlerInputStyle(type, newValue) {
let nodeCache = '';
this.styleAttrs.forEach(ele => {
if (!nodeCache) {
nodeCache = this.$refs.deOutWidget.$refs[type].$el.querySelector('.el-input__inner') || this.$refs.deOutWidget.$refs[type].$el
}
nodeCache.style[this.attrsMap[ele]] = newValue[ele];
this[this.element.serviceName] && this[this.element.serviceName](this.selectRange(type), ele, newValue[ele])
})
},
selectRange(item) {
if (this.element.component === 'de-select-grid') {
return this.$refs.deOutWidget.$el;
}
return this.$refs.deOutWidget.$refs[item].$el;
},
timeDateRangeWidget: timeDateRangeWidget,
textInputWidget: textInputWidget,
typeTransform() {
let refNode = this.refComNameMap[this.element.component];
if (!refNode) return [];
if (!Array.isArray(refNode)) {
refNode = [refNode]
}
return refNode
}
} }
} },
watch: {
cssArr: {
handler(newValue) {
if (!this.isFilterComponent) return
this.typeTransform().forEach(ele => {
this.handlerInputStyle(ele, newValue)
})
},
deep: true
},
multiple: {
handler() {
if (!['de-select-tree', 'de-select'].includes(this.element.component)) return
const time = setTimeout(() => {
clearTimeout(time)
this.typeTransform().forEach(ele => {
this.handlerInputStyle(ele, this.cssArr)
})
}, 100)
},
deep: true
}
},
computed: {
cssArr() {
const { brColor, wordColor, innerBgColor } = this.element.style
return { brColor, wordColor, innerBgColor }
},
multiple() {
const { multiple = false } = this.element.options.attrs
return multiple
}
},
mounted() {
if (!this.isFilterComponent) return
this.typeTransform().forEach(item => {
const nodeCache = this.$refs.deOutWidget.$refs[item].$el.querySelector('.el-input__inner') || this.$refs.deOutWidget.$refs[item].$el
this.styleAttrs.forEach(ele => {
nodeCache.style[this.attrsMap[ele]] = this.element.style[ele]
this[this.element.serviceName] && this[this.element.serviceName](this.selectRange(item), ele, this.element.style[ele])
})
})
},
methods: {
handlerInputStyle(type, newValue) {
let nodeCache = ''
this.styleAttrs.forEach(ele => {
if (!nodeCache) {
nodeCache = this.$refs.deOutWidget.$refs[type].$el.querySelector('.el-input__inner') || this.$refs.deOutWidget.$refs[type].$el
}
nodeCache.style[this.attrsMap[ele]] = newValue[ele]
this[this.element.serviceName] && this[this.element.serviceName](this.selectRange(type), ele, newValue[ele])
})
},
selectRange(item) {
if (this.element.component === 'de-select-grid') {
return this.$refs.deOutWidget.$el
}
return this.$refs.deOutWidget.$refs[item].$el
},
timeDateRangeWidget: timeDateRangeWidget,
textInputWidget: textInputWidget,
typeTransform() {
let refNode = this.refComNameMap[this.element.component]
if (!refNode) return []
if (!Array.isArray(refNode)) {
refNode = [refNode]
}
return refNode
}
}
}

View File

@ -1,92 +1,91 @@
const attrsMap = { brColor: 'borderColor', wordColor: 'color', innerBgColor: 'backgroundColor' } const attrsMap = { brColor: 'borderColor', wordColor: 'color', innerBgColor: 'backgroundColor' }
const styleAttrs = ['innerBgColor', 'wordColor', 'brColor'] const styleAttrs = ['innerBgColor', 'wordColor', 'brColor']
function timeDateRangeWidget (nodeCache, name, value) { function timeDateRangeWidget(nodeCache, name, value) {
const classList = ['.el-range-input', '.el-range-separator'] const classList = ['.el-range-input', '.el-range-separator']
classList.forEach(ele => { classList.forEach(ele => {
let nodeList = nodeCache.querySelectorAll(ele); const nodeList = nodeCache.querySelectorAll(ele)
if (!nodeList.length) return; if (!nodeList.length) return
nodeList.forEach(ele => { nodeList.forEach(ele => {
ele.style[attrsMap[name]] = value; ele.style[attrsMap[name]] = value
})
}) })
})
} }
function textInputWidget (nodeCache, name, value) { function textInputWidget(nodeCache, name, value) {
let groupAppend = nodeCache.querySelector('.el-input-group__append'); const groupAppend = nodeCache.querySelector('.el-input-group__append')
groupAppend.style[attrsMap[name]] = value; groupAppend.style[attrsMap[name]] = value
if (name === 'brColor') { if (name === 'brColor') {
groupAppend.style.borderLeft = 'none' groupAppend.style.borderLeft = 'none'
} }
} }
function textSelectGridWidget (nodeCache, name, value) { function textSelectGridWidget(nodeCache, name, value) {
if (name === 'innerBgColor') { if (name === 'innerBgColor') {
nodeCache.querySelector('.list').style.backgroundColor = value; nodeCache.querySelector('.list').style.backgroundColor = value
}
if (name === 'wordColor') {
const elRadio = nodeCache.querySelectorAll('.el-radio')
const elCheckbox = nodeCache.querySelectorAll('.el-checkbox')
if (elRadio.length) {
elRadio.forEach(ele => {
ele.style.color = value
})
} }
if (name === 'wordColor') { if (elCheckbox.length) {
let elRadio = nodeCache.querySelectorAll('.el-radio') elCheckbox.forEach(ele => {
let elCheckbox = nodeCache.querySelectorAll('.el-checkbox') ele.style.color = value
if (elRadio.length) { })
elRadio.forEach(ele => {
ele.style.color = value;
});
}
if (elCheckbox.length) {
elCheckbox.forEach(ele => {
ele.style.color = value;
});
}
} }
}
} }
function textSelectTreeWidget(nodeCache, style) { function textSelectTreeWidget(nodeCache, style) {
textSelectWidget(nodeCache, style) textSelectWidget(nodeCache, style)
} }
function textSelectWidget(nodeCache, style) { function textSelectWidget(nodeCache, style) {
let elTag = nodeCache.querySelectorAll('.el-tag.el-tag--info') const elTag = nodeCache.querySelectorAll('.el-tag.el-tag--info')
if (elTag.length) { if (elTag.length) {
elTag.forEach(item => { elTag.forEach(item => {
item.style.flexWrap = 'wrap' item.style.flexWrap = 'wrap'
item.style.padding = '0' item.style.padding = '0'
const textNode = item.querySelector('.el-select__tags-text'); const textNode = item.querySelector('.el-select__tags-text')
const closeNode = item.querySelector('.el-tag__close'); const closeNode = item.querySelector('.el-tag__close')
textNode.style.width = '100%'; textNode.style.width = '100%'
item.style.position = 'relative'; item.style.position = 'relative'
textNode.style.padding = '0 20px 0 8px'; textNode.style.padding = '0 20px 0 8px'
textNode.style.borderRadius = '3px'; textNode.style.borderRadius = '3px'
if (closeNode) { if (closeNode) {
closeNode.style.position = 'absolute'; closeNode.style.position = 'absolute'
closeNode.style.top = '60%'; closeNode.style.top = '60%'
closeNode.style.transform = 'translateY(-50%)'; closeNode.style.transform = 'translateY(-50%)'
closeNode.style.right = '2px'; closeNode.style.right = '2px'
} }
styleAttrs.forEach((ele) => { styleAttrs.forEach((ele) => {
if (ele !== 'brColor' && closeNode) { if (ele !== 'brColor' && closeNode) {
closeNode.style[attrsMap[ele]] = style[ele]; closeNode.style[attrsMap[ele]] = style[ele]
} else { } else {
item.style[attrsMap[ele]] = style[ele]; item.style[attrsMap[ele]] = style[ele]
} }
textNode.style[attrsMap[ele]] = style[ele]; textNode.style[attrsMap[ele]] = style[ele]
}) })
})
}); }
}
} }
function handlerInputStyle (node, style) { function handlerInputStyle(node, style) {
if (!node) return; if (!node) return
styleAttrs.forEach(ele => { styleAttrs.forEach(ele => {
node.style[attrsMap[ele]] = style[ele]; node.style[attrsMap[ele]] = style[ele]
}) })
} }
export { export {
attrsMap, attrsMap,
styleAttrs, styleAttrs,
timeDateRangeWidget, timeDateRangeWidget,
textInputWidget, textInputWidget,
textSelectGridWidget, textSelectGridWidget,
textSelectTreeWidget, textSelectTreeWidget,
textSelectWidget, textSelectWidget,
handlerInputStyle, handlerInputStyle,
} }

View File

@ -64,42 +64,41 @@ export const bottom2TopDrag = {
} }
} }
const closePress = { const closePress = {
inserted: function (el) { inserted: function(el) {
el.querySelector('.el-drawer__close-btn').onmousedown = function (e) { el.querySelector('.el-drawer__close-btn').onmousedown = function(e) {
e.currentTarget.style.background = '#d2d3d4'; e.currentTarget.style.background = '#d2d3d4'
} }
el.querySelector('.el-drawer__close-btn').onmouseup = function (e) { el.querySelector('.el-drawer__close-btn').onmouseup = function(e) {
e.currentTarget.style.background = 'none'; e.currentTarget.style.background = 'none'
} }
} }
} }
const btnPress = { const btnPress = {
update: function (el, binding) { update: function(el, binding) {
el.onmousedown = function (e) { el.onmousedown = function(e) {
e.currentTarget.style.setProperty('background', binding.value || '#EFF0F1', 'important'); e.currentTarget.style.setProperty('background', binding.value || '#EFF0F1', 'important')
} }
el.onmouseup = function (e) { el.onmouseup = function(e) {
e.currentTarget.style.background = 'none'; e.currentTarget.style.background = 'none'
} }
}, },
} }
const customStyle = { const customStyle = {
inserted: function (el, binding) { inserted: function(el, binding) {
const label = el.querySelector('.el-checkbox__label'); const label = el.querySelector('.el-checkbox__label')
if (label) { if (label) {
if (label.getAttribute("data-color") === binding.value.wordColor) { if (label.getAttribute('data-color') === binding.value.wordColor) {
return return
}; }
label.style.setProperty('color', binding.value.wordColor, 'important'); label.style.setProperty('color', binding.value.wordColor, 'important')
label.setAttribute("data-color", binding.value.wordColor); label.setAttribute('data-color', binding.value.wordColor)
} }
}, },
} }
export default { export default {
install(Vue) { install(Vue) {
// Vue.directive('data-permission', dataPermission) // Vue.directive('data-permission', dataPermission)

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
import { hexColorToRGBA } from '@/views/chart/chart/util' import { hexColorToRGBA } from '@/views/chart/chart/util'
import { componentStyle, seniorCfg } from '../common/common' import { componentStyle, seniorCfg } from '../common/common'
import {BASE_ECHARTS_SELECT, DEFAULT_TOOLTIP} from '@/views/chart/chart/chart' import { BASE_ECHARTS_SELECT, DEFAULT_TOOLTIP } from '@/views/chart/chart/chart'
let bubbleArray = [] let bubbleArray = []
let terminalType = 'pc' let terminalType = 'pc'

View File

@ -400,7 +400,7 @@ span{
.field-style{ .field-style{
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: start; justify-content: flex-start;
} }
.field-text{ .field-text{

View File

@ -1,14 +1,13 @@
export class BaseConfig { export class BaseConfig {
set(options, notUndefined) { set(options, notUndefined) {
options = this.initOptions(options) options = this.initOptions(options)
for (let name in options) { for (const name in options) {
if (options.hasOwnProperty(name)) { if (options.hasOwnProperty(name)) {
if (!(this[name] instanceof Array)) { if (!(this[name] instanceof Array)) {
if (notUndefined === true) { if (notUndefined === true) {
this[name] = options[name] === undefined ? this[name] : options[name]; this[name] = options[name] === undefined ? this[name] : options[name]
} else { } else {
this[name] = options[name]; this[name] = options[name]
} }
} }
} }
@ -18,10 +17,10 @@ export class BaseConfig {
sets(types, options) { sets(types, options) {
options = this.initOptions(options) options = this.initOptions(options)
if (types) { if (types) {
for (let name in types) { for (const name in types) {
if (types.hasOwnProperty(name) && options.hasOwnProperty(name)) { if (types.hasOwnProperty(name) && options.hasOwnProperty(name)) {
options[name].forEach(o => { options[name].forEach(o => {
this[name].push(new types[name](o)); this[name].push(new types[name](o))
}) })
} }
} }
@ -29,137 +28,137 @@ export class BaseConfig {
} }
initOptions(options) { initOptions(options) {
return options || {}; return options || {}
} }
isValid() { isValid() {
return true; return true
} }
} }
export class KeyValue extends BaseConfig { export class KeyValue extends BaseConfig {
constructor(options) { constructor(options) {
options = options || {}; options = options || {}
options.enable = options.enable === undefined ? true : options.enable; options.enable = options.enable === undefined ? true : options.enable
super(); super()
this.name = undefined; this.name = undefined
this.value = undefined; this.value = undefined
this.type = undefined; this.type = undefined
this.files = undefined; this.files = undefined
this.enable = undefined; this.enable = undefined
this.uuid = undefined; this.uuid = undefined
this.time = undefined; this.time = undefined
this.contentType = undefined; this.contentType = undefined
this.set(options); this.set(options)
} }
isValid() { isValid() {
return (!!this.name || !!this.value) && this.type !== 'file'; return (!!this.name || !!this.value) && this.type !== 'file'
} }
isFile() { isFile() {
return (!!this.name || !!this.value) && this.type === 'file'; return (!!this.name || !!this.value) && this.type === 'file'
} }
} }
export class Body extends BaseConfig { export class Body extends BaseConfig {
constructor(options) { constructor(options) {
super(); super()
this.type = "KeyValue"; this.type = 'KeyValue'
this.raw = undefined; this.raw = undefined
this.kvs = []; this.kvs = []
this.binary = []; this.binary = []
this.set(options); this.set(options)
this.sets({kvs: KeyValue}, {binary: KeyValue}, options); this.sets({ kvs: KeyValue }, { binary: KeyValue }, options)
} }
isValid() { isValid() {
if (this.isKV()) { if (this.isKV()) {
return this.kvs.some(kv => { return this.kvs.some(kv => {
return kv.isValid(); return kv.isValid()
}) })
} else { } else {
return !!this.raw; return !!this.raw
} }
} }
isKV() { isKV() {
return [BODY_TYPE.FORM_DATA, BODY_TYPE.WWW_FORM, BODY_TYPE.BINARY].indexOf(this.type) > 0; return [BODY_TYPE.FORM_DATA, BODY_TYPE.WWW_FORM, BODY_TYPE.BINARY].indexOf(this.type) > 0
} }
} }
export const createComponent = function (name) { export const createComponent = function(name) {
let component = MODELS[name]; const component = MODELS[name]
if (component) { if (component) {
return new component(); return new component()
} else { } else {
return new UnsupportedComponent() return new UnsupportedComponent()
} }
} }
export const BODY_TYPE = { export const BODY_TYPE = {
KV: "KeyValue", KV: 'KeyValue',
FORM_DATA: "Form_Data", FORM_DATA: 'Form_Data',
RAW: "Raw", RAW: 'Raw',
WWW_FORM: "WWW_FORM", WWW_FORM: 'WWW_FORM',
XML: "XML", XML: 'XML',
JSON: "JSON" JSON: 'JSON'
} }
export class Scenario extends BaseConfig { export class Scenario extends BaseConfig {
constructor(options = {}) { constructor(options = {}) {
super(); super()
this.id = undefined; this.id = undefined
this.name = undefined; this.name = undefined
this.url = undefined; this.url = undefined
this.variables = []; this.variables = []
this.headers = []; this.headers = []
this.requests = []; this.requests = []
this.environmentId = undefined; this.environmentId = undefined
this.dubboConfig = undefined; this.dubboConfig = undefined
this.environment = undefined; this.environment = undefined
this.enableCookieShare = false; this.enableCookieShare = false
this.enable = true; this.enable = true
this.databaseConfigs = []; this.databaseConfigs = []
this.tcpConfig = undefined; this.tcpConfig = undefined
this.set(options); this.set(options)
this.sets({ this.sets({
variables: KeyValue, variables: KeyValue,
headers: KeyValue, headers: KeyValue,
requests: RequestFactory, requests: RequestFactory,
databaseConfigs: DatabaseConfig databaseConfigs: DatabaseConfig
}, options); }, options)
} }
initOptions(options = {}) { initOptions(options = {}) {
options.id = options.id || uuid(); options.id = options.id || uuid()
options.requests = options.requests || [new RequestFactory()]; options.requests = options.requests || [new RequestFactory()]
options.databaseConfigs = options.databaseConfigs || []; options.databaseConfigs = options.databaseConfigs || []
options.dubboConfig = new DubboConfig(options.dubboConfig); options.dubboConfig = new DubboConfig(options.dubboConfig)
options.tcpConfig = new TCPConfig(options.tcpConfig); options.tcpConfig = new TCPConfig(options.tcpConfig)
return options; return options
} }
clone() { clone() {
let clone = new Scenario(this); const clone = new Scenario(this)
clone.id = uuid(); clone.id = uuid()
return clone; return clone
} }
isValid() { isValid() {
if (this.enable) { if (this.enable) {
for (let i = 0; i < this.requests.length; i++) { for (let i = 0; i < this.requests.length; i++) {
let validator = this.requests[i].isValid(this.environmentId, this.environment); const validator = this.requests[i].isValid(this.environmentId, this.environment)
if (!validator.isValid) { if (!validator.isValid) {
return validator; return validator
} }
} }
} }
return {isValid: true}; return { isValid: true }
} }
isReference() { isReference() {
return this.id.indexOf("#") !== -1 return this.id.indexOf('#') !== -1
} }
} }

View File

@ -1,20 +1,19 @@
const isBoolean = require("lodash.isboolean"); const isBoolean = require('lodash.isboolean')
const isEmpty = require("lodash.isempty"); const isEmpty = require('lodash.isempty')
const isInteger = require("lodash.isinteger"); const isInteger = require('lodash.isinteger')
const isNull = require("lodash.isnull"); const isNull = require('lodash.isnull')
const isNumber = require("lodash.isnumber"); const isNumber = require('lodash.isnumber')
const isObject = require("lodash.isobject"); const isObject = require('lodash.isobject')
const isString = require("lodash.isstring"); const isString = require('lodash.isstring')
const isArray = Array.isArray; const isArray = Array.isArray
class Convert { class Convert {
constructor() { constructor() {
this._option = { this._option = {
$id: "http://example.com/root.json", $id: 'http://example.com/root.json',
$schema: "http://json-schema.org/draft-07/schema#", $schema: 'http://json-schema.org/draft-07/schema#',
} }
this._object = null; this._object = null
} }
/** /**
@ -25,22 +24,22 @@ class Convert {
format(object, option = {}) { format(object, option = {}) {
// 数据校验确保传入的的object只能是对象或数组 // 数据校验确保传入的的object只能是对象或数组
if (!isObject(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; this._object = object
let convertRes; let convertRes
// 数组类型和对象类型结构不一样 // 数组类型和对象类型结构不一样
if (isArray(object)) { if (isArray(object)) {
convertRes = this._arrayToSchema(); convertRes = this._arrayToSchema()
} else { } else {
convertRes = this._objectToSchema(); convertRes = this._objectToSchema()
} }
// 释放 // 释放
this._object = null; this._object = null
return convertRes; return convertRes
} }
/** /**
@ -48,22 +47,22 @@ class Convert {
*/ */
_arrayToSchema() { _arrayToSchema() {
// root节点基本信息 // 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) { if (this._object.length > 0) {
let itemArr = []; const itemArr = []
for (let index = 0; index < this._object.length; index++) { for (let index = 0; index < this._object.length; index++) {
// 创建items对象的基本信息 // 创建items对象的基本信息
let objectItem = this._object[index] const objectItem = this._object[index]
let item = this._value2object(objectItem, `#/items`, 'items'); let item = this._value2object(objectItem, `#/items`, 'items')
if (isObject(objectItem) && !isEmpty(objectItem)) { 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 return result
} }
@ -72,8 +71,8 @@ class Convert {
* 对象类型转换成JSONSCHEMA * 对象类型转换成JSONSCHEMA
*/ */
_objectToSchema() { _objectToSchema() {
let baseResult = this._value2object(this._object, this._option.$id, "", true) let baseResult = this._value2object(this._object, this._option.$id, '', true)
let objectSchema = this._json2schema(this._object) const objectSchema = this._json2schema(this._object)
baseResult = Object.assign(baseResult, objectSchema) baseResult = Object.assign(baseResult, objectSchema)
return baseResult return baseResult
} }
@ -83,69 +82,69 @@ class Convert {
* @param {*} object 需要转换对象 * @param {*} object 需要转换对象
* @param {*} name $id值 * @param {*} name $id值
*/ */
_json2schema(object, name = "") { _json2schema(object, name = '') {
// 如果递归值不是对象那么return掉 // 如果递归值不是对象那么return掉
if (!isObject(object)) { if (!isObject(object)) {
return; return
} }
// 处理当前路径$id // 处理当前路径$id
if (name === "" || name == undefined) { if (name === '' || name == undefined) {
name = "#" name = '#'
} }
let result = {}; const result = {}
// 判断传入object是对象还是数组。 // 判断传入object是对象还是数组。
if (isArray(object)) { if (isArray(object)) {
result.items = {}; result.items = {}
} else { } else {
result.properties = {}; result.properties = {}
} }
// 遍历传入的对象 // 遍历传入的对象
for (const key in object) { for (const key in object) {
if (object.hasOwnProperty(key)) { if (object.hasOwnProperty(key)) {
const element = object[key]; const element = object[key]
// 如果只是undefined。跳过 // 如果只是undefined。跳过
if (element === undefined) { if (element === undefined) {
continue; continue
} }
let $id = `${name}/properties/${key}` const $id = `${name}/properties/${key}`
// 判断当前 element 的值 是否也是对象如果是就继续递归不是就赋值给result // 判断当前 element 的值 是否也是对象如果是就继续递归不是就赋值给result
if(!result["properties"]){ if (!result['properties']) {
continue; continue
} }
if (isObject(element)) { if (isObject(element)) {
// 创建当前属性的基本信息 // 创建当前属性的基本信息
result["properties"][key] = this._value2object(element, $id, key) result['properties'][key] = this._value2object(element, $id, key)
if (isArray(element)) { if (isArray(element)) {
// 针对空数组和有值的数组做不同处理 // 针对空数组和有值的数组做不同处理
if (element.length > 0) { if (element.length > 0) {
// 是数组 // 是数组
let itemArr = []; const itemArr = []
for (let index = 0; index < element.length; index++) { for (let index = 0; index < element.length; index++) {
let elementItem = element[index]; const elementItem = element[index]
// 创建items对象的基本信息 // 创建items对象的基本信息
let item = this._value2object(elementItem, `${$id}/items`, key + 'items'); let item = this._value2object(elementItem, `${$id}/items`, key + 'items')
// 判断第一项是否是对象,且对象属性不为空 // 判断第一项是否是对象,且对象属性不为空
if (isObject(elementItem) && !isEmpty(elementItem)) { if (isObject(elementItem) && !isEmpty(elementItem)) {
// 新增的properties才合并进来 // 新增的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 { } 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 { } else {
// 一般属性直接获取基本信息 // 一般属性直接获取基本信息
if (result["properties"]) { if (result['properties']) {
result["properties"][key] = this._value2object(element, $id, key); result['properties'][key] = this._value2object(element, $id, key)
} }
} }
} }
} }
return result; return result
} }
/** /**
@ -155,39 +154,39 @@ class Convert {
* @param {*} key * @param {*} key
*/ */
_value2object(value, $id, key = '', root = false) { _value2object(value, $id, key = '', root = false) {
let objectTemplate = { const objectTemplate = {
$id: $id, $id: $id,
title: `The ${key} Schema`, title: `The ${key} Schema`,
mock: { mock: {
"mock": value 'mock': value
}, },
} }
// 判断是否为初始化root数据 // 判断是否为初始化root数据
if (root) { if (root) {
objectTemplate["$schema"] = this._option.$schema; objectTemplate['$schema'] = this._option.$schema
objectTemplate["title"] = `The Root Schema`; objectTemplate['title'] = `The Root Schema`
objectTemplate["mock"] = undefined; objectTemplate['mock'] = undefined
} }
if (isBoolean(value)) { if (isBoolean(value)) {
objectTemplate.type = "boolean"; objectTemplate.type = 'boolean'
} else if (isInteger(value)) { } else if (isInteger(value)) {
objectTemplate.type = "integer"; objectTemplate.type = 'integer'
} else if (isNumber(value)) { } else if (isNumber(value)) {
objectTemplate.type = "number"; objectTemplate.type = 'number'
} else if (isString(value)) { } else if (isString(value)) {
objectTemplate.type = "string"; objectTemplate.type = 'string'
} else if (isNull(value)) { } else if (isNull(value)) {
objectTemplate.type = "null"; objectTemplate.type = 'null'
} else if (isArray(value)) { } else if (isArray(value)) {
objectTemplate.type = "array"; objectTemplate.type = 'array'
objectTemplate["mock"] = undefined; objectTemplate['mock'] = undefined
} else if (isObject(value)) { } else if (isObject(value)) {
objectTemplate.type = "object" objectTemplate.type = 'object'
objectTemplate["mock"] = undefined; objectTemplate['mock'] = undefined
} }
return objectTemplate; return objectTemplate
} }
} }

View File

@ -1,142 +1,134 @@
export function formatJson (json) { export function formatJson(json) {
let i = 0, let i = 0
il = 0, let il = 0
tab = " ", const tab = ' '
newJson = "", let newJson = ''
indentLevel = 0, let indentLevel = 0
inString = false, let inString = false
currentChar = null; let currentChar = null
let flag = false; let flag = false
for (i = 0, il = json.length; i < il; i += 1) { for (i = 0, il = json.length; i < il; i += 1) {
currentChar = json.charAt(i); currentChar = json.charAt(i)
switch (currentChar) { switch (currentChar) {
case '{': case '{':
if (i != 0 && json.charAt(i - 1) === '$') { if (i != 0 && json.charAt(i - 1) === '$') {
newJson += currentChar; newJson += currentChar
flag = true; flag = true
} else if (!inString) { } else if (!inString) {
newJson += currentChar + "\n" + repeat(tab, indentLevel + 1); newJson += currentChar + '\n' + repeat(tab, indentLevel + 1)
indentLevel += 1 indentLevel += 1
} else { } else {
newJson += currentChar newJson += currentChar
} }
break; break
case '[': case '[':
if (!inString) { if (!inString) {
newJson += currentChar + "\n" + repeat(tab, indentLevel + 1); newJson += currentChar + '\n' + repeat(tab, indentLevel + 1)
indentLevel += 1 indentLevel += 1
} else { } else {
newJson += currentChar newJson += currentChar
} }
break; break
case '}': case '}':
if (flag) { if (flag) {
newJson += currentChar; newJson += currentChar
flag = false; flag = false
} else if (!inString) { } else if (!inString) {
indentLevel -= 1; indentLevel -= 1
newJson += "\n" + repeat(tab, indentLevel) + currentChar newJson += '\n' + repeat(tab, indentLevel) + currentChar
} else { } else {
newJson += currentChar newJson += currentChar
} }
break; break
case ']': case ']':
if (!inString) { if (!inString) {
indentLevel -= 1; indentLevel -= 1
newJson += "\n" + repeat(tab, indentLevel) + currentChar newJson += '\n' + repeat(tab, indentLevel) + currentChar
} else { } else {
newJson += currentChar newJson += currentChar
} }
break; break
case ',': case ',':
if (!inString) { if (!inString) {
newJson += ",\n" + repeat(tab, indentLevel) newJson += ',\n' + repeat(tab, indentLevel)
} else { } else {
newJson += currentChar newJson += currentChar
} }
break; break
case ':': case ':':
if (!inString) { if (!inString) {
newJson += ": " newJson += ': '
} else { } else {
newJson += currentChar newJson += currentChar
} }
break; break
case ' ': case ' ':
case "\n": case '\n':
case "\t": case '\t':
if (inString) { if (inString) {
newJson += currentChar newJson += currentChar
} }
break; break
case '"': case '"':
if (i > 0 && json.charAt(i - 1) !== '\\') { if (i > 0 && json.charAt(i - 1) !== '\\') {
inString = !inString inString = !inString
} }
newJson += currentChar; newJson += currentChar
break; break
default: default:
newJson += currentChar; newJson += currentChar
break break
} }
} }
return newJson; return newJson
} }
function repeat(s, count) { function repeat(s, count) {
return new Array(count + 1).join(s) return new Array(count + 1).join(s)
} }
export function formatXml(text) { export function formatXml(text) {
//去掉多余的空格 // 去掉多余的空格
text = '\n' + text.replace(/(<\w+)(\s.*?>)/g, function ($0, name, props) { text = '\n' + text.replace(/(<\w+)(\s.*?>)/g, function($0, name, props) {
return name + ' ' + props.replace(/\s+(\w+=)/g, " $1"); return name + ' ' + props.replace(/\s+(\w+=)/g, ' $1')
}); })
//把注释编码 // 把注释编码
text = text.replace(/<!--(.+?)-->/g, function ($0, text) { text = text.replace(/<!--(.+?)-->/g, function($0, text) {
var ret = '<!--' + escape(text) + '-->'; var ret = '<!--' + escape(text) + '-->'
//alert(ret); return ret
return ret; })
}); // 调整格式
//调整格式 var rgx = /\n(<(([^\?]).+?)(?:\s|\s*?>|\s*?(\/)>)(?:.*?(?:(?:(\/)>)|(?:<(\/)\2>)))?)/mg
var rgx = /\n(<(([^\?]).+?)(?:\s|\s*?>|\s*?(\/)>)(?:.*?(?:(?:(\/)>)|(?:<(\/)\2>)))?)/mg; var nodeStack = []
var nodeStack = []; var output = text.replace(rgx, function($0, all, name, isBegin, isCloseFull1, isCloseFull2, isFull1, isFull2) {
var output = text.replace(rgx, function ($0, all, name, isBegin, isCloseFull1, isCloseFull2, isFull1, isFull2) { var isClosed = (isCloseFull1 == '/') || (isCloseFull2 == '/') || (isFull1 == '/') || (isFull2 == '/')
var isClosed = (isCloseFull1 == '/') || (isCloseFull2 == '/' ) || (isFull1 == '/') || (isFull2 == '/'); var prefix = ''
//alert([all,isClosed].join('='));
var prefix = '';
if (isBegin == '!') { if (isBegin == '!') {
prefix = getPrefix(nodeStack.length); prefix = getPrefix(nodeStack.length)
} } else {
else {
if (isBegin != '/') { if (isBegin != '/') {
prefix = getPrefix(nodeStack.length); prefix = getPrefix(nodeStack.length)
if (!isClosed) { if (!isClosed) {
nodeStack.push(name); nodeStack.push(name)
} }
} } else {
else { nodeStack.pop()
nodeStack.pop(); prefix = getPrefix(nodeStack.length)
prefix = getPrefix(nodeStack.length);
} }
} }
var ret = '\n' + prefix + all; var ret = '\n' + prefix + all
return ret; return ret
}); })
var prefixSpace = -1; var prefixSpace = -1
var outputText = output.substring(1); var outputText = output.substring(1)
//把注释还原并解码,调格式 // 把注释还原并解码,调格式
outputText = outputText.replace(/(\s*)<!--(.+?)-->/g, function ($0, prefix, text) { outputText = outputText.replace(/(\s*)<!--(.+?)-->/g, function($0, prefix, text) {
if (prefix.charAt(0) == '\r') if (prefix.charAt(0) == '\r') { prefix = prefix.substring(1) }
prefix = prefix.substring(1); text = unescape(text).replace(/\r/g, '\n')
text = unescape(text).replace(/\r/g, '\n'); var ret = '\n' + prefix + '<!--' + text.replace(/^\s*/mg, prefix) + '-->'
var ret = '\n' + prefix + '<!--' + text.replace(/^\s*/mg, prefix) + '-->'; return ret
//alert(ret); })
return ret; return outputText.replace(/\s+$/g, '').replace(/\r/g, '\r\n')
});
return outputText.replace(/\s+$/g, '').replace(/\r/g, '\r\n');
} }
/** /**
@ -146,17 +138,17 @@ export function formatXml(text) {
* @example formatTime('2018-1-29', '{y}/{m}/{d} {h}:{i}:{s}') // -> 2018/01/29 00:00:00 * @example formatTime('2018-1-29', '{y}/{m}/{d} {h}:{i}:{s}') // -> 2018/01/29 00:00:00
*/ */
export function formatTime(time, cFormat) { export function formatTime(time, cFormat) {
if (arguments.length === 0) return null; if (arguments.length === 0) return null
if ((time + '').length === 10) { if ((time + '').length === 10) {
time = +time * 1000; time = +time * 1000
} }
let format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}', date; const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'; let date
if (typeof time === 'object') { if (typeof time === 'object') {
date = time; date = time
} else { } else {
date = new Date(time); date = new Date(time)
} }
let formatObj = { const formatObj = {
y: date.getFullYear(), y: date.getFullYear(),
m: date.getMonth() + 1, m: date.getMonth() + 1,
d: date.getDate(), d: date.getDate(),
@ -164,22 +156,22 @@ export function formatTime(time, cFormat) {
i: date.getMinutes(), i: date.getMinutes(),
s: date.getSeconds(), s: date.getSeconds(),
a: date.getDay() a: date.getDay()
}; }
return format.replace(/{([ymdhisa])+}/g, (result, key) => { return format.replace(/{([ymdhisa])+}/g, (result, key) => {
let value = formatObj[key]; let value = formatObj[key]
if (key === 'a') return ['一', '二', '三', '四', '五', '六', '日'][value - 1]; if (key === 'a') return ['一', '二', '三', '四', '五', '六', '日'][value - 1]
if (result.length > 0 && value < 10) { if (result.length > 0 && value < 10) {
value = '0' + value; value = '0' + value
} }
return value || 0; return value || 0
}); })
} }
function getPrefix(prefixIndex) { function getPrefix(prefixIndex) {
var span = ' '; var span = ' '
var output = []; var output = []
for (var i = 0; i < prefixIndex; ++i) { for (var i = 0; i < prefixIndex; ++i) {
output.push(span); output.push(span)
} }
return output.join(''); return output.join('')
} }

View File

@ -746,7 +746,7 @@ export default {
text-align: right; text-align: right;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: end; justify-content: flex-end;
.el-input--medium .el-input__icon { .el-input--medium .el-input__icon {
line-height: 32px; line-height: 32px;