Skip to content

Commit

Permalink
文件上传优化
Browse files Browse the repository at this point in the history
  • Loading branch information
JakePrim committed Jun 22, 2018
1 parent e727487 commit 0e62791
Show file tree
Hide file tree
Showing 17 changed files with 994 additions and 255 deletions.
319 changes: 191 additions & 128 deletions README.md

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ android {
}

dependencies {
implementation 'com.android.support:support-v4:25.4.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:25.3.1'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.prim.lib:prim-picker:1.0.4'
compile project(':primweb-core')
compile 'com.squareup.picasso:picasso:2.3.2'
}
42 changes: 7 additions & 35 deletions app/src/main/assets/upload_file/jsuploadfile.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
// alert("我是" + this + "元素, 你点击了我!");

//alert("Js 调 Android 方法成功");
if (window.agentWeb != null && typeof(window.agentWeb) != "undefined") {
window.agentWeb.uploadFile();
if (window.upload != null && typeof(window.upload) != "undefined") {
window.upload.uploadFile();
} else {
alert(typeof(window.agentWeb));
alert(typeof(window.upload));
}
});

Expand All @@ -66,54 +66,26 @@

//这里返回来的是一个 Json 数组 //
function uploadFileResult(objs) {

// console.log(message);
//alert(objs);
//alert("Android 调 Js 方法");

if (objs == null || typeof(objs) == "undefined" || objs.length == 0) {

//alert("");
alert(objs);
if (objs == null || typeof(objs) == "undefined" ) {

} else {

var img = document.getElementById("preview");
/*for(var i=0;i<objs.length;i++){ //
img.src="data:image/png;base64," + objs[i].fileBase64*/
if (objs[0] == null || objs[0] == 'undefined' || objs[0] == '' || objs[0].fileBase64 == null || objs[0].fileBase64 == 'undefined') {

} else {
img.src = "data:image/png;base64," + objs[0].fileBase64;
}

img.src = "data:image/png;base64," + objs;
}




}
</script>
</head>

<body style="width: 100%;height: 100%;margin: 0;padding: 0; position: relative;">
<div style="position: absolute; left: 0 ;right: 0 ; top: 0 ; margin:0 auto;max-width: 750px;height: 100%">
<div id="div_id" style="width: 100% ; height:100%;border: 1px ;background:#000000 ; margin: 0px;">
<!-- 头部nav -->
<div id="nav" style="width: 100%; height: 10%;background: #f9f9f9;padding-top: 0px ;position: absolute;padding: 0px">
<div style="width: 200px;height: 100px; position:relative;left: 50%;top: 50%;margin-left: -100px;margin-top: -50px;overflow: scroll;">
<font color="#000">
<h4 style="text-align:center;line-height: 50px;">请上传身份证</h4> </font>
</div>
<div style="width: 100%;height: 1px;background: #c6c6c6;position: relative;margin-top: -50px;top: 99%">
</div>
</div>
<!-- body -->
<div id="content" style="width: 100%; height: 90% ; background: #ebebeb ;position: absolute;top: 10%;">
<div style="margin: 0 auto;width: 80%;height: 80%;border:3px solid #41a0f2;margin-top: 50px;overflow:scroll;">
<div style="margin: 0 auto;width: 80%;height: 80%;overflow:scroll;">
<img id="preview" src="./id.png" style="display: block;margin: 0 auto;max-width: 80%;margin-top: 20px;">
</img>

<p class="fontBlue ta-c mt5" style="text-align: center;">上传身份证</p>
<div id="file_upload" href="javascript:;" class="file" style="display: block;margin: 0 auto;width: 50%;height: 25px;text-align: center;line-height: 25px;margin-bottom: 20px">
选择文件
</div>
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/java/com/prim/web/activity/CommonActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,32 @@ private void openFragment(String extra) {
fragmentTransaction.add(R.id.frame_layout, webFragment = WebFragment.newInstance(url, "JS - Upload"), WebFragment.class.getSimpleName());
break;
case "6":
url = "file:///android_asset/upload/h5-standard.html";
fragmentTransaction.add(R.id.frame_layout, webFragment = WebFragment.newInstance(url, "ThridUpload"), WebFragment.class.getSimpleName());
break;
case "7":
url = "https://m.jd.com/";
fragmentTransaction.add(R.id.frame_layout, webFragment = WebFragment.newInstance(url, "Download"), WebFragment.class.getSimpleName());
break;
case "8":
url = "https://m.jd.com/";
fragmentTransaction.add(R.id.frame_layout, webFragment = WebFragment.newInstance(url, "setting"), WebFragment.class.getSimpleName());
break;
case "9":
url = "https://m.jd.com/";
fragmentTransaction.add(R.id.frame_layout, webFragment = WebFragment.newInstance(url, "progress"), WebFragment.class.getSimpleName());
break;
case "10":
url = "https://m.jd.com/";
fragmentTransaction.add(R.id.frame_layout, webFragment = WebFragment.newInstance(url, "down-rebound"), WebFragment.class.getSimpleName());
break;
case "11":
url = "https://m.jd.com/";
fragmentTransaction.add(R.id.frame_layout, webFragment = WebFragment.newInstance(url, "down-refresh"), WebFragment.class.getSimpleName());
break;
case "12":
url = "https://github.com/Justson/AgentWeb";
fragmentTransaction.add(R.id.frame_layout, webFragment = WebFragment.newInstance(url, "thanks"), WebFragment.class.getSimpleName());
break;
}
fragmentTransaction.commit();
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/prim/web/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class MainActivity extends AppCompatActivity implements OnItemClickListen
"Java与Js之间的通信",
"input标签文件上传",
"Js通信文件上传",
"调用第三方文件选择库上传文件",
"文件下载",
"自定义WebSetting设置",
"自定义进度条",
Expand Down Expand Up @@ -93,6 +94,15 @@ public void itemClick(int position) {
case 10:
startActivity(new Intent(this, CommonActivity.class).putExtra(CommonActivity.TYPE, "9"));
break;
case 11:
startActivity(new Intent(this, CommonActivity.class).putExtra(CommonActivity.TYPE, "10"));
break;
case 12:
startActivity(new Intent(this, CommonActivity.class).putExtra(CommonActivity.TYPE, "11"));
break;
case 13:
startActivity(new Intent(this, CommonActivity.class).putExtra(CommonActivity.TYPE, "12"));
break;
}
}

Expand Down
Loading

0 comments on commit 0e62791

Please sign in to comment.