identifyPestIndex.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <template>
  2. <view>
  3. <!-- 作物列表 -->
  4. <view class="plantList_ul">
  5. <!-- 上次定位 -->
  6. <view class="plantList_li" v-if="lastTimeShow">
  7. <view class="plantList_tlt"> 上次选择 </view>
  8. <view class="plantList_li_ul">
  9. <view class="plantList_li_List" @click="
  10. recognizeData(
  11. (identifyPestObj[type].data)[lastTimeIndex].num,
  12. (identifyPestObj[type].data)[lastTimeIndex].name,
  13. lastTimeIndex
  14. )
  15. ">
  16. <image :src="
  17. 'http://web.hnyfwlw.com:58003/bigservers/' +
  18. (identifyPestObj[type].data)[lastTimeIndex].img
  19. " mode=""></image>
  20. <view class="">
  21. {{ (identifyPestObj[type].data)[lastTimeIndex].name }}
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. <!-- 全部 -->
  27. <view class="plantList_li">
  28. <view class="plantList_tlt"> 全部 </view>
  29. <view class="plantList_li_ul">
  30. <view @click="recognizeData(item.num, item.name, index)" class="plantList_li_List"
  31. v-for="(item, index) in (identifyPestObj[type].data)" :key="index">
  32. <image :src="'http://web.hnyfwlw.com:58003/bigservers/' + item.img" mode=""></image>
  33. <view class="">
  34. {{ item.name }}
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <!-- 其他 -->
  40. <!-- <view class="plantList_li">
  41. <view class="plantList_tlt">
  42. 其他
  43. <text>(此项目开发中,结果可能会有误差)</text>
  44. </view>
  45. <view class="plantList_li_ul">
  46. <view class="plantList_li_List" @click="restsData()">
  47. <image :src="'http://web.hnyfwlw.com:58003/bigservers/' + 'images/detail_9.png'" mode=""></image>
  48. <view class="">
  49. 其他
  50. </view>
  51. </view>
  52. </view>
  53. </view> -->
  54. </view>
  55. <!-- 裁剪组件 -->
  56. <kps-image-cutter @ok="axiosData" @cancel="oncancle" :url="url" v-if="url" :fixed="false" :blob="false" :maxWidth="500"
  57. :maxHeight="500"></kps-image-cutter>
  58. <!-- 弹框 -->
  59. <u-modal :mask-close-able="true" @cancel="insectData('1')" @confirm="insectData('2')" confirm-text="虫害"
  60. cancel-text="病害" v-model="show" :show-cancel-button="true" :content="content"></u-modal>
  61. </view>
  62. </template>
  63. <script>
  64. import kpsImageCutter from '@/components/ksp-image-cutter/ksp-image-cutter.vue'; //裁剪图片
  65. export default {
  66. data() {
  67. return {
  68. url: '',
  69. serialNum: '', //获取到作物序号码
  70. urlData: {}, //图片全部信息
  71. urlName: '', //识别失败作物名称
  72. insectNum: '', //区别病虫害 1病 2虫
  73. lastTimeShow: false, //是否显示上次选择
  74. lastTimeIndex: null, //上次选择下标
  75. type: 'economicsPlant', // 当前拍照类型 economicsPlant:经济作物 cerealPlant:粮食作物
  76. identifyPestObj: {
  77. economicsPlant: {
  78. title: '经济作物',
  79. data: [
  80. // {
  81. // 'name': '棉花',
  82. // 'img': 'images/plant_2.jpg',
  83. // 'num': '21'
  84. // },
  85. // {
  86. // 'name': '茶',
  87. // 'img': 'images/plant_1.jpg',
  88. // 'num': '22'
  89. // },
  90. {
  91. name: '油菜',
  92. img: 'images/plant_3.jpg',
  93. num: '13',
  94. }
  95. ]
  96. },
  97. cerealPlant: {
  98. title: '粮食作物',
  99. data: [
  100. {
  101. 'name': '水稻',
  102. 'img': 'images/plant_16.jpg',
  103. 'num': '12',
  104. },
  105. {
  106. 'name': '小麦',
  107. 'img': 'images/plant_19.jpg',
  108. 'num': '11',
  109. },
  110. {
  111. 'name': '玉米',
  112. 'img': 'images/plant_17.jpg',
  113. 'num': '14',
  114. }
  115. ]
  116. }
  117. }
  118. }
  119. },
  120. methods: {
  121. recognizeData(num, name, index) {
  122. console.log(index);
  123. this.url = '';
  124. uni.setStorage({
  125. key: this.type,
  126. data: index,
  127. success: function() {
  128. console.log('success');
  129. },
  130. });
  131. this.urlName = name;
  132. this.insectNum = '';
  133. this.serialNum = num;
  134. console.log('-------------------------------- recogonization');
  135. uni.chooseImage({
  136. count: 1,
  137. sourceType: ['camera', 'album'], //从相册选择
  138. success: (res) => {
  139. // 设置url的值,显示控件
  140. console.log(res);
  141. this.urlData = res.tempFiles[0];
  142. this.url = res.tempFilePaths[0];
  143. this.urlFile = res.tempFilePaths[0]; //失败跳转显示的图片
  144. },
  145. fail(err) {
  146. console.log(err, '------------------------ choose image');
  147. },
  148. });
  149. },
  150. // 取消上传
  151. oncancle() {
  152. this.url = '';
  153. },
  154. axiosData(ev) {
  155. console.log(ev);
  156. this.urlData = ev;
  157. this.urlFile = ev.path;
  158. setTimeout(() => {
  159. uni.showLoading({
  160. title: '识别中...',
  161. });
  162. });
  163. let that = this;
  164. if (that.serialNum == '' && that.insectNum !== '') {
  165. // 老接口
  166. var url = 'other_discern';
  167. var num = that.insectNum;
  168. } else if (that.serialNum !== '' && that.insectNum == '') {
  169. //新接口
  170. var url = 'discern';
  171. var num = that.serialNum;
  172. }
  173. const session_key = uni.getStorageSync('session_key');
  174. console.log(num);
  175. uni.uploadFile({
  176. // url: 'https://wx.hnyfwlw.com/bigservers/' + url + '?type=' + num,
  177. url: `https://wx.hnyfwlw.com/api/api_gateway?method=wheat.discreen.plan`,
  178. // url: `http://192.168.2.163:8003/api/api_gateway?method=wheat.discreen.plan`,
  179. fileType: 'image',
  180. // file: this.urlData,
  181. filePath: ev.path,
  182. formData: {
  183. type: num,
  184. token: session_key
  185. },
  186. name: 'img_addr',
  187. success(res) {
  188. console.log(res);
  189. uni.hideLoading();
  190. that.url = '';
  191. // 判断是否识别成功 -新接口
  192. // if (data.code == 200) {
  193. if (res.statusCode !== 500) {
  194. var data = JSON.parse(res.data).data;
  195. if (data.returnResult.returnStatus == 1) {
  196. // 成功
  197. uni.navigateTo({
  198. url: '/pages/identifyPest/recognizeSucceed/recognizeSucceed?data=' +
  199. JSON.stringify(data.returnResult),
  200. });
  201. console.log('新接口');
  202. } else if (data.returnResult.returnStatus == 0) {
  203. //失败
  204. var img = [];
  205. img.push(that.urlFile);
  206. uni.navigateTo({
  207. url: '/pages/identifyPest/recognizeFail/recognizeFail?data=' +
  208. img +
  209. '&name=' +
  210. that.urlName,
  211. });
  212. }
  213. } else {
  214. //失败
  215. var img = [];
  216. img.push(that.urlFile);
  217. uni.navigateTo({
  218. url: '/pages/identifyPest/recognizeFail/recognizeFail?data=' +
  219. img +
  220. '&name=' +
  221. that.urlName,
  222. });
  223. }
  224. },
  225. fail(err) {
  226. var img = [];
  227. img.push(that.urlFile);
  228. uni.navigateTo({
  229. url: '/pages/identifyPest/recognizeFail/recognizeFail?data=' +
  230. img +
  231. '&name=' +
  232. that.urlName,
  233. });
  234. },
  235. complete(com) {
  236. that.loadingShow = false;
  237. uni.hideLoading()
  238. },
  239. });
  240. },
  241. // 其他--老识别接口
  242. restsData() {
  243. this.show = true;
  244. },
  245. // 确定
  246. insectData(num) {
  247. this.urlName = '其他';
  248. this.serialNum = '';
  249. this.insectNum = num;
  250. uni.chooseImage({
  251. count: 1,
  252. success: (res) => {
  253. // 设置url的值,显示控件
  254. this.urlData = res.tempFiles[0];
  255. this.url = res.tempFilePaths[0];
  256. this.urlFile = res.tempFilePaths[0]; //失败跳转显示的图片
  257. },
  258. });
  259. },
  260. },
  261. components: {
  262. kpsImageCutter,
  263. },
  264. onLoad(option) {
  265. console.log(option)
  266. this.url = '';
  267. this.type = option.type;
  268. uni.setNavigationBarTitle({
  269. title: `选择${this.identifyPestObj[option.type].title}` // 设置为你想要的标题
  270. });
  271. },
  272. onShow() {
  273. var that = this;
  274. uni.getStorage({
  275. key: this.type,
  276. success: function(res) {
  277. that.lastTimeShow = true;
  278. console.log(res.data);
  279. that.lastTimeIndex = res.data;
  280. },
  281. fail: function(err) {
  282. that.lastTimeShow = false;
  283. console.log(err);
  284. },
  285. });
  286. },
  287. }
  288. </script>
  289. <style lang="scss">
  290. // 搜索
  291. uni-view,
  292. uni-text {
  293. // width: 740rpx;
  294. // margin: 0 auto;
  295. }
  296. // 作物选择
  297. .plantList_ul {
  298. .plantList_li {
  299. margin: 55rpx 0 55rpx 0;
  300. .plantList_tlt {
  301. font-weight: 550;
  302. font-size: 16px;
  303. width: 700rpx;
  304. margin: 0 auto;
  305. text {
  306. color: #7e7e7e;
  307. font-size: 12px;
  308. }
  309. }
  310. .plantList_li_ul {
  311. display: flex;
  312. flex-wrap: wrap;
  313. margin-top: 10rpx;
  314. .plantList_li_List {
  315. margin: 10rpx 0 0 18rpx;
  316. width: 150rpx;
  317. image {
  318. width: 130rpx;
  319. height: 130rpx;
  320. border-radius: 55px;
  321. margin: 0 auto;
  322. display: block;
  323. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
  324. }
  325. view {
  326. width: 150rpx;
  327. color: #646464;
  328. text-align: center;
  329. margin: 10rpx 0 0 0;
  330. font-size: 13px;
  331. }
  332. }
  333. }
  334. }
  335. }
  336. </style>