• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import router from '@system.router';
17import cardEmulation from '@ohos.nfc.cardEmulation';
18
19export default {
20    data: {
21        itemIndex: -1,
22        hceService: null,
23        value: '',
24        str: '',
25        title: 'nfc',
26        pass: 'true ;',
27        fail: 'false;'
28    },
29
30    onInit() {
31        console.info('onInit');
32    },
33
34    onDestroy() {
35        console.info('onDestroy');
36        this.hceService.stopHCE();
37    },
38
39    nfcOperate() {
40        console.info('nfcOperate');
41        this.value = '';
42        this.hceService = new cardEmulation.HceService();
43        this.hceService.startHCE([
44            'F0010203040506', 'A0000000041010'
45        ]);
46        this.hceService.on('hceCmd', (res) => {
47            this.value = 'success';
48            console.info('callback => Operation hceCmd succeeded. Data: ' + res);
49            this.hceService.sendResponse([0x00, 0xa4, 0x04, 0x00, 0x0e, 0x32, 0x50, 0x41, 0x59,
50                0x2e, 0x53, 0x59, 0x53, 0x2e, 0x44, 0x44, 0x46, 0x30, 0x31, 0x00]);
51        });
52    },
53
54    help() {
55        router.replace({
56            uri: 'pages/help/index',
57            params: {
58                step: '操作步骤:点击读卡按钮(接口中已有模拟卡片数据)',
59                result: '预期结果:显示读卡:success',
60                url: 'pages/nfc/index',
61                itemIndex: this.itemIndex
62            }
63        });
64    },
65
66    back() {
67        console.info('onclick back ');
68        router.replace({
69            uri: 'pages/second-api/index',
70            params: {
71                itemIndex: this.itemIndex
72            }
73        });
74    },
75
76    changeResult(result) {
77        getApp().data.keyList[this.title] = result;
78        this.back();
79    },
80};
81