Browse Source

去掉base64编码错误时的alter,支持输入base64编码自动添加'data:'前缀

zhangning 5 years ago
parent
commit
1437dc033d
4 changed files with 35 additions and 3 deletions
  1. 4 1
      .gitignore
  2. 6 0
      apps/image-base64/index.css
  3. 0 0
      apps/image-base64/index.html
  4. 25 2
      apps/image-base64/index.js

+ 4 - 1
.gitignore

@@ -4,4 +4,7 @@
 node_modules/
 package-lock.json
 output/apps/
-output-firefox/
+output-firefox/
+
+*.crx
+*.pem

+ 6 - 0
apps/image-base64/index.css

@@ -115,4 +115,10 @@ form {display: none}
 .x-switch {
     color:#f00;
     border-bottom: 1px solid #f00;
+}
+
+.x-error {
+   margin: 0px 0px 10px 0px;
+   padding-bottom: 10px;
+   color:#f00;
 }

File diff suppressed because it is too large
+ 0 - 0
apps/image-base64/index.html


+ 25 - 2
apps/image-base64/index.js

@@ -11,8 +11,27 @@ new Vue({
         toolName: {'image': '图片转Base64', 'base64': 'Base64转图片'},
         curType: 'image',
         nextType: 'base64',
-        txtBase64Input: ''
+        txtBase64Input: '',
+        txtBase64Output: '',
+        error:''
     },
+
+    watch: {
+        txtBase64Input:{
+            immediate: true,
+            handler(newVal, oldVal) {
+                this.error = ''   
+                this.txtBase64Output = ''
+                if(newVal.length === 0) return
+                if(newVal.indexOf("data:") === -1) {
+                    this.txtBase64Output = "data:image/jpeg;base64,"+newVal
+                } else {
+                    this.txtBase64Output = newVal
+                }
+            },
+        }
+    },
+
     mounted: function () {
 
         let MSG_TYPE = Tarp.require('../static/js/msg_type');
@@ -181,6 +200,10 @@ new Vue({
             }
         },
 
+        format:function(){
+            return this.txtBase64Output
+        },
+
         trans: function () {
             this.curType = {image: 'base64', base64: 'image'}[this.curType];
             this.nextType = {image: 'base64', base64: 'image'}[this.nextType];
@@ -188,7 +211,7 @@ new Vue({
 
         loadError: function (e) {
             if(this.curType === 'base64' && this.txtBase64Input.trim().length) {
-                alert('无法识别的Base64编码,请确认是正确的图片Data URI?');
+                this.error ='无法识别的Base64编码,请确认是正确的图片Data URI?';
             }
         }
     }

Some files were not shown because too many files changed in this diff