identifyPestIndex.vue 8.6 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="
  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" :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. 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. // url: `http://192.168.2.163:8003/api/api_gateway?method=wheat.discreen.plan`,
  178. fileType: 'image',
  179. // file: this.urlData,
  180. filePath: ev.path,
  181. formData: {
  182. type: num,
  183. token: session_key
  184. },
  185. name: 'img_addr',
  186. success(res) {
  187. console.log(res);
  188. uni.hideLoading();
  189. that.url = '';
  190. // 判断是否识别成功 -新接口
  191. // if (data.code == 200) {
  192. if (res.statusCode !== 500) {
  193. var data = JSON.parse(res.data).data;
  194. if (data.returnResult.returnStatus == 1) {
  195. // 成功
  196. uni.navigateTo({
  197. url: '/pages/identifyPest/recognizeSucceed/recognizeSucceed?data=' +
  198. JSON.stringify(data.returnResult),
  199. });
  200. console.log('新接口');
  201. } else if (data.returnResult.returnStatus == 0) {
  202. //失败
  203. var img = [];
  204. img.push(that.urlFile);
  205. uni.navigateTo({
  206. url: '/pages/identifyPest/recognizeFail/recognizeFail?data=' +
  207. img +
  208. '&name=' +
  209. that.urlName,
  210. });
  211. }
  212. } else {
  213. //失败
  214. var img = [];
  215. img.push(that.urlFile);
  216. uni.navigateTo({
  217. url: '/pages/identifyPest/recognizeFail/recognizeFail?data=' +
  218. img +
  219. '&name=' +
  220. that.urlName,
  221. });
  222. }
  223. },
  224. fail(err) {
  225. var img = [];
  226. img.push(that.urlFile);
  227. uni.navigateTo({
  228. url: '/pages/identifyPest/recognizeFail/recognizeFail?data=' +
  229. img +
  230. '&name=' +
  231. that.urlName,
  232. });
  233. },
  234. complete(com) {
  235. that.loadingShow = false;
  236. uni.hideLoading()
  237. },
  238. });
  239. },
  240. // 其他--老识别接口
  241. restsData() {
  242. this.show = true;
  243. },
  244. // 确定
  245. insectData(num) {
  246. this.urlName = '其他';
  247. this.serialNum = '';
  248. this.insectNum = num;
  249. uni.chooseImage({
  250. count: 1,
  251. success: (res) => {
  252. // 设置url的值,显示控件
  253. this.urlData = res.tempFiles[0];
  254. this.url = res.tempFilePaths[0];
  255. this.urlFile = res.tempFilePaths[0]; //失败跳转显示的图片
  256. },
  257. });
  258. },
  259. },
  260. components: {
  261. kpsImageCutter,
  262. },
  263. onLoad(option) {
  264. console.log(option)
  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>