index.vue 5.3 KB

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