vegetablesPlant.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <template>
  2. <view>
  3. <!-- 搜索 -->
  4. <!-- <u-search :disabled="true" margin="15rpx auto" :input-style="{width: '20rpx'}" input-align="center" :animation="true" placeholder="搜索作物名称"
  5. shape="square" :show-action="false" v-model="keyword"></u-search> -->
  6. <!-- 作物列表 -->
  7. <view class="plantList_ul">
  8. <!-- 上次定位 -->
  9. <view class="plantList_li" v-if="lastTimeShow">
  10. <view class="plantList_tlt">
  11. 上次选择
  12. </view>
  13. <view class="plantList_li_ul">
  14. <view class="plantList_li_List" @click="recognizeData(allPlantData[lastTimeIndex].num, allPlantData[lastTimeIndex].name, lastTimeIndex)">
  15. <image :src="$imageURL_58003+'/bigservers/' + allPlantData[lastTimeIndex].img" mode=""></image>
  16. <view class="">
  17. {{ allPlantData[lastTimeIndex].name }}
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. <!-- 全部 -->
  23. <view class="plantList_li">
  24. <view class="plantList_tlt">
  25. 该模型开发中。。。
  26. </view>
  27. <view class="plantList_li_ul">
  28. <view @click="recognizeData(item.num, item.name, index)" class="plantList_li_List" v-for="(item, index) in allPlantData" :key="index">
  29. <image :src="$imageURL_58003+'/bigservers/' + item.img" mode=""></image>
  30. <view class="">
  31. {{ item.name }}
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. <!-- 其他 -->
  37. <!-- <view class="plantList_li">
  38. <view class="plantList_tlt">
  39. 其他
  40. <text>(此项目开发中,结果可能会有误差)</text>
  41. </view>
  42. <view class="plantList_li_ul">
  43. <view class="plantList_li_List" @click="restsData()">
  44. <image :src="$imageURL_58003+'/bigservers/' + 'images/detail_9.png'" mode=""></image>
  45. <view class="">
  46. 其他
  47. </view>
  48. </view>
  49. </view>
  50. </view> -->
  51. </view>
  52. <!-- 裁剪组件 -->
  53. <kps-image-cutter @ok="axiosData" @cancel="oncancle" :url="url" :fixed="false" :blob="false" :maxWidth="500" :maxHeight="500"></kps-image-cutter>
  54. <!-- 弹框 -->
  55. <u-modal :mask-close-able="true" @cancel="insectData('1')" @confirm="insectData('2')" confirm-text="虫害" cancel-text="病害" v-model="show" :show-cancel-button="true" :content="content"></u-modal>
  56. <!--loading-->
  57. <ourLoading v-show="loadingShow" isFullScreen active text="识别中..." />
  58. </view>
  59. </template>
  60. <script>
  61. import kpsImageCutter from "@/components/ksp-image-cutter/ksp-image-cutter.vue"; //裁剪图片
  62. export default {
  63. data() {
  64. return {
  65. keyword: '', //搜索
  66. show: false,
  67. content: '请选择测试虫害还是病害',
  68. allPlantData: [
  69. // {
  70. // 'name': '黄瓜',
  71. // 'img': 'images/plant_10.jpg',
  72. // 'num': '8',
  73. // },
  74. // {
  75. // 'name': '番茄',
  76. // 'img': 'images/plant_11.jpg',
  77. // 'num': '17',
  78. // },
  79. // {
  80. // 'name': '南瓜',
  81. // 'img': 'images/plant_12.jpg',
  82. // 'num': '18',
  83. // },
  84. // {
  85. // 'name': '辣椒',
  86. // 'img': 'images/plant_10.jpg',
  87. // 'num': '19',
  88. // },
  89. // {
  90. // 'name': '白菜',
  91. // 'img': 'images/plant_14.jpg',
  92. // 'num': '24',
  93. // },
  94. // {
  95. // 'name': '马铃薯',
  96. // 'img': 'images/plant_15.jpg',
  97. // 'num': '25',
  98. // },
  99. // {
  100. // 'name': '萝卜',
  101. // 'img': 'images/plant_9.jpg',
  102. // 'num': '6',
  103. // }
  104. ],
  105. url: "", //裁剪
  106. serialNum: '', //获取到作物序号码
  107. urlData: {}, //图片全部信息
  108. urlName: '', //识别失败作物名称
  109. insectNum: '', //区别病虫害 1虫 2病
  110. lastTimeShow: false, //是否显示上次选择
  111. lastTimeIndex: null, //上次选择下标
  112. loadingShow: false, //加载
  113. }
  114. },
  115. methods: {
  116. recognizeData(num, name, index) {
  117. uni.setStorage({
  118. key: 'lastTimeC',
  119. data: index,
  120. success: function () {
  121. console.log('success');
  122. }
  123. });
  124. this.insectNum = ''
  125. this.urlName = name
  126. this.serialNum = num
  127. uni.chooseImage({
  128. count: 1,
  129. success: (res) => {
  130. // 设置url的值,显示控件
  131. // console.log(res)
  132. this.urlData = res
  133. this.url = res.tempFilePaths[0];
  134. this.urlFile = res.tempFilePaths[0]; //失败跳转显示的图片
  135. }
  136. });
  137. },
  138. // 将base64转换为blob
  139. // dataURLtoFile(dataURI, type) {
  140. // let binary = atob(dataURI.split(",")[1]);
  141. // let array = [];
  142. // for (let i = 0; i < binary.length; i++) {
  143. // array.push(binary.charCodeAt(i));
  144. // }
  145. // return new Blob([new Uint8Array(array)], {
  146. // type: type
  147. // });
  148. // },
  149. // 图片提交事件。把bold格式转为formData格式进行提交。
  150. // submitPic(fileData) {
  151. // let form = new FormData();
  152. // // let fileOfBlob = new File([fileData], 'plantinsect.jpg'); // 重命名了
  153. // let fileOfBlob = new File([fileData], this.serialNum); // 重命名了
  154. // // console.log(this.fileA);
  155. // form.append("file", fileOfBlob);
  156. // return form;
  157. // },
  158. // 取消上传
  159. oncancle() {
  160. this.url = '';
  161. },
  162. // 确定上传
  163. axiosData(ev) {
  164. let that = this
  165. that.loadingShow = true
  166. // let blob = that.dataURLtoFile(ev.path, 'image/jpeg'); //将base64转换为blob
  167. // let data = that.submitPic(blob); //再将blob转换为file
  168. // var img = data.get("file");
  169. if (that.serialNum == '' && that.insectNum !== '') {
  170. // 老接口
  171. var url = 'other_discern'
  172. var num = that.insectNum
  173. } else if (that.serialNum !== '' && that.insectNum == '') {
  174. //新接口
  175. var url = 'discern'
  176. var num = that.serialNum
  177. }
  178. uni.uploadFile({
  179. url: 'https://wx.hnyfwlw.com/bigservers/'+ url + '?type=' + num,
  180. fileType: 'image',
  181. file: this.urlData.tempFiles[0],
  182. filePath: this.urlData.tempFiles[0].path,
  183. name: 'img_addr',
  184. success(res) {
  185. that.url = '';
  186. if (res.statusCode !== 500) {
  187. var data = JSON.parse(res.data)
  188. // 判断是否识别成功 -新接口
  189. if (data.returnResult.returnStatus == 1) {
  190. // 成功
  191. var img = []
  192. img.push(that.urlFile)
  193. if (that.urlName == '其他') {
  194. var f = JSON.parse(res.data)
  195. if (f.data == null || f.data[0].prevention == "[防治方法] null") {
  196. console.log('失败')
  197. uni.navigateTo({
  198. url: '/pages/recognizeFail/recognizeFail?data=' + img + '&name=' + that.urlName
  199. })
  200. } else {
  201. uni.navigateTo({
  202. url: '/pages/recognizeSucceedWorn/recognizeSucceedWorn?data=' + JSON.stringify(data.data) + '&name=' + that.urlName + '&img=' + img
  203. })
  204. console.log('成功')
  205. }
  206. } else {
  207. uni.navigateTo({
  208. url: '/pages/recognizeSucceed/recognizeSucceed?data=' + (data.returnResult.returnImageUrl)
  209. })
  210. }
  211. // uni.navigateTo({
  212. // url: '/pages/recognizeSucceed/recognizeSucceed?data=' + JSON.stringify(data.data)
  213. // })
  214. } else if (data.code !== 200) {
  215. //失败
  216. var img = []
  217. img.push(that.urlFile)
  218. uni.navigateTo({
  219. url: '/pages/recognizeFail/recognizeFail?data=' + img + '&name=' + that.urlName
  220. })
  221. }
  222. } else {
  223. //失败
  224. var img = []
  225. img.push(that.urlFile)
  226. uni.navigateTo({
  227. url: '/pages/recognizeFail/recognizeFail?data=' + img + '&name=' + that.urlName
  228. })
  229. }
  230. },
  231. fail(err) {
  232. //失败
  233. var img = []
  234. img.push(that.urlFile)
  235. uni.navigateTo({
  236. url: '/pages/recognizeFail/recognizeFail?data=' + img + '&name=' + that.urlName
  237. })
  238. },
  239. complete(com) {
  240. that.loadingShow = false
  241. }
  242. })
  243. },
  244. // 其他--老识别接口
  245. restsData() {
  246. this.show = true;
  247. },
  248. // 确定
  249. insectData(num) {
  250. this.urlName = '其他'
  251. this.serialNum = ''
  252. this.insectNum = num
  253. uni.chooseImage({
  254. count: 1,
  255. success: (res) => {
  256. // 设置url的值,显示控件
  257. this.urlData = res
  258. this.url = res.tempFilePaths[0];
  259. this.urlFile = res.tempFilePaths[0]; //失败跳转显示的图片
  260. }
  261. });
  262. },
  263. },
  264. components: {
  265. kpsImageCutter
  266. },
  267. onShow() {
  268. var that = this
  269. uni.getStorage({
  270. key: 'lastTimeC',
  271. success: function (res) {
  272. that.lastTimeShow = true
  273. console.log(res.data);
  274. that.lastTimeIndex = res.data
  275. },
  276. fail: function (err) {
  277. that.lastTimeShow = false
  278. console.log(err)
  279. }
  280. });
  281. },
  282. }
  283. </script>
  284. <style lang="scss">
  285. // 搜索
  286. // uni-view,
  287. // uni-text {
  288. // width: 740rpx;
  289. // margin: 0 auto;
  290. // }
  291. // 作物选择
  292. .plantList_ul {
  293. .plantList_li {
  294. margin: 55rpx 0 55rpx 0;
  295. .plantList_tlt {
  296. font-weight: 550;
  297. font-size: 16px;
  298. width: 700rpx;
  299. margin: 0 auto;
  300. text {
  301. color: #7e7e7e;
  302. font-size: 12px;
  303. }
  304. }
  305. .plantList_li_ul {
  306. display: flex;
  307. flex-wrap: wrap;
  308. margin-top: 10rpx;
  309. .plantList_li_List {
  310. margin: 10rpx 0 0 18rpx;
  311. width: 150rpx;
  312. image {
  313. width: 130rpx;
  314. height: 130rpx;
  315. border-radius: 55px;
  316. margin: 0 auto;
  317. display: block;
  318. box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
  319. }
  320. view {
  321. width: 150rpx;
  322. color: #646464;
  323. text-align: center;
  324. margin: 10rpx 0 0 0;
  325. font-size: 13px;
  326. }
  327. }
  328. }
  329. }
  330. }
  331. </style>