#3402
This commit is contained in:
梁灏 2018-06-21 09:15:00 +08:00
parent 9c52988555
commit 7737645142
10 changed files with 467 additions and 156 deletions

File diff suppressed because one or more lines are too long

View file

@ -9,12 +9,12 @@
provide () { provide () {
return { return {
cellGroup: this cellGroup: this
} };
}, },
methods: { methods: {
handleClick (name) { handleClick (name) {
this.$emit('on-click', name); this.$emit('on-click', name);
} }
} }
} };
</script> </script>

View file

@ -28,5 +28,5 @@
default: '' default: ''
}, },
} }
} };
</script> </script>

View file

@ -70,7 +70,7 @@
data () { data () {
return { return {
prefixCls: prefixCls prefixCls: prefixCls
} };
}, },
computed: { computed: {
classes () { classes () {
@ -89,5 +89,5 @@
this.cellGroup.handleClick(this.name); this.cellGroup.handleClick(this.name);
} }
} }
} };
</script> </script>

View file

@ -50,8 +50,8 @@
slotClasses() { slotClasses() {
return [ return [
`${prefixCls}-inner-text`, `${prefixCls}-inner-text`,
] ];
}
} }
} }
};
</script> </script>

View file

@ -7,13 +7,26 @@
export default { export default {
name: 'Icon', name: 'Icon',
props: { props: {
type: {
type: String, type: String,
default: ''
},
size: [Number, String], size: [Number, String],
color: String color: String,
custom: {
type: String,
default: ''
}
}, },
computed: { computed: {
classes () { classes () {
return `${prefixCls} ${prefixCls}-${this.type}`; return [
`${prefixCls}`,
{
[`${prefixCls}-${this.type}`]: this.type !== '',
[`${this.custom}`]: this.custom !== '',
}
];
}, },
styles () { styles () {
let style = {}; let style = {};

View file

@ -1,2 +1,2 @@
import Split from './split.vue' import Split from './split.vue';
export default Split export default Split;

View file

@ -24,7 +24,7 @@
<script> <script>
import { oneOf } from '../../utils/assist'; import { oneOf } from '../../utils/assist';
import { on, off } from '../../utils/dom'; import { on, off } from '../../utils/dom';
import Trigger from './trigger.vue' import Trigger from './trigger.vue';
export default { export default {
name: 'Split', name: 'Split',
components: { components: {
@ -37,7 +37,7 @@ export default {
}, },
mode: { mode: {
validator (value) { validator (value) {
return oneOf(value, ['horizontal', 'vertical']) return oneOf(value, ['horizontal', 'vertical']);
}, },
default: 'horizontal' default: 'horizontal'
}, },
@ -62,94 +62,94 @@ export default {
offset: 0, offset: 0,
oldOffset: 0, oldOffset: 0,
isMoving: false isMoving: false
} };
}, },
computed: { computed: {
wrapperClasses () { wrapperClasses () {
return [ return [
`${this.prefix}-wrapper`, `${this.prefix}-wrapper`,
this.isMoving ? 'no-select' : '' this.isMoving ? 'no-select' : ''
] ];
}, },
isHorizontal () { isHorizontal () {
return this.mode === 'horizontal' return this.mode === 'horizontal';
}, },
anotherOffset () { anotherOffset () {
return 100 - this.offset return 100 - this.offset;
}, },
valueIsPx () { valueIsPx () {
return typeof this.value === 'string' return typeof this.value === 'string';
}, },
offsetSize () { offsetSize () {
return this.isHorizontal ? 'offsetWidth' : 'offsetHeight' return this.isHorizontal ? 'offsetWidth' : 'offsetHeight';
}, },
computedMin () { computedMin () {
return this.getComputedThresholdValue('min') return this.getComputedThresholdValue('min');
}, },
computedMax () { computedMax () {
return this.getComputedThresholdValue('max') return this.getComputedThresholdValue('max');
} }
}, },
methods: { methods: {
px2percent (numerator, denominator) { px2percent (numerator, denominator) {
return parseFloat(numerator) / parseFloat(denominator) return parseFloat(numerator) / parseFloat(denominator);
}, },
getComputedThresholdValue (type) { getComputedThresholdValue (type) {
let size = this.$refs.outerWrapper[this.offsetSize] let size = this.$refs.outerWrapper[this.offsetSize];
if (this.valueIsPx) return typeof this[type] === 'string' ? this[type] : size * this[type] if (this.valueIsPx) return typeof this[type] === 'string' ? this[type] : size * this[type];
else return typeof this[type] === 'string' ? this.px2percent(this[type], size) : this[type] else return typeof this[type] === 'string' ? this.px2percent(this[type], size) : this[type];
}, },
getMin (value1, value2) { getMin (value1, value2) {
if (this.valueIsPx) return `${Math.min(parseFloat(value1), parseFloat(value2))}px` if (this.valueIsPx) return `${Math.min(parseFloat(value1), parseFloat(value2))}px`;
else return Math.min(value1, value2) else return Math.min(value1, value2);
}, },
getMax (value1, value2) { getMax (value1, value2) {
if (this.valueIsPx) return `${Math.max(parseFloat(value1), parseFloat(value2))}px` if (this.valueIsPx) return `${Math.max(parseFloat(value1), parseFloat(value2))}px`;
else return Math.max(value1, value2) else return Math.max(value1, value2);
}, },
getAnotherOffset (value) { getAnotherOffset (value) {
let res = 0 let res = 0;
if (this.valueIsPx) res = `${this.$refs.outerWrapper[this.offsetSize] - parseFloat(value)}px` if (this.valueIsPx) res = `${this.$refs.outerWrapper[this.offsetSize] - parseFloat(value)}px`;
else res = 1 - value else res = 1 - value;
return res return res;
}, },
handleMove (e) { handleMove (e) {
let pageOffset = this.isHorizontal ? e.pageX : e.pageY let pageOffset = this.isHorizontal ? e.pageX : e.pageY;
let offset = pageOffset - this.initOffset let offset = pageOffset - this.initOffset;
let outerWidth = this.$refs.outerWrapper[this.offsetSize] let outerWidth = this.$refs.outerWrapper[this.offsetSize];
let value = this.valueIsPx ? `${parseFloat(this.oldOffset) + offset}px` : (this.px2percent(outerWidth * this.oldOffset + offset, outerWidth)) let value = this.valueIsPx ? `${parseFloat(this.oldOffset) + offset}px` : (this.px2percent(outerWidth * this.oldOffset + offset, outerWidth));
let anotherValue = this.getAnotherOffset(value) let anotherValue = this.getAnotherOffset(value);
if (parseFloat(value) <= parseFloat(this.computedMin)) value = this.getMax(value, this.computedMin) if (parseFloat(value) <= parseFloat(this.computedMin)) value = this.getMax(value, this.computedMin);
if (parseFloat(anotherValue) <= parseFloat(this.computedMax)) value = this.getAnotherOffset(this.getMax(anotherValue, this.computedMax)) if (parseFloat(anotherValue) <= parseFloat(this.computedMax)) value = this.getAnotherOffset(this.getMax(anotherValue, this.computedMax));
e.atMin = this.value === this.computedMin e.atMin = this.value === this.computedMin;
e.atMax = this.valueIsPx ? this.getAnotherOffset(this.value) === this.computedMax : this.getAnotherOffset(this.value).toFixed(5) === this.computedMax.toFixed(5) e.atMax = this.valueIsPx ? this.getAnotherOffset(this.value) === this.computedMax : this.getAnotherOffset(this.value).toFixed(5) === this.computedMax.toFixed(5);
this.$emit('input', value) this.$emit('input', value);
this.$emit('on-moving', e) this.$emit('on-moving', e);
}, },
handleUp () { handleUp () {
this.isMoving = false this.isMoving = false;
off(document, 'mousemove', this.handleMove) off(document, 'mousemove', this.handleMove);
off(document, 'mouseup', this.handleUp) off(document, 'mouseup', this.handleUp);
this.$emit('on-move-end') this.$emit('on-move-end');
}, },
handleMousedown (e) { handleMousedown (e) {
this.initOffset = this.isHorizontal ? e.pageX : e.pageY this.initOffset = this.isHorizontal ? e.pageX : e.pageY;
this.oldOffset = this.value this.oldOffset = this.value;
this.isMoving = true this.isMoving = true;
on(document, 'mousemove', this.handleMove) on(document, 'mousemove', this.handleMove);
on(document, 'mouseup', this.handleUp) on(document, 'mouseup', this.handleUp);
this.$emit('on-move-start') this.$emit('on-move-start');
} }
}, },
watch: { watch: {
value () { value () {
this.offset = (this.valueIsPx ? this.px2percent(this.value, this.$refs.outerWrapper[this.offsetSize]) : this.value) * 10000 / 100 this.offset = (this.valueIsPx ? this.px2percent(this.value, this.$refs.outerWrapper[this.offsetSize]) : this.value) * 10000 / 100;
} }
}, },
mounted () { mounted () {
this.$nextTick(() => { this.$nextTick(() => {
this.offset = (this.valueIsPx ? this.px2percent(this.value, this.$refs.outerWrapper[this.offsetSize]) : this.value) * 10000 / 100 this.offset = (this.valueIsPx ? this.px2percent(this.value, this.$refs.outerWrapper[this.offsetSize]) : this.value) * 10000 / 100;
}) });
}
} }
};
</script> </script>

View file

@ -16,24 +16,24 @@ export default {
return { return {
prefix: 'ivu-split-trigger', prefix: 'ivu-split-trigger',
initOffset: 0 initOffset: 0
} };
}, },
computed: { computed: {
isVertical () { isVertical () {
return this.mode === 'vertical' return this.mode === 'vertical';
}, },
classes () { classes () {
return [ return [
this.prefix, this.prefix,
this.isVertical ? `${this.prefix}-vertical` : `${this.prefix}-horizontal` this.isVertical ? `${this.prefix}-vertical` : `${this.prefix}-horizontal`
] ];
}, },
barConClasses () { barConClasses () {
return [ return [
`${this.prefix}-bar-con`, `${this.prefix}-bar-con`,
this.isVertical ? 'vertical' : 'horizontal' this.isVertical ? 'vertical' : 'horizontal'
] ];
}
} }
} }
};
</script> </script>

View file

@ -15,4 +15,4 @@ export default {
} }
} }
} }
} };