bpi-code-conventer/ele/resistance.html

378 lines
15 KiB
HTML
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="cn"><!-- InstanceBegin template="/Templates/product-template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>BPI编码转换工具</title>
<!-- InstanceEndEditable -->
<meta name="theme-color" content="#03a9f4">
<meta name="description" content="BPI官方网站 Banana Pi DIY 电脑开发板包括 BPI-M1, 四核的BPI-M2+ , 八核的BPI-M3 单板电脑, BPI-R1 路由器等.">
<meta name="keywords"
content="香蕉派, 开发板BPI-M2U, Banana Pi, BPI, development board, DIY, banana pi m3, banana pi m2, banana pi m64, banana pi m1, bpi-m3, bpi-m2, bpi-m1, android, nas" />
<!-- CSS -->
<link href="../style/css/materialize.css" type="text/css" rel="stylesheet" media="screen,projection" />
<link href="../style/css/style.css" type="text/css" rel="stylesheet" media="screen,projection" />
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
<link rel="shortcut icon" type="image/ico" href="../images/logos/bpilogo.ico" />
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>
<body class="white">
<!-- start of the header and drawer-------------------------------------------------------------------------------------------->
<!-- BREAK -->
<div class="navbar-fixed">
<nav class="white" role="navigation">
<div class="nav-wrapper">
<a id="logo-container" href="../index.html" style="margin-left:15px;" class="brand-logo black-text"><img
style="max-height:55px; margin-top:10px;" src="../images/logos/logo-home.png"></a>
<ul class="right hide-on-med-and-down">
<li><a class="dropdown-button waves-effect waves-light black-text" href="ic.html">
<hnav>电子料</hnav>
</a></li>
<li><a class="dropdown-button waves-effect waves-light black-text" href="#!">
<hnav>塑料类</hnav>
</a></li>
<!-- <li><a class="waves-effect waves-light black-text" href="blog.html"><hnav>博客</hnav></a></li> -->
<li><a class="waves-effect waves-light black-text" href="download.html">
<hnav>机构杂料类</hnav>
</a></li>
<li><a class="dropdown-button waves-effect waves-light black-text" href="shop.html">
<hnav>BPI产品</hnav>
</a></li>
</div>
</nav>
</div>
<!-- end of header and drawer------------------------------------------------------------------------------------------------->
<!-- the start of the main content--------------------------------------------------------------------------------------------->
<!-- main download area--------------------------------------------------------------------------------------------->
<div>
<nav style="box-shadow:none;" onLoad="myFunction3()">
<div class="nav-wrapper" style="background-color:#FFF;">
<ul id="nav-mobile" class="left hide-on-med-and-down" style="height:50px;">
<li><a id="ic" href="ic.html">IC类</a></li>
<li><a id="resistance" href="resistance.html">电阻</a></li>
<li><a id="capacitance" href="capacitance.html">电容</a></li>
<li><a id="diode" href="diode.html">二极管</a></li>
<li><a id="triode" href="triode.html">三极管</a></li>
<li><a id="mos" href="mos.html">场效应管MOS管</a></li>
<li><a id="inductance" href="inductance.html">电感类</a></li>
<li><a id="oscillator" href="oscillator.html">晶振类</a></li>
<li><a id="electroacoustic" href="electroacoustic.html">电声器件</a></li>
<li><a id="lcd" href="lcd.html">LCD类</a></li>
<li><a id="led" href="led.html">(背)光源</a></li>
<li><a id="motor" href="motor.html">电机/马达类</a></li>
<li><a id="ant" href="ant.html">待用(天线)</a></li>
<li><a id="camera" href="camera.html">摄像头</a></li>
<li><a id="fuse" href="fuse.html">保险丝</a></li>
<li><a id="pcb" href="pcb.html">PCB板类</a></li>
<li><a id="zebra" href="zebra.html">斑马纸</a></li>
<li><a id="key" href="key.html">按键/开关类</a></li>
<li><a id="socket" href="socket.html">插座/接插件类</a></li>
<li><a id="cable" href="cable.html">连接线</a></li>
<li><a id="power" href="power.html">电源类</a></li>
<li><a id="card" href="card.html">电脑软件/存储卡类</a></li>
</ul>
</div>
</nav>
</div>
<!-- InstanceBeginEditable name="overview" -->
<br><br><br>
<div class="navbar-fixed">
<div>
<div class="caption center-align">
<h4 class="light text-lighten-3">电阻物料编码生成</h4>
</div>
</div>
</div>
<div class="box">
<div class="card-container">
<div class="card">
<label for="typeSelect" class="label1">&nbsp;&nbsp;选择电阻类型:</label>
<select id="typeSelect" class="browser-default">
<option value="choose">点这里选择电阻类型</option>
<option value="general-re">普通电阻</option>
<option value="metal-re">金属膜电阻</option>
<option value="temp-re">热敏电阻</option>
<option value="lignt-re">光敏电阻</option>
<option value="other-re">其他类IC</option>
</select>
</div>
<div class="card">
<label for="valueInput" class="label1">&nbsp;&nbsp;阻值:</label>
<div class="col">
<input type="text" id="valueInput" class="form-control" placeholder="&nbsp;&nbsp;电阻阻值支持单位k,m,g及小于1的阻值"
onkeydown="handleKeyDown(event)">
</div>
</div>
<div class="card">
<label for="printSelect" class="label1">&nbsp;&nbsp;选择封装类型:</label>
<select id="printSelect" class="browser-default">
<option value="chooseprint">&nbsp;&nbsp;点这里选择封装类型</option>
<option value="dip-re">直插</option>
<option value="smd-re">贴片</option>
</select>
</div>
<div class="card">
<label for="serialSelect" class="label1">&nbsp;&nbsp;选择封装:</label>
<select id="serialSelect" class="browser-default">
<option value="chooseserial">&nbsp;&nbsp;点这里选择封装</option>
<option value="0201">0201</option>
<option value="0402">0402</option>
<option value="0603">0603</option>
<option value="0805">0805</option>
<option value="1206">1206</option>
<option value="1210">1210</option>
<option value="1812">1812</option>
<option value="2010">2010</option>
<option value="2512">2512</option>
</select>
</div>
<div class="card">
<label for="precisionSelect" class="label1">&nbsp;&nbsp;选择精度:</label>
<select id="precisionSelect" class="browser-default">
<option value="chooseprecision">&nbsp;&nbsp;点这里选择精度</option>
<option value="precision1">±1%</option>
<option value="precision5">±5%</option>
<option value="precision01">±0.1%</option>
</select>
</div>
</div>
<br>
<div class="form-group">
<center><button onclick="convertValue()" class="btn btn-primary">转换</button></center>
</div>
<br><br>
<div class="card">
<div class="form-group">
<p id="output" class="error-output">转换结果将在这里显示</p>
</div>
</div>
</div>
<!-- InstanceEndEditable -->
<!-- the end of the main content----------------------------------------------------------------------------------------------->
<!-- start of footer area-------------------------------------------------------------------------------------------------------------->
<!-- Scripts-->
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="style/js/materialize.js"></script>
<script src="style/js/init.js"></script>
<script>
$(document).ready(function () {
$("#resistance").addClass("light-blue white-text bold");
});
function convertValue() {
const typeSelect = document.getElementById("typeSelect");//电阻类型选择
const valueInput = document.getElementById("valueInput");//阻值选择
const printSelect = document.getElementById("printSelect");//直插贴片选择
const serialSelect = document.getElementById("serialSelect");//封装选择
const precisionSelect = document.getElementById("precisionSelect");//精度选择
const outputElement = document.getElementById("output");//输出
const valueType = typeSelect.value;//电阻类型
let inputValue = valueInput.value;//阻值类型
const printType = printSelect.value;//直插贴片类型
const serialType = serialSelect.value;//封装类型
const precisionType = precisionSelect.value;//精度类型
const errors = [];
try {
if (valueType === "choose") {
errors.push("请选择电阻类型");
}
if (valueType === "chooseprint") {
errors.push("请选择封装类型");
}
if (valueType === "chooseprecision") {
errors.push("请选择精度");
}
if (valueType === "chooseserial") {
errors.push("请选择封装");
}
//1%
if (precisionType == "precision1" && (serialType == "0201")) {
serialValue = "00";
} else if (precisionType == "precision1" && (serialType == "0402")) {
serialValue = "01";
} else if (precisionType == "precision1" && (serialType == "0603")) {
serialValue = "02";
} else if (precisionType == "precision1" && (serialType == "0805")) {
serialValue = "03";
} else if (precisionType == "precision1" && (serialType == "1206")) {
serialValue = "04";
} else if (precisionType == "precision1" && (serialType == "1210")) {
serialValue = "05";
} else if (precisionType == "precision1" && (serialType == "1812")) {
serialValue = "06";
} else if (precisionType == "precision1" && (serialType == "2010")) {
serialValue = "07";
} else if (precisionType == "precision1" && (serialType == "2512")) {
serialValue = "08";
}
//1%
if (precisionType == "precision5" && (serialType == "0201")) {
serialValue = "10";
} else if (precisionType == "precision5" && (serialType == "0402")) {
serialValue = "11";
} else if (precisionType == "precision5" && (serialType == "0603")) {
serialValue = "12";
} else if (precisionType == "precision5" && (serialType == "0805")) {
serialValue = "13";
} else if (precisionType == "precision5" && (serialType == "1206")) {
serialValue = "14";
} else if (precisionType == "precision5" && (serialType == "1210")) {
serialValue = "15";
} else if (precisionType == "precision5" && (serialType == "1812")) {
serialValue = "16";
} else if (precisionType == "precision5" && (serialType == "2010")) {
serialValue = "17";
} else if (precisionType == "precision5" && (serialType == "2512")) {
serialValue = "18";
}
//0.1%
if (precisionType == "precision01" && (serialType == "0201")) {
serialValue = "10";
} else if (precisionType == "precision01" && (serialType == "0402")) {
serialValue = "11";
} else if (precisionType == "precision01" && (serialType == "0603")) {
serialValue = "12";
} else if (precisionType == "precision01" && (serialType == "0805")) {
serialValue = "13";
} else if (precisionType == "precision01" && (serialType == "1206")) {
serialValue = "14";
} else if (precisionType == "precision01" && (serialType == "1210")) {
serialValue = "15";
} else if (precisionType == "precision01" && (serialType == "1812")) {
serialValue = "16";
} else if (precisionType == "precision01" && (serialType == "2010")) {
serialValue = "17";
} else if (precisionType == "precision01" && (serialType == "2512")) {
serialValue = "18";
}
if (errors.length > 0) {
throw new Error(errors.join(""));
}
if (printType === "dip-re") {
printValue = "1";
} else if (printType === "smd-re") {
printValue = "0";
}
let convertedValue;
if (valueType === "general-re") {
convertedValue = "1110" + res_namer(inputValue) + printValue + serialValue;
} else if (valueType === "metal-re") {
convertedValue = "1111" + res_namer(inputValue) + printValue + serialValue;
} else if (valueType === "temp-re") {
convertedValue = "1112" + res_namer(inputValue) + printValue + serialValue;
} else if (valueType === "lignt-re") {
convertedValue = "1113" + res_namer(inputValue) + printValue + serialValue;
} else if (valueType === "other-re") {
convertedValue = "1119" + res_namer(inputValue) + printValue + serialValue;
}
outputElement.textContent = "物料编码:" + convertedValue;
} catch (error) {
outputElement.textContent = "错误:" + error.message;
}
}
function res_namer(value_str) {
value_str = value_str.toLowerCase();
if (value_str.includes('k')) {
base = 1000;
} else if (value_str.includes('m')) {
base = 1000000;
} else if (value_str.includes('g')) {
base = 1000000000;
} else if (value_str.includes('r')) {
base = 1;
} else {
throw '错误的值';
}
value_flt = parseFloat(value_str);
inner_flt = value_flt * base;
if (inner_flt < 1 && inner_flt > 0) {
inner_flt = inner_flt * 10
code = "0" + inner_flt.toString().replace('.', '')+"0";
if (code.length == 3)
{
code = code + "0";
}
}
else if (inner_flt < 10 && inner_flt > 1) {
code = inner_flt.toString().replace('.', '');
} else {
code = inner_flt.toString().slice(0, 3) + (inner_flt.toString().length - 1);
}
return code;
}
function isNumeric(value) {
return /^\d+$/.test(value);
}
function handleKeyDown(event) {
if (event.key === "Enter") {
convertValue();
}
}
</script>
</body>
<!-- InstanceEnd -->
</html>