首页 > 其他分享 >JS-数学表达式正则表达式支持(包含希腊字母、小数点等)

JS-数学表达式正则表达式支持(包含希腊字母、小数点等)

时间:2023-04-24 20:58:26浏览次数:49  
标签:strNewRule v1Right 小数点 JS length var else 希腊字母 row

//技术状况规则
/**
evt:
{
  target:{
    value:''
  }
},
row:
{
"propName":""
"propRule":""
}
*/
function checkRule(evt, row, propName, propRule) { //匹配a=5,a>5,a<5,a≤6,a≥5等 var rule1 = /[ΆΈ-ώa-zA-z]+([1-9][0-9]*([\.][0-9]{1,2})?)+[=≤<>≥]([1-9][0-9]*([\.][0-9]{1,2})?)+/; var rule1Left = /[ΆΈ-ώa-zA-z]+([1-9][0-9]*([\.][0-9]{1,2})?)+[=≤<>≥]/; var rule1Right = /[=≤<>≥][0-9]+/; //匹配5<p<10,5<p1<20,5≤p1<20,5<p1≤20等 var rule2 = /([1-9][0-9]*([\.][0-9]{1,2})?)+[≤<]+[ΆΈ-ώa-zA-Z0-9]+[≤<]+([1-9][0-9]*([\.][0-9]{1,2})?)+/; var rule2Min = /([1-9][0-9]*([\.][0-9]{1,2})?)+[≤<]+/; var rule2Max = /[≤<]+([1-9][0-9]*([\.][0-9]{1,2})?)+/; var rule2Mid = /[≤<]+[ΆΈ-ώa-zA-Z]+([1-9][0-9]*([\.][0-9]{1,2})?)+[≤<]+/; var tv0 = evt.target.value.replace(/\s*/g, "").replace(/^\s*|\s*$/g, ""); var tv = tv0.replace("<", "<").replace(">", ">").trim(); row[propName] = tv; var v1 = tv.match(rule1); var v2 = tv.match(rule2); if (v1 == null && v2 == null) { row[propRule] = ''; row[propName] = ''; return; } if (v2 != null && v2.length > 0) { var v2Min = v2[0].match(rule2Min); var v2Max = v2[0].match(rule2Max); var v2Mid = v2[0].match(rule2Mid); var leftChar = ''; var rightChar = ''; var leftCharNew = ''; var rightCharNew = ''; var midCharNew = ''; if (v2Min.length > 0) { //提取左边符号 leftChar = v2Min[0][v2Min[0].length - 1]; leftCharNew = v2Min[0].substr(0, v2Min[0].length - 1); } if (v2Max.length > 0) { //提取右边符号 rightChar = v2Max[0][0]; rightCharNew = v2Max[0].substr(1, v2Max[0].length - 1); } if (v2Mid.length > 0) { midCharNew = v2Mid[0].substr(1, v2Mid[0].length - 2); } if (leftChar == '≤') leftChar = '['; else if (leftChar == '<') leftChar = '('; else leftChar = ''; if (rightChar == '≤') rightChar = ']'; else if (rightChar == '<') rightChar = ')'; else rightChar = ''; if (leftChar.length == 0 || rightChar.length == 0) { row[propRule] = ''; row[propName] = ''; return; } var strNewRule = leftChar + parseFloat(leftCharNew) + ',' + parseFloat(rightCharNew) + rightChar; row[propRule] = strNewRule; row[propName] = v2; return; } else if (v1 != null && v1.length > 0) { var v1Char = ''; var v1Left = v1[0].match(rule1Left); var v1Right = v1[0].match(rule1Right); if (v1Left.length > 0) { //提取右边符号 v1Char = v1Left[0][v1Left[0].length - 1]; //去除左边符号 v1Left = v1Left[0].substr(0, v1Left[0].length - 1); } if (v1Right.length > 0) { //去除左边符号 v1Right = v1Right[0].substr(1, v1Right[0].length - 1); } var strNewRule = ''; if (v1Char == '=') { strNewRule = "[" + v1Right + "," + v1Right + "]"; } else if (v1Char == '<') { strNewRule = v1Right + ")"; } else if (v1Char == '≤') { strNewRule = v1Right + "]"; } else if (v1Char == '>') { strNewRule = "(" + v1Right; } else if (v1Char == '≥') { strNewRule = "[" + v1Right; } row[propRule] = strNewRule; row[propName] = v1; } else { row[propName] = ''; row[propRule] = ''; return; } }

调用示例:

<el-table :data="props.row.Details"
          border
          :ref="'subTable'+props.$index"
          style="width:100%;"
          :span-method="rowSpanMethod"
          v-show="props.row.Details && props.row.Details.length>0">
    <el-table-column label="计算规则">
        <template slot-scope="prop">
            <el-form-item :prop="'Items.' + props.$index + '.Details.' + prop.$index + '.EvalRuleValue'"
                          :rules="[
                          {required: true, message: '计算规则不能为空', trigger: 'blur'}
                          ]">
                @*<el-input v-model="prop.row.EvalRuleValue" v-on:keyup.native="onNumber($event,prop.row,'EvalRuleValue')" min="0" max="10000">*@
                <el-input v-model="prop.row.EvalRuleValue" v-bind:disabled="!isDisabled">
                </el-input>
            </el-form-item>
        </template>
    </el-table-column>
    <el-table-column label="规则展示">
        <template slot-scope="prop">
            <el-form-item :prop="'Items.' + props.$index + '.Details.' + prop.$index + '.EvalRuleName'"
                          :rules="[
                            {required: true, message: '规则展示不能为空', trigger: 'blur'}
                          ]">
                @*<el-input v-model="prop.row.EvalRuleName" v-on:keyup.native="onRuleShow($event,prop.row,'EvalRuleName','EvalRuleValue')">*@
                <el-input v-model="prop.row.EvalRuleName" v-on:blur.capture="onRuleShow($event,prop.row,'EvalRuleName','EvalRuleValue')"></el-input>
            </el-form-item>
        </template>
    </el-table-column>      
</el-table>

示例效果:

 

标签:strNewRule,v1Right,小数点,JS,length,var,else,希腊字母,row
From: https://www.cnblogs.com/oumi/p/17350866.html

相关文章

  • vue3+jointjs demo
    下面是使用Vue3和JointJS添加元素的示例代码:1.安装JointJS```terminalnpminstalljointjs--save```2.创建JointJS图形```javascriptimport{ref,onMounted}from'vue';import*asjointfrom'jointjs';exportdefault{setup(){constgraphC......
  • Python学习笔记--json序列化时间报错-改源码
    问题:转换时间报错执行代码为:importjsonfromdatetimeimportdate,datetimed={"time1":date.today(),"time2":datetime.today()}res=json.dumps(d)#报错  TypeError:ObjectoftypedateisnotJSONserializable方案1:手动转换str()方案2:继承类......
  • js树形结构中搜索某一项数据
    在树形结构中搜索checkItems值为某某某的数据,返回的是子数据。constsearchTree=(tree,checkItems)=>{letres='';letstate=false;constreadTree=(_tree,_checkItems)=>{if(state)return;for(leti=0;i<_tree.length;i+......
  • UE4 构造Json
    先记录:格式一:数组嵌套 实现1FStringGenerateJson(constFStringMsg)2{3TSharedPtr<FJsonObject>RootJsonObj=MakeShareable<FJsonObject>(newFJsonObject);4RootJsonObj->SetStringField(TEXT("prompt"),Msg);56TAr......
  • js 实现继承
    一、使用原型链functionAnimal1(leg){this.leg=leg;}functionDog1(name){this.name=name;Animal1.call(this,4)//!!import1}Dog1.prototype.__proto_......
  • Vue.js 目录
    Vue.js大致介绍Vue官网Vue.js搭建Vue开发环境(p4~p6)Vue.js模板语法Vue.js数据绑定Vue.jsel与data的两种写法Vue.js理解MVVMVue.js数据代理-回顾Object.defineProperty方法&数据代理理解Vue.js事件处理-事件的基本使用v-on传参Vue.js事件处理-事件修饰符Vue.js事......
  • js 如何实现类
    一、使用原型functionChicken1(name){this.name=name}Chicken1.prototype.kind='chicken';Chicken1.prototype.say=function(){console.log(`hello,i'ma${this......
  • 纯人工手解jsjiami.v5|jsjiami.v6过程分析记录
    JSJiami.v6是一种JavaScript代码混淆工具,它可以将JavaScript代码转化为难以理解和阅读的形式,从而增强代码的保密性和安全性。在本文中,我们将介绍JSJiami.v6的工作原理,并提供一些实际的案例代码。JSJiami.v6的工作原理JSJiami.v6采用了多种混淆技术,包括代码结构转化、变量重命名、......
  • 《JSON 必知必会》阅读摘要记录
    [《JSON必知必会》阅读摘要记录|国光](https://www.sqlsec.com/2020/04/jsonbook.html#10-2-%E7%BB%93%E8%AF%AD)JSON必知必会书籍学习记录笔记,想深入一下JSONHijacking漏洞,所以就打算找一本JSON的书籍来读一遍,打捞自己的基础,于是就选了这本书来学习,以后这种读书笔记的......
  • JS逆向中 cookie加密的HOOK方法
    Object.defineProperty(obj,prop,descriptor)其中,参数obj是要定义属性的对象,    prop是要定义或修改的属性名,    descriptor是属性描述符对象。     属性描述符对象的属性包括value、writable、enumerable、configurable和get和se......