Browse Source

fix 修复部分bug,优化代码

YueYunyun 1 month ago
parent
commit
bc8640c874

+ 2 - 3
SourceCode/DataMiddleware/app/stores/mysql_store.py

@@ -290,12 +290,11 @@ class MysqlStore:
     def update_project_data(self, project_item: ProjectItemModel) -> bool:
         query = "SElECT standard_no FROM project_item WHERE id = %s"
         params = (project_item.id,)
-        u_query = "UPDATE project_item SET device_unit= %s,device_count= %s,standard_no = %s,update_time = %s WHERE id = %s"
-        u_params = (project_item.device_unit, project_item.device_count, project_item.standard_no, datetime.now(), project_item.id)
+        u_query = "UPDATE project_item SET device_name= %s,device_model= %s,device_unit= %s,device_count= %s,standard_no = %s,update_time = %s WHERE id = %s"
+        u_params = (project_item.device_name, project_item.device_model,project_item.device_unit, project_item.device_count, project_item.standard_no, datetime.now(), project_item.id)
         with self._db_helper:
             result = self._db_helper.fetch_one(query, params)
             if result:
-
                 self._db_helper.execute_non_query(u_query, u_params)
                 self.insert_or_update_standard_data(
                     StandardModel(device_name=project_item.device_name,

+ 4 - 0
SourceCode/DataMiddleware/app/ui/project_services.py

@@ -128,6 +128,10 @@ class SourceDataService:
     def update_project_item(self, item:ProjectItemModel):
         project_item = self._store.query_project_item_by_id(item.id)
         if project_item:
+            project_item.device_name = item.device_name
+            project_item.device_model = item.device_model
+            project_item.device_unit = item.device_unit
+            project_item.device_count = item.device_count
             project_item.standard_no = item.standard_no
             self._store.update_project_data(project_item)
             #TODO 更新标准数据库

+ 6 - 1
SourceCode/DataMiddleware/app/ui/project_views.py

@@ -149,6 +149,7 @@ def add_project_item():
     device_name = data.get('device_name')
     device_model = data.get('device_model')
     device_unit = data.get('device_unit')
+    device_count = data.get('device_count')
     standard_no = data.get('standard_no')
     new_item = ProjectItemModel(project_id=project_id, device_name=device_name, device_model=device_model, device_unit=device_unit, standard_no=standard_no)
     item_id = SourceDataService.add_project_item(new_item)
@@ -160,10 +161,14 @@ def update_data_item():
     item_id = data.get('id')
     if not item_id:
         return jsonify({'success': False, 'error': 'ID 不能为空'}), 400
+    device_name = data.get('device_name')
+    device_model = data.get('device_model')
+    device_unit = data.get('device_unit')
+    device_count = data.get('device_count')
     standard_no = data.get('standard_no')
     # if not standard_no:
     #     return jsonify({'success': False, 'error': 'Standard No is missing'}), 400
-    item = ProjectItemModel(item_id=int(item_id), standard_no=standard_no)
+    item =ProjectItemModel(item_id=item_id,project_id=project_id, device_name=device_name, device_model=device_model, device_unit=device_unit, standard_no=standard_no)
     SourceDataService.update_project_item(item)
     return jsonify({'success': True})
 

+ 118 - 116
SourceCode/DataMiddleware/app/ui/static/project_item_list.js

@@ -1,11 +1,11 @@
 function addNewItem(project_id) {
-    const table = document.querySelector('table.table tbody');
-    const rows = table.querySelectorAll('tr.edit-mode');
-    rows.forEach(row => row.classList.remove('edit-mode'));
+	const table = document.querySelector('table.table tbody')
+	const rows = table.querySelectorAll('tr.edit-mode')
+	rows.forEach((row) => row.classList.remove('edit-mode'))
 
-    const newRow = document.createElement('tr');
-    newRow.classList.add('edit-mode');
-    newRow.innerHTML = `
+	const newRow = document.createElement('tr')
+	newRow.classList.add('edit-mode')
+	newRow.innerHTML = `
         <td class="editable name"><span class="edit"><input type="text" class="form-control" placeholder="名称"> </span></td>
         <td class="editable model"><span class="edit"><input type="text" class="form-control" placeholder="规格型号"> </span></td>
         <td class="editable count"><span class="edit"><input type="text" class="form-control" placeholder="数量"> </span></td>
@@ -19,123 +19,125 @@ function addNewItem(project_id) {
                 <button class="btn btn-warning" onclick="cancelNewChanges(this.parentNode.parentNode.parentNode)">取消</button>
             </span>
         </td>
-    `;
-    table.insertBefore(newRow, table.firstChild);
+    `
+	table.insertBefore(newRow, table.firstChild)
 }
 
-function saveItemCreate(row,project_id) {
-    const deviceName = row.querySelector('td.name input').value;
-    const deviceModel = row.querySelector('td.model input').value;
-    const deviceUnit = row.querySelector('td.unit input').value;
-    const deviceCount = row.querySelector('td.count input').value;
-    const standardNo = row.querySelector('td.standard_no input').value;
-    if (deviceName === '') {
-        alert('名称不能为空');
-        return;
-    }
-    if (deviceModel === '') {
-        alert('规格型号不能为空');
-        return;
-    }
-    if (deviceCount === '') {
-        alert('数量不能为空');
-        return;
-    }
-    if (deviceUnit === '') {
-        alert('单位不能为空');
-        return;
-    }
-    // if (standardNo === '') {
-    //     alert('标准编号不能为空');
-    //     return;
-    // }
+function saveItemCreate(row, project_id) {
+	const deviceName = row.querySelector('td.name input').value
+	const deviceModel = row.querySelector('td.model input').value
+	const deviceUnit = row.querySelector('td.unit input').value
+	const deviceCount = row.querySelector('td.count input').value
+	const standardNo = row.querySelector('td.standard_no input').value
+	if (deviceName === '') {
+		alert('名称不能为空')
+		return
+	}
+	if (deviceModel === '') {
+		alert('规格型号不能为空')
+		return
+	}
+	if (deviceCount === '') {
+		alert('数量不能为空')
+		return
+	}
+	if (deviceUnit === '') {
+		alert('单位不能为空')
+		return
+	}
+	// if (standardNo === '') {
+	//     alert('标准编号不能为空');
+	//     return;
+	// }
 
-    fetch(`/add_project_item`, {
-        method: 'POST',
-        headers: {
-            'Content-Type': 'application/json'
-        },
-        body: JSON.stringify({project_id:project_id,device_name: deviceName, device_model: deviceModel, device_unit: deviceUnit,device_count: deviceCount, standard_no: standardNo })
-    }).then(response => response.json())
-        .then(data => {
-            if (data.success) {
-                alert('添加成功');
-                window.location.href = `/project_item_list/${project_id}`;
-            } else {
-                alert('添加失败:'+data.error);
-            }
-        })
-        .catch(error => {
-            console.error('添加失败:', error);
-            alert('添加失败');
-        });
+	fetch(`/add_project_item`, {
+		method: 'POST',
+		headers: {
+			'Content-Type': 'application/json',
+		},
+		body: JSON.stringify({ project_id: project_id, device_name: deviceName, device_model: deviceModel, device_unit: deviceUnit, device_count: deviceCount, standard_no: standardNo }),
+	})
+		.then((response) => response.json())
+		.then((data) => {
+			if (data.success) {
+				alert('添加成功')
+				window.location.href = `/project_item_list/${project_id}`
+			} else {
+				alert('添加失败:' + data.error)
+			}
+		})
+		.catch((error) => {
+			console.error('添加失败:', error)
+			alert('添加失败')
+		})
 }
 
 function saveItemEdit(row, itemId) {
-    const standardNo = row.querySelector('.standard_no input').value;
-    const deviceUnit = row.querySelector('.unit input').value;
-    const deviceCount = row.querySelector('.count input').value;
-    // if (standardNo === '') {
-    //     alert('标准编号不能为空');
-    //     return;
-    // }
-    if (deviceCount === '') {
-        alert('数量不能为空');
-        return;
-    }
-    if (deviceUnit === '') {
-        alert('单位不能为空');
-        return;
-    }
-    fetch(`/update_data_item`, {
-        method: 'POST',
-        headers: {
-            'Content-Type': 'application/json'
-        },
-        body: JSON.stringify({id: itemId, standard_no: standardNo, device_count: deviceCount,device_unit:deviceUnit })
-    }).then(response => response.json())
-        .then(data => {
-            if (data.success) {
-                alert('保存成功');
-                row.classList.remove('edit-mode');
-                row.querySelector('.standard_no .show').textContent = standardNo;
-                // window.location.reload();
-            } else {
-                alert('保存失败:'+data.error);
-            }
-        })
-        .catch(error => {
-            console.error('保存失败:', error);
-            alert('保存失败');
-        });
+	const deviceName = row.querySelector('td.name input').value
+	const deviceModel = row.querySelector('td.model input').value
+	const standardNo = row.querySelector('.standard_no input').value
+	const deviceUnit = row.querySelector('.unit input').value
+	const deviceCount = row.querySelector('.count input').value
+	// if (standardNo === '') {
+	//     alert('标准编号不能为空');
+	//     return;
+	// }
+	if (deviceCount === '') {
+		alert('数量不能为空')
+		return
+	}
+	if (deviceUnit === '') {
+		alert('单位不能为空')
+		return
+	}
+	fetch(`/update_data_item`, {
+		method: 'POST',
+		headers: {
+			'Content-Type': 'application/json',
+		},
+		body: JSON.stringify({ id: itemId, device_name: deviceName, device_model: deviceModel, standard_no: standardNo, device_count: deviceCount, device_unit: deviceUnit }),
+	})
+		.then((response) => response.json())
+		.then((data) => {
+			if (data.success) {
+				alert('保存成功')
+				row.classList.remove('edit-mode')
+				row.querySelector('.standard_no .show').textContent = standardNo
+				// window.location.reload();
+			} else {
+				alert('保存失败:' + data.error)
+			}
+		})
+		.catch((error) => {
+			console.error('保存失败:', error)
+			alert('保存失败')
+		})
 }
 
-
 function confirmItemDelete(itemId) {
-    if (confirm('确定要删除该设备吗?')) {
-        fetch(`/delete_project_item/${itemId}`, {
-            method: 'POST',
-            headers: {
-                'Content-Type': 'application/json'
-            }
-        })
-        .then(response => response.json())
-        .then(data => {
-            if (data.success) {
-                alert('删除成功');
-                // 删除对应的行
-                const row = document.querySelector(`tr[data-id="${itemId}"]`);
-                if (row) {
-                    row.remove();
-                }
-            } else {
-                alert('删除失败:'+data.error);
-            }
-        })
-        .catch(error => {
-            console.error('删除失败:', error);
-            alert('删除失败');
-        });
-    }
+	if (confirm('确定要删除该设备吗?')) {
+		fetch(`/delete_project_item/${itemId}`, {
+			method: 'POST',
+			headers: {
+				'Content-Type': 'application/json',
+			},
+		})
+			.then((response) => response.json())
+			.then((data) => {
+				if (data.success) {
+					alert('删除成功')
+					// 删除对应的行
+					const row = document.querySelector(`tr[data-id="${itemId}"]`)
+					if (row) {
+						row.remove()
+					}
+				} else {
+					alert('删除失败:' + data.error)
+				}
+			})
+			.catch((error) => {
+				console.error('删除失败:', error)
+				alert('删除失败')
+			})
+	}
 }
-

+ 44 - 31
SourceCode/DataMiddleware/app/ui/static/project_list.js

@@ -4,13 +4,9 @@ function addProject() {
 	inputs.forEach((input) => {
 		input.value = ''
 	})
-	// 移除已存在的delete_old_data复选框
-	const existingCheckbox = document.getElementById('delete_old_data')
-	if (existingCheckbox) {
-		existingCheckbox.parentNode.remove()
-	}
-	document.getElementById('new_project_file').parentNode.innerHTML = `<label for="new_project_file">项目数据:</label><input type="file" id="new_project_file" class="form-control" accept=".xlsx,.xls,.csv" multiple>`
-	document.getElementById('new_standard_version').value ='2'
+	const file = document.getElementById('new_project_file').parentNode
+	file.innerHTML = `<label for="new_project_file">项目数据:</label><input type="file" id="new_project_file" class="form-control" accept=".xlsx,.xls,.csv" multiple>`
+
 	editBox.classList.add('show')
 }
 
@@ -26,7 +22,7 @@ function updateProject(row, id) {
 		existingCheckbox.parentNode.remove()
 	}
 	const checkboxDiv = document.createElement('div')
-	checkboxDiv.innerHTML = `<label for="delete_old_data">删除原数据:</label><input type="checkbox" id="delete_old_data" class="form-control" style="width: auto;flex: 0;">`
+	checkboxDiv.innerHTML = `<label for="delete_old_data">删除原数据:</label><input type="checkbox" id="delete_old_data" class="form-control" style="width: auto;">`
 	file.parentNode.insertBefore(checkboxDiv, file.nextSibling)
 	document.getElementById('new_work_catalog').value = row.querySelector('.work_catalog .form-control').value
 	document.getElementById('new_work_content').value = row.querySelector('.work_content .form-control').value
@@ -74,10 +70,7 @@ function saveProject() {
 	formData.append('work_catalog', catalog)
 	formData.append('work_content', content)
 	formData.append('standard_version', version)
-	const delete_old_data =	document.getElementById('delete_old_data')
-	if (delete_old_data) {
-		formData.append('delete_old_data', delete_old_data.checked)
-	}
+	formData.append('delete_old_data', document.getElementById('delete_old_data').checked)
 
 	fetch('/save_project', {
 		method: 'POST',
@@ -149,32 +142,51 @@ function saveProjectUpdate(row, id) {
 		})
 }
 
-function confirmStartTask(id) {
-	if (confirm('确定要开始执行任务吗?')) {
-		_process_task('start_project_task',id)
+function confirmCollectData(id) {
+	if (confirm('确定要开始采集数据吗?')) {
+		fetch(`/collect_project/${id}`, {
+			method: 'POST',
+			headers: {
+				'Content-Type': 'application/json',
+			},
+		})
+			.then((response) => response.json())
+			.then((data) => {
+				if (data.success) {
+					alert('操作成功')
+					window.location.reload()
+				} else {
+					alert('采集失败:' + data.error)
+				}
+			})
+			.catch((error) => {})
 	}
 }
 
-function confirmReStartTask(id) {
-	if (confirm('确定要重新采集数据吗?')) {
-		_process_task('start_project_task',id)
+function confirmProcessData(id) {
+	if (confirm('确定要开始分析处理数据吗?')) {
+		fetch(`/process_project/${id}`, {
+			method: 'POST',
+			headers: {
+				'Content-Type': 'application/json',
+			},
+		})
+			.then((response) => response.json())
+			.then((data) => {
+				if (data.success) {
+					alert('操作成功')
+					window.location.reload()
+				} else {
+					alert('分析处理失败:' + data.error)
+				}
+			})
+			.catch((error) => {})
 	}
 }
 
-function confirmReProcessData(id) {
-	if (confirm('确定要重新处理数据吗?')) {
-		_process_task('process_project',id)
-
-	}
-}
 function confirmSendData(id) {
 	if (confirm('确定要开始上传数据吗?')) {
-		_process_task('send_project',id)
-	}
-}
-
-function _process_task(url,id){
-	fetch(`/${url}/${id}`, {
+		fetch(`/send_project/${id}`, {
 			method: 'POST',
 			headers: {
 				'Content-Type': 'application/json',
@@ -186,10 +198,11 @@ function _process_task(url,id){
 					alert('操作成功')
 					window.location.reload()
 				} else {
-					alert('操作失败:' + data.error)
+					alert('分析处理失败:' + data.error)
 				}
 			})
 			.catch((error) => {})
+	}
 }
 
 function confirmProjectDelete(id) {

+ 16 - 4
SourceCode/DataMiddleware/app/ui/static/styles.css

@@ -97,6 +97,16 @@ h6 {
 	border: 1px solid #ddd;
 	border-radius: 4px;
 }
+.box_header .box_title {
+	font-size: 18px;
+	font-weight: bolder;
+	color: #333;
+	margin-left: 20px;
+}
+.box_header .separator {
+	margin: 0 20px;
+}
+
 .box_header dl {
 	display: flex;
 	align-items: center;
@@ -110,7 +120,9 @@ h6 {
 	margin-left: 10px;
 	color: #555;
 }
-
+.search-box .form-select {
+	width: 100px;
+}
 .box_body {
 	margin-top: 10px;
 }
@@ -161,7 +173,7 @@ td.editable .edit {
 
 .pagination .page {
 	height: 40px;
-	min-width: 20px;
+	min-width: 40px;
 	padding: 0 10px;
 	display: flex;
 	align-items: center;
@@ -204,7 +216,7 @@ td.editable .edit {
 }
 .edit-box.show {
 	display: block;
-	margin-top: -15px ;
+	margin-top: -15px;
 }
 
 .edit-box .form-group {
@@ -213,7 +225,7 @@ td.editable .edit {
 	gap: 15px;
 	padding: 15px;
 	width: 60%;
-    margin: 0 auto;
+	margin: 0 auto;
 }
 
 .edit-box .form-group > div {

+ 158 - 164
SourceCode/DataMiddleware/app/ui/templates/project/project_item_list.html

@@ -1,167 +1,161 @@
 <!DOCTYPE html>
 <html lang="en">
-<head>
-    <meta charset="UTF-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>设备列表</title>
-    <link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
-    <style>
-        .box_header .project_info{
-            display: flex;
-            justify-content: left;
-            width: 60%;
-        }
+	<head>
+		<meta charset="UTF-8" />
+		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
+		<title>设备列表</title>
+		<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}" />
+		<style>
+			.box_header .project_info {
+				display: flex;
+				justify-content: left;
+				align-items: center;
+				width: 60%;
+			}
+		</style>
+		<script src="{{ url_for('static', filename='utils.js') }}"></script>
+		<script src="{{ url_for('static', filename='project_item_list.js') }}"></script>
+		<script>
+			function searchData() {
+				var keyword = document.getElementById('search_input').value
+				window.location.href = `{{ url_for('project.project_item_list', project_id=project.id) }}?k=` + keyword
+			}
+			function reSearchData() {
+				window.location.href = `{{ url_for('project.project_item_list', project_id=project.id) }}`
+			}
+		</script>
+	</head>
+	<body>
+		<div class="box">
+			<div class="box_header">
+				<div class="project_info">
+					<button class="btn btn-info btn-large" onclick="goTo(`{{ url_for('project.project_list') }}`)">返回</button>
+					<h3 class="box_title">设备列表</h3>
+					<span class="separator">|</span>
+					<dl>
+						<dt>项目编号:</dt>
+						<dd>{{ project.project_no }}</dd>
+					</dl>
+					<dl>
+						<dt>项目名称:</dt>
+						<dd>{{ project.project_name }}</dd>
+					</dl>
+					<dl>
+						<dt>标准版本:</dt>
+						<dd>
+							{% if project.standard_version == '1' %}
+							<span class="label label-warning">旧版</span>
+							{% elif project.standard_version == '2' %}
+							<span class="label label-info">新版</span>
+							{% endif %}
+						</dd>
+					</dl>
+				</div>
+			</div>
+			<div class="box_header">
+				<div class="btn_box">
+					<button class="btn btn-success btn-large" onclick="addNewItem('{{ project.id}}')">添加</button>
+				</div>
+				<div class="search_box">
+					<input type="text" id="search_input" class="form-control" placeholder="请输入查询关键字" value="{{ keyword }}" />
+					<button type="button" class="btn btn-info btn-large" onclick="searchData()">查询</button>
+					<button type="button" class="btn btn-warning btn-large" onclick="reSearchData()">重置</button>
+				</div>
+			</div>
 
-    </style>
-    <script src="{{ url_for('static', filename='utils.js') }}"></script>
-    <script src="{{ url_for('static', filename='project_item_list.js') }}"></script>
-    <script>
-         function searchData(){
-            var keyword = document.getElementById('search_input').value;
-            window.location.href = '{{ url_for('project.project_item_list', project_id=project.id) }}?k=' + keyword;
-        }
-        function reSearchData(){
-            window.location.href = '{{ url_for('project.project_item_list', project_id=project.id) }}';
-        }
-    </script>
-</head>
-<body>
-<div class="box">
-    <div class="box_header">
-        <div class="project_info">
-            <button class="btn btn-info btn-large" onclick="goTo('{{ url_for('project.project_list') }}')">返回</button>
-            <h3 style="margin-left:20px">设备列表</h3>
-            <span style="margin:0 20px">|</span>
-            <dl>
-                <dt>项目编号:</dt>
-                <dd>{{ project.project_no }}</dd>
-            </dl>
-            <dl>
-                <dt>项目名称:</dt>
-                <dd>{{ project.project_name }}</dd>
-            </dl>
-            <dl>
-                <dt>标准版本:</dt>
-                <dd>
-                    {% if project.standard_version == '1' %}
-                    <span class="label label-warning">旧版</span>
-                    {% elif project.standard_version == '2' %}
-                    <span class="label label-info">新版</span>
-                    {% endif %}
-                </dd>
-            </dl>
-        </div>
-    </div>
-    <div class="box_header">
-        <div class="btn_box">
-            <button class="btn btn-success btn-large" onclick="addNewItem('{{ project.id}}')">添加</button>
-        </div>
-        <div class="search_box">
-            <input type="text" id="search_input" class="form-control" placeholder="请输入查询关键字" value="{{ keyword }}">
-            <button type="button" class="btn btn-info btn-large" onclick="searchData()">查询</button>
-            <button type="button" class="btn btn-warning btn-large" onclick="reSearchData()">重置</button>
-        </div>
-    </div>
-
-    <div class="box_body">
-        <table class="table">
-            <thead>
-                <tr>
-                    <th width="25%">名称</th>
-                    <th>规格型号</th>
-                    <th width="200px">数量</th>
-                    <th width="8%">单位</th>
-                    <th width="15%">定额编号</th>
-                    <th width="180px">操作</th>
-                </tr>
-            </thead>
-            <tbody>
-                {% if project_items %}
-                    {% for item in project_items %}
-                        <tr>
-                            <td class="name">{{ item.device_name }}</td>
-                            <td class="model">{{ item.device_model }}</td>
-                            <td class="editable count">
-                                <span class="show">{{ item.device_count if item.device_count else '-' }}</span>
-                                <span class="edit">
-                                    <input type="text" class="form-control" value="{{ item.device_count if item.device_count else '' }}">
-                                </span>
-                            </td>
-                            <td class="editable unit">
-                                <span class="show">{{ item.device_unit if item.device_unit else '-' }}</span>
-                                <span class="edit">
-                                    <input type="text" class="form-control" value="{{ item.device_unit if item.device_unit else '' }}">
-                                </span>
-                            </td>
-                            <td class="editable standard_no">
-                                <span class="show">{{ item.standard_no if item.standard_no else '-' }}</span>
-                                <span class="edit">
-                                    <input type="text" class="form-control" value="{{ item.standard_no if item.standard_no else '' }}">
-                                </span>
-                            </td>
-                            <td class="editable tool">
-                                <span class="show">
-                                    <button class="btn btn-info" onclick="toggleEditMode(this.parentNode.parentNode.parentNode)">编辑</button>
-                                    <button class="btn btn-danger" onclick="confirmItemDelete('{{ item.id }}')">删除</button>
-                                </span>
-                                <span class="edit">
-                                    <button class="btn btn-success" onclick="saveItemEdit(this.parentNode.parentNode.parentNode, '{{ item.id }}')">保存</button>
-                                    <button class="btn btn-warning" onclick="cancelChanges(this.parentNode.parentNode.parentNode)">取消</button>
-                                </span>
-                            </td>
-                        </tr>
-                    {% endfor %}
-                {% else %}
-                    <tr>
-                        <td colspan="15">没有找到设备数据</td>
-                    </tr>
-                {% endif %}
-            </tbody>
-        </table>
-        <div class="pagination">
-            <div class="pagination-info">
-                {% set total_pages = (total_count|int + per_page|int - 1)//per_page %}
-               <span class="page">
-                    总共 {{ total_count }} 条数据,每页 {{ per_page }} 条,当前第 {{ page }} 页 / 共 {{ total_pages }} 页
-               </span>
-            </div>
-            <div class="pagination-links">
-                {% if page > 1 %}
-                    <a class="page page-link" href="{{ url_for('project.project_item_list', project_id=project.id, k=keyword, p=1, pp=per_page) }}">首页</a>
-                {% endif %}
-                {% if page > 1 %}
-                    <a class="page page-link" href="{{ url_for('project.project_item_list', project_id=project.id, k=keyword, p=page-1, pp=per_page) }}">上一页</a>
-                {% endif %}
-                {% set start_page = [1, page - 2]|max %}
-                {% set end_page = [total_pages, page + 2]|min %}
-                {% if start_page > 1 %}
-                    <a class="page page-link" href="{{ url_for('project.project_item_list', project_id=project.id, k=keyword, p=1, pp=per_page) }}">1</a>
-                    {% if start_page > 2 %}
-                        <span class="page">...</span>
-                    {% endif %}
-                {% endif %}
-                {% for p in range(start_page, end_page + 1) %}
-                    {% if p == page %}
-                    <a class="page page-link active" href="{{ url_for('project.project_item_list', project_id=project.id, k=keyword, p=p, pp=per_page) }}" >{{ p }}</a>
-                    {% else %}
-                    <a class="page page-link" href="{{ url_for('project.project_item_list', project_id=project.id, k=keyword, p=p, pp=per_page) }}" >{{ p }}</a>
-                    {% endif %}
-                {% endfor %}
-                {% if end_page < total_pages %}
-                    {% if end_page < total_pages - 1 %}
-                        <span class="page">...</span>
-                    {% endif %}
-                    <a class="page page-link" href="{{ url_for('project.project_item_list', project_id=project.id, k=keyword, p=total_pages, pp=per_page) }}">{{ total_pages }}</a>
-                {% endif %}
-                {% if page < total_pages %}
-                    <a class="page page-link" href="{{ url_for('project.project_item_list', project_id=project.id, k=keyword, p=page+1, pp=per_page) }}">下一页</a>
-                {% endif %}
-                {% if page < total_pages %}
-                    <a class="page page-link" href="{{ url_for('project.project_item_list', project_id=project.id, k=keyword, p=total_pages, pp=per_page) }}">末页</a>
-                {% endif %}
-            </div>
-        </div>
-    </div>
-</div>
-</body>
-</html>
+			<div class="box_body">
+				<table class="table">
+					<thead>
+						<tr>
+							<th width="25%">名称</th>
+							<th>规格型号</th>
+							<th width="200px">数量</th>
+							<th width="8%">单位</th>
+							<th width="15%">定额编号</th>
+							<th width="180px">操作</th>
+						</tr>
+					</thead>
+					<tbody>
+						{% if project_items %} {% for item in project_items %}
+						<tr>
+							<td class="editable name">
+								<span class="show">{{ item.device_name if item.device_name else '-' }}</span>
+								<span class="edit">
+									<input type="text" class="form-control" title="设备名称" value="{{ item.device_name if item.device_name else '' }}" />
+								</span>
+							</td>
+							<td class="editable model">
+								<span class="show">{{ item.device_model if item.device_model else '-' }}</span>
+								<span class="edit">
+									<input type="text" class="form-control" title="设备规格型号" value="{{ item.device_model if item.device_model else '' }}" />
+								</span>
+							</td>
+							<td class="editable count">
+								<span class="show">{{ item.device_count if item.device_count else '-' }}</span>
+								<span class="edit">
+									<input type="text" class="form-control" title="设备数量" value="{{ item.device_count if item.device_count else '' }}" />
+								</span>
+							</td>
+							<td class="editable unit">
+								<span class="show">{{ item.device_unit if item.device_unit else '-' }}</span>
+								<span class="edit">
+									<input type="text" class="form-control" title="设备单位" value="{{ item.device_unit if item.device_unit else '' }}" />
+								</span>
+							</td>
+							<td class="editable standard_no">
+								<span class="show">{{ item.standard_no if item.standard_no else '-' }}</span>
+								<span class="edit">
+									<input type="text" class="form-control" title="设备定额编号" value="{{ item.standard_no if item.standard_no else '' }}" />
+								</span>
+							</td>
+							<td class="editable tool">
+								<span class="show">
+									<button class="btn btn-info" onclick="toggleEditMode(this.parentNode.parentNode.parentNode)">编辑</button>
+									<button class="btn btn-danger" onclick="confirmItemDelete('{{ item.id }}')">删除</button>
+								</span>
+								<span class="edit">
+									<button class="btn btn-success" onclick="saveItemEdit(this.parentNode.parentNode.parentNode, '{{ item.id }}')">保存</button>
+									<button class="btn btn-warning" onclick="cancelChanges(this.parentNode.parentNode.parentNode)">取消</button>
+								</span>
+							</td>
+						</tr>
+						{% endfor %} {% else %}
+						<tr>
+							<td colspan="15">没有找到设备数据</td>
+						</tr>
+						{% endif %}
+					</tbody>
+				</table>
+				<div class="pagination">
+					<div class="pagination-info">
+						{% set total_pages = (total_count|int + per_page|int - 1)//per_page %}
+						<span class="page"> 总共 {{ total_count }} 条数据,每页 {{ per_page }} 条,当前第 {{ page }} 页 / 共 {{ total_pages }} 页 </span>
+					</div>
+					<div class="pagination-links">
+						{% if page > 1 %}
+						<a class="page page-link" href="{{ url_for('project.project_item_list', project_id=project.id, k=keyword, p=1, pp=per_page) }}">首页</a>
+						{% endif %} {% if page > 1 %}
+						<a class="page page-link" href="{{ url_for('project.project_item_list', project_id=project.id, k=keyword, p=page-1, pp=per_page) }}">上一页</a>
+						{% endif %} {% set start_page = [1, page - 2]|max %} {% set end_page = [total_pages, page + 2]|min %} {% if start_page > 1 %}
+						<a class="page page-link" href="{{ url_for('project.project_item_list', project_id=project.id, k=keyword, p=1, pp=per_page) }}">1</a>
+						{% if start_page > 2 %}
+						<span class="page">...</span>
+						{% endif %} {% endif %} {% for p in range(start_page, end_page + 1) %} {% if p == page %}
+						<a class="page page-link active" href="{{ url_for('project.project_item_list', project_id=project.id, k=keyword, p=p, pp=per_page) }}">{{ p }}</a>
+						{% else %}
+						<a class="page page-link" href="{{ url_for('project.project_item_list', project_id=project.id, k=keyword, p=p, pp=per_page) }}">{{ p }}</a>
+						{% endif %} {% endfor %} {% if end_page < total_pages %} {% if end_page < total_pages - 1 %}
+						<span class="page">...</span>
+						{% endif %}
+						<a class="page page-link" href="{{ url_for('project.project_item_list', project_id=project.id, k=keyword, p=total_pages, pp=per_page) }}">{{ total_pages }}</a>
+						{% endif %} {% if page < total_pages %}
+						<a class="page page-link" href="{{ url_for('project.project_item_list', project_id=project.id, k=keyword, p=page+1, pp=per_page) }}">下一页</a>
+						{% endif %} {% if page < total_pages %}
+						<a class="page page-link" href="{{ url_for('project.project_item_list', project_id=project.id, k=keyword, p=total_pages, pp=per_page) }}">末页</a>
+						{% endif %}
+					</div>
+				</div>
+			</div>
+		</div>
+	</body>
+</html>

+ 10 - 10
SourceCode/DataMiddleware/app/ui/templates/project/project_list.html

@@ -11,24 +11,24 @@
         function searchData(){
             var keyword = document.getElementById('search_input').value;
             var status = document.getElementById('status_select').value;
-            window.location.href = '{{ url_for('project.project_list') }}?k=' + keyword + '&s=' + status;
+            window.location.href = `{{ url_for('project.project_list') }}?k=${keyword}&s=${status}`;
         }
         function reSearchData(){
-            window.location.href = '{{ url_for('project.project_list') }}';
+            window.location.href = `{{ url_for('project.project_list') }}`;
         }
     </script>
 </head>
 <body>
     <div class="box">
         <div class="box_header">
-            <div><h3>项目列表</h3></div>
+            <div><h3 class="box_title">项目列表</h3></div>
         </div>
         <div class="box_header">
             <div class="btn_box">
                 <button type="button" class="btn btn-success btn-large" onclick="addProject()">添加</button>
             </div>
             <div class="search_box">
-                <select id="status_select" class="form-control" style="width: 100px;">
+                <select id="status_select" class="form-control form-select" title="状态选择">
                     <option value="-1" {% if status == -1 %}selected{% endif %}>所有状态</option>
                     <option value="0" {% if status == 0 %}selected{% endif %}>新建</option>
                     <option value="5" {% if status == 5 %}selected{% endif %}>完成</option>
@@ -104,25 +104,25 @@
                             <td class="editable project_no">
                                 <span class="show">{{ project.project_no if project.project_no else '-' }}</span>
                                 <span class="edit">
-                                    <input type="text" class="form-control" value="{{ project.project_no if project.project_no else '' }}">
+                                    <input type="text" class="form-control" title="项目编号" name="project_no" value="{{ project.project_no if project.project_no else '' }}">
                                 </span>
                             </td>
                             <td class="editable project_name">
                                 <span class="show">{{ project.project_name if project.project_name else '-' }}</span>
                                 <span class="edit">
-                                    <input type="text" class="form-control" value="{{ project.project_name if project.project_name else '' }}">
+                                    <input type="text" class="form-control" title="项目名称" name="project_name" value="{{ project.project_name if project.project_name else '' }}">
                                 </span>
                             </td>
                             <td class="editable work_catalog">
                                 <span class="show">{{ project.work_catalog if project.work_catalog else '-' }}</span>
                                 <span class="edit">
-                                    <input type="text" class="form-control" value="{{ project.work_catalog if project.work_catalog else '' }}">
+                                    <input type="text" class="form-control" title="工作目录" name="work_catalogvalue="{{ project.work_catalog if project.work_catalog else '' }}">
                                 </span>
                             </td>
                             <td class="editable work_content">
                                 <span class="show">{{ project.work_content if project.work_content else '-' }}</span>
                                 <span class="edit">
-                                    <input type="text" class="form-control" value="{{ project.work_content if project.work_content else '' }}">
+                                    <input type="text" class="form-control" title="工作内容" value="{{ project.work_content if project.work_content else '' }}">
                                 </span>
                             </td>
                             <td class="editable standard_version">
@@ -134,7 +134,7 @@
                                     {% endif %}
                                 </span>
                                 <span class="edit">
-                                    <select class="form-control" >
+                                    <select class="form-control" title="标准版本">
                                         <option value="1" {% if project.standard_version == '1' %}selected{% endif %}>旧版</option>
                                         <option value="2" {% if project.standard_version == '2' %}selected{% endif %}>新版</option>
                                     </select>
@@ -180,7 +180,7 @@
                                     {% elif project.status == 13 %}
                                     <button class="btn btn-success" type="button" onclick="confirmSendData('{{ project.id }}')">重新发送</button>
                                     {% elif project.status == 5 or project.status == 32 or project.status == 13 or project.status == 23 or project.status == 33 %}
-                                    <button class="btn btn-info" type="button" onclick="goTo('{{ url_for('project.project_item_list', project_id=project.id) }}')">详情</button>
+                                    <button class="btn btn-info" type="button" onclick="goTo(`{{ url_for('project.project_item_list', project_id=project.id) }}`)">详情</button>
                                     {% endif %}
                                     {% if project.status != 21  and project.status != 22 %}
                                     <button class="btn btn-danger" onclick="confirmProjectDelete('{{ project.id }}')">删除</button>