index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <el-select
  3. :key="config.code"
  4. v-model="value"
  5. :popper-class="'basic-component-select select-popper-' + config.code"
  6. :class="['basic-component-select', `select-${config.code}`]"
  7. :placeholder="config.customize.placeholder"
  8. clearable
  9. :filterable="filterable"
  10. :style="{'--input-placeholder-color':config.customize.placeholderColor,'--input-placeholder-font-size':config.customize.placeholderFontSize + 'px'}"
  11. @visible-change="visibleChange"
  12. @change="selectChange"
  13. @mouseenter.native="mouseenter"
  14. >
  15. <el-option
  16. v-for="(option, key) in optionData"
  17. :key="key"
  18. :label="option[config.dataSource.dimensionField]"
  19. :value="option[config.dataSource.metricField]"
  20. />
  21. </el-select>
  22. </template>
  23. <script>
  24. import commonMixins from 'data-room-ui/js/mixins/commonMixins'
  25. import linkageMixins from 'data-room-ui/js/mixins/linkageMixins'
  26. import { settingToTheme } from 'data-room-ui/js/utils/themeFormatting'
  27. import cloneDeep from 'lodash/cloneDeep'
  28. window.dataSetFields = []
  29. export default {
  30. name: 'BasicComponentSelect',
  31. components: {},
  32. mixins: [commonMixins, linkageMixins],
  33. props: {
  34. // 组件配置
  35. config: {
  36. type: Object,
  37. default: () => ({})
  38. }
  39. },
  40. data () {
  41. return {
  42. value: '',
  43. innerConfig: {},
  44. optionData: [],
  45. filterable: false
  46. }
  47. },
  48. computed: {
  49. isPreview () {
  50. return (this.$route.path === window?.BS_CONFIG?.routers?.previewUrl) || (this.$route.path === '/big-screen/preview')
  51. }
  52. },
  53. watch: {},
  54. created () {
  55. },
  56. mounted () {
  57. this.changeStyle(this.config)
  58. if (this.isPreview) {
  59. this.filterable = true
  60. } else {
  61. document.querySelector(`.select-${this.config.code}`).style.pointerEvents = 'none'
  62. }
  63. },
  64. beforeDestroy () { },
  65. methods: {
  66. dataFormatting (config, data) {
  67. // 数据返回成功则赋值
  68. if (data.success) {
  69. data = data.data
  70. // 获取到后端返回的数据,有则赋值
  71. if (config.dataHandler) {
  72. try {
  73. // 此处函数处理data
  74. eval(config.dataHandler)
  75. } catch (e) {
  76. console.info(e)
  77. }
  78. }
  79. this.optionData = data
  80. // 语音播报
  81. } else {
  82. // 数据返回失败则赋前端的模拟数据
  83. config.option.data = []
  84. this.optionData = []
  85. }
  86. return config
  87. },
  88. changeStyle (config) {
  89. config = { ...this.config, ...config }
  90. // 样式改变时更新主题配置
  91. config.theme = settingToTheme(cloneDeep(config), this.customTheme)
  92. this.changeChartConfig(config)
  93. this.innerConfig = config
  94. // 选择器元素
  95. const selectInputEl = document.querySelector(`.select-${config.code} .el-input__inner`)
  96. // 背景颜色
  97. selectInputEl.style.backgroundColor = config.customize.backgroundColor
  98. // 字体大小
  99. selectInputEl.style.fontSize = config.customize.fontSize + 'px'
  100. // 字体颜色
  101. selectInputEl.style.color = config.customize.fontColor
  102. // 边框颜色
  103. selectInputEl.style.borderColor = config.customize.borderColor
  104. // 下拉图标
  105. const selectDropdownIcon = document.querySelector(`.select-${config.code} .el-icon-arrow-up`)
  106. selectDropdownIcon.style.fontSize = config.customize.fontSize + 'px'
  107. // 选择器下拉框元素
  108. const selectDropdownEl = document.querySelector(`.select-${config.code} .el-select-dropdown`)
  109. // 箭头背景颜色和下拉框背景颜色一致
  110. if (selectDropdownEl) {
  111. // 下拉框无边框
  112. selectDropdownEl.style.border = 'none'
  113. // 背景颜色
  114. selectDropdownEl.style.backgroundColor = config.customize.dropDownBackgroundColor
  115. }
  116. },
  117. // 组件联动
  118. selectChange (val) {
  119. if (val) {
  120. this.linkage(this.optionData.find(item => item[this.config.dataSource.metricField] === val))
  121. }
  122. },
  123. visibleChange (val) {
  124. if (val) {
  125. // 修改下拉框背景颜色,让下拉框背景颜色和箭头背景颜色一致
  126. const selectDropdownEl = document.querySelector(`.select-popper-${this.innerConfig.code}`)
  127. selectDropdownEl.style.color = this.innerConfig.customize.dropDownBackgroundColor
  128. // 空状态
  129. const selectDropdownEmptyEl = document.querySelector(`.select-popper-${this.innerConfig.code} .el-select-dropdown__empty`)
  130. if (selectDropdownEmptyEl) {
  131. selectDropdownEmptyEl.style.backgroundColor = this.innerConfig.customize.dropDownBackgroundColor
  132. }
  133. // 下拉项hover颜色
  134. const selectDropdownWrap = document.querySelector(`.select-popper-${this.innerConfig.code} .el-select-dropdown__wrap`)
  135. selectDropdownWrap.style.setProperty('--drop-down-hover-font-color', this.innerConfig.customize.dropDownHoverFontColor)
  136. selectDropdownWrap.style.setProperty('--drop-down-hover-background-color', this.innerConfig.customize.dropDownHoverBackgroundColor)
  137. }
  138. // 不是激活项的还是使用背景颜色
  139. const selectDropdownItemEl = document.querySelectorAll(`.select-popper-${this.innerConfig.code} .el-select-dropdown__item`)
  140. selectDropdownItemEl.forEach(item => {
  141. // 检查是否是激活项,不是则使用背景颜色
  142. if (!item.classList.contains('selected')) {
  143. item.style.color = this.innerConfig.customize.dropDownFontColor
  144. item.style.backgroundColor = this.innerConfig.customize.dropDownBackgroundColor
  145. }
  146. })
  147. },
  148. // 鼠标进入
  149. mouseenter () {
  150. if (this.value) {
  151. setTimeout(() => {
  152. // 清空图标
  153. const selectDropdownCloseIcon = document.querySelector(`.select-${this.innerConfig.code} .el-icon-circle-close`)
  154. if (selectDropdownCloseIcon) {
  155. selectDropdownCloseIcon.style.fontSize = this.innerConfig.customize.fontSize + 'px'
  156. }
  157. }, 30)
  158. }
  159. }
  160. }
  161. }
  162. </script>
  163. <style lang="scss">
  164. .basic-component-select {
  165. .el-select-dropdown__wrap {
  166. margin-bottom: 0px !important;
  167. }
  168. .el-select-group__wrap:not(:last-of-type)::after {
  169. background-color: transparent !important;
  170. }
  171. .popper__arrow {
  172. bottom: -6px !important;
  173. border-top-color: var(--color) !important;
  174. border-bottom-color: var(--color) !important;
  175. &::after {
  176. bottom: 0px !important;
  177. border-top-color: var(--color) !important;
  178. border-bottom-color: var(--color) !important;
  179. }
  180. }
  181. }
  182. </style>
  183. <style lang="scss" scoped>
  184. .basic-component-select {
  185. width: 100%;
  186. height: 100%;
  187. ::v-deep .el-input {
  188. height: 100% !important;
  189. .el-select__caret {
  190. width: 100%;
  191. height: 100%;
  192. display: flex;
  193. align-items: center;
  194. }
  195. // 选择器输入框样式
  196. .el-input__inner {
  197. height: 100% !important;
  198. }
  199. }
  200. ::v-deep .el-input__inner::placeholder {
  201. color: var(--input-placeholder-color);
  202. font-size: var(--input-placeholder-font-size);
  203. }
  204. .el-select-dropdown__item.hover,
  205. .el-select-dropdown__item:hover {
  206. color: var(--drop-down-hover-font-color) !important;
  207. background-color: var(--drop-down-hover-background-color) !important;
  208. }
  209. .el-tag.el-tag--info {
  210. color: var(--bs-el-text) !important;
  211. }
  212. }
  213. </style>