index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <div
  3. style="width: 100%;height: 100%"
  4. class="bs-design-wrap"
  5. >
  6. <dv-border-box-5
  7. :id="'dataV' + config.code"
  8. :background-color="(config.border.gradientColor&&(config.border.gradientColor[0]||config.border.gradientColor[1]))?`url(#${borderBgId})`:'transparent'"
  9. :color='borderColor'
  10. :key="updateKey"
  11. :reverse='config.border.reverse'
  12. >
  13. <div class="element"
  14. v-if="config.border.isTitle"
  15. :style="`
  16. color:${color};
  17. font-size:${config.border.fontSize}px;
  18. line-height:${config.border.titleHeight}px;
  19. height:${config.border.titleHeight};
  20. padding:0 0 0 20px`"
  21. >
  22. {{config.title}}</div>
  23. </dv-border-box-5>
  24. </div>
  25. </template>
  26. <script>
  27. import { refreshComponentMixin } from 'data-room-ui/js/mixins/refreshComponent'
  28. import DvBorderBox5 from '@jiaminghi/data-view/lib/components/borderBox5/src/main.vue'
  29. import '@jiaminghi/data-view/lib/components/borderBox5/src/main.css'
  30. export default {
  31. name: 'Border5',
  32. components: {
  33. DvBorderBox5
  34. },
  35. mixins: [refreshComponentMixin],
  36. props: {
  37. // 卡片的属性
  38. config: {
  39. type: Object,
  40. default: () => ({})
  41. }
  42. },
  43. data () {
  44. return {
  45. borderBgId: `borderBg${this.config.code}`
  46. }
  47. },
  48. computed: {
  49. borderColor () {
  50. return this.config.border.borderMainColor ||
  51. this.config.border.borderSecondaryColor
  52. ? [
  53. this.config.border.borderMainColor,
  54. this.config.border.borderSecondaryColor
  55. ]
  56. : null
  57. },
  58. color () {
  59. return this.config.border.fontColor ? this.config.border.fontColor
  60. : '#fff'
  61. },
  62. },
  63. watch: {
  64. updateKey:{
  65. handler (val) {
  66. this.$nextTick(()=>{
  67. this.changeColor()
  68. })
  69. },
  70. deep: true
  71. },
  72. 'config.border.gradientColor':{
  73. handler (val) {
  74. this.changeColor()
  75. },immediate: true
  76. },
  77. 'config.border.gradientDirection':{
  78. handler (val) {
  79. this.changeColor()
  80. },immediate: true
  81. },
  82. 'config.border.opacity':{
  83. handler (val) {
  84. this.changeColor()
  85. },immediate: true
  86. }
  87. },
  88. mounted () {
  89. this.changeColor()
  90. },
  91. methods: {
  92. changeColor(){
  93. if(!this.config.border.opacity){
  94. this.config.border.opacity=100
  95. }
  96. if(!this.config.border.gradientColor) return
  97. if (document.querySelector(`#dataV${this.config.code}`)) {
  98. const borderElement = document.querySelector(`#dataV${this.config.code}`).querySelector('.border') || document.querySelector(`#dataV${this.config.code}`)?.querySelector('.dv-border-svg-container')
  99. if (borderElement) {
  100. borderElement.style.opacity = (this.config.border.opacity / 100)
  101. let gradientDirection = ''
  102. switch (this.config.border.gradientDirection) {
  103. case 'to right':
  104. gradientDirection = 'x1="0%" y1="0%" x2="100%" y2="0%"'
  105. break
  106. case 'to left':
  107. gradientDirection = 'x1="100%" y1="0%" x2="0%" y2="0%"'
  108. break
  109. case 'to bottom':
  110. gradientDirection = 'x1="0%" y1="0%" x2="0%" y2="100%"'
  111. break
  112. case 'to top':
  113. gradientDirection = 'x1="0%" y1="100%" x2="0%" y2="0%"'
  114. break
  115. case 'to bottom right':
  116. gradientDirection = 'x1="0%" y1="0%" x2="100%" y2="100%"'
  117. break
  118. case 'to bottom left':
  119. gradientDirection = 'x1="100%" y1="0%" x2="0%" y2="100%"'
  120. break
  121. case 'to top right':
  122. gradientDirection = 'x1="0%" y1="100%" x2="100%" y2="0%"'
  123. break
  124. case 'to top left':
  125. gradientDirection = 'x1="100%" y1="100%" x2="0%" y2="0%"'
  126. break
  127. default:
  128. gradientDirection = 'x1="0%" y1="0%" x2="100%" y2="0%"'
  129. break
  130. }
  131. // 在目标元素内的第一个位置插入 <defs> 和其中的内容
  132. borderElement.insertAdjacentHTML(
  133. 'afterbegin',
  134. `<defs>
  135. <linearGradient id="${this.borderBgId}" ${gradientDirection}>
  136. <stop offset="0%" stop-color="${this.config.border.gradientColor[0]?this.config.border.gradientColor[0]:this.config.border.gradientColor[1]}" />
  137. <stop offset="100%" stop-color="${this.config.border.gradientColor[1]?this.config.border.gradientColor[1]:this.config.border.gradientColor[0]}" />
  138. </linearGradient>
  139. </defs>`
  140. )
  141. }
  142. }
  143. }
  144. }
  145. }
  146. </script>
  147. <style lang="scss" scoped>
  148. .bs-design-wrap {
  149. position: absolute;
  150. width: 100%;
  151. height: 100%;
  152. // padding: 0 16px;
  153. background-color: transparent;
  154. border-radius: 4px;
  155. box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.1);
  156. box-sizing: border-box;
  157. }
  158. /*滚动条样式*/
  159. ::v-deep ::-webkit-scrollbar {
  160. width: 4px;
  161. border-radius: 4px;
  162. height: 4px;
  163. }
  164. ::v-deep ::-webkit-scrollbar-thumb {
  165. background: #dddddd !important;
  166. border-radius: 10px;
  167. }
  168. </style>