| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- <!doctype html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title></title>
- <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
- <link href="../css/mui.min.css" rel="stylesheet" />
- <link rel="stylesheet" type="text/css" href="../css/iconfont.css" />
- <link href="../css/common.css" rel="stylesheet" />
- <style type="text/css">
- .innerBox{
- width: 80%;
- margin: 10% auto;
- border-radius: 10px;
- background: #fff;
- position: relative;
- padding-bottom: 30px;
- }
- .discernImg >img{
- border-radius: 10px 10px 0 0;
- }
- .detailsBox{
- padding: 0 10%;
- }
- .detailsBox h1{
- font-size: 20px;
- line-height: 50px;
- border-bottom: 1px solid #d3d3d3;
- }
- .detailsBox >div{
- color: #626262;
- text-indent: 30px;
- }
- /*上传按钮*/
- .upfileBox{
- position: absolute;
- left: 0;
- right: 0;
- text-align: center;
- bottom: -27px;
- }
- .upfileBox:after{
- position: absolute;
- bottom: -23px;
- content: '上传图片可识别昆虫,获取昆虫资料';
- left: 0;
- right: 0;
- color: #d0cece;
- }
- #upFile{
- width: 150px;
- height: 50px;
- border-radius: 27px;
- background: url(../images/upfilebj.png) no-repeat;
- background-size: cover;
- border: none;
- }
- </style>
- </head>
- <body>
- <header class="mui-bar mui-bar-nav">
- <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
- <h1 class="mui-title">拍照识别</h1>
- </header>
- <div class="mui-content">
- <div class="innerBox">
- <div class="introduceBox">
- <div class="discernImg">
- <img src="../images/ant.jpg" width="100%"/>
- </div>
- <div class="detailsBox">
- <h1>蚂蚁</h1>
- <div class="">
- 蚂蚁是一种昆虫,别名蚁、玄驹、昆蜉、蚍蜉蚂,属节肢动物门,昆虫纲,膜翅目,蚁科。蚂蚁的种类繁多,世界上已知有11700多种,有21亚科283属,中国境内已确定的蚂蚁种类有600多种。
- </div>
- </div>
- </div>
- <div class="upfileBox">
- <button id="upFile"></button>
- </div>
- </div>
- </div>
- <script src="../js/jquery-2.1.0.js"></script>
- <script src="../js/mui.min.js"></script>
- <script type="text/javascript">
- //上传
- document.getElementById('upFile').addEventListener('tap', function() {
- if(mui.os.plus) {
- var a = [{
- title: '拍照'
- }, {
- title: '从手机相册选择'
- }];
- plus.nativeUI.actionSheet({
- title: '识别图片',
- cancel: '取消',
- buttons: a
- }, function(b) {
- console.log(b.index)
- switch(b.index) {
- case 0:
- break;
- case 1:
- //拍照
- getImages();
- break;
- case 2:
- //打开相册
- galleryImages();
- break;
- default:
- break;
- }
- }, false);
- }
- });
- //拍照
- function getImages() {
- var mobileCamera = plus.camera.getCamera();
- mobileCamera.captureImage(function(e) {
- plus.io.resolveLocalFileSystemURL(e, function(entry) {
- var path = entry.toLocalURL() + '?version=' + new Date().getTime();
- uploadHeadImg(path);
- }, function(e) {
- console.log("读取拍照文件错误");
- });
- }, function(e) {
- console.log("er", e);
- }, function() {
- filename: '_doc/head.png';
- });
- }
- //从本地相册选择
- function galleryImages() {
- console.log("你选择了从相册选择");
- plus.gallery.pick(function(a) {
- plus.io.resolveLocalFileSystemURL(a, function(entry) {
- plus.io.resolveLocalFileSystemURL('_doc/', function(root) {
- root.getFile('head.png', {}, function(file) {
- //文件已经存在
- file.remove(function() {
- console.log("文件移除成功");
- entry.copyTo(root, 'head.png', function(e) {
- var path = e.fullPath + '?version=' + new Date().getTime();
- uploadHeadImg(path);
- }, function(err) {
- console.log("copy image fail: ", err);
- });
- }, function(err) {
- console.log("删除图片失败:(" + JSON.stringify(err) + ")");
- });
- }, function(err) {
- //打开文件失败
- entry.copyTo(root, 'head.png', function(e) {
- var path = e.fullPath + '?version=' + new Date().getTime();
- uploadHeadImg(path);
- }, function(err) {
- console.log("上传图片失败:(" + JSON.stringify(err) + ")");
- });
- });
- }, function(e) {
- console.log("读取文件夹失败:(" + JSON.stringify(err) + ")");
- });
- });
- }, function(err) {
- console.log("读取拍照文件失败: ", err);
- }, {
- filter: 'image'
- });
- };
- //上传图片
- function uploadHeadImg(imgPath) {
- //服务端接口路径
- var server = "http://192.168.1.11:8000/app_insect_discern";
- //获取图片元素
- var wt = plus.nativeUI.showWaiting('上传中...');
- var task = plus.uploader.createUpload(server, {
- method: "POST",
- // timeout:10
- },
- function(t, status) { //上传完成
- if(status == 200) {
- // alert("上传成功:" + t.responseText);
- wt.close(); //关闭等待提示按钮
- mui.openWindow({
- url:'autoDiscernResult.html',
- id:'autoDiscernResult',
- extras: {
- responseText: t.responseText
- },
- })
- } else {
- alert("上传失败");
- wt.close(); //关闭等待提示按钮
- }
- }
- );
- //添加其他参数
- // task.addData("name", "test");
- task.addData("req", "change_photo");
- task.addFile(imgPath, {
- key: "imagefile"
- });
- task.start();
- }
- </script>
- </body>
- </html>
|