index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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.gradientColor0||config.border.gradientColor1)?`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,
  53. this.config.border.borderSecondaryColor
  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.gradientColor0':{
  72. handler (val) {
  73. this.changeColor()
  74. },immediate: true
  75. },
  76. 'config.border.gradientColor1':{
  77. handler (val) {
  78. this.changeColor()
  79. },immediate: true
  80. },
  81. 'config.border.gradientDirection':{
  82. handler (val) {
  83. this.changeColor()
  84. },immediate: true
  85. },
  86. 'config.border.opacity':{
  87. handler (val) {
  88. this.changeColor()
  89. },immediate: true
  90. }
  91. },
  92. mounted () {
  93. this.changeColor()
  94. },
  95. methods: {
  96. changeColor(){
  97. if(!this.config.border.opacity){
  98. this.config.border.opacity=100
  99. }
  100. if(!this.config.border.gradientColor0&&!this.config.border.gradientColor1) return
  101. if (document.querySelector(`#dataV${this.config.code}`)) {
  102. const borderElement = document.querySelector(`#dataV${this.config.code}`).querySelector('.border') || document.querySelector(`#dataV${this.config.code}`)?.querySelector('.dv-border-svg-container')
  103. if (borderElement) {
  104. borderElement.style.opacity = (this.config.border.opacity / 100)
  105. let gradientDirection = ''
  106. switch (this.config.border.gradientDirection) {
  107. case 'to right':
  108. gradientDirection = 'x1="0%" y1="0%" x2="100%" y2="0%"'
  109. break
  110. case 'to left':
  111. gradientDirection = 'x1="100%" y1="0%" x2="0%" y2="0%"'
  112. break
  113. case 'to bottom':
  114. gradientDirection = 'x1="0%" y1="0%" x2="0%" y2="100%"'
  115. break
  116. case 'to top':
  117. gradientDirection = 'x1="0%" y1="100%" x2="0%" y2="0%"'
  118. break
  119. case 'to bottom right':
  120. gradientDirection = 'x1="0%" y1="0%" x2="100%" y2="100%"'
  121. break
  122. case 'to bottom left':
  123. gradientDirection = 'x1="100%" y1="0%" x2="0%" y2="100%"'
  124. break
  125. case 'to top right':
  126. gradientDirection = 'x1="0%" y1="100%" x2="100%" y2="0%"'
  127. break
  128. case 'to top left':
  129. gradientDirection = 'x1="100%" y1="100%" x2="0%" y2="0%"'
  130. break
  131. default:
  132. gradientDirection = 'x1="0%" y1="0%" x2="100%" y2="0%"'
  133. break
  134. }
  135. // 在目标元素内的第一个位置插入 <defs> 和其中的内容
  136. borderElement.insertAdjacentHTML(
  137. 'afterbegin',
  138. `<defs>
  139. <linearGradient id="${this.borderBgId}" ${gradientDirection}>
  140. <stop offset="0%" stop-color="${this.config.border.gradientColor0?this.config.border.gradientColor0:this.config.border.gradientColor1}" />
  141. <stop offset="100%" stop-color="${this.config.border.gradientColor1?this.config.border.gradientColor1:this.config.border.gradientColor0}" />
  142. </linearGradient>
  143. </defs>`
  144. )
  145. }
  146. }
  147. }
  148. }
  149. }
  150. </script>
  151. <style lang="scss" scoped>
  152. .bs-design-wrap {
  153. position: absolute;
  154. width: 100%;
  155. height: 100%;
  156. background-color: transparent;
  157. border-radius: 4px;
  158. box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.1);
  159. box-sizing: border-box;
  160. }
  161. /*滚动条样式*/
  162. ::v-deep ::-webkit-scrollbar {
  163. width: 4px;
  164. border-radius: 4px;
  165. height: 4px;
  166. }
  167. ::v-deep ::-webkit-scrollbar-thumb {
  168. background: #dddddd !important;
  169. border-radius: 10px;
  170. }
  171. </style>