mirror of https://github.com/ElemeFE/element
Eliminate junk code
parent
0abc94e210
commit
7691439db7
|
@ -50,7 +50,7 @@ export default {
|
||||||
default: null
|
default: null
|
||||||
},
|
},
|
||||||
value: {
|
value: {
|
||||||
type: [String, Number, Date],
|
type: [String, Number],
|
||||||
default: ''
|
default: ''
|
||||||
},
|
},
|
||||||
prefix: {
|
prefix: {
|
||||||
|
@ -90,40 +90,43 @@ export default {
|
||||||
watch: {
|
watch: {
|
||||||
value: function() {
|
value: function() {
|
||||||
this.branch();
|
this.branch();
|
||||||
},
|
|
||||||
groupSeparator() {
|
|
||||||
this.dispose();
|
|
||||||
},
|
|
||||||
mulriple() {
|
|
||||||
this.dispose();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
branch() {
|
branch() {
|
||||||
let { timeIndices, countDown, dispose} = this;
|
let { timeIndices, countDown, dispose} = this;
|
||||||
if (timeIndices) {
|
timeIndices ? countDown() : dispose();
|
||||||
countDown(this.value.valueOf() || this.value);
|
|
||||||
} else {
|
|
||||||
dispose();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
magnification(num, mulriple = 1000, groupSeparator = ',') {
|
magnification(num, mulriple = 1000, groupSeparator = ',') {
|
||||||
// magnification factor
|
// magnification factor
|
||||||
const level = String(mulriple).length ;
|
const level = String(mulriple).length - 1;
|
||||||
return num.replace(new RegExp(`(\\d)(?=(\\d{${level - 1}})+$)`, 'g'), `$1${groupSeparator}`);
|
const reg = new RegExp(`\\d{1,${level}}(?=(\\d{${level}})+$)`, 'g');
|
||||||
|
const result = String(num)
|
||||||
|
.replace(reg, '$&,')
|
||||||
|
.split(',')
|
||||||
|
.join(groupSeparator);
|
||||||
|
return result;
|
||||||
},
|
},
|
||||||
dispose() {
|
dispose() {
|
||||||
let { value, rate, groupSeparator } = this;
|
let { value, precision, groupSeparator, rate } = this;
|
||||||
if (!isNumber(value)) return false;
|
if (!isNumber(value)) return false;
|
||||||
if (this.precision) {
|
|
||||||
value = value.toFixed(this.precision);
|
|
||||||
}
|
|
||||||
let [integer, decimal] = String(value).split('.');
|
let [integer, decimal] = String(value).split('.');
|
||||||
|
if (precision) {
|
||||||
|
decimal = `${decimal || ''}${(1)
|
||||||
|
.toFixed(precision)
|
||||||
|
.replace('.', '')
|
||||||
|
.slice(1)}`;
|
||||||
|
decimal = decimal.slice(0, precision);
|
||||||
|
}
|
||||||
|
let result = 0;
|
||||||
// 1000 multiplying power
|
// 1000 multiplying power
|
||||||
if (groupSeparator) {
|
if (groupSeparator) {
|
||||||
integer = this.magnification(integer, rate, groupSeparator);
|
integer = this.magnification(integer, rate, groupSeparator);
|
||||||
}
|
}
|
||||||
let result = `${integer}${decimal ? this.decimalSeparator + decimal : ''}`;
|
|
||||||
|
result = [integer, decimal].join(
|
||||||
|
decimal ? this.decimalSeparator : ''
|
||||||
|
);
|
||||||
this.disposeValue = result;
|
this.disposeValue = result;
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
@ -185,12 +188,12 @@ export default {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
countDown(timeVlaue) {
|
countDown() {
|
||||||
let {REFRESH_INTERVAL, timeTask, diffDate, formatTimeStr, stopTime, suspend } = this;
|
let {REFRESH_INTERVAL, timeTask, diffDate, formatTimeStr, stopTime, suspend} = this;
|
||||||
if (timeTask) return;
|
if (timeTask) return;
|
||||||
let than = this;
|
let than = this;
|
||||||
this.timeTask = setInterval(()=> {
|
this.timeTask = setInterval(()=> {
|
||||||
let diffTiem = diffDate(timeVlaue, Date.now());
|
let diffTiem = diffDate(than.value, Date.now());
|
||||||
than.disposeValue = formatTimeStr(diffTiem);
|
than.disposeValue = formatTimeStr(diffTiem);
|
||||||
stopTime(diffTiem);
|
stopTime(diffTiem);
|
||||||
}, REFRESH_INTERVAL);
|
}, REFRESH_INTERVAL);
|
||||||
|
|
Loading…
Reference in New Issue