Replace let with const where variable is never reassigned in Vue files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-06 09:38:40 +08:00
parent 64372c7043
commit 1d0d938193
21 changed files with 176 additions and 191 deletions

View File

@@ -349,12 +349,12 @@ export default {
* @param {object} data new watch's value 監聽到後端傳來的報告 data
*/
setConformanceTempReportData(data){
let total = getNumberLabel(Object.values(data.counts).reduce((acc, val) => acc + val, 0));
let sum = data.counts.conforming + data.counts.not_conforming;
let rate = ((data.counts.conforming / sum) * 100).toFixed(1);
let isNullTime = value => value === null ? null : getNumberLabel((value / 86400).toFixed(1));
let isNullCase = value => value === null ? null : getNumberLabel(value.toFixed(1));
let setLoopData = value => value.map(item => {
const total = getNumberLabel(Object.values(data.counts).reduce((acc, val) => acc + val, 0));
const sum = data.counts.conforming + data.counts.not_conforming;
const rate = ((data.counts.conforming / sum) * 100).toFixed(1);
const isNullTime = value => value === null ? null : getNumberLabel((value / 86400).toFixed(1));
const isNullCase = value => value === null ? null : getNumberLabel(value.toFixed(1));
const setLoopData = value => value.map(item => {
return {
no: item.no,
label: item.description,
@@ -363,7 +363,7 @@ export default {
ratio: this.getPercentLabel(item.count / data.counts.conforming),
}
});
let setIssueData = value => value.map(item => {
const setIssueData = value => value.map(item => {
return {
no: item.no,
label: item.description,
@@ -372,10 +372,10 @@ export default {
ratio: this.getPercentLabel(item.count / data.counts.not_conforming),
}
});
let isNullLoops = value => value === null ? null : setLoopData(value);
let isNullIsssue = value => value === null ? null : setIssueData(value);
const isNullLoops = value => value === null ? null : setLoopData(value);
const isNullIsssue = value => value === null ? null : setIssueData(value);
let result = {
const result = {
total: `Total ${total}`,
counts: {
conforming: getNumberLabel(data.counts.conforming),
@@ -627,14 +627,14 @@ export default {
* @param {number} yMin Time Trend yMin
*/
setTimeChartData(data, xMax, xMin, yMax, yMin) {
let max = yMax * 1.1;
let xVal = timeRange(xMin, xMax, 100);
let yVal = yTimeRange(data, 100, yMin, yMax);
const max = yMax * 1.1;
const xVal = timeRange(xMin, xMax, 100);
const yVal = yTimeRange(data, 100, yMin, yMax);
xVal.map((x, index) => ({ x, y: yVal[index] }));
let formattedXVal = xVal.map(value => formatTime(value));
formattedXVal = formatMaxTwo(formattedXVal);
let selectTimeMinIndex = getXIndex(xVal, this.selectDurationTime.min);
let selectTimeMaxIndex = getXIndex(xVal, this.selectDurationTime.max);
const selectTimeMinIndex = getXIndex(xVal, this.selectDurationTime.min);
const selectTimeMaxIndex = getXIndex(xVal, this.selectDurationTime.max);
const start = selectTimeMinIndex;
const end = selectTimeMaxIndex;
const inside = (ctx, value) => ctx.p0DataIndex >= start && ctx.p1DataIndex <= end ? value : undefined;

View File

@@ -121,7 +121,7 @@ export default {
},
},
created() {
let newlist = JSON.parse(JSON.stringify(this.listSeq));
const newlist = JSON.parse(JSON.stringify(this.listSeq));
this.listSequence = this.isSubmit ? newlist : [];
this.$emitter.on('reset', (data) => {
this.listSequence = [];

View File

@@ -82,7 +82,7 @@ export default {
},
computed: {
selectCfmSeqSE: function() {
let data = [];
const data = [];
if(this.selectCfmSeqStart) data.push(this.selectCfmSeqStart);
if(this.selectCfmSeqEnd) data.push(this.selectCfmSeqEnd);
data.sort((a, b) => {
@@ -92,7 +92,7 @@ export default {
return data;
},
selectCfmPtEteSE: function() {
let data = [];
const data = [];
if(this.selectCfmPtEteSEStart) data.push(this.selectCfmPtEteSEStart);
if(this.selectCfmPtEteSEEnd) data.push(this.selectCfmPtEteSEEnd);
data.sort((a, b) => {
@@ -102,7 +102,7 @@ export default {
return data;
},
selectCfmPtPSE: function() {
let data = [];
const data = [];
if(this.selectCfmPtPSEStart) data.push(this.selectCfmPtPSEStart);
if(this.selectCfmPtPSEEnd) data.push(this.selectCfmPtPSEEnd);
data.sort((a, b) => {
@@ -112,7 +112,7 @@ export default {
return data;
},
selectCfmWtEteSE: function() {
let data = [];
const data = [];
if(this.selectCfmWtEteSEStart) data.push(this.selectCfmWtEteSEStart);
if(this.selectCfmWtEteSEEnd) data.push(this.selectCfmWtEteSEEnd);
data.sort((a, b) => {
@@ -122,7 +122,7 @@ export default {
return data;
},
selectCfmWtPSE: function() {
let data = [];
const data = [];
if(this.selectCfmWtPSEStart) data.push(this.selectCfmWtPSEStart);
if(this.selectCfmWtPSEEnd) data.push(this.selectCfmWtPSEEnd);
data.sort((a, b) => {
@@ -132,7 +132,7 @@ export default {
return data;
},
selectCfmCtEteSE: function() {
let data = [];
const data = [];
if(this.selectCfmCtEteSEStart) data.push(this.selectCfmCtEteSEStart);
if(this.selectCfmCtEteSEEnd) data.push(this.selectCfmCtEteSEEnd);
data.sort((a, b) => {
@@ -182,7 +182,7 @@ export default {
this.containstTasksData = data;
});
this.$emitter.on('actRadioData', (newData) => {
let data = JSON.parse(JSON.stringify(newData)); // 深拷貝原始 cases 的內容
const data = JSON.parse(JSON.stringify(newData)); // 深拷貝原始 cases 的內容
const categoryMapping = {
'cfmSeqStart': ['Start', 'selectCfmSeqStart', 'selectCfmSeqEnd'],

View File

@@ -93,7 +93,7 @@ export default {
return this.traceList.length;
},
traceList: function() {
let sum = this.listTraces.map(trace => trace.count).reduce((acc, cur) => acc + cur, 0);
const sum = this.listTraces.map(trace => trace.count).reduce((acc, cur) => acc + cur, 0);
return this.listTraces.map(trace => {
return {
@@ -148,7 +148,7 @@ export default {
this.showTraceId = newValue;
},
showTraceId: function(newValue, oldValue) {
let isScrollTop = document.querySelector('.infiniteTable');
const isScrollTop = document.querySelector('.infiniteTable');
if(isScrollTop && typeof isScrollTop.scrollTop !== 'undefined') if(newValue !== oldValue) isScrollTop.scrollTop = 0;
},
firstCases: function(newValue, oldValue){
@@ -240,7 +240,7 @@ export default {
*/
createCy(){
this.$nextTick(() => {
let graphId = this.$refs.cfmTrace;
const graphId = this.$refs.cfmTrace;
this.setNodesData();
this.setEdgesData();

View File

@@ -195,11 +195,10 @@ export default {
attRangeData: function() {
let data = [];
const type = this.selectedAttName.type;
let sum = this.selectedAttName.options.map(item => item.freq).reduce((acc, cur) => acc + cur, 0);
const sum = this.selectedAttName.options.map(item => item.freq).reduce((acc, cur) => acc + cur, 0);
data = this.selectedAttName.options.map((item, index) => {
let result;
let ratio = item.freq / sum;
result = {
const ratio = item.freq / sum;
const result = {
id: index + 1,
key: this.selectedAttName.key,
type: type,
@@ -231,8 +230,8 @@ export default {
sliderData: function() {
let xAxisMin;
let xAxisMax;
let min = this.valueData.min;
let max = this.valueData.max;
const min = this.valueData.min;
const max = this.valueData.max;
const type = this.valueData.type;
switch (type) {
case 'dummy':
@@ -245,8 +244,8 @@ export default {
xAxisMax = max;
break;
}
let range = xAxisMax - xAxisMin;
let step = range / this.selectRange;
const range = xAxisMax - xAxisMin;
const step = range / this.selectRange;
let sliderData = []
for (let i = 0; i <= this.selectRange; i++) {
@@ -276,7 +275,6 @@ export default {
attValueTypeStartEnd: function() {
let start;
let end;
let data;
const type = this.selectedAttName.type;
switch (type) {
@@ -290,7 +288,7 @@ export default {
end = this.valueEnd;
break;
}
data = { // 傳給後端的資料
const data = { // 傳給後端的資料
type: type,
data: {
key: this.selectedAttName.key,
@@ -303,11 +301,11 @@ export default {
return [start, end];
},
labelsData: function() {
let min = new Date(this.valueData.min).getTime();
let max = new Date(this.valueData.max).getTime();
let numPoints = 11;
let step = (max - min) / (numPoints - 1);
let data = [];
const min = new Date(this.valueData.min).getTime();
const max = new Date(this.valueData.max).getTime();
const numPoints = 11;
const step = (max - min) / (numPoints - 1);
const data = [];
for(let i = 0; i< numPoints; i++) {
const x = min + i * step;
data.push(x);
@@ -435,8 +433,8 @@ export default {
* @param {object} chart 取得 chart.js 資料
*/
resizeMask(chart) {
let from = (this.selectArea[0] * 0.01) / (this.selectRange * 0.01);
let to = (this.selectArea[1] * 0.01) / (this.selectRange * 0.01);
const from = (this.selectArea[0] * 0.01) / (this.selectRange * 0.01);
const to = (this.selectArea[1] * 0.01) / (this.selectRange * 0.01);
this.resizeLeftMask(chart, from);
this.resizeRightMask(chart, to);
},
@@ -630,9 +628,9 @@ export default {
*/
changeSelectArea(e) {
// 日曆改變時,滑塊跟著改變
let sliderData = this.sliderData;
let start = sliderData[e[0].toFixed()];
let end = sliderData[e[1].toFixed()]; // 取得 index須為整數。
const sliderData = this.sliderData;
const start = sliderData[e[0].toFixed()];
const end = sliderData[e[1].toFixed()]; // 取得 index須為整數。
switch (this.selectedAttName.type) {
case 'dummy':
@@ -663,8 +661,8 @@ export default {
*/
sliderValueRange(e, direction) {
// 找到最鄰近的 index時間格式: 毫秒時間戳
let sliderData = this.sliderData;
let isDateType = this.selectedAttName.type === 'date';
const sliderData = this.sliderData;
const isDateType = this.selectedAttName.type === 'date';
let targetTime = [];
let inputValue;

View File

@@ -59,7 +59,7 @@ export default {
* @param {numble} index rule's index
*/
isRule(e, index){
let rule = this.isRuleData[index];
const rule = this.isRuleData[index];
// 先取得 rule object
// 為了讓 data 順序不亂掉,將值指向 0submitAll 時再刪掉
if(!e) this.temporaryData[index] = 0;

View File

@@ -67,19 +67,19 @@ export default{
computed: {
// user select time start and end
timeFrameStartEnd: function() {
let start = getMoment(this.startTime).format('YYYY-MM-DDTHH:mm:00');
let end = getMoment(this.endTime).format('YYYY-MM-DDTHH:mm:00');
const start = getMoment(this.startTime).format('YYYY-MM-DDTHH:mm:00');
const end = getMoment(this.endTime).format('YYYY-MM-DDTHH:mm:00');
this.selectTimeFrame = [start, end]; // 傳給後端的資料
return [start, end];
},
// 找出 slidrData時間格式:毫秒時間戳
sliderData: function() {
let xAxisMin = new Date(this.filterTimeframe.x_axis.min).getTime();
let xAxisMax = new Date(this.filterTimeframe.x_axis.max).getTime();
let range = xAxisMax - xAxisMin;
let step = range / this.selectRange;
let sliderData = []
const xAxisMin = new Date(this.filterTimeframe.x_axis.min).getTime();
const xAxisMax = new Date(this.filterTimeframe.x_axis.max).getTime();
const range = xAxisMax - xAxisMin;
const step = range / this.selectRange;
const sliderData = []
for (let i = 0; i <= this.selectRange; i++) {
sliderData.push(xAxisMin + (step * i));
@@ -89,7 +89,7 @@ export default{
},
// 加入最大、最小值
timeFrameData: function(){
let data = this.filterTimeframe.data.map(i=>({x:i.x,y:i.y}))
const data = this.filterTimeframe.data.map(i=>({x:i.x,y:i.y}))
// y 軸斜率計算請參考 ./public/timeFrameSlope 的圖
// x 值為 0 ~ 11,
// 將三的座標(ax, ay), (bx, by), (cx, cy)命名為 (a, b), (c, d), (e, f)
@@ -97,22 +97,22 @@ export default{
// 最大值: (f - b)(e - c) = (f - d)(e - a),求 f = (be - bc -de + da) / (a - c)
// y 軸最小值
let a = 0;
const a = 0;
let b;
let c = 1;
let d = this.filterTimeframe.data[0].y;
let e = 2;
let f = this.filterTimeframe.data[1].y;
const c = 1;
const d = this.filterTimeframe.data[0].y;
const e = 2;
const f = this.filterTimeframe.data[1].y;
b = (e*d - a*d - f*a - f*c) / (e - c - a);
if(b < 0) {
b = 0;
}
// y 軸最大值
let ma = 9;
let mb = this.filterTimeframe.data[8].y;
let mc = 10;
let md = this.filterTimeframe.data[9].y;
let me = 11;
const ma = 9;
const mb = this.filterTimeframe.data[8].y;
const mc = 10;
const md = this.filterTimeframe.data[9].y;
const me = 11;
let mf = (mb*me - mb*mc -md*me + md*ma) / (ma - mc);
if(mf < 0) {
mf = 0;
@@ -132,11 +132,11 @@ export default{
return data;
},
labelsData: function() {
let min = new Date(this.filterTimeframe.x_axis.min_base).getTime();
let max = new Date(this.filterTimeframe.x_axis.max_base).getTime();
let numPoints = 11;
let step = (max - min) / (numPoints - 1);
let data = [];
const min = new Date(this.filterTimeframe.x_axis.min_base).getTime();
const max = new Date(this.filterTimeframe.x_axis.max_base).getTime();
const numPoints = 11;
const step = (max - min) / (numPoints - 1);
const data = [];
for(let i = 0; i< numPoints; i++) {
const x = min + i * step;
data.push(x);
@@ -160,8 +160,8 @@ export default{
* @param {object} chart 取得 chart.js 資料
*/
resizeMask(chart) {
let from = (this.selectArea[0] * 0.01) / (this.selectRange * 0.01);
let to = (this.selectArea[1] * 0.01) / (this.selectRange * 0.01);
const from = (this.selectArea[0] * 0.01) / (this.selectRange * 0.01);
const to = (this.selectArea[1] * 0.01) / (this.selectRange * 0.01);
if(this.selectValue[0] === 'Timeframes') {
this.resizeLeftMask(chart, from);
this.resizeRightMask(chart, to);
@@ -295,9 +295,9 @@ export default{
*/
changeSelectArea(e) {
// 日曆改變時,滑塊跟著改變
let sliderData = this.sliderData;
let start = sliderData[e[0].toFixed()];
let end = sliderData[e[1].toFixed()]; // 取得 index須為整數。
const sliderData = this.sliderData;
const start = sliderData[e[0].toFixed()];
const end = sliderData[e[1].toFixed()]; // 取得 index須為整數。
this.startTime = new Date(start);
this.endTime = new Date(end);
@@ -316,7 +316,7 @@ export default{
*/
sliderTimeRange(e, direction) {
// 找到最鄰近的 index時間格式: 毫秒時間戳
let sliderData = this.sliderData;
const sliderData = this.sliderData;
const targetTime = [new Date(this.timeFrameStartEnd[0]).getTime(), new Date(this.timeFrameStartEnd[1]).getTime()];
const closestIndexes = targetTime.map(target => {
let closestIndex = 0;

View File

@@ -117,7 +117,7 @@ export default {
}).slice(this.selectArea[0], this.selectArea[1]);
},
caseTotalPercent: function() {
let ratioSum = this.traceList.map(trace => trace.base_count).reduce((acc, cur) => acc + cur, 0) / this.traceCountTotal;
const ratioSum = this.traceList.map(trace => trace.base_count).reduce((acc, cur) => acc + cur, 0) / this.traceCountTotal;
return this.getPercentLabel(ratioSum)
},
chartData: function() {
@@ -170,7 +170,7 @@ export default {
},
watch: {
selectArea: function(newValue, oldValue) {
let roundValue = Math.round(newValue[1].toFixed());
const roundValue = Math.round(newValue[1].toFixed());
if(newValue[1] !== roundValue) this.selectArea[1] = roundValue;
if(newValue != oldValue) this.$emit('filter-trace-selectArea', newValue); // 判斷 Apply 是否 disable
},
@@ -178,7 +178,7 @@ export default {
if(newValue === 404) this.infinitMaxItems = true;
},
showTraceId: function(newValue, oldValue) {
let isScrollTop = document.querySelector('.infiniteTable');
const isScrollTop = document.querySelector('.infiniteTable');
if(isScrollTop && typeof isScrollTop.scrollTop !== 'undefined') if(newValue !== oldValue) isScrollTop.scrollTop = 0;
},
},
@@ -310,7 +310,7 @@ export default {
* create trace cytoscape's map
*/
createCy(){
let graphId = this.$refs.cyTrace;
const graphId = this.$refs.cyTrace;
this.setNodesData();
this.setEdgesData();

View File

@@ -293,9 +293,9 @@ export default {
* @param {array} array filterStartToEnd / filterEndToStart可傳入以上任一。
*/
setActData(array) {
let list = [];
const list = [];
array.forEach((task, index) => {
let data = {
const data = {
label: task.label,
occ_value: Number(task.occurrence_ratio * 100),
occurrences: task.occurrences.toLocaleString('en-US'),
@@ -389,7 +389,7 @@ export default {
setRule(e) {
let label, type;
const includeStr = e.is_exclude? "exclude" : "include";
let containmentMap = {
const containmentMap = {
'occurred-in' : 'contained in',
'started-in' : 'started in',
'completed-in' : 'ended in',

View File

@@ -92,8 +92,8 @@ export default {
return this.traces.length;
},
traceList: function() {
let sum = this.traces.map(trace => trace.count).reduce((acc, cur) => acc + cur, 0);
let result = this.traces.map(trace => {
const sum = this.traces.map(trace => trace.count).reduce((acc, cur) => acc + cur, 0);
const result = this.traces.map(trace => {
return {
id: trace.id,
value: this.progressWidth(Number(((trace.count / sum) * 100).toFixed(1))),
@@ -143,7 +143,7 @@ export default {
immediate: true
},
showTraceId: function(newValue, oldValue) {
let isScrollTop = document.querySelector('.infiniteTable');
const isScrollTop = document.querySelector('.infiniteTable');
if(isScrollTop && typeof isScrollTop.scrollTop !== 'undefined') if(newValue !== oldValue) isScrollTop.scrollTop = 0;
},
infiniteFirstCases: function(newValue){
@@ -226,7 +226,7 @@ export default {
* create trace cytoscape's map
*/
createCy(){
let graphId = this.$refs.cyTrace;
const graphId = this.$refs.cyTrace;
this.setNodesData();
this.setEdgesData();

View File

@@ -144,9 +144,9 @@ export default {
}
},
async mounted() {
let params = this.$route.params;
let file = this.$route.meta.file;
let isCheckPage = this.$route.name.includes('Check');
const params = this.$route.params;
const file = this.$route.meta.file;
const isCheckPage = this.$route.name.includes('Check');
switch (params.type) {
case 'log':

View File

@@ -214,7 +214,7 @@ export default {
*/
getNavViewName() {
let name = this.$route.name;
const name = this.$route.name;
let valueToSet;
if(this.$route.name === 'NotFound404') {

View File

@@ -131,7 +131,7 @@ export default {
},
inputTimeFields: {
get() {
let paddedTimeFields = [];
const paddedTimeFields = [];
this.inputTypes.forEach(inputTypeUnit => {
// Pad the dd/hh/mm/ss field string to 2 digits and add it to the list
paddedTimeFields.push(this.tUnits[inputTypeUnit].val.toString().padStart(2, '0'));
@@ -193,7 +193,7 @@ export default {
* @param {event} event input 傳入的事件
*/
onChange(event) {
let baseInputValue = event.target.value;
const baseInputValue = event.target.value;
let decoratedInputValue;
// 讓前綴數字自動補 0
if(isNaN(event.target.value)){
@@ -276,7 +276,7 @@ export default {
* @returns {number} 新的數值
*/
getNewValue(input) {
let newVal = parseInt(input.value, 10);
const newVal = parseInt(input.value, 10);
return isNaN(newVal) ? 0 : newVal;
},
@@ -398,7 +398,7 @@ export default {
* 初始化
*/
async createData() {
let size = this.size;
const size = this.size;
if (this.maxTotal !== await null && this.minTotal !== await null) {
switch (size) {
@@ -438,7 +438,7 @@ export default {
directives: {
'closable': {
mounted(el, {value}) {
let handleOutsideClick = function(e) {
const handleOutsideClick = function(e) {
let target = e.target;
while (target && target.id !== value.id) {
target = target.parentElement;