gasRecordCard.vue 5.8 KB

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