autoDiscern.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  7. <link href="../css/mui.min.css" rel="stylesheet" />
  8. <link rel="stylesheet" type="text/css" href="../css/iconfont.css" />
  9. <link href="../css/common.css" rel="stylesheet" />
  10. <style type="text/css">
  11. .innerBox{
  12. width: 80%;
  13. margin: 10% auto;
  14. border-radius: 10px;
  15. background: #fff;
  16. position: relative;
  17. padding-bottom: 30px;
  18. }
  19. .discernImg >img{
  20. border-radius: 10px 10px 0 0;
  21. }
  22. .detailsBox{
  23. padding: 0 10%;
  24. }
  25. .detailsBox h1{
  26. font-size: 20px;
  27. line-height: 50px;
  28. border-bottom: 1px solid #d3d3d3;
  29. }
  30. .detailsBox >div{
  31. color: #626262;
  32. text-indent: 30px;
  33. }
  34. /*上传按钮*/
  35. .upfileBox{
  36. position: absolute;
  37. left: 0;
  38. right: 0;
  39. text-align: center;
  40. bottom: -27px;
  41. }
  42. .upfileBox:after{
  43. position: absolute;
  44. bottom: -23px;
  45. content: '上传图片可识别昆虫,获取昆虫资料';
  46. left: 0;
  47. right: 0;
  48. color: #d0cece;
  49. }
  50. #upFile{
  51. width: 150px;
  52. height: 50px;
  53. border-radius: 27px;
  54. background: url(../images/upfilebj.png) no-repeat;
  55. background-size: cover;
  56. border: none;
  57. }
  58. </style>
  59. </head>
  60. <body>
  61. <header class="mui-bar mui-bar-nav">
  62. <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
  63. <h1 class="mui-title">拍照识别</h1>
  64. </header>
  65. <div class="mui-content">
  66. <div class="innerBox">
  67. <div class="introduceBox">
  68. <div class="discernImg">
  69. <img src="../images/ant.jpg" width="100%"/>
  70. </div>
  71. <div class="detailsBox">
  72. <h1>蚂蚁</h1>
  73. <div class="">
  74. 蚂蚁是一种昆虫,别名蚁、玄驹、昆蜉、蚍蜉蚂,属节肢动物门,昆虫纲,膜翅目,蚁科。蚂蚁的种类繁多,世界上已知有11700多种,有21亚科283属,中国境内已确定的蚂蚁种类有600多种。
  75. </div>
  76. </div>
  77. </div>
  78. <div class="upfileBox">
  79. <button id="upFile"></button>
  80. </div>
  81. </div>
  82. </div>
  83. <script src="../js/jquery-2.1.0.js"></script>
  84. <script src="../js/mui.min.js"></script>
  85. <script type="text/javascript">
  86. //上传
  87. document.getElementById('upFile').addEventListener('tap', function() {
  88. if(mui.os.plus) {
  89. var a = [{
  90. title: '拍照'
  91. }, {
  92. title: '从手机相册选择'
  93. }];
  94. plus.nativeUI.actionSheet({
  95. title: '识别图片',
  96. cancel: '取消',
  97. buttons: a
  98. }, function(b) {
  99. console.log(b.index)
  100. switch(b.index) {
  101. case 0:
  102. break;
  103. case 1:
  104. //拍照
  105. getImages();
  106. break;
  107. case 2:
  108. //打开相册
  109. galleryImages();
  110. break;
  111. default:
  112. break;
  113. }
  114. }, false);
  115. }
  116. });
  117. //拍照
  118. function getImages() {
  119. var mobileCamera = plus.camera.getCamera();
  120. mobileCamera.captureImage(function(e) {
  121. plus.io.resolveLocalFileSystemURL(e, function(entry) {
  122. var path = entry.toLocalURL() + '?version=' + new Date().getTime();
  123. uploadHeadImg(path);
  124. }, function(e) {
  125. console.log("读取拍照文件错误");
  126. });
  127. }, function(e) {
  128. console.log("er", e);
  129. }, function() {
  130. filename: '_doc/head.png';
  131. });
  132. }
  133. //从本地相册选择
  134. function galleryImages() {
  135. console.log("你选择了从相册选择");
  136. plus.gallery.pick(function(a) {
  137. plus.io.resolveLocalFileSystemURL(a, function(entry) {
  138. plus.io.resolveLocalFileSystemURL('_doc/', function(root) {
  139. root.getFile('head.png', {}, function(file) {
  140. //文件已经存在
  141. file.remove(function() {
  142. console.log("文件移除成功");
  143. entry.copyTo(root, 'head.png', function(e) {
  144. var path = e.fullPath + '?version=' + new Date().getTime();
  145. uploadHeadImg(path);
  146. }, function(err) {
  147. console.log("copy image fail: ", err);
  148. });
  149. }, function(err) {
  150. console.log("删除图片失败:(" + JSON.stringify(err) + ")");
  151. });
  152. }, function(err) {
  153. //打开文件失败
  154. entry.copyTo(root, 'head.png', function(e) {
  155. var path = e.fullPath + '?version=' + new Date().getTime();
  156. uploadHeadImg(path);
  157. }, function(err) {
  158. console.log("上传图片失败:(" + JSON.stringify(err) + ")");
  159. });
  160. });
  161. }, function(e) {
  162. console.log("读取文件夹失败:(" + JSON.stringify(err) + ")");
  163. });
  164. });
  165. }, function(err) {
  166. console.log("读取拍照文件失败: ", err);
  167. }, {
  168. filter: 'image'
  169. });
  170. };
  171. //上传图片
  172. function uploadHeadImg(imgPath) {
  173. //服务端接口路径
  174. var server = "http://192.168.1.11:8000/app_insect_discern";
  175. //获取图片元素
  176. var wt = plus.nativeUI.showWaiting('上传中...');
  177. var task = plus.uploader.createUpload(server, {
  178. method: "POST",
  179. // timeout:10
  180. },
  181. function(t, status) { //上传完成
  182. if(status == 200) {
  183. // alert("上传成功:" + t.responseText);
  184. wt.close(); //关闭等待提示按钮
  185. mui.openWindow({
  186. url:'autoDiscernResult.html',
  187. id:'autoDiscernResult',
  188. extras: {
  189. responseText: t.responseText
  190. },
  191. })
  192. } else {
  193. alert("上传失败");
  194. wt.close(); //关闭等待提示按钮
  195. }
  196. }
  197. );
  198. //添加其他参数
  199. // task.addData("name", "test");
  200. task.addData("req", "change_photo");
  201. task.addFile(imgPath, {
  202. key: "imagefile"
  203. });
  204. task.start();
  205. }
  206. </script>
  207. </body>
  208. </html>