fix bugs on start and stop windows service

This commit is contained in:
r0n1n7an 2024-07-17 16:08:39 +08:00
parent d352576581
commit d60e82b5f7
4 changed files with 223 additions and 8 deletions

Binary file not shown.

View File

@ -47,7 +47,7 @@ func init() {
logger = log.New(&lumberjack.Logger{
Filename: strings.TrimSuffix(os.Args[0], ".exe") + ".log",
MaxAge: 30,
MaxAge: 90,
MaxSize: 10,
MaxBackups: 100,
LocalTime: true,
@ -135,8 +135,8 @@ func main() {
logger.Printf("[ERR] Stop Service Failed: %s\r\n", err.Error())
os.Exit(1)
}
log.Printf("[MSG] Service Stop.\r\n")
logger.Printf("[MSG] Service Stop.\r\n")
log.Printf("[MSG] Service Stopped.\r\n")
logger.Printf("[MSG] Service Stopped.\r\n")
return
}
@ -148,8 +148,8 @@ func main() {
logger.Printf("[ERR] Stop Service Failed: %s\r\n", err.Error())
os.Exit(1)
}
log.Printf("[MSG] Service Stop.\r\n")
logger.Printf("[MSG] Service Stop.\r\n")
log.Printf("[MSG] Service Stopped.\r\n")
logger.Printf("[MSG] Service Stopped.\r\n")
time.Sleep(time.Second * 1)
err = winsvc.StartService(svc)
@ -170,8 +170,9 @@ func main() {
logger.Printf("[ERR] Run As Service Failed: %s\r\n", err.Error())
os.Exit(1)
}
log.Printf("[MSG] Run As Service ...\r\n")
logger.Printf("[MSG] Run As Service ...\r\n")
// log.Printf("[MSG] Run As Service ...\r\n")
// logger.Printf("[MSG] Run As Service ...\r\n")
return
}
}
@ -194,7 +195,7 @@ func startSvc() {
func stopSvc() {
log.Printf("[MSG] Stopping Service ...\r\n")
logger.Printf("[MSG] Stopping Service ...\r\n")
os.Exit(0)
// os.Exit(0)
}
func handleIndex(w http.ResponseWriter, r *http.Request) {

156
EditableTable.html Normal file
View File

@ -0,0 +1,156 @@
<!DOCTYPE html>
<html>
<head>
<title>可编辑表格示例</title>
<style>
table {
border-collapse: collapse;
}
th, td {
border: 1px solid black;
padding: 5px;
}
td[contenteditable="true"] {
background-color: lightyellow;
}
.delete-button {
background-color: red;
color: white;
border: none;
padding: 5px;
cursor: pointer;
}
.delete-button:focus {
outline: none;
}
#save-button, #add-row-button {
margin-top: 10px;
}
</style>
</head>
<body>
<table id="editable-table">
<thead>
<tr>
<th>姓名</th>
<th>年龄</th>
<th>城市</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr>
<td contenteditable="true">John</td>
<td contenteditable="true">25</td>
<td contenteditable="true">New York</td>
<td><button class="delete-button" onclick="deleteRow(this)">删除</button></td>
</tr>
<tr>
<td contenteditable="true">Jane</td>
<td contenteditable="true">30</td>
<td contenteditable="true">London</td>
<td><button class="delete-button" onclick="deleteRow(this)">删除</button></td>
</tr>
</tbody>
</table>
<button id="add-row-button">新增行</button>
<button id="save-button">保存</button>
<script>
const saveButton = document.getElementById('save-button');
const addRowButton = document.getElementById('add-row-button');
const table = document.getElementById('editable-table');
saveButton.addEventListener('click', () => {
const data = collectDataFromTable();
// 将数据传送到服务器端进行进一步处理或保存
sendDataToServer(data);
});
addRowButton.addEventListener('click', () => {
const row = document.createElement('tr');
const nameCell = createEditableCell();
const ageCell = createEditableCell();
const cityCell = createCityCell();
row.appendChild(nameCell);
row.appendChild(ageCell);
row.appendChild(cityCell);
const deleteCell = document.createElement('td');
const deleteButton = document.createElement('button');
deleteButton.className = 'delete-button';
deleteButton.textContent = '删除';
deleteButton.addEventListener('click', () => {
deleteRow(deleteButton);
});
deleteCell.appendChild(deleteButton);
row.appendChild(deleteCell);
table.appendChild(row);
});
function collectDataFromTable() {
const data = [];
const rows = table.getElementsByTagName('tr');
for (let i = 1; i < rows.length; i++) {
const row = rows[i];
const name = row.cells[0].innerText;
const age = row.cells[1].innerText;
const city = row.cells[2].querySelector('select').value;
data.push({ name, age, city });
}
return data;
}
function sendDataToServer(data) {
// 在这里使用 AJAX 或 Fetch API 等发送数据到服务器
// 例如:使用 Fetch API 发送 POST 请求
fetch('/10.60.230.109/save-data', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(result => {
console.log('数据已成功保存至服务器');
})
.catch(error => {
console.error('保存数据时出现错误:', error);
});
}
function createEditableCell() {
const cell = document.createElement('td');
cell.contentEditable = true;
return cell;
}
function createCityCell() {
const cell = document.createElement('td');
const select = document.createElement('select');
const cities = ['New York', 'London', 'Tokyo', 'Paris'];
cities.forEach(city => {
const option = document.createElement('option');
option.textContent = city;
select.appendChild(option);
});
cell.appendChild(select);
return cell;
}
function deleteRow(button) {
const row = button.closest('tr');
row.parentNode.removeChild(row);
}
</script>
</body>
</html>

58
EditableTable1.html Normal file
View File

@ -0,0 +1,58 @@
<!DOCTYPE html>
<html>
<head>
<title>Tables</title>
<style>
table {
border-collapse: collapse;
}
td, th {
border: 1px solid grey;
padding: 5px;
}
td[contenteditable="true"] {
background-color: lightgrey;
}
</style>
</head>
<body leftmargin="10px" >
<h4>Model Maintainance</h4>
<form name="tableUpdate" action="/tables/" method="POST" target="result">
<table>
<thead>
<tr>
<th>Model</th>
<th>Project Code</th>
<th>Remark</th>
</tr>
</thead>
<tbody>
<tr>
<td contenteditable="true">John</td>
<td contenteditable="true">25</td>
<td contenteditable="true">
<select>
<option>New York</option>
<option>London</option>
<option>Tokyo</option>
<option>Paris</option>
</select>
</td>
</tr>
<tr>
<td contenteditable="true">Jane</td>
<td contenteditable="true">30</td>
<td contenteditable="true">
<select>
<option>New York</option>
<option>London</option>
<option>Tokyo</option>
<option>Paris</option>
</select>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>