index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <div
  3. class="border-box"
  4. :style="{
  5. backgroundColor: customize.backgroundColor
  6. }"
  7. >
  8. <div
  9. v-if="customize.diagonalType === 'leftTopRightBottom'"
  10. class="left-diagonal"
  11. >
  12. <div
  13. class="top"
  14. :style="{
  15. width: customize.borderLength + 'px',
  16. height: customize.borderWidth + 'px',
  17. borderTopRightRadius: customize.borderRadius + 'px',
  18. borderBottomRightRadius: customize.borderRadius + 'px',
  19. backgroundColor: customize.borderColor
  20. }"
  21. />
  22. <div
  23. class="left"
  24. :style="{
  25. width: customize.borderLength + 'px',
  26. height: customize.borderWidth + 'px',
  27. borderTopRightRadius: customize.borderRadius + 'px',
  28. borderBottomRightRadius: customize.borderRadius + 'px',
  29. backgroundColor: customize.borderColor
  30. }"
  31. />
  32. <div
  33. class="right"
  34. :style="{
  35. width: customize.borderLength + 'px',
  36. height: customize.borderWidth + 'px',
  37. borderTopLeftRadius: customize.borderRadius + 'px',
  38. borderBottomLeftRadius: customize.borderRadius + 'px',
  39. backgroundColor: customize.borderColor
  40. }"
  41. />
  42. <div
  43. class="bottom"
  44. :style="{
  45. width: customize.borderLength + 'px',
  46. height: customize.borderWidth + 'px',
  47. borderTopLeftRadius: customize.borderRadius + 'px',
  48. borderBottomLeftRadius: customize.borderRadius + 'px',
  49. backgroundColor: customize.borderColor
  50. }"
  51. />
  52. </div>
  53. <div
  54. v-if="customize.diagonalType === 'rightTopLeftBottom'"
  55. class="right-diagonal"
  56. >
  57. <div
  58. class="top"
  59. :style="{
  60. width: customize.borderLength + 'px',
  61. height: customize.borderWidth + 'px',
  62. borderTopLeftRadius: customize.borderRadius + 'px',
  63. borderBottomLeftRadius: customize.borderRadius + 'px',
  64. backgroundColor: customize.borderColor
  65. }"
  66. />
  67. <div
  68. class="right"
  69. :style="{
  70. width: customize.borderLength + 'px',
  71. height: customize.borderWidth + 'px',
  72. borderTopLeftRadius: customize.borderRadius + 'px',
  73. borderBottomLeftRadius: customize.borderRadius + 'px',
  74. backgroundColor: customize.borderColor
  75. }"
  76. />
  77. <div
  78. class="left"
  79. :style="{
  80. width: customize.borderLength + 'px',
  81. height: customize.borderWidth + 'px',
  82. borderTopRightRadius: customize.borderRadius + 'px',
  83. borderBottomRightRadius: customize.borderRadius + 'px',
  84. backgroundColor: customize.borderColor
  85. }"
  86. />
  87. <div
  88. class="bottom"
  89. :style="{
  90. width: customize.borderLength + 'px',
  91. height: customize.borderWidth + 'px',
  92. borderTopRightRadius: customize.borderRadius + 'px',
  93. borderBottomRightRadius: customize.borderRadius + 'px',
  94. backgroundColor: customize.borderColor
  95. }"
  96. />
  97. </div>
  98. </div>
  99. </template>
  100. <script>
  101. export default {
  102. name: 'DiagonalBorder',
  103. components: {
  104. },
  105. props: {
  106. config: {
  107. type: Object,
  108. default: () => ({})
  109. }
  110. },
  111. data () {
  112. return {
  113. }
  114. },
  115. computed: {
  116. option () {
  117. return this.config.option
  118. },
  119. optionData () {
  120. return this.option.data
  121. },
  122. customize () {
  123. return this.option.customize
  124. }
  125. },
  126. mounted () {
  127. if (this.customize.diagonalType === 'leftTopRightBottom') {
  128. const leftDiagonal = document.querySelector('.left-diagonal').querySelector('.left')
  129. const rightDiagonal = document.querySelector('.left-diagonal').querySelector('.right')
  130. leftDiagonal.style.left = `${this.customize.borderWidth / 2}px`
  131. leftDiagonal.style.top = `${this.customize.borderWidth / 2}px`
  132. rightDiagonal.style.right = `${this.customize.borderWidth / 2}px`
  133. rightDiagonal.style.bottom = `${this.customize.borderWidth / 2}px`
  134. } else {
  135. const leftDiagonal = document.querySelector('.right-diagonal').querySelector('.left')
  136. const rightDiagonal = document.querySelector('.right-diagonal').querySelector('.right')
  137. leftDiagonal.style.left = `${this.customize.borderWidth / 2}px`
  138. leftDiagonal.style.bottom = `${this.customize.borderWidth / 2}px`
  139. rightDiagonal.style.right = `${this.customize.borderWidth / 2}px`
  140. rightDiagonal.style.top = `${this.customize.borderWidth / 2}px`
  141. }
  142. },
  143. methods: { }
  144. }
  145. </script>
  146. <style lang="scss" scoped>
  147. .border-box {
  148. width: 100%;
  149. height: 100%;
  150. position: relative;
  151. .left-diagonal {
  152. .top {
  153. box-sizing: border-box;
  154. position: absolute;
  155. top: 0;
  156. left: 0;
  157. }
  158. // 顺时针旋转90度
  159. .left {
  160. box-sizing: border-box;
  161. position: absolute;
  162. top: 0;
  163. left: 0;
  164. transform: rotate(90deg);
  165. transform-origin: left;
  166. }
  167. .right {
  168. box-sizing: border-box;
  169. position: absolute;
  170. bottom: 0;
  171. right: 0;
  172. transform: rotate(90deg);
  173. transform-origin: right;
  174. }
  175. .bottom {
  176. box-sizing: border-box;
  177. position: absolute;
  178. bottom: 0;
  179. right: 0;
  180. transform-origin: right;
  181. }
  182. }
  183. .right-diagonal {
  184. .top {
  185. box-sizing: border-box;
  186. position: absolute;
  187. top: 0;
  188. right: 0;
  189. }
  190. .right {
  191. box-sizing: border-box;
  192. position: absolute;
  193. top: 0;
  194. right: 0;
  195. transform: rotate(-90deg);
  196. transform-origin: right;
  197. }
  198. .left {
  199. box-sizing: border-box;
  200. position: absolute;
  201. bottom: 0;
  202. left: 0;
  203. transform: rotate(-90deg);
  204. transform-origin: left;
  205. }
  206. .bottom {
  207. box-sizing: border-box;
  208. position: absolute;
  209. bottom: 0;
  210. left: 0;
  211. transform-origin: left;
  212. }
  213. }
  214. }
  215. </style>