| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <template>
- <view class="container">
- <uni-easyinput v-model="nfcWriteData" placeholder="请输入要写入NFC的数据" @input="input" />
- <view class="btn-box">
- <button class="btn" type="primary" @click="readData()">读取NFC</button>
- <button class="btn" type="primary" @click="writeData()">写入NFC</button>
- </view>
- <view class="btn-box">
- <button class="btn" type="primary" @click="getNfcState()">NFC状态</button>
- <button class="btn" type="warn" @click="writeAndLock()">写入并锁定</button>
- </view>
- <view class="btn-box">
- <button class="btn" type="warn" @click="setPassword()">设置密码</button>
- <button class="btn" type="warn" @click="delPassword()">清除密码</button>
- </view>
- </view>
- </template>
- <script>
- // import nfc from '../../utils/ouu-nfc.js'
- export default {
- data() {
- return {
- nfcWriteData: 'http://www.beswell.com'
- }
- },
- mounted() {
- console.log('[nfc] mounted')
- // nfc.listenNFCStatus();
- },
- onLoad() {
- console.log('[nfc] onLoad')
- this.$nfc.inputChanage(this.nfcWriteData)
- },
- onShow() {
- console.log('[nfc] onShow')
- uni.$off('NfcRead')
- uni.$on('NfcRead', this.onNfcRead)
- },
- onHide() {
- console.log('[nfc] onHide')
- },
- beforeDestroy() {
- console.log('[nfc] beforeDestroy')
- uni.$off('NfcRead')
- },
- methods: {
- input(data) {
- // console.log('input, data: ' + JSON.stringify(data))
- this.$nfc.inputChanage(data)
- },
- onNfcRead(data) {
- console.log('监听到事件来自 nfcRead, data: ' + JSON.stringify(data))
- // console.log(data)
- uni.showToast({
- title: `[${data.id}] '${data.data}'`,
- icon: 'none',
- duration: 2000
- })
- },
- writeData() {
- this.$nfc.writeData()
- },
- readData() {
- this.$nfc.readData()
- },
- setPassword() {
- this.$nfc.setPwdData()
- },
- delPassword() {
- this.$nfc.delPwdData()
- },
- getNfcState() {
- this.$nfc.getNfcState()
- },
- writeAndLock() {
- this.$nfc.writeAndLock()
- }
- }
- }
- </script>
- <style scoped lang="scss">
- .container {
- padding: 15px;
- box-sizing: border-box;
- .btn-box {
- display: flex;
- justify-content: center;
- align-items: center;
- margin-top: 20px;
- .btn {
- width: 35%;
- }
- }
- }
- </style>
|