index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 44px;">
  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="'http://static.yfpyx.com/bigdata_app'+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://182.92.193.64:8002/api/api_gateway?method=base.bases.base_photo', //仅为示例,非真实的接口地址
  102. url: 'http://182.92.193.64:8002/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://182.92.193.64:8002/api/api_gateway?method=base.bases.base_photo', //仅为示例,非真实的接口地址
  118. url: 'http://182.92.193.64:8002/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 = "/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 = "/image/10ca93e17420371a82826073c8425c0.png"
  146. } else {
  147. if(data.img_urls==""){
  148. this.path2 = "/image/e1cd85dc59139760f43ddbac15136f2.png"
  149. }else{
  150. this.path2 = data.img_urls
  151. }
  152. this.name = data.name
  153. this.tishi = true
  154. this.prevention = data.prevention
  155. var regex2 = /\[(.+?)\]/g; // [] 中括号
  156. var str = this.prevention
  157. var arr = str.match(regex2)
  158. var arrindex = []
  159. for (var i = 0; i < arr.length; i++) {
  160. arrindex.push(str.indexOf(arr[i]))
  161. }
  162. for (var i = 0; i < arr.length; i++) {
  163. 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"){
  164. this.preventionArr.push("暂无信息")
  165. }else{
  166. this.preventionArr.push(str.slice(arrindex[i] + arr[i].length, arrindex[i + 1]))
  167. }
  168. }
  169. for (var i = 0; i < arr.length; i++) {
  170. arr[i] = arr[i].slice(1, arr[i].length - 1)
  171. }
  172. this.regexptitle = arr
  173. }
  174. },
  175. examine(url) {
  176. var imgarr =[]
  177. imgarr.push(url)
  178. console.log(imgarr)
  179. uni.previewImage({
  180. urls: imgarr
  181. });
  182. },
  183. },
  184. onLoad(option) {
  185. console.log(option)
  186. this.path = option.path
  187. this.optionverify(JSON.parse(option.datas).data)
  188. }
  189. }
  190. </script>
  191. <style lang="scss">
  192. .loading{
  193. position: absolute;
  194. top: 0;
  195. left: 0;
  196. z-index: 100;
  197. width:100%;
  198. height: 100vh;
  199. background-color: rgba(0,0,0,0.5);
  200. display: flex;
  201. justify-content: center;
  202. align-items: center;
  203. }
  204. .image_box {
  205. position: absolute;
  206. top: 44px;
  207. width: 100%;
  208. height: 400rpx;
  209. .image {
  210. width: 100%;
  211. height: 400rpx;
  212. }
  213. }
  214. .recognition {
  215. position: absolute;
  216. top: 254px;
  217. width: 100%;
  218. height: 800rpx;
  219. .recognition_title {
  220. width: 100%;
  221. text-align: center;
  222. font-size: 36rpx;
  223. font-weight: 700;
  224. margin: 60rpx 0;
  225. }
  226. .recognition_img {
  227. border: 2rpx dashed #06B535;
  228. width: 450rpx;
  229. height: 450rpx;
  230. border-radius: 50%;
  231. margin: 0 auto;
  232. text-align: center;
  233. line-height: 450rpx;
  234. image {
  235. margin-top: 50rpx;
  236. width: 340rpx;
  237. height: 340rpx;
  238. }
  239. }
  240. .recognition_img_two {
  241. width: 450rpx;
  242. height: 450rpx;
  243. border-radius: 50%;
  244. margin: 0 auto;
  245. text-align: center;
  246. line-height: 450rpx;
  247. image {
  248. margin-top: 10rpx;
  249. width: 340rpx;
  250. height: 340rpx;
  251. }
  252. }
  253. .recognition_details {
  254. width: 400rpx;
  255. height: 80rpx;
  256. border-radius: 40rpx;
  257. margin: 30rpx auto;
  258. font-size: 30rpx;
  259. background-color: #67B25F;
  260. color: #FFFFFF;
  261. }
  262. }
  263. .datas {
  264. position: absolute;
  265. top: 284px;
  266. width: 95%;
  267. left: 2.5%;
  268. .datas_title {
  269. font-size: 32rpx;
  270. font-weight: 700;
  271. margin-left: 30rpx;
  272. }
  273. .recognition_details {
  274. width: 400rpx;
  275. height: 80rpx;
  276. border-radius: 40rpx;
  277. margin: 30rpx auto;
  278. font-size: 30rpx;
  279. background-color: #67B25F;
  280. color: #FFFFFF;
  281. }
  282. }
  283. .prevention {
  284. font-size: 28rpx;
  285. color: #919191;
  286. width: 95%;
  287. margin: 20rpx auto;
  288. .prevention_title {
  289. display: flex;
  290. p {
  291. margin-left: 20rpx;
  292. color: #000000;
  293. font-size: 28rpx;
  294. font-weight: 700;
  295. }
  296. }
  297. .prevention_con {
  298. padding-left: 6%;
  299. }
  300. }
  301. </style>