ADD file via upload

master
m94fc2tgb 8 months ago
parent 4ac01f3f07
commit 962a600dc1

@ -0,0 +1,606 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>导入药品信息</title>
<link rel=" stylesheet" href="./Import-information.css">
</head>
<body>
<button id = "2" class="button2" onclick="daoc()">导入药品数据</button>
<h1></h1>
<div class="cookie-card">
<span class="title">温馨提示</span>
<p class="description">导入的药品数据格式如下:</p>
<p class="description">____________________________________________________________________________________________________</p>
<p class="description">"name","company","phonenumber","price","amount","purprice"</p>
<p class="description">"筋骨贴","吉及林","1234","17.6","19","14.6"</p>
<p class="description">"沈阳红贴膏","沈阳","83","23.8","20","18.5"</p>
<p class="description">____________________________________________________________________________________________________</p>
<p class="description">注意药品数据将被导入数据库中与csv文件名相同的表中,第一行为本列数据的属性。导入过程中第一行不会被导入数据库中。</p>
</div>
<h1></h1>
<div id="in" style="display: none;">
<input type="file" name="file" id="filePicker" onchange="show()" />
<br>
<h1></h1>
<textarea id="story" name="story" rows="15" cols="60">
</textarea>
<h1></h1>
<div>
<button id = "1" class="button2" onclick="pri()">确认导入以上csv数据</button>
</div>
</div>
</body>
<script>
if (document.getElementById("story").value == ' '){
document.getElementById("story").value = '';
}
function show()
{
var reader = new FileReader();
var f = document.getElementById("filePicker").files[0];
reader.readAsText(f);
reader.onload = function()
{
//alert(this.result)
story.value=this.result
}
}
function pri()
{
var text = document.getElementById("story").value;
var biao = document.getElementById("filePicker").files[0].name.replace(".csv",'');
console.log(biao);
if (document.getElementById("story").value != ''){
if (biao == '主页面'){
const lines = text.trim().split(/\r?\n/);
lines.shift();
const processedLines = lines.map(line => {
line = line.replace(/^"|"$/g, '');
const fields = [];
let currentField = '';
let inQuote = false;
for (let i = 0; i < line.length; i++) {
const char = line[i];
if (char === '"') {
inQuote = !inQuote;
} else if (!inQuote && char === ',') {
fields.push(currentField.trim());
currentField = '';
} else {
currentField += char;
}
if (i === line.length - 1 && !inQuote) {
fields.push(currentField.trim());
}
}
return fields.join(' ').concat('\n');
});
const jsonArray = [];
processedLines.forEach(line => {
const fields = line.trim().split(',').map(field => field.trim());
const jsonObject = {
id: parseInt(fields[0]),
type: fields[1],
name: fields[2],
price: parseFloat(fields[3]), // 转换为浮点数
amount: parseInt(fields[4], 10) // 转换为整数并指定基数为10
};
jsonArray.push(jsonObject);
});
const requestBody = {"wenti":1001,"table":biao,"shuju":jsonArray};
console.log(requestBody);
fetch('http://localhost:3000', {
method: 'POST',
headers: {
'Content-Type': 'application/json' // 设置请求头为JSON
},
body: JSON.stringify(requestBody) // 将请求体转换为JSON字符串
})
.then(response =>
response.json())
.then(data => {
console.log(data);
}) // 打印服务器返回的数据
.catch(error => console.error('Error:', error)
);
}
if (biao == '骨科用药'){
const lines = text.trim().split(/\r?\n/);
lines.shift();
const processedLines = lines.map(line => {
line = line.replace(/^"|"$/g, '');
const fields = [];
let currentField = '';
let inQuote = false;
for (let i = 0; i < line.length; i++) {
const char = line[i];
if (char === '"') {
inQuote = !inQuote;
} else if (!inQuote && char === ',') {
fields.push(currentField.trim());
currentField = '';
} else {
currentField += char;
}
if (i === line.length - 1 && !inQuote) {
fields.push(currentField.trim());
}
}
return fields.join(' ').concat('\n');
});
const jsonArray = [];
processedLines.forEach(line => {
const fields = line.trim().split(',').map(field => field.trim());
const jsonObject = {
name: fields[0],
company: fields[1],
phonenumber: fields[2],
price: parseFloat(fields[3]), // 转换为浮点数
amount: parseInt(fields[4], 10), // 转换为整数并指定基数为10
purprice: parseFloat(fields[5])
};
jsonArray.push(jsonObject);
});
const requestBody = {"wenti":1001,"table":biao,"shuju":jsonArray};
console.log(requestBody);
fetch('http://localhost:3000', {
method: 'POST',
headers: {
'Content-Type': 'application/json' // 设置请求头为JSON
},
body: JSON.stringify(requestBody) // 将请求体转换为JSON字符串
})
.then(response =>
response.json())
.then(data => {
console.log(data);
}) // 打印服务器返回的数据
.catch(error => console.error('Error:', error)
);
}
if (biao == '眼科用药'){
const lines = text.trim().split(/\r?\n/);
lines.shift();
const processedLines = lines.map(line => {
line = line.replace(/^"|"$/g, '');
const fields = [];
let currentField = '';
let inQuote = false;
for (let i = 0; i < line.length; i++) {
const char = line[i];
if (char === '"') {
inQuote = !inQuote;
} else if (!inQuote && char === ',') {
fields.push(currentField.trim());
currentField = '';
} else {
currentField += char;
}
if (i === line.length - 1 && !inQuote) {
fields.push(currentField.trim());
}
}
return fields.join(' ').concat('\n');
});
const jsonArray = [];
processedLines.forEach(line => {
const fields = line.trim().split(',').map(field => field.trim());
const jsonObject = {
name: fields[0],
company: fields[1],
phonenumber: fields[2],
price: parseFloat(fields[3]), // 转换为浮点数
amount: parseInt(fields[4], 10), // 转换为整数并指定基数为10
purprice: parseFloat(fields[5])
};
jsonArray.push(jsonObject);
});
const requestBody = {"wenti":1001,"table":biao,"shuju":jsonArray};
console.log(requestBody);
fetch('http://localhost:3000', {
method: 'POST',
headers: {
'Content-Type': 'application/json' // 设置请求头为JSON
},
body: JSON.stringify(requestBody) // 将请求体转换为JSON字符串
})
.then(response =>
response.json())
.then(data => {
console.log(data);
}) // 打印服务器返回的数据
.catch(error => console.error('Error:', error)
);
}
if (biao == '皮肤科用药'){
const lines = text.trim().split(/\r?\n/);
lines.shift();
const processedLines = lines.map(line => {
line = line.replace(/^"|"$/g, '');
const fields = [];
let currentField = '';
let inQuote = false;
for (let i = 0; i < line.length; i++) {
const char = line[i];
if (char === '"') {
inQuote = !inQuote;
} else if (!inQuote && char === ',') {
fields.push(currentField.trim());
currentField = '';
} else {
currentField += char;
}
if (i === line.length - 1 && !inQuote) {
fields.push(currentField.trim());
}
}
return fields.join(' ').concat('\n');
});
const jsonArray = [];
processedLines.forEach(line => {
const fields = line.trim().split(',').map(field => field.trim());
const jsonObject = {
name: fields[0],
company: fields[1],
phonenumber: fields[2],
price: parseFloat(fields[3]), // 转换为浮点数
amount: parseInt(fields[4], 10), // 转换为整数并指定基数为10
purprice: parseFloat(fields[5])
};
jsonArray.push(jsonObject);
});
const requestBody = {"wenti":1001,"table":biao,"shuju":jsonArray};
fetch('http://localhost:3000', {
method: 'POST',
headers: {
'Content-Type': 'application/json' // 设置请求头为JSON
},
body: JSON.stringify(requestBody) // 将请求体转换为JSON字符串
})
.then(response =>
response.json())
.then(data => {
console.log(data);
}) // 打印服务器返回的数据
.catch(error => console.error('Error:', error)
);
}
if (biao == '消化系统药'){
const lines = text.trim().split(/\r?\n/);
lines.shift();
const processedLines = lines.map(line => {
line = line.replace(/^"|"$/g, '');
const fields = [];
let currentField = '';
let inQuote = false;
for (let i = 0; i < line.length; i++) {
const char = line[i];
if (char === '"') {
inQuote = !inQuote;
} else if (!inQuote && char === ',') {
fields.push(currentField.trim());
currentField = '';
} else {
currentField += char;
}
if (i === line.length - 1 && !inQuote) {
fields.push(currentField.trim());
}
}
return fields.join(' ').concat('\n');
});
const jsonArray = [];
processedLines.forEach(line => {
const fields = line.trim().split(',').map(field => field.trim());
const jsonObject = {
name: fields[0],
company: fields[1],
phonenumber: fields[2],
price: parseFloat(fields[3]), // 转换为浮点数
amount: parseInt(fields[4], 10), // 转换为整数并指定基数为10
purprice: parseFloat(fields[5])
};
jsonArray.push(jsonObject);
});
const requestBody = {"wenti":1001,"table":biao,"shuju":jsonArray};
fetch('http://localhost:3000', {
method: 'POST',
headers: {
'Content-Type': 'application/json' // 设置请求头为JSON
},
body: JSON.stringify(requestBody) // 将请求体转换为JSON字符串
})
.then(response =>
response.json())
.then(data => {
console.log(data);
}) // 打印服务器返回的数据
.catch(error => console.error('Error:', error)
);
}
if (biao == '心血管系统药'){
const lines = text.trim().split(/\r?\n/);
lines.shift();
const processedLines = lines.map(line => {
line = line.replace(/^"|"$/g, '');
const fields = [];
let currentField = '';
let inQuote = false;
for (let i = 0; i < line.length; i++) {
const char = line[i];
if (char === '"') {
inQuote = !inQuote;
} else if (!inQuote && char === ',') {
fields.push(currentField.trim());
currentField = '';
} else {
currentField += char;
}
if (i === line.length - 1 && !inQuote) {
fields.push(currentField.trim());
}
}
return fields.join(' ').concat('\n');
});
const jsonArray = [];
processedLines.forEach(line => {
const fields = line.trim().split(',').map(field => field.trim());
const jsonObject = {
name: fields[0],
company: fields[1],
phonenumber: fields[2],
price: parseFloat(fields[3]), // 转换为浮点数
amount: parseInt(fields[4], 10), // 转换为整数并指定基数为10
purprice: parseFloat(fields[5])
};
jsonArray.push(jsonObject);
});
const requestBody = {"wenti":1001,"table":biao,"shuju":jsonArray};
fetch('http://localhost:3000', {
method: 'POST',
headers: {
'Content-Type': 'application/json' // 设置请求头为JSON
},
body: JSON.stringify(requestBody) // 将请求体转换为JSON字符串
})
.then(response =>
response.json())
.then(data => {
console.log(data);
}) // 打印服务器返回的数据
.catch(error => console.error('Error:', error)
);
}
if (biao == '呼吸系统药'){
const lines = text.trim().split(/\r?\n/);
lines.shift();
const processedLines = lines.map(line => {
line = line.replace(/^"|"$/g, '');
const fields = [];
let currentField = '';
let inQuote = false;
for (let i = 0; i < line.length; i++) {
const char = line[i];
if (char === '"') {
inQuote = !inQuote;
} else if (!inQuote && char === ',') {
fields.push(currentField.trim());
currentField = '';
} else {
currentField += char;
}
if (i === line.length - 1 && !inQuote) {
fields.push(currentField.trim());
}
}
return fields.join(' ').concat('\n');
});
const jsonArray = [];
processedLines.forEach(line => {
const fields = line.trim().split(',').map(field => field.trim());
const jsonObject = {
name: fields[0],
company: fields[1],
phonenumber: fields[2],
price: parseFloat(fields[3]), // 转换为浮点数
amount: parseInt(fields[4], 10), // 转换为整数并指定基数为10
purprice: parseFloat(fields[5])
};
jsonArray.push(jsonObject);
});
const requestBody = {"wenti":1001,"table":biao,"shuju":jsonArray};
fetch('http://localhost:3000', {
method: 'POST',
headers: {
'Content-Type': 'application/json' // 设置请求头为JSON
},
body: JSON.stringify(requestBody) // 将请求体转换为JSON字符串
})
.then(response =>
response.json())
.then(data => {
console.log(data);
}) // 打印服务器返回的数据
.catch(error => console.error('Error:', error)
);
}
if (biao == '进库药品统计'){
const lines = text.trim().split(/\r?\n/);
lines.shift();
const processedLines = lines.map(line => {
line = line.replace(/^"|"$/g, '');
const fields = [];
let currentField = '';
let inQuote = false;
for (let i = 0; i < line.length; i++) {
const char = line[i];
if (char === '"') {
inQuote = !inQuote;
} else if (!inQuote && char === ',') {
fields.push(currentField.trim());
currentField = '';
} else {
currentField += char;
}
if (i === line.length - 1 && !inQuote) {
fields.push(currentField.trim());
}
}
return fields.join(' ').concat('\n');
});
const jsonArray = [];
processedLines.forEach(line => {
const fields = line.trim().split(',').map(field => field.trim());
const jsonObject = {
name: fields[0],
company: fields[1],
phonenumber: fields[2],
amount: parseInt(fields[3], 10),// 转换为整数并指定基数为10
price: parseFloat(fields[4]), // 转换为浮点数
purprice: parseFloat(fields[5]),
time:fields[6]
};
jsonArray.push(jsonObject);
});
const requestBody = {"wenti":1001,"table":biao,"shuju":jsonArray};
fetch('http://localhost:3000', {
method: 'POST',
headers: {
'Content-Type': 'application/json' // 设置请求头为JSON
},
body: JSON.stringify(requestBody) // 将请求体转换为JSON字符串
})
.then(response =>
response.json())
.then(data => {
console.log(data);
}) // 打印服务器返回的数据
.catch(error => console.error('Error:', error)
);
}
if (biao == '出库药品统计'){
const lines = text.trim().split(/\r?\n/);
lines.shift();
const processedLines = lines.map(line => {
line = line.replace(/^"|"$/g, '');
const fields = [];
let currentField = '';
let inQuote = false;
for (let i = 0; i < line.length; i++) {
const char = line[i];
if (char === '"') {
inQuote = !inQuote;
} else if (!inQuote && char === ',') {
fields.push(currentField.trim());
currentField = '';
} else {
currentField += char;
}
if (i === line.length - 1 && !inQuote) {
fields.push(currentField.trim());
}
}
return fields.join(' ').concat('\n');
});
const jsonArray = [];
processedLines.forEach(line => {
const fields = line.trim().split(',').map(field => field.trim());
const jsonObject = {
name: fields[0],
company: fields[1],
phonenumber: fields[2],
amount: parseInt(fields[3], 10),// 转换为整数并指定基数为10
price: parseFloat(fields[4]), // 转换为浮点数
purprice: parseFloat(fields[5]),
time:fields[6]
};
jsonArray.push(jsonObject);
});
const requestBody = {"wenti":1001,"table":biao,"shuju":jsonArray};
fetch('http://localhost:3000', {
method: 'POST',
headers: {
'Content-Type': 'application/json' // 设置请求头为JSON
},
body: JSON.stringify(requestBody) // 将请求体转换为JSON字符串
})
.then(response =>
response.json())
.then(data => {
console.log(data);
}) // 打印服务器返回的数据
.catch(error => console.error('Error:', error)
);
console.log(requestBody);
}
}
else{
alert('请选择要导入的csv文件');
}
}
function daoc(){
var yincang = document.getElementById("in").style.display;
if (yincang == "none"){
document.getElementById("in").style.display="block";
}
else if (yincang == "block"){
document.getElementById("in").style.display="none";
}
}
</script>
</html>
Loading…
Cancel
Save