-
Notifications
You must be signed in to change notification settings - Fork 18
/
demo.html
91 lines (83 loc) · 2.88 KB
/
demo.html
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<html ng-app="app">
<head>
<title>Bematech printer: Hello world</title>
<link rel="stylesheet" href="assets/vendor/bootstrap/bootstrap.css">
<link rel="stylesheet" href="assets/vendor/font-awesome/css/font-awesome.min.css">
<script src="assets/vendor/socket.io/socket.io.js"></script>
<script src="assets/vendor/angular/angular.js"></script>
</head>
<body ng-controller="appController">
<div class="container" style="margin-top: 30px;">
<div class="row">
<div class="col-md-6">
<button class="btn btn-success btn-lg" ng-click="connect()" ng-disabled="socket && socket.connected">
Conectar com impressora
</button>
</div>
<div class="col-md-6">
<button class="btn btn-success btn-lg" ng-click="disconnect()" ng-disabled="!socket || !socket.disconnected">
Desconectar
</button>
</div>
</div>
<br>
<br>
<br>
<label for="">Contéudo dinâmico</label>
<input type="text" class="form-control" ng-model="helloMessage" />
<br>
<br>
<div class="row">
<div class="col-md-6">
<button class="btn btn-success btn-lg" ng-click="print({ layout: 'teste'})" ng-disabled="!socket && !socket.disconnected">
Imprimir modelo de impressão
</button>
</div>
<div class="col-md-6">
<button class="btn btn-success btn-lg" ng-click="print({ layout: 'hello'})" ng-disabled="!socket && !socket.disconnected">
Imprimir modelo dinâmico
</button>
</div>
</div>
</div>
<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
<script>
let controller = ($scope, $filter, $timeout, $window) => {
$scope.socket = { };
$scope.helloMessage = 'Olá mundo'
$scope.appAddress = 'http://localhost:7333'
$scope.printer = {
ip: '1.1.1.51',
port: 9000
};
$scope.connect = () => {
if(!$scope.socket.connected) {
$scope.socket = io($scope.appAddress);
$scope.socket.on('socket:connected', () => {
alert('conectado a impressora')
})
// Adiciona evento de erro
$scope.socket.on('print:error', (data) => {
console.log('erro', data.type);
console.log('descrição', data.description);
});
}
};
$scope.disconnect = () => {
$scope.socket = {};
};
$scope.print = (params) => {
$scope.socket.emit('print', {
layout: params.layout,
copies: 1,
printer: $scope.printer,
data: {
hello: $scope.helloMessage
}
});
};
};
angular.module('app', []).controller('appController', controller);
</script>
</body>
</html>