diff --git a/nezha-fronted/src/assets/stylus/main.scss b/nezha-fronted/src/assets/stylus/main.scss index 6f8d94bae..e87ddacc6 100644 --- a/nezha-fronted/src/assets/stylus/main.scss +++ b/nezha-fronted/src/assets/stylus/main.scss @@ -829,6 +829,9 @@ li{ .el-scrollbar__thumb { background-color: #aaa; } +.el-autocomplete-suggestion__wrap.el-scrollbar__wrap { + margin-bottom: 0 !important; +} .el-scrollbar__thumb:hover { background-color: #999; } diff --git a/nezha-fronted/src/components/common/header.vue b/nezha-fronted/src/components/common/header.vue index b70cdff81..526750dfd 100644 --- a/nezha-fronted/src/components/common/header.vue +++ b/nezha-fronted/src/components/common/header.vue @@ -90,7 +90,7 @@ - {{$t('overall.config')}} + {{$t('overall.config')}} {{$t('config.account.account')}} @@ -101,6 +101,9 @@ {{$t('config.dc.dc')}} + + {{$t('config.model.model')}} + diff --git a/nezha-fronted/src/components/common/language/en.js b/nezha-fronted/src/components/common/language/en.js index 30638d212..182ea48f0 100644 --- a/nezha-fronted/src/components/common/language/en.js +++ b/nezha-fronted/src/components/common/language/en.js @@ -214,7 +214,7 @@ const en = { addAssetType:'New asset type',//'新增资产类型' existAssetType:'Existed asset type'//'已存在的资产类型' }, - vendor:'Vendor',//'厂商/型号' + vendorModel:'Vendor/Model',//'厂商/型号' vendorTab:{ vendor:'Vendor/Model',//'厂商/型号' vendorName:'New vendor',//'新厂商' @@ -420,7 +420,8 @@ const en = { assets: "Assets", editModel: 'Edit model', createModel: 'Create model', - remark: 'Remark' + remark: 'Remark', + type: 'Type' } }, alert: { diff --git a/nezha-fronted/src/components/common/rightBox/assetBox.vue b/nezha-fronted/src/components/common/rightBox/assetBox.vue index bb4687d0b..b6b2e80f0 100644 --- a/nezha-fronted/src/components/common/rightBox/assetBox.vue +++ b/nezha-fronted/src/components/common/rightBox/assetBox.vue @@ -66,7 +66,7 @@ + @change="getAllModelOptionData()"> - + + <!–右上角按钮–> {{$t('overall.esc')}} - + <!–标题–> {{$t('asset.createAssetTab.assetTypeTab.assetType')}} - + <!–表单内容–> {{$t('asset.createAssetTab.assetTypeTab.addAssetType')}} @@ -155,11 +155,11 @@ - + --> {{assetViewData.assetType}} - + + - + {{currentModel.name}} + + + + + + - + {{currentModel.remark}} @@ -109,27 +122,89 @@ save() { this.$refs.modelForm.validate((valid) => { if (valid) { - if (this.currentModel.id) { - this.$put('model', this.currentModel).then(response => { - if (response.code === 200) { - this.$message({duration: 1000, type: 'success', message: this.$t("tip.saveSuccess")}); - this.rightBox.show = false; - this.$emit('reload'); - } else { - this.$message.error(response.msg); - } - }); + let errMsg = []; + //vendor和type如果是新记录,需要先请求后台新增,再获取code + let vendorReady = false; + let vendorCode = this.autocompleteExist('vendor', this.currentModel.vendor.value); + if (vendorCode) { + this.currentModel.vendorCode = vendorCode; + vendorReady = true; } else { - this.$post('model', this.currentModel).then(response => { + let vendor = {type: 'vendor', value: this.currentModel.vendor.value}; + this.$post("sys/dict/save", vendor).then(response => { if (response.code === 200) { - this.$message({duration: 1000, type: 'success', message: this.$t("tip.saveSuccess")}); - this.rightBox.show = false; - this.$emit("reload"); + //保存成功后,重新获取 + this.$get('sys/dict/all?type=vendor').then(response => { + if (response.code === 200) { + this.vendorData = response.data; + this.currentModel.vendorCode = this.autocompleteExist('vendor', this.currentModel.vendor.value); + vendorReady = true; + } + }); } else { - this.$message.error(response.msg); + errMsg.push("vendor"); } }); } + + let typeReady = false; + let typeCode = this.autocompleteExist('type', this.currentModel.type.value); + if (typeCode) { + this.currentModel.typeCode = typeCode; + typeReady = true; + } else { + let type = {type: 'assetType', value: this.currentModel.type.value}; + this.$post("sys/dict/save", type).then(response => { + if (response.code === 200) { + this.$get('sys/dict/all?type=assetType').then(response => { + if (response.code === 200) { + this.typeData = response.data; + this.currentModel.typeCode = this.autocompleteExist('type', this.currentModel.type.value); + typeReady = true; + } + }); + } else { + errMsg.push("type"); + } + }); + } + + let intervalTime = 1; //设置3秒超时 + let interval = setInterval(() => { + if (vendorReady && typeReady) { + if (this.currentModel.id) { + this.$put('model', this.currentModel).then(response => { + if (response.code === 200) { + this.$message({duration: 1000, type: 'success', message: this.$t("tip.saveSuccess")}); + this.rightBox.show = false; + this.$emit('reload'); + } else { + this.$message.error(response.msg); + } + }); + } else { + this.$post('model', this.currentModel).then(response => { + if (response.code === 200) { + this.$message({duration: 1000, type: 'success', message: this.$t("tip.saveSuccess")}); + this.rightBox.show = false; + this.$emit("reload"); + } else { + this.$message.error(response.msg); + } + }); + } + clearInterval(interval); + } else if (intervalTime > 15) { + if (errMsg.length > 0) { + this.$message.error(errMsg.join() + " error"); + } else { + this.$message.error("Time out"); + } + clearInterval(interval); + } else { + intervalTime++; + } + }, 200); } else { return false; } @@ -164,16 +239,16 @@ getVendorData() { this.$get('sys/dict/all?type=vendor').then(response => { if (response.code === 200) { - this.vendorData = response.data + this.vendorData = response.data; } - }) + }); }, getTypeData() { this.$get('sys/dict/all?type=assetType').then(response => { if (response.code === 200) { - this.typeData = response.data + this.typeData = response.data; } - }) + }); }, //vendor的输入建议 vendorSuggestion(queryString, callback) { @@ -184,11 +259,45 @@ callback(this.suggestionFilter('type', queryString)); }, suggestionFilter(type, queryString) { + let data = []; if (type == 'vendor') { - + if (!queryString) { + data = this.vendorData; + } else { + for (let i = 0; i < this.vendorData.length; i++) { + if (this.vendorData[i].value.toLowerCase().indexOf(queryString.toLowerCase()) != -1) { + data.push(this.vendorData[i]); + } + } + } } else if (type == 'type') { - + if (!queryString) { + data = this.typeData; + } else { + for (let i = 0; i < this.typeData.length; i++) { + if (this.typeData[i].value.toLowerCase().indexOf(queryString.toLowerCase()) != -1) { + data.push(this.typeData[i]); + } + } + } } + return data; + }, + autocompleteExist(type, string) { + let result = false; + let data = []; + if (type == 'vendor') { + data = this.vendorData; + } else if (type == 'type') { + data = this.typeData; + } + for (let i = 0; i < data.length; i++) { + if (data[i].value.toLowerCase() == string.toLowerCase()) { + result = data[i].code; + break; + } + } + return result; } }, mounted() {