admin 管理员组文章数量: 887019
增强搜索:
import.htm
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CPU_import</title>
</head>
<body>
<h1 align="center">导入数据</h1>
<hr>
<p>
数据库路径:<br>
Linux: ~/.config/chrome/Default/databases/file__0/*<br>
Windows:
<div id="msg"></div>
<script>
var msg = document.getElementById('msg');
if (!window.openDatabase) {
msg.textContent = 'Databases are not supported by your browser !';
} else {
//创建一个数据库对象,4个参数分别是数据库名,版本号,数据库的描述,数据库大小
var db = openDatabase('CPU', '1.0', 'CPU parameters', 102400);
if (!db) {
msg.textContent = '数据库创建失败!';
} else {
msg.textContent = '数据库创建成功!';
//开启SQLite数据库事务,它用一个回调函数作为参数表明要执行的语句
db.transaction(function (tx) {
var sql = 'DROP TABLE IF EXISTS CPU';
tx.executeSql(sql, [],
function (tx, result) {
var p = document.createElement('p');
p.textContent = sql;
p.appendChild(document.createElement('br'));
p.appendChild(document.createTextNode('成功!'));
msg.appendChild(p);
},
function (tx, error) {
var p = document.createElement('p');
p.textContent = sql;
p.appendChild(document.createElement('br'));
p.appendChild(document.createTextNode('失败:' + error.message));
msg.appendChild(p);
}
);
})
db.transaction(function (tx) {
//创建数据库表和字段
var sql = 'CREATE TABLE CPU(id INTEGER PRIMARY KEY, path TEXT, model TEXT, architecture TEXT, release_date TEXT, lithography TEXT, core TEXT, thread TEXT, GPU TEXT, package TEXT, TDP TEXT)';
tx.executeSql(sql, [],
function (tx, result) {
var p = document.createElement('p');
p.textContent = sql;
p.appendChild(document.createElement('br'));
p.appendChild(document.createTextNode('成功!'));
msg.appendChild(p);
},
function (tx, error) {
var p = document.createElement('p');
p.textContent = sql;
p.appendChild(document.createElement('br'));
p.appendChild(document.createTextNode('失败:' + error.message));
msg.appendChild(p);
}
);
})
//批量插入数据
db.transaction(function (tx) {
sql = "INSERT INTO CPU(path, model, architecture, release_date, lithography, core, thread, GPU, package, TDP) VALUES \
('0/', 'CPU', '', '', '', '', '', '', '', ''),\
('0/0', 'intel', '', '', '', '', '', '', '', ''),\
('0/1', 'AMD', '', '', '', '', '', '', '', ''),\
('0/0/0', 'Celeron', '', '', '', '', '', '', '', ''),\
('0/0/1', 'Pentium', '', '', '', '', '', '', '', ''),\
('0/0/2', 'i3', '', '', '', '', '', '', '', ''),\
('0/0/3', 'i5', '', '', '', '', '', '', '', ''),\
('0/0/4', 'i7', '', '', '', '', '', '', '', ''),\
('0/0/5', 'i9', '', '', '', '', '', '', '', ''),\
('0/0/6', 'XEON', '', '', '', '', '', '', '', ''),\
('0/0/0/0', 'Celeron G530', 'Sandy Bridge', '2011', '32nm', '2', '2', 'HD Graphic', 'LGA1155', '65W'),\
('0/0/1/0', 'Pentium G620', 'Sandy Bridge', '2011', '32nm', '2', '2', 'HD Graphic', 'LGA1155', '65W'),\
('0/0/2/0', 'i3 530', 'Clarkdale', '2009', '32nm', '2', '4', 'HD Graphic', 'LGA1156', '73W'),\
('0/0/2/0', 'i3 2100', 'Sandy Bridge', '2011', '32nm', '2', '4', 'HD Graphic 2000', 'LGA1155', '65W'),\
('0/0/6/0', 'Xeon E3-1260L', 'Sandy Bridge', '2011', '32nm', '4', '8', 'HD Graphic 2000', 'LGA1156', '45W'),\
('0/1/0', 'Athlon', '', '', '', '', '', '', '', ''),\
('0/1/1', 'A4', '', '', '', '', '', '', '', ''),\
('0/1/2', 'A6', '', '', '', '', '', '', '', ''),\
('0/1/3', 'A8', '', '', '', '', '', '', '', ''),\
('0/1/4', 'A9', '', '', '', '', '', '', '', ''),\
('0/1/5', 'A10', '', '', '', '', '', '', '', ''),\
('0/1/6', 'A12', '', '', '', '', '', '', '', ''),\
('0/1/0/0', 'Athlon X4 740', 'Richland', '2012 Q4', '32nm', '4', '4', '', 'Socket FM2', '65W'),\
('0/1/0/0', 'Athlon 200GE', 'Zen', '2018/09/06', '14nm', '2', '4', 'Radeon Vega 3', 'AM4', '35W'),\
('0/1/0/1', 'Athlon 3000G', 'Zen', '2019/11', '14nm', '2', '4', 'Radeon Vega 3', 'AM4', '35W'),\
('0/1/1/0', 'A4 5300', 'Trinity', '2013/06/05', '32nm', '2', '2', 'Radeon HD7480D', 'Socket FM2', '65W'),\
('0/1/1/0', 'A4 6300', 'Richland', '2012 Q4', '32nm', '2', '2', 'Radeon HD8370D', 'Socket FM2', '65W'),\
('0/1/3/0', 'A8 7500', 'Kaveri', '2016 Q2', '32nm', '4', '4', 'Radeon R7', 'Socket FM2+', '65W')";
tx.executeSql(sql, [],
function (tx, result) {
var p = document.createElement('p');
p.textContent = sql;
p.appendChild(document.createElement('br'));
p.appendChild(document.createTextNode('成功!'));
msg.appendChild(p);
},
function (tx, error) {
var p = document.createElement('p');
p.textContent = sql;
p.appendChild(document.createElement('br'));
p.appendChild(document.createTextNode('失败:' + error.message));
msg.appendChild(p);
}
);
});
}
}
</script>
</body>
</html>
index.htm
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CPU</title>
<style>
h1 { text-align: center; }
a { text-decoration: none; padding: 5px; }
span { padding: 5px; }
table { margin: 0 auto; }
button { margin: 10px 5px; }
.class:focus { background-color: lightblue; }
#datatable { border-collapse: collapse; }
#datatable td, th { border: 1px solid black; padding: 5px; text-align: center; }
#datatable tr:hover { background: lightblue; }
</style>
</head>
<body>
<div id="msg"></div>
<h1>CPU</h1>
<div align="center"><input type="text" id="text" size=6> <button id="button_search">搜索</button> <button id="button_clear">清除</button></div>
<div id="nav1" align="center"></div>
<div id="nav2" align="center"></div>
<table id="datatable"></table>
<p align="center">参考:
<a href="https://www.ijrsoftware/cpu-l/" target="_blank">CPU-L</a>
<a href="https://www.mydrivers/zhuanti/tianti/cpu/index.html" target="_blank">桌面CPU性能天梯图</a>
<a href="https://wwwblogs/kissdodog/p/3297894.html" target="_blank">树形数据库设计</a>
<a href="https://www.intel/" target="_blank">intel</a>
<a href="https://www.amd/" target="_blank">AMD</a>
</p>
<p align="center">© Copyright 2022 版权所有 海天鹰出品 sonichy@163</p>
<script>
function $id(s) { return document.getElementById(s); }
var datatable = document.getElementById('datatable');
function tablehead() {
var tr = document.createElement('tr');
var th = document.createElement('th');
th.innerHTML = 'id';
tr.appendChild(th);
th = document.createElement('th');
th.innerHTML = 'path';
tr.appendChild(th);
th = document.createElement('th');
th.innerHTML = 'model';
tr.appendChild(th);
th = document.createElement('th');
th.innerHTML = 'architecture';
tr.appendChild(th);
th = document.createElement('th');
th.innerHTML = 'release_date';
tr.appendChild(th);
th = document.createElement('th');
th.innerHTML = 'lithography';
tr.appendChild(th);
th = document.createElement('th');
th.innerHTML = 'core';
tr.appendChild(th);
th = document.createElement('th');
tr.appendChild(th);
th.innerHTML = 'thread';
tr.appendChild(th);
th = document.createElement('th');
th.innerHTML = 'GPU';
tr.appendChild(th);
th = document.createElement('th');
th.innerHTML = 'package';
tr.appendChild(th);
th = document.createElement('th');
th.innerHTML = 'TDP';
tr.appendChild(th);
datatable.appendChild(tr);
}
//创建一个数据库对象,4个参数分别是数据库名,版本号,数据库的描述,数据库大小
var db = openDatabase('CPU', '', 'CPU parameters', 102400);
//构建指定数据库行的数据对应的HTML文本。传入参数:数据库结果集中的某一行记录
function showData(row, i) {
var tr = document.createElement('tr');
var td = document.createElement('td');
td.innerHTML = i + 1;
tr.appendChild(td);
td = document.createElement('td');
td.innerHTML = row.path;
tr.appendChild(td);
td = document.createElement('td');
td.innerHTML = row.model;
tr.appendChild(td);
td = document.createElement('td');
td.innerHTML = row.architecture;
tr.appendChild(td);
td = document.createElement('td');
td.innerHTML = row.release_date;
tr.appendChild(td);
td = document.createElement('td');
td.innerHTML = row.lithography;
tr.appendChild(td);
td = document.createElement('td');
td.innerHTML = row.core;
tr.appendChild(td);
td = document.createElement('td');
td.innerHTML = row.thread;
tr.appendChild(td);
td = document.createElement('td');
td.innerHTML = row.GPU;
tr.appendChild(td);
td = document.createElement('td');
td.innerHTML = row.package;
tr.appendChild(td);
td = document.createElement('td');
td.innerHTML = row.TDP;
tr.appendChild(td);
datatable.appendChild(tr);
}
//这个函数用于显示所有的行到表格中,这些行是从数据库中拿出来的
function showAllData(where, order) {
datatable.innerHTML = '';
//开启SQLite数据库事务,它用一个回调函数作为参数表明要执行的语句
if (order == '')
order = ' order by id';
db.transaction(function (tx) {
var sql = 'select * from CPU' + where + order;
console.log(sql);
tx.executeSql(sql, [],
function (tx, rs) {
tablehead();
//遍历结果集,对于每一行,依次调用showData来在table上创建对于的html文本
for (var i = 0; i < rs.rows.length; i++) {
//对于item(i),也就是某一行记录,我们显示其内容到页面的表格中(构建对应的HTML片断)
showData(rs.rows.item(i), i);
}
},
function (tx, error) {
var p = document.createElement('p');
p.textContent = sql;
p.appendChild(document.createElement('br'));
p.appendChild(document.createTextNode('失败:' + error.message));
msg.appendChild(p);
}
);
});
}
showAllData('', '');
function class1() {
db.transaction(function (tx) {
var sql = "select * from CPU where path like '0/_' order by model asc";
console.log(sql);
tx.executeSql(sql, [],
function (tx, rs) {
for (var i = 0; i < rs.rows.length; i++) {
var button = document.createElement('button');
button.className = "class1";
button.textContent = rs.rows.item(i).model;
button.value = rs.rows.item(i).path;
button.onclick = function () {
class2(this.value);
var class1 = document.getElementsByClassName("class1");
for (var j=0; j<class1.length; j++) {
class1[j].style.backgroundColor = "";
}
this.style.backgroundColor = "lightblue";
};
$id('nav1').appendChild(button);
}
},
function (tx, error) {
var p = document.createElement('p');
p.textContent = sql;
p.appendChild(document.createElement('br'));
p.appendChild(document.createTextNode('失败:' + error.message));
msg.appendChild(p);
}
);
})
}
class1();
function class2(path) {
datatable.innerHTML = '';
db.transaction(function (tx) {
var sql = "select * from CPU where path like '" + path + "/_'";
console.log(sql);
tx.executeSql(sql, [],
function (tx, rs) {
$id('nav2').innerHTML = '';
for (var i = 0; i < rs.rows.length; i++) {
var button = document.createElement('button');
button.className = "class2";
button.textContent = rs.rows.item(i).model;
button.value = rs.rows.item(i).path;
button.onclick = function () {
showAllData(' where path like "' + this.value + '/_"', '');
var class2 = document.getElementsByClassName("class2");
for (var j=0; j<class2.length; j++) {
class2[j].style.backgroundColor = "";
}
this.style.backgroundColor = "lightblue";
};
$id('nav2').appendChild(button);
}
});
})
}
function search(s) {
$id('nav2').innerHTML = "";
var text = $id('text').value;
var where = '';
if (text.indexOf('/') != -1) {
var core = text.substring(0, text.indexOf('/'));
var thread = text.substring(text.indexOf('/') + 1);
if (core == '')
where = " where thread='" + thread + "'";
else if (thread == '')
where = " where core='" + core + "'";
else
where = " where core='" + core + "' and thread='" + thread + "'";
} else {
where = " where model like '%" + text + "%' or core like '%" + text + "%' or thread like '%" + text + "%' or GPU like '%" + text + "%' or package like '%" + text + "%'";
}
showAllData(where, '');
}
$id('text').addEventListener('keydown', function (e) {
if (e.keyCode == 13) {
search($id('text').value);
}
});
$id('button_search').addEventListener('click', function () {
search($id('text').value);
});
$id('button_clear').addEventListener('click', function () {
$id('text').value = '';
search('');
});
</script>
</body>
</html>
版权声明:本文标题:JS数据库:CPU列表 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1725895784h888962.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论