|
@@ -1,17 +1,17 @@
|
|
|
<template>
|
|
|
<div class="cqcy-content" style="margin: 0;height: calc(100% - 70px);">
|
|
|
<breadcrumb-view :breadcrumbList="breadcrumbList" :show-index="false"></breadcrumb-view>
|
|
|
+ <div class="cy-nav-sx">
|
|
|
+ <el-input placeholder="请输入名称或者四则运算表达式"
|
|
|
+ v-model="searchTxt"
|
|
|
+ style="margin-left: 5px; width: 300px;"
|
|
|
+ prefix-icon="el-icon-search">
|
|
|
+ </el-input>
|
|
|
+ <el-button style="margin-left: 5px;" @click="searchRuleEvent">查询</el-button>
|
|
|
+ </div>
|
|
|
<el-button type="primary" class="cy-nav-btn" icon="el-icon-circle-plus-outline" size="mini" @click="handleAdd">新增</el-button>
|
|
|
<el-divider></el-divider>
|
|
|
<div class="cy-main">
|
|
|
- <div style="margin-bottom: 10px;">
|
|
|
- <el-input placeholder="请输入名称或者四则运算表达式"
|
|
|
- v-model="searchTxt"
|
|
|
- style="margin-left: 5px; width: 300px;"
|
|
|
- prefix-icon="el-icon-search">
|
|
|
- </el-input>
|
|
|
- <el-button style="margin-left: 5px;" @click="searchRuleEvent">查询</el-button>
|
|
|
- </div>
|
|
|
<el-table
|
|
|
:data="tableData" border :stripe="true"
|
|
|
:header-cell-style="{background: '#E8E8E8'}"
|
|
@@ -73,7 +73,7 @@
|
|
|
<!-- 新增数据模型 -->
|
|
|
<el-dialog
|
|
|
:title="dialogDataModelTitle"
|
|
|
- width="80%"
|
|
|
+ width="650px"
|
|
|
top="10vh"
|
|
|
center
|
|
|
v-dialog-drag
|
|
@@ -87,7 +87,8 @@
|
|
|
<el-input v-model="dataModelForm.remark" placeholder="请输入名称" maxlength="20" show-word-limit></el-input>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="四则运算表达式" prop="operationRule">
|
|
|
- <el-input v-model="dataModelForm.operationRule" placeholder="请输入四则运算表达式"></el-input>
|
|
|
+ <el-input v-model="dataModelForm.operationRule" style="width: calc(100% - 85px);" placeholder="请输入四则运算表达式"></el-input>
|
|
|
+ <el-button @click="testEditEvent" style="float: right;width: 80px;">测试</el-button>
|
|
|
<span style="font-size: 12px;">
|
|
|
提示:四则运算支持的英文符号 【<b>+</b>】、【<b>-</b>】、【<b>*</b>】、【<b>/</b>】、【<b>()</b>】,真实数据值使用固定字符串 【<b>calcVal</b>】
|
|
|
</span>
|
|
@@ -104,12 +105,12 @@
|
|
|
|
|
|
<script>
|
|
|
import BreadcrumbView from '@/components/BreadcrumbView'
|
|
|
-import {customCompare, showAlertWin, showLoading} from '@/utils/cqcy'
|
|
|
+import {customCompare, showAlertWin, showAlertWinTips, showLoading} from '@/utils/cqcy'
|
|
|
import {
|
|
|
addDataModel,
|
|
|
delDataModelById,
|
|
|
getAllDataModel, getDataModelById,
|
|
|
- testDataModelById,
|
|
|
+ testDataModelById, testDataModelByModel,
|
|
|
updateDataModel
|
|
|
} from "@/api/datasource";
|
|
|
|
|
@@ -119,33 +120,6 @@ export default {
|
|
|
BreadcrumbView
|
|
|
},
|
|
|
data() {
|
|
|
- /** 四则运算表达式验证 */
|
|
|
- let validateCalc = (rule, value, callback) => {
|
|
|
- try {
|
|
|
- value = value.replace(/ /g, '')
|
|
|
- value = value.replace(/calcVal/g, '99999')
|
|
|
- if (/^[\d|\-|\+|\*|\/|\.|\(|\)]+$/.test(value)) {
|
|
|
- // 排除连续的运算符
|
|
|
- if (/[\-|\+|\*|\/]{2,}/.test(value)) {
|
|
|
- callback(new Error('表达式验证失败,请修改后再试'))
|
|
|
- return
|
|
|
- }
|
|
|
- // 解决 0.5 简写成 .5
|
|
|
- if (/\D\./.test(value)) {
|
|
|
- callback(new Error('表达式验证失败,请修改后再试'))
|
|
|
- return
|
|
|
- }
|
|
|
- let val = eval(value)
|
|
|
- if (typeof val == 'number' && val != Infinity) {
|
|
|
- callback()
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
- callback(new Error('表达式验证失败,请修改后再试'))
|
|
|
- } catch (e) {
|
|
|
- callback(new Error('表达式验证失败,请修改后再试'))
|
|
|
- }
|
|
|
- }
|
|
|
return {
|
|
|
breadcrumbList: ['数据模型'],
|
|
|
dialogDataModelVisible: false,
|
|
@@ -164,7 +138,7 @@ export default {
|
|
|
dataModelRules: {
|
|
|
operationRule: [
|
|
|
{ required: true, message: '表达式不能为空', trigger: 'blur' },
|
|
|
- { validator: validateCalc }
|
|
|
+ { validator: this.validateCalc }
|
|
|
],
|
|
|
remark: [
|
|
|
{ required: true, message: '名称不能为空', trigger: 'blur' }
|
|
@@ -183,6 +157,33 @@ export default {
|
|
|
sortChange({ prop, order }) {
|
|
|
this.tableData.sort(customCompare(prop, order))
|
|
|
},
|
|
|
+ /** 四则运算表达式验证 */
|
|
|
+ validateCalc(rule, value, callback) {
|
|
|
+ try {
|
|
|
+ value = value.replace(/ /g, '')
|
|
|
+ value = value.replace(/calcVal/g, '99999')
|
|
|
+ if (/^[\d|\-|\+|\*|\/|\.|\(|\)]+$/.test(value)) {
|
|
|
+ // 排除连续的运算符
|
|
|
+ if (/[\-|\+|\*|\/]{2,}/.test(value)) {
|
|
|
+ callback(new Error('表达式验证失败,请修改后再试'))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 解决 0.5 简写成 .5
|
|
|
+ if (/\D\./.test(value)) {
|
|
|
+ callback(new Error('表达式验证失败,请修改后再试'))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let val = eval(value)
|
|
|
+ if (typeof val == 'number' && val != Infinity) {
|
|
|
+ callback()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ callback(new Error('表达式验证失败,请修改后再试'))
|
|
|
+ } catch (e) {
|
|
|
+ callback(new Error('表达式验证失败,请修改后再试'))
|
|
|
+ }
|
|
|
+ },
|
|
|
/** 新增数据模型 */
|
|
|
handleAdd() {
|
|
|
this.dataModelForm = {
|
|
@@ -207,8 +208,22 @@ export default {
|
|
|
showAlertWin(this, e)
|
|
|
})
|
|
|
},
|
|
|
+ /** 新增编辑测试 */
|
|
|
+ testEditEvent() {
|
|
|
+ let txt = this.dataModelForm.operationRule
|
|
|
+ this.validateCalc(null, txt, (e) => {
|
|
|
+ if (e) {
|
|
|
+ this.$message({
|
|
|
+ message: e.message,
|
|
|
+ type: 'warning'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.handleTest(null, null, txt)
|
|
|
+ })
|
|
|
+ },
|
|
|
/** 测试数据模型值 */
|
|
|
- handleTest(index, row) {
|
|
|
+ handleTest(index, row, ruleModel) {
|
|
|
this.$prompt('请输入数值', '四则运算表达式验证', {
|
|
|
confirmButtonText: '确定',
|
|
|
cancelButtonText: '取消',
|
|
@@ -224,6 +239,25 @@ export default {
|
|
|
}
|
|
|
}).then(({ value }) => {
|
|
|
const loading = showLoading(this, '计算中,请稍候···')
|
|
|
+ if (ruleModel) {
|
|
|
+ let params = {
|
|
|
+ 'parameter': 'calcVal',
|
|
|
+ 'mathString': ruleModel,
|
|
|
+ 'dataValue': value
|
|
|
+ }
|
|
|
+ testDataModelByModel(params).then(res => {
|
|
|
+ loading.close()
|
|
|
+ let bds = ruleModel
|
|
|
+ bds = bds.replaceAll(/calcVal/g, value)
|
|
|
+ bds += '='
|
|
|
+ bds += res.data
|
|
|
+ showAlertWinTips(this, '计算结果', bds)
|
|
|
+ }).catch((e) => {
|
|
|
+ loading.close()
|
|
|
+ showAlertWin(this, e)
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
let params = {
|
|
|
'id': row.id,
|
|
|
'dataValue': value
|
|
@@ -234,7 +268,7 @@ export default {
|
|
|
bds = bds.replaceAll(/calcVal/g, value)
|
|
|
bds += '='
|
|
|
bds += res.data
|
|
|
- showAlertWin(this, bds)
|
|
|
+ showAlertWinTips(this, '计算结果', bds)
|
|
|
}).catch((e) => {
|
|
|
loading.close()
|
|
|
showAlertWin(this, e)
|