bpi-code-conventer/resistance.html
2023-07-04 23:45:28 +08:00

269 lines
11 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="#!">
<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" -->
<div class="navbar-fixed">
<div>
<div class="caption center-align">
<h4 class="light text-lighten-3">电阻物料编码生成</h4>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="card">
<!-- 在这里添加 card 的内容 -->
<label for="typeSelect">选择电阻类型:</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 class="form-group row">
<div class="col">
<label for="valueInput">阻值:</label>
<input type="text" id="valueInput" class="form-control" placeholder="电阻阻值支持单位k,m,g及小于1的阻值"
onkeydown="handleKeyDown(event)">
</div>
<br><br>
<br><br>
<label for="printSelect">选择封装类型:</label>
<select id="printSelect" class="browser-default">
<option value="chooseprint">点这里选择封装类型</option>
<option value="dip-re">直插</option>
<option value="smd-re">贴片</option>
</select>
<div class="col">
<label for="serialInput">流水号:</label>
<input type="text" id="serialInput" class="form-control" placeholder="IC流水号"
onkeydown="handleKeyDown(event)">
</div>
</div>
<div class="form-group">
<button onclick="convertValue()" class="btn btn-primary">转换</button>
</div>
<div class="form-group">
<p id="output" class="error-output">转换结果将在这里显示</p>
</div>
</div>
</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 serialInput = document.getElementById("serialInput");
const outputElement = document.getElementById("output");
const valueType = typeSelect.value;
let inputValue = valueInput.value;
const printType = printSelect.value;
const serialValue = serialInput.value;
const errors = [];
try {
if (valueType === "choose") {
errors.push("请选择电阻类型");
}
if (valueType === "choose") {
errors.push("请选择封装类型");
}
if (!isNumeric(serialValue) || serialValue.length !== 2) {
errors.push("流水号错误");
}
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"+"R"+inner_flt.toString().replace('.', '');
}
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>