|
@@ -87,12 +87,18 @@
|
|
|
<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" style="width: calc(100% - 85px);" maxlength="100" show-word-limit placeholder="请输入四则运算表达式"></el-input>
|
|
|
- <el-button @click="testEditEvent" style="float: right;width: 80px;">测试</el-button>
|
|
|
+ <el-input v-model="dataModelForm.operationRule" maxlength="100" show-word-limit placeholder="请输入四则运算表达式"></el-input>
|
|
|
<span style="font-size: 12px;">
|
|
|
提示:四则运算支持的英文符号 【<b>+</b>】、【<b>-</b>】、【<b>*</b>】、【<b>/</b>】、【<b>()</b>】,真实数据值使用固定字符串 【<b>calcVal</b>】
|
|
|
</span>
|
|
|
</el-form-item>
|
|
|
+ <el-form-item label="测试数据值" prop="testVal">
|
|
|
+ <el-input v-model="dataModelForm.testVal" style="width: calc(100% - 85px);" maxlength="6" placeholder="请输入测试数据值"></el-input>
|
|
|
+ <el-button @click="testEditEvent" style="float: right;width: 80px;">测试</el-button>
|
|
|
+ <span style="font-size: 12px;">
|
|
|
+ 测试结果:{{ calcValResult }}
|
|
|
+ </span>
|
|
|
+ </el-form-item>
|
|
|
<el-form-item style="text-align: center;">
|
|
|
<el-button type="primary" @click="saveDataModelEvent">确定</el-button>
|
|
|
<el-button @click="dialogClose">取消</el-button>
|
|
@@ -100,6 +106,35 @@
|
|
|
</el-form>
|
|
|
</el-dialog>
|
|
|
|
|
|
+ <!-- 测试数据模型 -->
|
|
|
+ <el-dialog
|
|
|
+ title="四则运算表达式验证"
|
|
|
+ width="650px"
|
|
|
+ top="10vh"
|
|
|
+ center
|
|
|
+ v-dialog-drag
|
|
|
+ v-if="dialogDataModelTestVisible"
|
|
|
+ :before-close="dialogClose"
|
|
|
+ :visible.sync="dialogDataModelTestVisible"
|
|
|
+ :close-on-click-modal="false"
|
|
|
+ :append-to-body="true">
|
|
|
+ <el-form ref="dataModelTestForm" :model="dataModelTestForm" label-width="110px" label-position="top">
|
|
|
+ <el-form-item label="四则运算表达式" prop="operationRule">
|
|
|
+ <el-input v-model="dataModelTestForm.operationRule" readonly placeholder="请输入四则运算表达式"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="测试数据值" prop="testVal">
|
|
|
+ <el-input v-model="dataModelTestForm.testVal" style="width: calc(100% - 85px);" maxlength="6" placeholder="请输入测试数据值"></el-input>
|
|
|
+ <el-button @click="testByIdEvent" style="float: right;width: 80px;">测试</el-button>
|
|
|
+ <span style="font-size: 12px;">
|
|
|
+ 测试结果:{{ calcValResult }}
|
|
|
+ </span>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item style="text-align: center;">
|
|
|
+ <el-button @click="dialogClose">取消</el-button>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ </el-dialog>
|
|
|
+
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
@@ -109,8 +144,7 @@ import {
|
|
|
customCompare, showAlertMsgWin,
|
|
|
showAlertWin,
|
|
|
showConfirmWin,
|
|
|
- showLoading,
|
|
|
- showPromptWin
|
|
|
+ showLoading
|
|
|
} from '@/utils/cqcy'
|
|
|
import {
|
|
|
addDataModel,
|
|
@@ -129,18 +163,26 @@ export default {
|
|
|
return {
|
|
|
breadcrumbList: ['数据模型'],
|
|
|
dialogDataModelVisible: false,
|
|
|
+ dialogDataModelTestVisible: false,
|
|
|
dialogDataModelTitle: '新增数据模型',
|
|
|
tablePage: 1,
|
|
|
tableLimit: 10,
|
|
|
tableTotal: 0,
|
|
|
tableData: [],
|
|
|
searchTxt: '',
|
|
|
+ calcValResult: '',
|
|
|
dataModelForm: {
|
|
|
id: '',
|
|
|
mathParameter: 'calcVal',
|
|
|
operationRule: '',
|
|
|
+ testVal: '',
|
|
|
remark: ''
|
|
|
},
|
|
|
+ dataModelTestForm: {
|
|
|
+ id: '',
|
|
|
+ operationRule: '',
|
|
|
+ testVal: ''
|
|
|
+ },
|
|
|
dataModelRules: {
|
|
|
operationRule: [
|
|
|
{ required: true, message: '表达式不能为空', trigger: 'blur' },
|
|
@@ -196,8 +238,10 @@ export default {
|
|
|
id: '',
|
|
|
mathParameter: 'calcVal',
|
|
|
operationRule: '',
|
|
|
+ testVal: '',
|
|
|
remark: ''
|
|
|
}
|
|
|
+ this.calcValResult = ''
|
|
|
this.dialogDataModelTitle = '新增数据模型'
|
|
|
this.dialogDataModelVisible = true
|
|
|
},
|
|
@@ -208,6 +252,7 @@ export default {
|
|
|
loading.close()
|
|
|
this.dialogDataModelTitle = '编辑数据模型'
|
|
|
this.dataModelForm = res.data
|
|
|
+ this.calcValResult = ''
|
|
|
this.dialogDataModelVisible = true
|
|
|
}).catch((e) => {
|
|
|
loading.close()
|
|
@@ -217,61 +262,67 @@ export default {
|
|
|
/** 新增编辑测试 */
|
|
|
testEditEvent() {
|
|
|
let txt = this.dataModelForm.operationRule
|
|
|
+ let testVal = this.dataModelForm.testVal
|
|
|
this.validateCalc(null, txt, (e) => {
|
|
|
if (e) {
|
|
|
showAlertMsgWin(this, null, e.message)
|
|
|
return
|
|
|
}
|
|
|
- this.handleTest(null, null, txt)
|
|
|
- })
|
|
|
- },
|
|
|
- /** 测试数据模型值 */
|
|
|
- handleTest(index, row, ruleModel) {
|
|
|
- showPromptWin(this, '四则运算表达式验证', '请输入数值', '', (val) => {
|
|
|
- if (!/^(\-)?\d+(\.\d{1,2})?$/.test(val)) {
|
|
|
- return '请输入正确的数字'
|
|
|
- }
|
|
|
- if (val.length > 6) {
|
|
|
- return '请输入小于6位的数字'
|
|
|
- }
|
|
|
- }, (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
|
|
|
- showAlertWin(this, '计算结果', bds)
|
|
|
- }).catch((e) => {
|
|
|
- loading.close()
|
|
|
- showAlertWin(this, null, e)
|
|
|
- })
|
|
|
+ if (!/^(\-)?\d+(\.\d{1,2})?$/.test(testVal)) {
|
|
|
+ showAlertMsgWin(this, null, '请输入正确的测试数据值')
|
|
|
return
|
|
|
}
|
|
|
+ const loading = showLoading(this, '计算中,请稍候···')
|
|
|
let params = {
|
|
|
- 'id': row.id,
|
|
|
- 'dataValue': value
|
|
|
+ 'parameter': 'calcVal',
|
|
|
+ 'mathString': txt,
|
|
|
+ 'dataValue': testVal
|
|
|
}
|
|
|
- testDataModelById(params).then(res => {
|
|
|
+ testDataModelByModel(params).then(res => {
|
|
|
loading.close()
|
|
|
- let bds = row.operationRule
|
|
|
- bds = bds.replaceAll(/calcVal/g, value)
|
|
|
+ let bds = txt
|
|
|
+ bds = bds.replaceAll(/calcVal/g, testVal)
|
|
|
bds += '='
|
|
|
bds += res.data
|
|
|
- showAlertWin(this, '计算结果', bds)
|
|
|
+ this.calcValResult = bds
|
|
|
}).catch((e) => {
|
|
|
loading.close()
|
|
|
showAlertWin(this, null, e)
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
+ /** 列表测试 */
|
|
|
+ testByIdEvent() {
|
|
|
+ let txt = this.dataModelTestForm.operationRule
|
|
|
+ let testVal = this.dataModelTestForm.testVal
|
|
|
+ let id = this.dataModelTestForm.id
|
|
|
+ if (!/^(\-)?\d+(\.\d{1,2})?$/.test(testVal)) {
|
|
|
+ showAlertMsgWin(this, null, '请输入正确的测试数据值')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const loading = showLoading(this, '计算中,请稍候···')
|
|
|
+ let params = {
|
|
|
+ 'id': id,
|
|
|
+ 'dataValue': testVal
|
|
|
+ }
|
|
|
+ testDataModelById(params).then(res => {
|
|
|
+ loading.close()
|
|
|
+ let bds = txt
|
|
|
+ bds = bds.replaceAll(/calcVal/g, testVal)
|
|
|
+ bds += '='
|
|
|
+ bds += res.data
|
|
|
+ this.calcValResult = bds
|
|
|
+ }).catch((e) => {
|
|
|
+ loading.close()
|
|
|
+ showAlertWin(this, null, e)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /** 测试数据模型值 */
|
|
|
+ handleTest(index, row, ruleModel) {
|
|
|
+ this.dataModelTestForm.operationRule = row.operationRule
|
|
|
+ this.dataModelTestForm.id = row.id
|
|
|
+ this.dialogDataModelTestVisible = true
|
|
|
+ },
|
|
|
/** 删除数据模型 */
|
|
|
handleDelete(index, row) {
|
|
|
showConfirmWin(this, null, '您确定要删除该表达式吗?', () => {
|
|
@@ -360,13 +411,17 @@ export default {
|
|
|
},
|
|
|
/** 弹出层关闭事件 */
|
|
|
dialogClose(done) {
|
|
|
+ this.calcValResult = ''
|
|
|
this.getAllDataModel()
|
|
|
if (typeof(done) === 'function') {
|
|
|
- this.$refs['dataModelForm'].resetFields()
|
|
|
+ if (this.$refs['dataModelForm']) this.$refs['dataModelForm'].resetFields()
|
|
|
+ if (this.$refs['dataModelTestForm']) this.$refs['dataModelTestForm'].resetFields()
|
|
|
done()
|
|
|
} else {
|
|
|
this.dialogDataModelVisible = false
|
|
|
- this.$refs['dataModelForm'].resetFields()
|
|
|
+ this.dialogDataModelTestVisible = false
|
|
|
+ if (this.$refs['dataModelForm']) this.$refs['dataModelForm'].resetFields()
|
|
|
+ if (this.$refs['dataModelTestForm']) this.$refs['dataModelTestForm'].resetFields()
|
|
|
}
|
|
|
}
|
|
|
}
|