update: 更新数据
This commit is contained in:
parent
c29f4c6481
commit
41e9face3e
@ -6,7 +6,7 @@
|
||||
"scripts": {
|
||||
"dev-front": "vite --host",
|
||||
"dev-front-test": "vite --host --mode=test",
|
||||
"build": "vue-tsc && vite build",
|
||||
"build-front": "vue-tsc && vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
|
@ -42,7 +42,7 @@
|
||||
</Tabs>
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="flex justify-center mt-10">
|
||||
<div class="flex justify-center mt-8">
|
||||
<Button key="submit" type="primary" @click="handleOk">确定</Button>
|
||||
</div>
|
||||
</template>
|
||||
|
87
src/pages/result/components/result-modal.vue
Normal file
87
src/pages/result/components/result-modal.vue
Normal file
@ -0,0 +1,87 @@
|
||||
<template>
|
||||
<Modal
|
||||
:open="visible" width="700px"
|
||||
@cancel="result = []"
|
||||
:maskClosable="false"
|
||||
:closable="false"
|
||||
title="测试结果"
|
||||
:footer="false"
|
||||
>
|
||||
<div class="grid result-list grid-cols-2 gap-4">
|
||||
<div class="flex result-item" v-for="(it,index) in result" :key="index">
|
||||
<div class="title">{{it.title}}:</div>
|
||||
<div class="value">{{getValue(it)}}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-center mt-8">
|
||||
<Button key="submit" type="primary" @click="result=[]">知道了</Button>
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import {Button, Modal} from "ant-design-vue";
|
||||
import {defineComponent, ref, watch} from "vue";
|
||||
|
||||
const visible = ref(false)
|
||||
|
||||
const result = defineModel<ResultItem[]>('result')
|
||||
defineComponent({
|
||||
name: 'ResultModal'
|
||||
})
|
||||
watch(() => result.value, () => {
|
||||
console.log('re', result.value)
|
||||
visible.value = result.value && result.value.length > 0
|
||||
})
|
||||
const percentKeys = ['danbai_rekabi', 'danbai_rekabi_baidanbai', 'tang_rekabi', 'zhifang_rekabi', 'changneibi', 'changwaibi'];
|
||||
function toFixed(num, fix = 3) {
|
||||
const numbers = Array(fix).fill('0').join('');
|
||||
// 保留几位小数后面添加几个0
|
||||
// for (var i = 0; i < val; i++) {
|
||||
// numbers += '0';
|
||||
// }
|
||||
const s = 1 + numbers;
|
||||
// 如果是整数需要添加后面的0
|
||||
const spot = "." + numbers;
|
||||
// Math.round四舍五入
|
||||
// parseFloat() 函数可解析一个字符串,并返回一个浮点数。
|
||||
let value = Math.round(parseFloat(num) * s) / s;
|
||||
// 从小数点后面进行分割
|
||||
const d = value.toString().split(".");
|
||||
if (d.length == 1) {
|
||||
value = value.toString() + spot;
|
||||
return value;
|
||||
}
|
||||
if (d.length > 1) {
|
||||
value = value.toString() + Array(fix - d[1].length).fill('0').join('');
|
||||
return value;
|
||||
}
|
||||
}
|
||||
function getValue(item:ResultItem){
|
||||
if(item.key == 'total'){
|
||||
return Math.floor(item.value)
|
||||
}
|
||||
if(!percentKeys.includes(item.key)){
|
||||
return toFixed(item.value, 3)
|
||||
}
|
||||
|
||||
let v = item.value * 100;
|
||||
if (v == 0 || v == 100) {
|
||||
v = v + '%';
|
||||
} else {
|
||||
v = toFixed(v, 2) + '%';
|
||||
}
|
||||
return v;
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.result-list{
|
||||
|
||||
}
|
||||
.result-item{
|
||||
.title{
|
||||
@apply font-bold mr-2;
|
||||
}
|
||||
.value{}
|
||||
}
|
||||
</style>
|
@ -2,14 +2,15 @@
|
||||
<div class="result-container">
|
||||
<PageHeader title="输出指标编辑" description="*输出指标: 使用输入参数进行计算,可对指标进行编辑操作。">
|
||||
<Space>
|
||||
<Button :icon="h(SettingOutlined)" @click="settingVisible=true">
|
||||
<Button @click="settingVisible=true">
|
||||
设置输入数据
|
||||
</Button>
|
||||
<Button @click="getResultValues">getResultValues</Button>
|
||||
<Button @click="showAllResult">输出计算</Button>
|
||||
<Button :icon="h(SaveOutlined)" :loading="loading" type="primary" @click="save">保存</Button>
|
||||
</Space>
|
||||
</PageHeader>
|
||||
</div>
|
||||
<ResultModal v-model:result="testResultValue" />
|
||||
<InputSetting v-model:input-values="inputValues" v-model:visible="settingVisible"/>
|
||||
<div class="result-calc-expression-list-container">
|
||||
<div class="result-expressions-inner overflow-auto grid grid-cols-1 gap-4"
|
||||
@ -60,6 +61,7 @@ import Tiptap from "@/components/editor/tiptap.vue";
|
||||
import useRequest from "@/service/useRequest";
|
||||
import {getAllProduct} from "@/service/use-result-vars.ts";
|
||||
import InputSetting from "@/pages/result/components/input-setting.vue";
|
||||
import ResultModal from "./components/result-modal.vue";
|
||||
|
||||
const {notification, message, modal} = App.useApp()
|
||||
const ResultExpressionList = ref<ResultExpression[]>([]);
|
||||
@ -67,6 +69,7 @@ const inputValues = ref<{
|
||||
[key: string]: number
|
||||
}>()
|
||||
const settingVisible = ref(false)
|
||||
const testResultValue = ref<ResultItem[]>([])
|
||||
|
||||
expressionList().then((res) => {
|
||||
ResultExpressionList.value = res.list;
|
||||
@ -82,7 +85,19 @@ const {loading, run: save} = useRequest(() => saveExpression(ResultExpressionLis
|
||||
function runCode(expression: string, vars: any) {
|
||||
return new Function('vars', `with(vars) { return ${expression};}`)(vars)
|
||||
}
|
||||
|
||||
function showAllResult(){
|
||||
const result = getResultValues();
|
||||
const resultList:ResultItem[] = [];
|
||||
ResultExpressionList.value.forEach(it=>{
|
||||
resultList.push({
|
||||
title:it.title,
|
||||
key:it.key,
|
||||
value: result[it.key] || 0
|
||||
})
|
||||
})
|
||||
console.log(resultList);
|
||||
testResultValue.value = resultList;
|
||||
}
|
||||
function getResultValues(){
|
||||
// 结果集
|
||||
const result:{
|
||||
@ -101,8 +116,9 @@ function getResultValues(){
|
||||
}catch (e) {}
|
||||
})
|
||||
return result;
|
||||
// console.log(result)
|
||||
}
|
||||
|
||||
|
||||
function testExpression(item: ResultExpression) {
|
||||
const expression = parseExpression(item.expression);
|
||||
try {
|
||||
@ -113,11 +129,11 @@ function testExpression(item: ResultExpression) {
|
||||
input: inputValues.value,
|
||||
})
|
||||
|
||||
console.log('result', value,expression,result) // ,JSON.stringify(productValues.value)
|
||||
// console.log('result', value,expression,result) // ,JSON.stringify(productValues.value)
|
||||
notification.info({
|
||||
message: '提示',
|
||||
description: `${item.title}:${value}`,
|
||||
duration: 0
|
||||
duration: 5
|
||||
})
|
||||
} catch (e) {
|
||||
modal.warning({
|
||||
@ -147,7 +163,6 @@ function parseExpression(str: string) {
|
||||
expList.push(expression);
|
||||
})
|
||||
return expList.join('');
|
||||
// console.log(JSON.stringify({content:doc.content[0].content}))
|
||||
}
|
||||
</script>
|
||||
|
||||
|
7
src/types/product.d.ts
vendored
7
src/types/product.d.ts
vendored
@ -57,3 +57,10 @@ interface ExpressionValue {
|
||||
}
|
||||
text: string;
|
||||
}
|
||||
|
||||
|
||||
interface ResultItem {
|
||||
title:string;
|
||||
key:string;
|
||||
value:number;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user