gasRecordCard.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <view class="gas-record-card">
  3. <view class="record-top-area">
  4. <view class="record-write-box">
  5. <text class="dialog-label">卡ID:</text>
  6. <u--input v-model="cardId" placeholder="请输入卡片ID" type="number" size="small" clearable
  7. style="width:220px;padding: 2px 9px;"></u--input>
  8. </view>
  9. <!-- <u-button type="primary" size="small" style="margin: 2px 0px;" @click="getNfcFormat">格式化tag</u-button> -->
  10. <u-button type="primary" size="small" style="margin: 2px 0px;" @click="getNfcWrite">录入</u-button>
  11. <u-button type="primary" size="small" style="margin: 2px 0px;" @click="getNfcRead">读取</u-button>
  12. </view>
  13. <view class="record-bot-area">
  14. <u-toast ref="uToast"></u-toast>
  15. <view class="record-container" v-if="cardData.id">
  16. <view class="record-title">
  17. <span class="record-text">卡片ID读取</span>
  18. </view>
  19. <view class="record-card">
  20. <view class="record-card-item">
  21. <text class="card-item-label">当前卡ID为:</text>
  22. <text class="card-item-value">{{ cardData.id }}</text>
  23. </view>
  24. <view class="record-card-item">
  25. <text class="card-item-label">当前巡检点为:</text>
  26. <text class="card-item-value">{{ cardData.address }}</text>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import api from "@/api/api";
  35. import testNfc from "@/common/util/hexiii-nfc.js"
  36. export default {
  37. name: 'gasRecordCard',
  38. data() {
  39. return {
  40. isNfc: false,
  41. cardId: '',
  42. cardData: { id: '', address: '' },
  43. }
  44. },
  45. computed: {},
  46. mounted() {
  47. testNfc.listenNFCStatus()
  48. },
  49. methods: {
  50. //获取NFC卡读取内容
  51. getCardLists(ids) {
  52. let that = this
  53. new Promise((resolve, reject) => {
  54. api
  55. .getCardList({ id: ids })
  56. .then((response) => {
  57. if (response.data.code == 200) {
  58. let data = response.data.result
  59. that.cardData.id = data.id
  60. that.cardData.address = data.strInstallPos
  61. } else {
  62. that.$refs.uToast.show({
  63. type: 'default',
  64. icon: false,
  65. message: response.data.message,
  66. })
  67. }
  68. })
  69. });
  70. },
  71. //格式化tag
  72. // getNfcFormat() {
  73. // testNfc.__write()
  74. // },
  75. //nfc 写入
  76. getNfcWrite() {
  77. let that = this
  78. new Promise((resolve, reject) => {
  79. api
  80. .enterCardId({ id: that.cardId, })
  81. .then((response) => {
  82. if (response.data.code == 200) {
  83. if (that.isNfc) {
  84. testNfc.getSettingText(that.cardId)
  85. testNfc.writeData()
  86. } else {
  87. that.$refs.uToast.show({
  88. type: 'default',
  89. icon: false,
  90. message: '录入成功!',
  91. })
  92. }
  93. } else {
  94. that.$refs.uToast.show({
  95. type: 'default',
  96. icon: false,
  97. message: response.data.message,
  98. })
  99. }
  100. })
  101. });
  102. },
  103. //nfc读取
  104. getNfcRead() {
  105. let that = this
  106. // that.cardId = ''
  107. if (that.isNfc) {
  108. testNfc.readData()
  109. console.log(testNfc.getReadContent(), 'reading')
  110. // let ids = testNfc.listenNFCStatus()
  111. if (ids) {
  112. that.getCardLists(ids)
  113. }
  114. }else {
  115. that.getCardLists(that.cardId)
  116. }
  117. }
  118. }
  119. }
  120. </script>
  121. <style lang="scss" scoped>
  122. .gas-record-card {
  123. position: relative;
  124. width: 100%;
  125. height: 100%;
  126. .record-top-area {
  127. display: flex;
  128. flex-direction: column;
  129. align-items: center;
  130. width: 100%;
  131. padding: 10px 20px;
  132. box-sizing: border-box;
  133. background-color: #FFF;
  134. margin-bottom: 2px;
  135. }
  136. .record-write-box {
  137. display: flex;
  138. align-items: center;
  139. justify-content: center;
  140. margin-bottom: 10px;
  141. .dialog-label {
  142. width: 60px;
  143. text-align: right;
  144. }
  145. }
  146. .record-bot-area {
  147. width: 100%;
  148. height: calc(100% - 138px);
  149. padding: 10px;
  150. box-sizing: border-box;
  151. background-color: #FFF;
  152. margin-bottom: 2px;
  153. overflow-y: auto;
  154. .record-container {
  155. .record-title {
  156. position: relative;
  157. width: 100%;
  158. height: 50rpx;
  159. background: url(/static/warndata/title.png);
  160. background-repeat: no-repeat;
  161. background-size: 100% 100%;
  162. display: flex;
  163. /* 将父级元素设置为 Flex 容器 */
  164. align-items: center;
  165. /* 垂直居中子元素 */
  166. }
  167. .record-text {
  168. margin: 20px;
  169. }
  170. .record-card {
  171. display: flex;
  172. flex-direction: column;
  173. justify-content: center;
  174. width: 100%;
  175. height: 100px;
  176. margin: 10px auto;
  177. border-radius: 10px;
  178. background: url(/static/warndata/work.png),
  179. linear-gradient(to right,
  180. rgba(55, 135, 254, 0.08),
  181. rgba(4, 184, 255, 0.08),
  182. rgba(60, 161, 237, 0.08));
  183. }
  184. .record-card-item {
  185. width: 100%;
  186. padding: 10px;
  187. font-size: 14px;
  188. box-sizing: border-box;
  189. .card-item-label {
  190. display: inline-block;
  191. width: 53%;
  192. text-align: right;
  193. color: #3787fe;
  194. font-weight: bold;
  195. }
  196. }
  197. }
  198. }
  199. }
  200. </style>