checkPointDetail.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <view class="warp">
  3. <uni-card :title="'序号: ' + ciDetail.cicode" :extra="'ID: ' + ciDetail.ciid">
  4. <view style="margin: 20rpx 0;">
  5. <uni-tag :circle="true" text="系统位置" type="success" size="small"
  6. style="font-weight: bold; margin-right: 30rpx;" />
  7. <!-- <text style="padding-right: 36rpx;">检查点位置</text> -->
  8. <text style="padding-right: 20rpx;"> 经度 {{ ciDetail.position.longitude }} </text>
  9. <text>纬度 {{ ciDetail.position.latitude }}</text>
  10. <!-- <text>高度 {{ ciDetail.position.altitude }}</text> -->
  11. </view>
  12. <view style="margin: 20rpx 0;">
  13. <uni-tag :circle="true" text="当前位置" type="warning" size="small"
  14. style="font-weight: bold; margin-right: 30rpx;" />
  15. <!-- <text style="padding-right: 65rpx;">当前位置</text> -->
  16. <text style="padding-right: 20rpx;">经度 {{ curPos.longitude }} </text>
  17. <text>纬度 {{ curPos.latitude }}</text>
  18. <!-- <text>高度 {{ curPos.altitude }}</text> -->
  19. </view>
  20. <view style="text-align: center; margin-top: 10rpx;">
  21. <button @click="getCurPos()" class="mini-btn" type="primary" size="mini"
  22. style="margin-right: 50rpx;">获取位置</button>
  23. <button @click="savePos()" class="mini-btn" type="primary" size="mini">上报位置</button>
  24. </view>
  25. </uni-card>
  26. <uni-section title="NFC列表" type="line">
  27. <uni-list v-if="nfcList.length > 0">
  28. <!-- <uni-list-item v-for="(item, index) in nfcList" :key="item.id" :title="item.id" :note="item.data"> -->
  29. <uni-list-item v-for="(item, index) in nfcList" :key="item" :title="item">
  30. <!-- 自定义 footer-->
  31. <template v-slot:footer>
  32. <button @click="delNfc(index)" class="mini-btn" type="warn" size="mini"
  33. style="height: 60rpx;">删除</button>
  34. </template>
  35. </uni-list-item>
  36. </uni-list>
  37. <view v-else style="text-align: center;">
  38. <text>NFC列表为空</text>
  39. </view>
  40. </uni-section>
  41. <view style="text-align: center; margin-top: 30rpx;">
  42. <button @click="readNfc()" class="mini-btn" type="primary" size="mini" style="margin-right: 50rpx;">读取
  43. NFC</button>
  44. <button @click="saveControlInfo()" class="mini-btn" type="primary" size="mini">上报 NFC</button>
  45. </view>
  46. <!-- 提示信息弹窗 -->
  47. <uni-popup ref="message" type="message">
  48. <uni-popup-message :type="msgType" :message="messageText" :duration="2000"></uni-popup-message>
  49. </uni-popup>
  50. </view>
  51. </template>
  52. <script>
  53. // import nfc from '../../utils/ouu-nfc.js'
  54. import {
  55. IdRequest,
  56. Position,
  57. } from "@/grpc/base_pb.js"
  58. import {
  59. AssControlInfoSaveRequest,
  60. AssControlInfoGpsSaveRequest
  61. } from "@/grpc/ass_api_pb.js"
  62. export default {
  63. components: {},
  64. data() {
  65. return {
  66. ciId: 0,
  67. ciDetail: {
  68. cicode: '',
  69. ciid: '',
  70. position: {
  71. longitude: '',
  72. latitude: '',
  73. altitude: ''
  74. },
  75. nfccodelistList: []
  76. },
  77. nfcList: [],
  78. curPos: {
  79. longitude: '',
  80. latitude: '',
  81. altitude: ''
  82. },
  83. msgType: 'success',
  84. messageText: '',
  85. }
  86. },
  87. computed: {},
  88. mounted() {
  89. // console.log('[checkPointDetail] mounted')
  90. // const appAuthorizeSetting = uni.getAppAuthorizeSetting()
  91. // console.log(appAuthorizeSetting.locationAuthorized)
  92. // console.log(appAuthorizeSetting.locationAccuracy)
  93. },
  94. onLoad(option) {
  95. // console.log('[checkPointDetail] onLoad')
  96. // console.log(option.ciId)
  97. if (option.ciId > 0) {
  98. // nfc.listenNFCStatus()
  99. this.ciId = option.ciId
  100. this.getAssControlInfoDetail()
  101. this.getCurPos()
  102. }
  103. },
  104. onShow() {
  105. console.log('[checkPointDetail] onShow')
  106. uni.$off('NfcRead')
  107. uni.$on('NfcRead', this.onNfcRead)
  108. },
  109. onHide() {
  110. console.log('[checkPointDetail] onHide')
  111. },
  112. beforeDestroy() {
  113. console.log('[checkPointDetail] beforeDestroy')
  114. uni.$off('NfcRead')
  115. },
  116. methods: {
  117. //msgType: success 成功 / warn 警告 / error 失败 / info 消息
  118. messageToggle(messageText = '操作成功', msgType = 'success') {
  119. this.msgType = msgType
  120. this.messageText = messageText
  121. this.$refs.message.open()
  122. },
  123. getAssControlInfoDetail() {
  124. // 创建请求参数并赋值
  125. var request = new IdRequest()
  126. request.setId(this.ciId)
  127. // 调用客户端相应的grpc方法,发送grpc请求,并接受后台发送回来的返回值
  128. this.$client.assControlInfoDetail(request, {}, (err, response) => {
  129. if (err) {
  130. console.log(`[assControlInfoDetail] err: code = ${err.code}` +
  131. `, message = "${err.message}"`)
  132. this.messageToggle('获取检查点信息失败', 'error')
  133. } else {
  134. // console.log(response)
  135. let res = response.toObject()
  136. console.log(res)
  137. this.ciDetail = res
  138. this.nfcList.length = 0
  139. this.nfcList = res.nfccodelistList
  140. }
  141. });
  142. },
  143. getCurPos() {
  144. let that = this
  145. uni.getLocation({
  146. type: 'wgs84',
  147. // altitude: true, // 传入 true 会返回高度信息,由于获取高度需要较高精确度,会减慢接口返回速度
  148. highAccuracyExpireTime: 10000, // 高精度定位超时时间(ms),指定时间内返回最高精度,该值3000ms以上高精度定位才有效果
  149. isHighAccuracy: true, // 开启高精度定位
  150. success: function(res) {
  151. console.log('res:' + JSON.stringify(res))
  152. console.log('当前位置的经度:' + res.longitude)
  153. console.log('当前位置的纬度:' + res.latitude)
  154. // console.log('当前位置的高度:' + res.altitude)
  155. that.curPos.longitude = res.longitude
  156. that.curPos.latitude = res.latitude
  157. // that.curPos.altitude = res.altitude
  158. }
  159. });
  160. },
  161. savePos() {
  162. // 创建请求参数并赋值
  163. var request = new AssControlInfoGpsSaveRequest()
  164. request.setCiid(this.ciId)
  165. var position = new Position()
  166. position.setLongitude(this.curPos.longitude)
  167. position.setLatitude(this.curPos.latitude)
  168. request.setPosition(position)
  169. // 调用客户端相应的grpc方法,发送grpc请求,并接受后台发送回来的返回值
  170. this.$client.assControlInfoGpsSave(request, {}, (err, response) => {
  171. if (err) {
  172. console.log(`[assControlInfoGpsSave] err: code = ${err.code}` +
  173. `, message = "${err.message}"`)
  174. this.messageToggle('上报位置信息失败', 'error')
  175. } else {
  176. // console.log(response)
  177. // let res = response.toObject()
  178. // console.log(res)
  179. this.getAssControlInfoDetail()
  180. this.messageToggle('上报位置信息成功')
  181. }
  182. });
  183. },
  184. readNfc() {
  185. this.$nfc.readData()
  186. },
  187. onNfcRead(data) {
  188. console.log('监听到事件来自 nfcRead, data: ' + JSON.stringify(data))
  189. let length = this.nfcList.length
  190. let find = false
  191. for (let i = 0; i < length; i++) {
  192. // if (this.nfcList[i].id === data.id) {
  193. if (this.nfcList[i] === data.id) {
  194. find = true
  195. }
  196. }
  197. if (!find) {
  198. // this.nfcList.push(data)
  199. this.nfcList.push(data.id)
  200. console.log(this.nfcList)
  201. } else {
  202. uni.showToast({
  203. title: 'NFC标签 [' + data.id + '] 已存在',
  204. icon: 'none',
  205. duration: 2000
  206. })
  207. }
  208. },
  209. delNfc(index) {
  210. let that = this
  211. uni.showModal({
  212. title: '操作提示',
  213. content: '确定删除该记录吗?',
  214. success: function(res) {
  215. if (res.confirm) {
  216. console.log('用户点击确定');
  217. that.nfcList.splice(index, 1)
  218. that.messageToggle('删除成功')
  219. } else if (res.cancel) {
  220. console.log('用户点击取消');
  221. }
  222. }
  223. });
  224. },
  225. saveControlInfo() {
  226. // 创建请求参数并赋值
  227. var request = new AssControlInfoSaveRequest()
  228. request.setCiid(this.ciId)
  229. request.setNfccodelistList(this.nfcList)
  230. // 调用客户端相应的grpc方法,发送grpc请求,并接受后台发送回来的返回值
  231. this.$client.assControlInfoSave(request, {}, (err, response) => {
  232. if (err) {
  233. console.log(`[assControlInfoSave] err: code = ${err.code}` +
  234. `, message = "${err.message}"`)
  235. this.messageToggle('上报NFC信息失败', 'error')
  236. } else {
  237. console.log(response)
  238. // let res = response.toObject()
  239. // console.log(res)
  240. this.messageToggle('上报NFC信息成功')
  241. }
  242. });
  243. }
  244. }
  245. }
  246. </script>
  247. <style lang="scss">
  248. .padding {
  249. padding: 0 20rpx;
  250. }
  251. </style>