This repository has been archived by the owner on May 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
171 lines (169 loc) · 5.57 KB
/
index.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!doctype html>
<html class="h-100">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="./static/bootstrap.min.css">
<link rel="stylesheet" href="./static/jquery-confirm.min.css">
<style>
.solution {
font-family: '黑体';
background-color: white;
font-size: 17px;
line-height: 17px;
}
</style>
<script src="./static/jquery-3.4.1.slim.min.js"></script>
<script src="./static/popper.min.js"></script>
<script src="./static/bootstrap.min.js"></script>
<script src="./static/jquery-confirm.min.js"></script>
<script src="./static/vue.min.js"></script>
<script src="./static/cutting-stock.js"></script>
<script src="./static/utils.js"></script>
<title>材料切割</title>
</head>
<body class="h-100" style="padding: 10px 0px;">
<div id="app" class="container-fluid h-100">
<div class="row h-100">
<div class="col-3 h-100 d-flex flex-column">
<div class="form-group was-validated">
<label for="material">材料长度</label>
<input type="number" class="form-control" required min="1" step="any" v-model.number="material">
</div>
<div class="form-group was-validated">
<label for="losses">切割损耗</label>
<input type="number" class="form-control" min="0" step="any" v-model.number="losses">
</div>
<div class="form-group was-validated">
<label for="orders">订单</label>
<div class="form-row">
<div class="col-5">
<input id="length" type="number" class="form-control" placeholder="尺寸" min="1" step="any" v-model.number="length" @keyup.enter="onAddOrder">
</div>
<div class="col-4">
<input type="number" class="form-control" placeholder="数量" required min="1" v-model.number="count" @keyup.enter="onAddOrder">
</div>
<div class="col-3">
<button class="btn btn-primary btn-block" @click="onAddOrder">添加</button>
</div>
</div>
</div>
<div class="form-group flex-grow-1 d-flex flex-column overflow-auto">
<ul class="list-group" id="orders">
<li class="list-group-item d-flex justify-content-between align-items-center" v-for="order in orders">
{{ order.length }} × {{ order.count }}
<button type="button" class="btn btn-danger" @click="onRemoveOrder(order.length)">删除</button>
</li>
</ul>
</div>
<button class="btn btn-primary btn-block" @click="onCompute">计算</button>
</div>
<div class="col h-100">
<textarea class="form-control h-100 solution" readonly v-model="solution"></textarea>
</div>
</div>
</div>
<script>
const app = new Vue({
el: '#app',
data: {
material: 600,
losses: 0.1,
length: null,
count: 1,
orders: [],
solution: ''
},
created() {
this.addOrder(100, 20)
this.addOrder(190, 20)
this.addOrder(300, 20)
},
watch: {
material: function(val) {
if (typeof(val) !== 'number' || val <= 0) {
this.material = null
}
},
losses: function(val) {
if (typeof(val) !== 'number' || val < 0) {
this.losses = null
}
if (val === this.material) {
error('切割损耗等于材料长度')
this.losses = null
}
if (val > this.material) {
error('切割损耗超出材料长度')
this.losses = null
}
},
length: function(val) {
if (typeof(val) !== 'number' || val <= 0) {
this.length = null
}
if (val > this.material) {
error('尺寸超出材料长度')
this.length = null
}
},
count: function(val) {
if (typeof(val) !== 'number' || val <= 0) {
this.count = null
}
}
},
methods: {
addOrder(length, count) {
if (typeof(length) !== 'number' || length <= 0
|| typeof(count) !== 'number' || count < 1
|| typeof(this.material) !== 'number' || length > this.material) {
return
}
list = this.orders.filter(o => o.length === length)
if (list.length > 0) {
list[0].count += count
} else {
this.orders.push({ length: length, count: count })
}
this.orders.sort((x, y) => x.length - y.length)
},
removeOrder(length) {
this.orders = this.orders.filter(order => order.length != length)
},
onAddOrder() {
this.addOrder(this.length, this.count)
this.length = null
this.count = 1
$('#length').focus()
},
onRemoveOrder(length) {
this.removeOrder(length)
},
onCompute() {
if (typeof(this.material) !== 'number' || this.material <= 0
|| this.losses < 0
|| this.material < this.losses) {
return
}
this.solution = cut_and_print(this.material, this.losses || 0, this.orders)
}
}
})
function error(s) {
$.confirm({
title: "错误",
content: s,
type: "red",
draggable: false,
buttons: {
close: {
text: "知道了",
action: function () { }
}
}
});
}
</script>
</body>
</html>