index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 40px;">
  5. <view style="position: fixed;z-index: 100;">
  6. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" title="病虫害识别"></uni-nav-bar>
  7. </view>
  8. <view class="image_box">
  9. <image :src="path" mode="" class="image" @click="examine(path)"></image>
  10. </view>
  11. <view class="recognition" v-if="datasTF">
  12. <p class="recognition_title">{{name}}</p>
  13. <view :class="tishi?'recognition_img':'recognition_img_two'">
  14. <image :src="path2" mode="" @error="error" @click="examine(path2)"></image>
  15. </view>
  16. <button class="recognition_details" v-if="tishi" @click="examines">查看详情</button>
  17. <button class="recognition_details" v-if="!tishi" @click="show=!show">再拍一张</button>
  18. </view>
  19. <view class="datas" v-else>
  20. <p class="datas_title">{{name}}</p>
  21. <view v-for="(item,index) in preventionArr" :key="index" class="prevention">
  22. <view class="prevention_title">
  23. <u-icon name="play-right-fill" size="24" color="#55A92D"></u-icon>
  24. <p>{{regexptitle[index]}}:</p>
  25. </view>
  26. <p class="prevention_con">{{item}}</p>
  27. </view>
  28. <button class="recognition_details" v-if="tishi" @click="examines">查看图片</button>
  29. </view>
  30. <u-modal v-model="show" :mask-close-able="true" title="" :show-cancel-button="true" confirm-text="拍病害" cancel-text="拍虫害"
  31. content="拍照识别病虫害" @confirm="confirm" @cancel="cancel"></u-modal>
  32. </view>
  33. <kps-image-cutter @ok="onok" @cancel="oncancle" :url="imgdata" :fixed="false" :blob="true"></kps-image-cutter>
  34. <view class="loading" v-if="loadTF">
  35. <u-loading mode="flower" size="100" :show="true" ></u-loading>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import kpsImageCutter from "@/components/ksp-image-cutter/ksp-image-cutter.vue";
  41. export default {
  42. components: {
  43. kpsImageCutter
  44. },
  45. data() {
  46. return {
  47. path: "",
  48. path2: "",
  49. tishi: true,
  50. name: "",
  51. prevention: "",
  52. datasTF: true,
  53. show: false,
  54. imgdata: "",
  55. preventionArr: [],
  56. regexptitle: [],
  57. loadTF:false
  58. }
  59. },
  60. methods: {
  61. clickLeft() {
  62. uni.switchTab({
  63. url: "../index/index"
  64. })
  65. },
  66. examines() {
  67. this.datasTF = !this.datasTF
  68. },
  69. confirm() {
  70. this.flag = 1
  71. var that = this
  72. // console.log(1)
  73. uni.chooseImage({
  74. count: 1, //默认9
  75. // sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  76. sourceType: ['camera', 'album'], //从相册选择
  77. success: (res) => {
  78. that.imgdata = res.tempFilePaths[0]
  79. that.path = res.tempFilePaths[0]
  80. },
  81. });
  82. },
  83. cancel() {
  84. var that = this
  85. this.flag = 2
  86. uni.chooseImage({
  87. count: 1, //默认9
  88. // sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  89. sourceType: ['camera', 'album'], //从相册选择
  90. success: (res) => {
  91. that.imgdata = res.tempFilePaths[0]
  92. that.path = res.tempFilePaths[0]
  93. }
  94. });
  95. },
  96. onok(ev) {
  97. this.loadTF = !this.loadTF
  98. if (this.flag == 2) {
  99. // pest.pests.insect_discern 虫害
  100. uni.uploadFile({
  101. // url: 'http://114.115.147.140:8002/api/api_gateway?method=base.bases.base_photo', //仅为示例,非真实的接口地址
  102. url: 'https://wx.hnyfwlw.com/api/api_gateway?method=pest.pests.insect_discern', //仅为示例,非真实的接口地址
  103. filePath: ev.path,
  104. name: 'img_file',
  105. formData: {
  106. 'user': 'test'
  107. },
  108. success: (uploadFileRes) => {
  109. console.log(JSON.parse(uploadFileRes.data))
  110. this.loadTF = !this.loadTF
  111. this.optionverify(JSON.parse(uploadFileRes.data).data)
  112. }
  113. });
  114. } else if (this.flag == 1) {
  115. //pest.pests.insect_discern病害识别
  116. uni.uploadFile({
  117. // url: 'http://114.115.147.140:8002/api/api_gateway?method=base.bases.base_photo', //仅为示例,非真实的接口地址
  118. url: 'https://wx.hnyfwlw.com/api/api_gateway?method=pest.pests.plant_discern', //仅为示例,非真实的接口地址
  119. filePath: ev.path,
  120. name: 'img_file',
  121. formData: {
  122. 'user': 'test'
  123. },
  124. success: (uploadFileRes) => {
  125. console.log(JSON.parse(uploadFileRes.data))
  126. this.loadTF = !this.loadTF
  127. this.optionverify(JSON.parse(uploadFileRes.data).data)
  128. }
  129. });
  130. }
  131. this.imgdata = "";
  132. },
  133. oncancle() {
  134. // url设置为空,隐藏控件
  135. this.imgdata = ''
  136. },
  137. error() {
  138. this.path2 = this.$imageURL+"/bigdata_app/image/e1cd85dc59139760f43ddbac15136f2.png"
  139. },
  140. optionverify(data) {
  141. console.log(data)
  142. if (data == null) {
  143. this.name = "识别失败,请换张图片"
  144. this.tishi = false
  145. this.path2 = this.$imageURL+"/bigdata_app/image/10ca93e17420371a82826073c8425c0.png"
  146. } else {
  147. if(data.img_urls==""){
  148. this.path2 = this.$imageURL+"/bigdata_app/image/e1cd85dc59139760f43ddbac15136f2.png"
  149. }else{
  150. console.log(data.img_urls)
  151. this.path2 = data.img_urls
  152. }
  153. this.name = data.name
  154. this.tishi = true
  155. this.prevention = data.prevention
  156. var regex2 = /\[(.+?)\]/g; // [] 中括号
  157. var str = this.prevention
  158. var arr = str.match(regex2)
  159. var arrindex = []
  160. for (var i = 0; i < arr.length; i++) {
  161. arrindex.push(str.indexOf(arr[i]))
  162. }
  163. for (var i = 0; i < arr.length; i++) {
  164. if(str.slice(arrindex[i] + arr[i].length, arrindex[i + 1]) == " null" || str.slice(arrindex[i] + arr[i].length, arrindex[i + 1])== "" ||str.slice(arrindex[i] + arr[i].length, arrindex[i + 1]) == "null"){
  165. this.preventionArr.push("暂无信息")
  166. }else{
  167. this.preventionArr.push(str.slice(arrindex[i] + arr[i].length, arrindex[i + 1]))
  168. }
  169. }
  170. for (var i = 0; i < arr.length; i++) {
  171. arr[i] = arr[i].slice(1, arr[i].length - 1)
  172. }
  173. this.regexptitle = arr
  174. }
  175. },
  176. examine(url) {
  177. var imgarr =[]
  178. imgarr.push(url)
  179. console.log(imgarr)
  180. uni.previewImage({
  181. urls: imgarr
  182. });
  183. },
  184. },
  185. onLoad(option) {
  186. console.log(option)
  187. this.path = option.path
  188. this.optionverify(JSON.parse(option.datas).data)
  189. }
  190. }
  191. </script>
  192. <style lang="scss">
  193. .loading{
  194. position: absolute;
  195. top: 0;
  196. left: 0;
  197. z-index: 100;
  198. width:100%;
  199. height: 100vh;
  200. background-color: rgba(0,0,0,0.5);
  201. display: flex;
  202. justify-content: center;
  203. align-items: center;
  204. }
  205. .image_box {
  206. position: absolute;
  207. top: 44px;
  208. width: 100%;
  209. height: 400rpx;
  210. .image {
  211. width: 100%;
  212. height: 400rpx;
  213. }
  214. }
  215. .recognition {
  216. position: absolute;
  217. top: 254px;
  218. width: 100%;
  219. height: 800rpx;
  220. .recognition_title {
  221. width: 100%;
  222. text-align: center;
  223. font-size: 36rpx;
  224. font-weight: 700;
  225. margin: 60rpx 0;
  226. }
  227. .recognition_img {
  228. border: 2rpx dashed #06B535;
  229. width: 450rpx;
  230. height: 450rpx;
  231. border-radius: 50%;
  232. margin: 0 auto;
  233. text-align: center;
  234. line-height: 450rpx;
  235. image {
  236. margin-top: 50rpx;
  237. width: 340rpx;
  238. height: 340rpx;
  239. }
  240. }
  241. .recognition_img_two {
  242. width: 450rpx;
  243. height: 450rpx;
  244. border-radius: 50%;
  245. margin: 0 auto;
  246. text-align: center;
  247. line-height: 450rpx;
  248. image {
  249. margin-top: 10rpx;
  250. width: 340rpx;
  251. height: 340rpx;
  252. }
  253. }
  254. .recognition_details {
  255. width: 400rpx;
  256. height: 80rpx;
  257. border-radius: 40rpx;
  258. margin: 30rpx auto;
  259. font-size: 30rpx;
  260. background-color: #67B25F;
  261. color: #FFFFFF;
  262. }
  263. }
  264. .datas {
  265. position: absolute;
  266. top: 284px;
  267. width: 95%;
  268. left: 2.5%;
  269. .datas_title {
  270. font-size: 32rpx;
  271. font-weight: 700;
  272. margin-left: 30rpx;
  273. }
  274. .recognition_details {
  275. width: 400rpx;
  276. height: 80rpx;
  277. border-radius: 40rpx;
  278. margin: 30rpx auto;
  279. font-size: 30rpx;
  280. background-color: #67B25F;
  281. color: #FFFFFF;
  282. }
  283. }
  284. .prevention {
  285. font-size: 28rpx;
  286. color: #919191;
  287. width: 95%;
  288. margin: 20rpx auto;
  289. .prevention_title {
  290. display: flex;
  291. p {
  292. margin-left: 20rpx;
  293. color: #000000;
  294. font-size: 28rpx;
  295. font-weight: 700;
  296. }
  297. }
  298. .prevention_con {
  299. padding-left: 6%;
  300. }
  301. }
  302. </style>