diff --git a/nezha-fronted/src/components/common/language/cn.js b/nezha-fronted/src/components/common/language/cn.js index c10a78b1c..6dbe412bb 100644 --- a/nezha-fronted/src/components/common/language/cn.js +++ b/nezha-fronted/src/components/common/language/cn.js @@ -97,7 +97,8 @@ const cn = { stack: '查看堆叠图', stackBack: '返回原始图' }, - SyncSave: '保存同时更新 Assets' + SyncSave: '保存同时更新 Assets', + copySuccess: '复制成功' }, setup: { step0: '欢迎', @@ -1175,12 +1176,12 @@ const cn = { scrape_timeout: '超时时间', scrape_timeout_placeholder: '默认全局超时时间', type: '类型', - bearer_token: 'Token', + bearer_token: 'bearer token', username: '用户名', password: '密码', - authTypeNull: '无', - authTypeWord: '用户名密码', - authTypeToken: 'Token', + authTypeNull: 'none', + authTypeWord: 'basic auth', + authTypeToken: 'bearer token', }, metrics: { metrics: '指标', diff --git a/nezha-fronted/src/components/common/language/en.js b/nezha-fronted/src/components/common/language/en.js index 5c03da258..2b3eb04e8 100644 --- a/nezha-fronted/src/components/common/language/en.js +++ b/nezha-fronted/src/components/common/language/en.js @@ -102,7 +102,8 @@ const en = { stack: 'Show stack chart', stackBack: 'Back to original chart' }, - SyncSave: 'Save&Sync' + SyncSave: 'Save&Sync', + copySuccess: 'Copy success' }, pageSize: '/page', setup: { @@ -1179,12 +1180,12 @@ const en = { scrape_timeout: 'Scrape timeout', scrape_timeout_placeholder: 'default global scrape timeout', type: 'Type', - bearer_token: 'Token', + bearer_token: 'bearer token', username: 'Username', password: 'Password', authTypeNull: 'None', - authTypeWord: 'Username and password', - authTypeToken: 'Token', + authTypeWord: 'basic auth', + authTypeToken: 'bearer token', }, metrics: { metrics: 'Metrics', // "指标" diff --git a/nezha-fronted/src/components/common/rightBox/moduleBox.vue b/nezha-fronted/src/components/common/rightBox/moduleBox.vue index e9ad84287..1af39e6b4 100644 --- a/nezha-fronted/src/components/common/rightBox/moduleBox.vue +++ b/nezha-fronted/src/components/common/rightBox/moduleBox.vue @@ -111,24 +111,24 @@ - - - - - - +
+ + + + + @@ -142,63 +142,54 @@
- - - -
- - - - - - - -
- -
-
-
- - - - = - - - - -
-
-
-
-
- - -
- - - - - +
+
+ + + + = + + + + + + +
+
+
+ +
+ + +
+
+ + + + = + + + +
- -
-
-
- - - - = - - - - -
-
-
- +
+
+ + + +
@@ -225,9 +216,10 @@ -
- asd -
+
+          {{configsCopyValue}}
+         
+        
@@ -322,10 +314,14 @@ export default { { name: this.$t('project.endpoint.authTypeNull'), value: 0 }, { name: this.$t('project.endpoint.authTypeWord'), value: 1 }, { name: this.$t('project.endpoint.authTypeToken'), value: 2 } - ] + ], + configsCopyValue: '' } }, methods: { + change(){ + console.log(this.$refs['select'+0]) + }, selectWalk (walk) { if (this.editModule.walk.indexOf(walk) != -1) { this.editModule.walk.splice(this.editModule.walk.indexOf(walk), 1) @@ -438,11 +434,12 @@ export default { }, /* 保存 */ save () { - this.editModule.configs.param = this.paramToJson(this.editModule.configs.paramObj) - this.editModule.configs.labels = this.labelsToJson(this.editModule.configs.labelModule) + this.editModule.configs.param = this.paramToJson(this.editModule.paramObj) + console.log(this.editModule.paramObj, this.editModule.configs.param) + this.editModule.configs.labels = this.labelsToJson(this.editModule.labelModule) const params = { ...this.editModule } params.configs.walk = params.walk - params.configs.prot = params.prot + params.configs.port = params.port params.configs = JSON.stringify(params.configs) if (this.authType === 2 && !this.editModule.configs.bearer_token) { this.$message.error("'token' is required") @@ -519,50 +516,49 @@ export default { }, // 清除param clearAllParam () { - this.editModule.configs.paramObj = [] + this.editModule.paramObj = [] }, // 新增param addParam () { - this.editModule.configs.paramObj.push({ key: '', value: '' }) + this.editModule.paramObj.push({ key: '', value: [] ,showList: false}) }, // 移除单个param removeParam (index) { - this.editModule.configs.paramObj.splice(index, 1) + this.editModule.paramObj.splice(index, 1) }, // 新增label addLabel () { - this.editModule.configs.labelModule.push({ key: '', value: '' }) + this.editModule.labelModule.push({ key: '', value: '' }) }, // 移除单个Label removeLabel (index) { - this.editModule.configs.labelModule.splice(index, 1) + if (this.editModule.labelModule.length === 1) { + return + } + this.editModule.labelModule.splice(index, 1) }, // 将param转为json字符串格式 paramToJson (param) { const tempParam = {} for (let i = 0; i < param.length; i++) { - eval('tempParam["' + param[i].key + '"]="' + param[i].value + '"') - } - const jsonString = JSON.stringify(tempParam) - if (jsonString == '{}') { - return '' - } else { - return jsonString + if (!param[i].key || !param[i].value.length) { + continue + } + tempParam[param[i].key] = param[i].value } + return tempParam }, // 将labels转为json字符串格式 labelsToJson (param) { const tempParam = {} for (let i = 0; i < param.length; i++) { + if (!param[i].key || !param[i].value) { + continue + } eval('tempParam["' + param[i].key + '"]="' + param[i].value + '"') } - const jsonString = JSON.stringify(tempParam) - if (jsonString == '{}') { - return '' - } else { - return jsonString - } + return tempParam }, // 输入建议 querySearch (queryString, cb) { @@ -582,6 +578,40 @@ export default { username: '', password: '' } + }, + copyValue () { + const domUrl = document.createElement('input') + domUrl.value = this.configsCopyValue + domUrl.id = 'creatDom' + document.body.appendChild(domUrl) + domUrl.select() // 选择对象 + document.execCommand('Copy') // 执行浏览器复制命令 + const creatDom = document.getElementById('creatDom') + creatDom.parentNode.removeChild(creatDom) + this.$message(this.$t('overall.copySuccess')) + }, + syntaxHighlight (json) { + if (typeof json != 'string') { + json = JSON.stringify(json, undefined, 2) + } + json = json.replace(/&/g, '&').replace(//g, '>') + return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, + function (match) { + let cls = 'number' + if (/^"/.test(match)) { + if (/:$/.test(match)) { + cls = 'key' + } else { + cls = 'string' + } + } else if (/true|false/.test(match)) { + cls = 'boolean' + } else if (/null/.test(match)) { + cls = 'null' + } + return '' + match + '' + } + ) } }, mounted () { @@ -629,6 +659,42 @@ export default { // } // } } + }, + editModule: { + deep: true, + immediate: true, + handler (n) { + console.log(n) + if (n && n.configs) { + const params = Object.assign({}, n.configs) + params.param = this.paramToJson(this.editModule.paramObj) + params.labels = this.labelsToJson(this.editModule.labelModule) + params.walk = n.walk + params.port = n.port + Object.keys(params).forEach(key => { + console.log(key, !params[key] || !params[key].length) + if (!params[key]) { + delete params[key] + } + if (Array.isArray(params[key]) && !params[key].length) { + delete params[key] + } + }) + if (params.basic_auth && !params.basic_auth.username) { + delete params.basic_auth + } + if (params.basic_auth && !params.basic_auth.password) { + delete params.basic_auth + } + if (!Object.keys(params.param).length) { + delete params.param + } + if (!Object.keys(params.labels).length) { + delete params.labels + } + this.configsCopyValue = JSON.stringify(params, null, 2) + } + } } } } @@ -684,6 +750,9 @@ export default { display: inline-block; padding: 0 18px 0 8px; } + .half-form-item:nth-child(even){ + padding-left: 0; + } /deep/ .el-tabs__item{ width: 90px; padding: 0; @@ -704,6 +773,9 @@ export default { /deep/ .el-autocomplete{ width: 100%; } + /deep/ .el-tabs__content{ + padding-left: 18px; + } .need-rotate.nz-icon-drop-down{ display: inline-block; transition: transform .3s; @@ -713,6 +785,36 @@ export default { -180deg ); } + .module-add-label{ + display: inline-block; + width: 300px; + height: 18px; + background: #FFFCF9; + border: 1px solid #FFE0BD; + border-radius: 2px; + text-align: center; + line-height: 18px; + margin-right: 80px; + } + .configs-copy-value{ + opacity: 0.9; + background: #F6F8FA; + border: 1px solid #E7EAED; + border-radius: 2px; + height: 140px; + overflow-y: auto; + position: relative; + margin-top: 10px; + padding: 10px 15px; + width: calc(100% - 40px); + margin-left: 20px; + } + .configs-copy-value .copy-value-content{ + position: absolute; + right: 20px; + top: 14px; + cursor: pointer; + } diff --git a/nezha-fronted/src/components/page/monitor/module/moduleList.vue b/nezha-fronted/src/components/page/monitor/module/moduleList.vue index 3567d6e1c..b6fe67921 100644 --- a/nezha-fronted/src/components/page/monitor/module/moduleList.vue +++ b/nezha-fronted/src/components/page/monitor/module/moduleList.vue @@ -67,24 +67,32 @@ export default { type: 'http', port: 9100, configs: { + walk: [], + snmpCredentialsId: '', + metrics_path: '', + port: '', + host: '{{asset.manageIp}}', scrape_interval: '', scrape_timeout: '', - metrics_path: '', + params: '', + labels: '', + paramObj: [], + labelModule: [], basic_auth: { username: '', password: '' }, - bearer_token: '', - labels: '', - params: '', - paramObj: [], - labelModule: [], - walk: [], - host: '{{asset.manageIp}}', - port: '', - snmpCredentialsId: 'public' + bearer_token: '' }, - walk: [] + walk: [], + labelModule: [{ + key: '', + value: '' + }], + paramObj: [{ + key: '', + value: [] + }] }, // 新增/编辑的module tableId: 'moduleTable', queryPermission: 'account_view', @@ -114,6 +122,22 @@ export default { this.object.configs = JSON.parse(this.object.configs) this.object.walk = this.object.configs.walk ? JSON.parse(JSON.stringify(this.object.configs.walk)) : [] this.object.port = this.object.configs.port ? JSON.parse(JSON.stringify(this.object.configs.port)) : 9100 + this.object.paramObj = [] + this.object.labelModule = [] + if (this.object.configs.labels !== '{}'&&this.object.configs.labels) { + Object.keys(this.object.configs.labels).forEach(key => { + this.object.labelModule.push({ key, value: this.object.configs.labels[key] }) + }) + } else { + this.object.labelModule.push({ key: '', value: '' }) + } + if (this.object.configs.param !== '{}'&&this.object.configs.param) { + Object.keys(this.object.configs.param).forEach(key => { + this.object.paramObj.push({ key, value: this.object.configs.param[key] }) + }) + } else { + this.object.paramObj.push({ key: '', value: [] }) + } this.rightBox.show = true } },