index.vue 5.2 KB

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