diff --git a/frontend/src/business/components/api/automation/report/ApiReportDetail.vue b/frontend/src/business/components/api/automation/report/ApiReportDetail.vue index 9293c4c48d..da22971204 100644 --- a/frontend/src/business/components/api/automation/report/ApiReportDetail.vue +++ b/frontend/src/business/components/api/automation/report/ApiReportDetail.vue @@ -130,6 +130,7 @@ export default { this.fullTreeNodes = []; this.failsTreeNodes = []; this.isRequestResult = false; + this.activeName = "total"; }, handleClick(tab, event) { this.isRequestResult = false; diff --git a/frontend/src/business/components/api/definition/components/assertion/ApiJsonpathSuggest.vue b/frontend/src/business/components/api/definition/components/assertion/ApiJsonpathSuggest.vue index 3efacbf922..2c42001ff0 100644 --- a/frontend/src/business/components/api/definition/components/assertion/ApiJsonpathSuggest.vue +++ b/frontend/src/business/components/api/definition/components/assertion/ApiJsonpathSuggest.vue @@ -2,7 +2,7 @@ @@ -16,8 +16,8 @@ let dotReplace = "#DOT_MASK#"; const clickoutside = { // 初始化指令 - bind (el, binding, vnode) { - function documentHandler (e) { + bind(el, binding, vnode) { + function documentHandler(e) { // 这里判断点击的元素是否是本身,是本身,则返回 if (el.contains(e.target)) { return false @@ -28,12 +28,14 @@ const clickoutside = { binding.value(e) } } + // 给当前元素绑定个私有变量,方便在unbind中可以解除事件监听 el.__vueClickOutside__ = documentHandler document.addEventListener('click', documentHandler) }, - update () { }, - unbind (el, binding) { + update() { + }, + unbind(el, binding) { // 解除事件监听 document.removeEventListener('click', el.__vueClickOutside__) delete el.__vueClickOutside__ @@ -43,7 +45,7 @@ const clickoutside = { export default { name: "MsApiJsonpathSuggest", components: {MsInstructionsIcon, MsDrawer}, - directives: { clickoutside }, + directives: {clickoutside}, data() { return { visible: false, @@ -59,116 +61,115 @@ export default { } }, }, - methods: { - close() { - this.visible = false; - }, - open(objStr) { - this.data = {}; - try { - // 解决精度丢失问题 - // let stringedJSON = objStr.replace(/:\s*([-+Ee0-9.]+)/g, ': "$1"'); - // 一些情况会解析失败,先注释掉 - let param = JSON.parse(objStr); - if (param instanceof Array) { - this.$warning('不支持解析JSON数组'); - return; - } - this.data = param; - } catch (e) { - this.$warning(this.$t('api_test.request.assertions.json_path_err')); + methods: { + close() { + this.visible = false; + }, + open(objStr) { + this.data = {}; + try { + // 解决精度丢失问题 + let JSONBig = require('json-bigint')({"storeAsString": true}); + let param = JSON.parse(JSON.stringify(JSONBig.parse(objStr))); + if (param instanceof Array) { + this.$warning('不支持解析JSON数组'); return; } - this.visible = true; - }, - pathChangeHandler(data) { - let paramNames = []; - let result = {}; - try { - paramNames = this.parseSpecialChar(data); - result = this.getParamValue(this.data, 0, paramNames); - } catch (e) { - result = {}; - result.key = 'var'; - } - result.path = '$.' + data; - this.$emit('addSuggest', result); - }, - // 替换. 等特殊字符 - parseSpecialChar(data) { - let paramNames = []; - let reg = /\['.*'\]/; - let searchStr = reg.exec(data); - if (searchStr) { - searchStr.forEach(item => { - if (data.startsWith("['")) { - data = data.replace(item, item.replace('.', dotReplace)); - } else { - data = data.replace(item, '.' + item.replace('.', dotReplace)); - } - }); - paramNames = data.split('.'); - } else { - paramNames = data.split('.'); - } - for (let i in paramNames) { - if (paramNames[i].search(reg) > -1) { - paramNames[i] = paramNames[i].substring(2, paramNames[i].length - 2); - } - paramNames[i] = paramNames[i].replace(dotReplace, '.'); - } - return paramNames; - }, - getParamValue(obj, index, params) { - if (params.length < 1) { - return {}; - } - - let param = params[index]; - let childObj; - - let reg = /\[\d\]$/; - let regIndex = param.search(reg); - if (regIndex > -1) { - let paramName = param.substring(0, regIndex); - let paramIndex = param.substring(regIndex + 1, param.length - 1); - param = paramIndex; - childObj = obj[paramName][paramIndex]; - } else { - childObj = obj[params[index]]; - } - if (index === params.length - 1) { - if (childObj instanceof Object) { - childObj = JSON.stringify(childObj); - } else { - childObj = childObj + ""; - } - return { - key: param, - value: childObj - }; - } - index++; - return this.getParamValue(childObj, index, params); + this.data = param; + } catch (e) { + this.$warning(this.$t('api_test.request.assertions.json_path_err')); + return; } + this.visible = true; + }, + pathChangeHandler(data) { + let paramNames = []; + let result = {}; + try { + paramNames = this.parseSpecialChar(data); + result = this.getParamValue(this.data, 0, paramNames); + } catch (e) { + result = {}; + result.key = 'var'; + } + result.path = '$.' + data; + this.$emit('addSuggest', result); + }, + // 替换. 等特殊字符 + parseSpecialChar(data) { + let paramNames = []; + let reg = /\['.*'\]/; + let searchStr = reg.exec(data); + if (searchStr) { + searchStr.forEach(item => { + if (data.startsWith("['")) { + data = data.replace(item, item.replace('.', dotReplace)); + } else { + data = data.replace(item, '.' + item.replace('.', dotReplace)); + } + }); + paramNames = data.split('.'); + } else { + paramNames = data.split('.'); + } + for (let i in paramNames) { + if (paramNames[i].search(reg) > -1) { + paramNames[i] = paramNames[i].substring(2, paramNames[i].length - 2); + } + paramNames[i] = paramNames[i].replace(dotReplace, '.'); + } + return paramNames; + }, + getParamValue(obj, index, params) { + if (params.length < 1) { + return {}; + } + + let param = params[index]; + let childObj; + + let reg = /\[\d\]$/; + let regIndex = param.search(reg); + if (regIndex > -1) { + let paramName = param.substring(0, regIndex); + let paramIndex = param.substring(regIndex + 1, param.length - 1); + param = paramIndex; + childObj = obj[paramName][paramIndex]; + } else { + childObj = obj[params[index]]; + } + if (index === params.length - 1) { + if (childObj instanceof Object) { + childObj = JSON.stringify(childObj); + } else { + childObj = childObj + ""; + } + return { + key: param, + value: childObj + }; + } + index++; + return this.getParamValue(childObj, index, params); } } +}