index.vue 5.2 KB

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