<template>
|
<div class="app-container">
|
<el-card class="box-card">
|
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
|
<el-form-item label="日期范围" prop="dateConditions">
|
<el-date-picker
|
v-model="queryParams.dateConditions"
|
type="daterange"
|
align="right"
|
unlink-panels
|
range-separator="至"
|
start-placeholder="开始日期"
|
end-placeholder="结束日期"
|
value-format="yyyy-MM-dd"
|
@change="handleDateChange">
|
</el-date-picker>
|
</el-form-item>
|
<el-form-item label="工位编号" prop="locationCode">
|
<el-select v-model="queryParams.locationCode" placeholder="请选择工位编号" clearable>
|
<el-option
|
v-for="item in locationOption"
|
:key="item.value"
|
:label="item.label"
|
:value="item.value"
|
/>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="数据类型" prop="paramName">
|
<el-select v-model="queryParams.paramName" @change="getSelectOptionMethod" placeholder="请选择数据类型" clearable>
|
<el-option
|
v-for="item in dataTypeList"
|
:key="item.value"
|
:label="item.label"
|
:value="item.value"
|
/>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="螺栓名称" prop="paramCode">
|
<el-select v-model="queryParams.paramCode" placeholder="请选择螺栓名称" clearable>
|
<el-option
|
v-for="item in screwNameList"
|
:key="item.value"
|
:label="item.label"
|
:value="item.value"
|
/>
|
</el-select>
|
</el-form-item>
|
|
|
<el-form-item style="float: right">
|
<el-button type="primary" icon="el-icon-search" size="mini" @click="queryChartMethod">搜索</el-button>
|
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
</el-form-item>
|
</el-form>
|
</el-card>
|
<el-card style="margin-top: 10px" class="box-card">
|
<el-row :gutter="10" class="mb8">
|
<el-tabs v-model="activeName" @tab-click="handleClick">
|
<el-tab-pane label="正态分布" name="first">
|
<div>
|
<!-- <v-chart :option="chartOption" :style="{width: '600px', height: '400px'}"/>-->
|
<div ref="chart1" :style="{ width: '900px', height: '400px' }"></div>
|
</div>
|
</el-tab-pane>
|
<el-tab-pane label="散列图" name="second">
|
<div ref="chart2" :style="{ width: '900px', height: '400px' }"></div>
|
</el-tab-pane>
|
</el-tabs>
|
</el-row>
|
<!-- <div>-->
|
<!--<!– <v-chart :option="chartOption" :style="{width: '600px', height: '400px'}"/>–>-->
|
<!-- <div ref="chart" :style="{ width: '100%', height: '400px' }"></div>-->
|
<!-- </div>-->
|
<!-- <el-table v-loading="loading" border :data="paramCollectionList" @selection-change="handleSelectionChange" v-if="paramCollectionList.length > 0">-->
|
|
<!-- </el-table>-->
|
|
<!-- <el-empty v-else>-->
|
<!-- <span slot="description">暂无数据</span>-->
|
<!-- </el-empty>-->
|
</el-card>
|
|
|
</div>
|
</template>
|
|
<script>
|
import {
|
addParamCollection,
|
delParamCollection,
|
getParamCollection,
|
updateParamCollection
|
} from "@/api/main/da/paramCollection/paramCollection";
|
import {
|
getSelectOption,
|
queryChart,
|
queryDaParamCollectionListForSearch
|
} from "../../../../api/main/da/paramCollection/paramCollection";
|
import VueECharts from 'vue-echarts';
|
import echarts from 'echarts'
|
import async from "async";
|
|
export default {
|
name: "ParamCollection",
|
components: {
|
'v-chart': VueECharts
|
},
|
data() {
|
return {
|
convertedData:[],
|
convertedData2:[],
|
activeName: 'second',
|
dataTypeList:[
|
{
|
value: "扭矩",
|
label: "扭矩"
|
},
|
{
|
value: "角度",
|
label: "角度"
|
},
|
],
|
locationOption:[],
|
screwNameList:[],
|
maxDate: '',
|
// 遮罩层
|
loading: true,
|
// 选中数组
|
ids: [],
|
// 非单个禁用
|
single: true,
|
// 非多个禁用
|
multiple: true,
|
// 显示搜索条件
|
showSearch: true,
|
// 总条数
|
total: 0,
|
// 设备产品过程参数采集表格数据
|
paramCollectionList: [],
|
// 弹出层标题
|
title: "",
|
// 是否显示弹出层
|
open: false,
|
// 查询参数
|
queryParams: {
|
dateConditions: [],
|
pageNum: 1,
|
pageSize: 10,
|
workOrderNo: null,
|
sfcCode: null,
|
productCode: null,
|
productionLine: null,
|
locationCode: null,
|
equipmentNo: null,
|
paramCode: null,
|
},
|
// 表单参数
|
form: {},
|
// 表单校验
|
rules: {
|
id: [
|
{ required: true, message: "主键id不能为空", trigger: "blur" }
|
],
|
// workOrderNo: [
|
// { required: true, message: "工单编号不能为空", trigger: "blur" }
|
// ],
|
sfcCode: [
|
{ required: true, message: "总成序列号不能为空", trigger: "blur" }
|
],
|
productCode: [
|
{ required: true, message: "产品编号不能为空", trigger: "blur" }
|
],
|
// productionLine: [
|
// { required: true, message: "产线编号不能为空", trigger: "blur" }
|
// ],
|
locationCode: [
|
{ required: true, message: "工位编号不能为空", trigger: "blur" }
|
],
|
paramCode: [
|
{ required: true, message: "参数编码不能为空", trigger: "blur" }
|
],
|
paramValue: [
|
{ required: true, message: "参数值不能为空", trigger: "blur" }
|
],
|
},
|
};
|
},
|
created() {
|
// this.getList();
|
},
|
mounted() {
|
this.initChart1();
|
this.initChart2();
|
this.getSelectOptionMethod()
|
},
|
methods: {
|
initChart1() {
|
// 基于准备好的dom,初始化echarts实例
|
const chart = echarts.init(this.$refs.chart1);
|
|
// 指定图表的配置项和数据
|
const option = {
|
title: {
|
text: '正态分布图',
|
},
|
tooltip: {},
|
xAxis: {
|
type: 'value',
|
scale: true
|
},
|
yAxis: {
|
type: 'value',
|
},
|
series: [
|
{
|
name: '正态分布',
|
type: 'line',
|
smooth: true,
|
// data: this.generateNormalDistributionData(10,0,1), // 均值0,标准差1的正态分布数据
|
// data: this.queryChartMethod(), // 均值0,标准差1的正态分布数据
|
data: this.convertedData, // 均值0,标准差1的正态分布数据
|
},
|
],
|
};
|
|
// 使用刚指定的配置项和数据显示图表。
|
chart.setOption(option);
|
},
|
initChart2() {
|
// 基于准备好的dom,初始化echarts实例
|
const chart = echarts.init(this.$refs.chart2);
|
|
// 指定图表的配置项和数据
|
const option = {
|
title: {
|
text: '散列图',
|
},
|
tooltip: {},
|
xAxis: {
|
type: 'category',
|
data:[]
|
},
|
yAxis: {
|
type: 'value',
|
scale: true
|
},
|
series: [
|
{
|
name: '散列图',
|
type: 'scatter',
|
data: this.convertedData2, // 均值0,标准差1的正态分布数据
|
},
|
],
|
};
|
|
// 使用刚指定的配置项和数据显示图表。
|
chart.setOption(option);
|
},
|
generateNormalDistributionData(numPoints, mean, stdDev) {
|
let data = [];
|
for (let i = 0; i < numPoints; i++) {
|
const x = (i - numPoints / 2) / (numPoints / 4); // 缩放到合适的X范围
|
const y = (1 / (stdDev * Math.sqrt(2 * Math.PI))) * Math.exp(-0.5 * Math.pow((x - mean) / stdDev, 2));
|
data.push([x, y]);
|
}
|
console.log('rrered1111111111ata',data)
|
data = this.chartData
|
return data;
|
},
|
getSelectOptionMethod(){
|
getSelectOption(this.queryParams).then(res => {
|
console.log('rrrrrrr',res)
|
if (res.code === 200){
|
this.locationOption = res.data.locationList
|
this.screwNameList = res.data.paramCodeList
|
}
|
})
|
},
|
async queryChartMethod(){
|
//计算方式可以百度
|
let convertedData = []
|
await queryChart(this.queryParams).then(res => {
|
if (res.code === 200){
|
console.log('res',res)
|
let dataArray = []
|
if (res.data.length > 0){
|
res.data.forEach(x => {
|
let num = parseFloat(x)
|
dataArray.push(num)
|
})
|
}
|
console.log('res222',dataArray)
|
this.convertedData2 = dataArray
|
let array=dataArray
|
console.log('arra',array)
|
// 平均值
|
let mean=(array.reduce((a,b)=>a+b))/array.length
|
mean = mean.toFixed(2)
|
console.log('mean',mean)
|
// 方差
|
let variance=array.map(x=>{
|
return Math.pow(x-mean,2)
|
}).reduce((a,b)=>a+b)/array.length
|
console.log('variance222',variance)
|
// 标准差
|
let StandardDeviation = Math.sqrt(variance)
|
StandardDeviation = StandardDeviation.toFixed(2)
|
console.log('StandardDeviation',StandardDeviation)
|
console.log('mean-3*StandardDeviation',mean - 3*StandardDeviation)
|
console.log('mean+3*StandardDeviation',parseFloat(mean) + 3*StandardDeviation)
|
let step = 0.1
|
|
for(let x=mean-3*StandardDeviation; x<=parseFloat(mean) + 3*StandardDeviation; x = parseFloat((x+step).toFixed(2))){
|
console.log('x',x)
|
//for循环中的条件代表你要生成几个标准差的数据,
|
// 再带入正态分布公式,就可以生成一条整条分布曲线的数据
|
console.log('(StandardDeviation*Math.sqrt(2*(Math.PI)))',(StandardDeviation*Math.sqrt(2*(Math.PI))))
|
console.log('1/(StandardDeviation*Math.sqrt(2*(Math.PI)))',1/(StandardDeviation*Math.sqrt(2*(Math.PI))))
|
console.log('-(Math.pow(x-mean,2))',-(Math.pow(x-mean,2)))
|
console.log('(2*(Math.pow(parseFloat(StandardDeviation),2)))',(2*(Math.pow(parseFloat(StandardDeviation),2))))
|
const temp =1/(StandardDeviation*Math.sqrt(2*(Math.PI)))*Math.exp(-(Math.pow(x-mean,2))/(2*(Math.pow(parseFloat(StandardDeviation),2))))
|
console.log('temp',temp)
|
let y = parseFloat(temp.toFixed(2))
|
console.log('yyyyyyyyyyy',y)
|
let a = []
|
a = [x,y]
|
console.log('a',a)
|
convertedData.push(a)
|
}
|
}
|
})
|
console.log('34535435345',convertedData)
|
this.convertedData = convertedData
|
this.initChart1()
|
this.initChart2()
|
},
|
handleClick(tab, event) {
|
console.log(tab, event);
|
},
|
handleDateChange(value) {
|
if (value && value.length === 2) {
|
const startDate = value[0];
|
const endDate = value[1];
|
const dayCount = this.daysBetween(startDate, endDate);
|
if (dayCount + 1 > 2) {
|
this.$message.error('请选择连续的2天!');
|
this.queryParams.dateConditions = []; // 重置日期范围
|
}
|
}
|
},
|
daysBetween(startDate, endDate) {
|
const oneDay = 24 * 60 * 60 * 1000; // 每天的毫秒数
|
const startTime = new Date(startDate).getTime();
|
const endTime = new Date(endDate).getTime();
|
return Math.round(Math.abs((startTime - endTime) / oneDay));
|
},
|
/** 查询设备产品过程参数采集列表 */
|
getList() {
|
this.loading = true;
|
if ((this.queryParams.sfcCode == null || this.queryParams.sfcCode === '') && this.queryParams.dateConditions.length === 0){
|
this.$message({
|
message: '请输入发动机号码或者选择查询日期',
|
type: 'info'
|
});
|
} else {
|
queryDaParamCollectionListForSearch(this.queryParams).then(response => {
|
this.paramCollectionList = response.rows;
|
this.total = response.total;
|
this.loading = false;
|
});
|
}
|
|
},
|
// 取消按钮
|
cancel() {
|
this.open = false;
|
this.reset();
|
},
|
// 表单重置
|
reset() {
|
this.form = {
|
id: null,
|
workOrderNo: null,
|
sfcCode: null,
|
productCode: null,
|
productionLine: null,
|
locationCode: null,
|
equipmentNo: null,
|
paramCode: null,
|
paramValue: null,
|
paramUpper: null,
|
paramLower: null,
|
paramStandard: null,
|
collectionTime: null,
|
spareField1: null,
|
spareField2: null,
|
createUser: null,
|
createTime: null,
|
updateUser: null,
|
updateTime: null,
|
state: null,
|
paramName: null,
|
unit: null,
|
type: null
|
};
|
this.resetForm("form");
|
},
|
/** 搜索按钮操作 */
|
handleQuery() {
|
this.queryParams.pageNum = 1;
|
this.getList();
|
},
|
/** 重置按钮操作 */
|
resetQuery() {
|
this.resetForm("queryForm");
|
this.handleQuery();
|
},
|
// 多选框选中数据
|
handleSelectionChange(selection) {
|
this.ids = selection.map(item => item.id)
|
this.single = selection.length!==1
|
this.multiple = !selection.length
|
},
|
/** 新增按钮操作 */
|
handleAdd() {
|
this.reset();
|
this.open = true;
|
this.title = "添加设备产品过程参数采集";
|
},
|
/** 修改按钮操作 */
|
handleUpdate(row) {
|
this.reset();
|
const id = row.id || this.ids
|
getParamCollection(id).then(response => {
|
this.form = response.data;
|
this.open = true;
|
this.title = "修改设备产品过程参数采集";
|
});
|
},
|
/** 提交按钮 */
|
submitForm() {
|
this.$refs["form"].validate(valid => {
|
if (valid) {
|
if (this.form.id != null) {
|
updateParamCollection(this.form).then(response => {
|
this.$modal.msgSuccess("修改成功");
|
this.open = false;
|
this.getList();
|
});
|
} else {
|
addParamCollection(this.form).then(response => {
|
this.$modal.msgSuccess("新增成功");
|
this.open = false;
|
this.getList();
|
});
|
}
|
}
|
});
|
},
|
/** 删除按钮操作 */
|
handleDelete(row) {
|
const ids = row.id || this.ids;
|
this.$modal.confirm('是否确认删除设备产品过程参数采集编号为"' + ids + '"的数据项?').then(function() {
|
return delParamCollection(ids);
|
}).then(() => {
|
this.getList();
|
this.$modal.msgSuccess("删除成功");
|
}).catch(() => {});
|
},
|
/** 导出按钮操作 */
|
handleExport() {
|
this.download('main/paramCollection/export', {
|
...this.queryParams
|
}, `paramCollection_${new Date().getTime()}.xlsx`)
|
}
|
}
|
};
|
</script>
|