index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. config.customize.title = config.option.data[config.dataSource.dimensionField] || config.customize.title
  81. // 语音播报
  82. } else {
  83. // 数据返回失败则赋前端的模拟数据
  84. config.option.data = []
  85. this.optionData = []
  86. }
  87. return config
  88. },
  89. changeStyle (config) {
  90. config = { ...this.config, ...config }
  91. // 样式改变时更新主题配置
  92. config.theme = settingToTheme(cloneDeep(config), this.customTheme)
  93. this.changeChartConfig(config)
  94. this.innerConfig = config
  95. // 选择器元素
  96. const selectInputEl = document.querySelector(`.select-${config.code} .el-input__inner`)
  97. // 背景颜色
  98. selectInputEl.style.backgroundColor = config.customize.backgroundColor
  99. // 字体大小
  100. selectInputEl.style.fontSize = config.customize.fontSize + 'px'
  101. // 字体颜色
  102. selectInputEl.style.color = config.customize.fontColor
  103. // 边框颜色
  104. selectInputEl.style.borderColor = config.customize.borderColor
  105. // 下拉图标
  106. const selectDropdownIcon = document.querySelector(`.select-${config.code} .el-icon-arrow-up`)
  107. selectDropdownIcon.style.fontSize = config.customize.fontSize + 'px'
  108. // 选择器下拉框元素
  109. const selectDropdownEl = document.querySelector(`.select-${config.code} .el-select-dropdown`)
  110. // 箭头背景颜色和下拉框背景颜色一致
  111. if (selectDropdownEl) {
  112. // 下拉框无边框
  113. selectDropdownEl.style.border = 'none'
  114. // 背景颜色
  115. selectDropdownEl.style.backgroundColor = config.customize.dropDownBackgroundColor
  116. }
  117. },
  118. // 组件联动
  119. selectChange (val) {
  120. if (val) {
  121. this.linkage(this.optionData.find(item => item[this.config.dataSource.metricField] === val))
  122. }
  123. },
  124. visibleChange (val) {
  125. if (val) {
  126. // 修改下拉框背景颜色,让下拉框背景颜色和箭头背景颜色一致
  127. const selectDropdownEl = document.querySelector(`.select-popper-${this.innerConfig.code}`)
  128. selectDropdownEl.style.color = this.innerConfig.customize.dropDownBackgroundColor
  129. // 空状态
  130. const selectDropdownEmptyEl = document.querySelector(`.select-popper-${this.innerConfig.code} .el-select-dropdown__empty`)
  131. if (selectDropdownEmptyEl) {
  132. selectDropdownEmptyEl.style.backgroundColor = this.innerConfig.customize.dropDownBackgroundColor
  133. }
  134. // 下拉项hover颜色
  135. const selectDropdownWrap = document.querySelector(`.select-popper-${this.innerConfig.code} .el-select-dropdown__wrap`)
  136. selectDropdownWrap.style.setProperty('--drop-down-hover-font-color', this.innerConfig.customize.dropDownHoverFontColor)
  137. selectDropdownWrap.style.setProperty('--drop-down-hover-background-color', this.innerConfig.customize.dropDownHoverBackgroundColor)
  138. }
  139. // 不是激活项的还是使用背景颜色
  140. const selectDropdownItemEl = document.querySelectorAll(`.select-popper-${this.innerConfig.code} .el-select-dropdown__item`)
  141. selectDropdownItemEl.forEach(item => {
  142. // 检查是否是激活项,不是则使用背景颜色
  143. if (!item.classList.contains('selected')) {
  144. item.style.color = this.innerConfig.customize.dropDownFontColor
  145. item.style.backgroundColor = this.innerConfig.customize.dropDownBackgroundColor
  146. }
  147. })
  148. },
  149. // 鼠标进入
  150. mouseenter () {
  151. if (this.value) {
  152. setTimeout(() => {
  153. // 清空图标
  154. const selectDropdownCloseIcon = document.querySelector(`.select-${this.innerConfig.code} .el-icon-circle-close`)
  155. if (selectDropdownCloseIcon) {
  156. selectDropdownCloseIcon.style.fontSize = this.innerConfig.customize.fontSize + 'px'
  157. }
  158. }, 30)
  159. }
  160. }
  161. }
  162. }
  163. </script>
  164. <style lang="scss">
  165. .basic-component-select {
  166. .el-select-dropdown__wrap {
  167. margin-bottom: 0px !important;
  168. }
  169. .el-select-group__wrap:not(:last-of-type)::after {
  170. background-color: transparent !important;
  171. }
  172. .popper__arrow {
  173. bottom: -6px !important;
  174. border-top-color: var(--color) !important;
  175. border-bottom-color: var(--color) !important;
  176. &::after {
  177. bottom: 0px !important;
  178. border-top-color: var(--color) !important;
  179. border-bottom-color: var(--color) !important;
  180. }
  181. }
  182. }
  183. </style>
  184. <style lang="scss" scoped>
  185. .basic-component-select {
  186. width: 100%;
  187. height: 100%;
  188. ::v-deep .el-input {
  189. height: 100% !important;
  190. .el-select__caret {
  191. width: 100%;
  192. height: 100%;
  193. display: flex;
  194. align-items: center;
  195. }
  196. // 选择器输入框样式
  197. .el-input__inner {
  198. height: 100% !important;
  199. }
  200. }
  201. ::v-deep .el-input__inner::placeholder {
  202. color: var(--input-placeholder-color);
  203. font-size: var(--input-placeholder-font-size);
  204. }
  205. .el-select-dropdown__item.hover,
  206. .el-select-dropdown__item:hover {
  207. color: var(--drop-down-hover-font-color) !important;
  208. background-color: var(--drop-down-hover-background-color) !important;
  209. }
  210. .el-tag.el-tag--info {
  211. color: var(--bs-el-text) !important;
  212. }
  213. }
  214. </style>