gasRecordCard.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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: true,
  41. cardId: '',
  42. cardData: { id: '', address: '' },
  43. }
  44. },
  45. computed: {
  46. cardIds: function () {
  47. return this.$store.getters.nfcreadtxt;
  48. }
  49. },
  50. watch: {
  51. cardIds: {
  52. handler(newV, oldV) {
  53. console.log(newV, 'newV------------------------')
  54. this.getCardLists(newV)
  55. },
  56. immediate: true
  57. }
  58. },
  59. mounted() {
  60. testNfc.listenNFCStatus()
  61. // testNfc.Into()
  62. },
  63. methods: {
  64. //获取NFC卡读取内容
  65. getCardLists(ids) {
  66. let that = this
  67. new Promise((resolve, reject) => {
  68. api
  69. .getCardList({ id: ids })
  70. .then((response) => {
  71. if (response.data.code == 200) {
  72. let data = response.data.result
  73. that.cardData.id = data.id
  74. that.cardData.address = data.strInstallPos
  75. } else {
  76. that.$refs.uToast.show({
  77. type: 'default',
  78. icon: false,
  79. message: response.data.message,
  80. })
  81. }
  82. })
  83. });
  84. },
  85. //格式化tag
  86. // getNfcFormat() {
  87. // testNfc.__write()
  88. // },
  89. //nfc 写入
  90. getNfcWrite() {
  91. let that = this
  92. new Promise((resolve, reject) => {
  93. api
  94. .enterCardId({ id: that.cardId, })
  95. .then((response) => {
  96. if (response.data.code == 200) {
  97. if (that.isNfc) {
  98. // 调用 js 文件里面的方法
  99. testNfc.setTxt(that.cardId);
  100. testNfc.writeData();
  101. } else {
  102. that.$refs.uToast.show({
  103. type: 'default',
  104. icon: false,
  105. message: '录入成功!',
  106. })
  107. }
  108. } else {
  109. that.$refs.uToast.show({
  110. type: 'default',
  111. icon: false,
  112. message: response.data.message,
  113. })
  114. // 调用 js 文件里面的方法
  115. // testNfc.setTxt(that.cardId);
  116. // testNfc.writeData();
  117. }
  118. })
  119. });
  120. },
  121. //nfc读取
  122. getNfcRead() {
  123. let that = this
  124. if (that.isNfc) {
  125. // 调用 js 文件里面的方法
  126. testNfc.readData();
  127. } else {
  128. that.getCardLists(that.cardId)
  129. }
  130. }
  131. }
  132. }
  133. </script>
  134. <style lang="scss" scoped>
  135. .gas-record-card {
  136. position: relative;
  137. width: 100%;
  138. height: 100%;
  139. .record-top-area {
  140. display: flex;
  141. flex-direction: column;
  142. align-items: center;
  143. width: 100%;
  144. padding: 10px 20px;
  145. box-sizing: border-box;
  146. background-color: #FFF;
  147. margin-bottom: 2px;
  148. }
  149. .record-write-box {
  150. display: flex;
  151. align-items: center;
  152. justify-content: center;
  153. margin-bottom: 10px;
  154. .dialog-label {
  155. width: 60px;
  156. text-align: right;
  157. }
  158. }
  159. .record-bot-area {
  160. width: 100%;
  161. height: calc(100% - 138px);
  162. padding: 10px;
  163. box-sizing: border-box;
  164. background-color: #FFF;
  165. margin-bottom: 2px;
  166. overflow-y: auto;
  167. .record-container {
  168. .record-title {
  169. position: relative;
  170. width: 100%;
  171. height: 50rpx;
  172. background: url(/static/warndata/title.png);
  173. background-repeat: no-repeat;
  174. background-size: 100% 100%;
  175. display: flex;
  176. /* 将父级元素设置为 Flex 容器 */
  177. align-items: center;
  178. /* 垂直居中子元素 */
  179. }
  180. .record-text {
  181. margin: 20px;
  182. }
  183. .record-card {
  184. display: flex;
  185. flex-direction: column;
  186. justify-content: center;
  187. width: 100%;
  188. height: 100px;
  189. margin: 10px auto;
  190. border-radius: 10px;
  191. background: url(/static/warndata/work.png),
  192. linear-gradient(to right,
  193. rgba(55, 135, 254, 0.08),
  194. rgba(4, 184, 255, 0.08),
  195. rgba(60, 161, 237, 0.08));
  196. }
  197. .record-card-item {
  198. width: 100%;
  199. padding: 10px;
  200. font-size: 14px;
  201. box-sizing: border-box;
  202. .card-item-label {
  203. display: inline-block;
  204. width: 53%;
  205. text-align: right;
  206. color: #3787fe;
  207. font-weight: bold;
  208. }
  209. }
  210. }
  211. }
  212. }
  213. </style>