index.vue 6.9 KB

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