identifyPestIndex.vue 8.5 KB

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