index.vue 5.3 KB

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