zrg
34 分钟以前 196e1b3cf2017cfa25038f9c8ef5071e046f0abf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import Vue from 'vue'
import { ConnectedDevice, Lifecycle } from '@psdk/frame-father';
import { CPCL, GenericCPCL } from '@psdk/cpcl';
import { GenericTSPL, TSPL } from '@psdk/tspl';
import { ESC, GenericESC } from '@psdk/esc';
 
class Printer {
    private _connectedDevice ?: ConnectedDevice;
    private _cpcl ?: GenericCPCL;
    private _tspl ?: GenericTSPL;
    private _esc ?: GenericESC;
    init(connectedDevice : ConnectedDevice) {
        this._connectedDevice = connectedDevice;
        const lifecycle = new Lifecycle(connectedDevice);
        this._cpcl = CPCL.generic(lifecycle);
        this._tspl = TSPL.generic(lifecycle);
        this._esc = ESC.generic(lifecycle);
    }
 
    isConnected() : boolean {
        return this._connectedDevice != null;
    }
 
    connectedDevice() : ConnectedDevice | undefined {
        return this._connectedDevice;
    }
 
 
    cpcl() : GenericCPCL {
        if (!this._connectedDevice)
            throw Error('The device is not connected');
        return this._cpcl!;
    }
    tspl() : GenericTSPL {
        if (!this._connectedDevice)
            throw Error('The device is not connected');
        return this._tspl!;
    }
    esc() : GenericESC {
        if (!this._connectedDevice)
            throw Error('The device is not connected');
        return this._esc!;
    }
}
 
export default {
    install: function () {
        Vue.prototype.$printer = new Printer();
    }
}