123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <template>
- <div
- class="border-box"
- :style="{
- backgroundColor: customize.backgroundColor
- }"
- >
- <div
- v-if="customize.diagonalType === 'leftTopRightBottom'"
- class="left-diagonal"
- >
- <div
- class="top"
- :style="{
- width: customize.borderLength + 'px',
- height: customize.borderWidth + 'px',
- borderTopRightRadius: customize.borderRadius + 'px',
- borderBottomRightRadius: customize.borderRadius + 'px',
- backgroundColor: customize.borderColor
- }"
- />
- <div
- class="left"
- :style="{
- width: customize.borderLength + 'px',
- height: customize.borderWidth + 'px',
- borderTopRightRadius: customize.borderRadius + 'px',
- borderBottomRightRadius: customize.borderRadius + 'px',
- backgroundColor: customize.borderColor
- }"
- />
- <div
- class="right"
- :style="{
- width: customize.borderLength + 'px',
- height: customize.borderWidth + 'px',
- borderTopLeftRadius: customize.borderRadius + 'px',
- borderBottomLeftRadius: customize.borderRadius + 'px',
- backgroundColor: customize.borderColor
- }"
- />
- <div
- class="bottom"
- :style="{
- width: customize.borderLength + 'px',
- height: customize.borderWidth + 'px',
- borderTopLeftRadius: customize.borderRadius + 'px',
- borderBottomLeftRadius: customize.borderRadius + 'px',
- backgroundColor: customize.borderColor
- }"
- />
- </div>
- <div
- v-if="customize.diagonalType === 'rightTopLeftBottom'"
- class="right-diagonal"
- >
- <div
- class="top"
- :style="{
- width: customize.borderLength + 'px',
- height: customize.borderWidth + 'px',
- borderTopLeftRadius: customize.borderRadius + 'px',
- borderBottomLeftRadius: customize.borderRadius + 'px',
- backgroundColor: customize.borderColor
- }"
- />
- <div
- class="right"
- :style="{
- width: customize.borderLength + 'px',
- height: customize.borderWidth + 'px',
- borderTopLeftRadius: customize.borderRadius + 'px',
- borderBottomLeftRadius: customize.borderRadius + 'px',
- backgroundColor: customize.borderColor
- }"
- />
- <div
- class="left"
- :style="{
- width: customize.borderLength + 'px',
- height: customize.borderWidth + 'px',
- borderTopRightRadius: customize.borderRadius + 'px',
- borderBottomRightRadius: customize.borderRadius + 'px',
- backgroundColor: customize.borderColor
- }"
- />
- <div
- class="bottom"
- :style="{
- width: customize.borderLength + 'px',
- height: customize.borderWidth + 'px',
- borderTopRightRadius: customize.borderRadius + 'px',
- borderBottomRightRadius: customize.borderRadius + 'px',
- backgroundColor: customize.borderColor
- }"
- />
- </div>
- </div>
- </template>
- <script>
- export default {
- name: 'DiagonalBorder',
- components: {
- },
- props: {
- config: {
- type: Object,
- default: () => ({})
- }
- },
- data () {
- return {
- }
- },
- computed: {
- option () {
- return this.config.option
- },
- optionData () {
- return this.option.data
- },
- customize () {
- return this.option.customize
- }
- },
- mounted () {
- if (this.customize.diagonalType === 'leftTopRightBottom') {
- const leftDiagonal = document.querySelector('.left-diagonal').querySelector('.left')
- const rightDiagonal = document.querySelector('.left-diagonal').querySelector('.right')
- leftDiagonal.style.left = `${this.customize.borderWidth / 2}px`
- leftDiagonal.style.top = `${this.customize.borderWidth / 2}px`
- rightDiagonal.style.right = `${this.customize.borderWidth / 2}px`
- rightDiagonal.style.bottom = `${this.customize.borderWidth / 2}px`
- } else {
- const leftDiagonal = document.querySelector('.right-diagonal').querySelector('.left')
- const rightDiagonal = document.querySelector('.right-diagonal').querySelector('.right')
- leftDiagonal.style.left = `${this.customize.borderWidth / 2}px`
- leftDiagonal.style.bottom = `${this.customize.borderWidth / 2}px`
- rightDiagonal.style.right = `${this.customize.borderWidth / 2}px`
- rightDiagonal.style.top = `${this.customize.borderWidth / 2}px`
- }
- },
- methods: { }
- }
- </script>
- <style lang="scss" scoped>
- .border-box {
- width: 100%;
- height: 100%;
- position: relative;
- .left-diagonal {
- .top {
- box-sizing: border-box;
- position: absolute;
- top: 0;
- left: 0;
- }
- // 顺时针旋转90度
- .left {
- box-sizing: border-box;
- position: absolute;
- top: 0;
- left: 0;
- transform: rotate(90deg);
- transform-origin: left;
- }
- .right {
- box-sizing: border-box;
- position: absolute;
- bottom: 0;
- right: 0;
- transform: rotate(90deg);
- transform-origin: right;
- }
- .bottom {
- box-sizing: border-box;
- position: absolute;
- bottom: 0;
- right: 0;
- transform-origin: right;
- }
- }
- .right-diagonal {
- .top {
- box-sizing: border-box;
- position: absolute;
- top: 0;
- right: 0;
- }
- .right {
- box-sizing: border-box;
- position: absolute;
- top: 0;
- right: 0;
- transform: rotate(-90deg);
- transform-origin: right;
- }
- .left {
- box-sizing: border-box;
- position: absolute;
- bottom: 0;
- left: 0;
- transform: rotate(-90deg);
- transform-origin: left;
- }
- .bottom {
- box-sizing: border-box;
- position: absolute;
- bottom: 0;
- left: 0;
- transform-origin: left;
- }
- }
- }
- </style>
|