diff --git a/nezha-fronted/src/components/common/project/addNode.vue b/nezha-fronted/src/components/common/project/addNode.vue index b5a20a233..cd44c3598 100644 --- a/nezha-fronted/src/components/common/project/addNode.vue +++ b/nezha-fronted/src/components/common/project/addNode.vue @@ -30,7 +30,7 @@ - + {{ item.imageName }} + + 上传文件 +
{{$t('alert.config.expr')}} @@ -260,6 +270,57 @@ del(){ this.$emit('del'); this.esc(); + }, + beforeAvatarUpload(file){ + const isJPG = file.type === 'image/jpeg'; + + const isLt2M = file.size / 1024 / 1024 < 2; + + if (!isJPG) { + this.$message.error('上传头像图片只能是 JPG 格式!'); + } + if (!isLt2M) { + this.$message.error('上传头像图片大小不能超过 2MB!'); + } + console.log(file); + this.getBase64(file).then(res => { + const params = res.split(',') + console.log(params, 'params') + if (params.length > 0) { + this.strimagebase64 = params[1] + console.log(this.strimagebase64); + } + }); + return isJPG && isLt2M; + }, + handleAvatarSuccess(file){ + + }, + onChange(file,fileList){ + this.getBase64(file.raw).then(res => { + const params = res.split(',') + console.log(params, 'params') + if (params.length > 0) { + this.strimagebase64 = params[1] + } + }); + }, + getBase64(file) { + + return new Promise(function(resolve, reject) { + const reader = new FileReader() + let imgResult = '' + reader.readAsDataURL(file) + reader.onload = function() { + imgResult = reader.result + } + reader.onerror = function(error) { + reject(error) + } + reader.onloadend = function() { + resolve(imgResult) + } + }) } }, @@ -267,6 +328,9 @@