index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <template>
  2. <el-time-picker
  3. v-model="config.customize.value"
  4. :picker-options="config.customize.pickerOptions"
  5. placeholder="选择时间"
  6. clearable
  7. :class="['basic-component-time-picker', `time-picker-${config.code}`]"
  8. :popper-class="'basic-component-time-picker time-picker-popper-' + config.code"
  9. :value-format="config.customize.valueFormat"
  10. :default-value="config.customize.value"
  11. @focus="focusEvent"
  12. @change="changeValue"
  13. @mouseenter.native="mouseenter"
  14. />
  15. </template>
  16. <script>
  17. import moment from 'moment'
  18. import cloneDeep from 'lodash/cloneDeep'
  19. import commonMixins from 'data-room-ui/js/mixins/commonMixins'
  20. import linkageMixins from 'data-room-ui/js/mixins/linkageMixins'
  21. import { getDataSetDetails } from 'data-room-ui/js/api/bigScreenApi'
  22. import { settingToTheme } from 'data-room-ui/js/utils/themeFormatting'
  23. import { mapState } from 'vuex'
  24. window.dataSetFields = []
  25. export default {
  26. name: 'BasicComponentSelect',
  27. components: {},
  28. mixins: [commonMixins, linkageMixins],
  29. props: {
  30. // 组件配置
  31. config: {
  32. type: Object,
  33. default: () => ({})
  34. }
  35. },
  36. data () {
  37. return {
  38. value: '',
  39. innerConfig: {}
  40. }
  41. },
  42. computed: {
  43. ...mapState({
  44. chartList: state => state.bigScreen.pageInfo.chartList
  45. }),
  46. isPreview () {
  47. return (this.$route.path === window?.BS_CONFIG?.routers?.previewUrl) || (this.$route.path === '/big-screen/preview')
  48. }
  49. },
  50. watch: { },
  51. created () { },
  52. mounted () {
  53. if (!this.isPreview) {
  54. document.querySelector(`.time-picker-${this.config.code}`).style.pointerEvents = 'none'
  55. }
  56. if (this.config.customize.value === '') {
  57. this.config.customize.value = moment(new Date()).format(this.config.customize.valueFormat)
  58. }
  59. this.changeStyle(this.config)
  60. },
  61. beforeDestroy () { },
  62. methods: {
  63. dataFormatting (config, data) {
  64. // 数据返回成功则赋值
  65. if (data.success) {
  66. data = data.data
  67. // 获取到后端返回的数据,有则赋值
  68. if (config.dataHandler) {
  69. try {
  70. // 此处函数处理data
  71. eval(config.dataHandler)
  72. } catch (e) {
  73. console.info(e)
  74. }
  75. }
  76. config.option.data = data
  77. config.customize.title = config.option.data[config.dataSource.dimensionField] || config.customize.title
  78. if (window.dataSetFields.length === 0) {
  79. getDataSetDetails(this.config.dataSource.businessKey).then(res => {
  80. window.dataSetFields = res.fields.map(field => {
  81. return {
  82. label: field.comment || field.fieldDesc,
  83. value: field.name || field.fieldName
  84. }
  85. })
  86. })
  87. }
  88. // 语音播报
  89. } else {
  90. // 数据返回失败则赋前端的模拟数据
  91. config.option.data = []
  92. }
  93. return config
  94. },
  95. changeStyle (config) {
  96. config = { ...this.config, ...config }
  97. // 样式改变时更新主题配置
  98. config.theme = settingToTheme(cloneDeep(config), this.customTheme)
  99. this.changeChartConfig(config)
  100. this.innerConfig = config
  101. // 时间选择器元素
  102. const timePicker = document.querySelector(`.time-picker-${config.code} .el-input__inner`)
  103. // 时间选择器背景颜色
  104. timePicker.style.backgroundColor = config.customize.backgroundColor
  105. // 时间选择器字体颜色
  106. timePicker.style.color = config.customize.fontColor
  107. // 时间选择器字体大小
  108. timePicker.style.fontSize = config.customize.fontSize + 'px'
  109. // 时间选择器图标
  110. const timePickerCloseIcon = document.querySelector(`.time-picker-${config.code} .el-input__icon`)
  111. if (timePickerCloseIcon) {
  112. timePickerCloseIcon.style.fontSize = config.customize.fontSize + 'px'
  113. }
  114. },
  115. // 组件联动
  116. changeValue (val) {
  117. console.log('val', val)
  118. this.linkage({ [this.config.code]: val })
  119. },
  120. focusEvent () {
  121. this.$nextTick(() => {
  122. const { code } = this.innerConfig
  123. const { dropDownBackgroundColor, dropDownFontColor, dropDownHoverFontColor, dropDownHoverBackgroundColor, dropDownSelectedFontColor } = this.innerConfig.customize
  124. const timePickerPopper = document.querySelector(`.time-picker-popper-${code}`)
  125. if (timePickerPopper) {
  126. // 去除边框
  127. timePickerPopper.style.border = 'none'
  128. // 确保下拉项的箭头颜色与下拉框的背景颜色保持一致
  129. timePickerPopper.style.color = dropDownBackgroundColor
  130. }
  131. // 下拉项背景颜色
  132. const pickerDropdownPanleContent = document.querySelector(`.time-picker-popper-${code}`)
  133. if (pickerDropdownPanleContent) {
  134. // 文字颜色
  135. pickerDropdownPanleContent.style.color = dropDownFontColor
  136. // 背景颜色
  137. pickerDropdownPanleContent.style.backgroundColor = dropDownBackgroundColor
  138. // 下拉项添加var变量
  139. pickerDropdownPanleContent.style.setProperty('--dropDownFontColor', dropDownFontColor)
  140. pickerDropdownPanleContent.style.setProperty('--dropDownHoverFontColor', dropDownHoverFontColor)
  141. pickerDropdownPanleContent.style.setProperty('--dropDownBackgroundColor', dropDownBackgroundColor)
  142. pickerDropdownPanleContent.style.setProperty('--dropDownSelectedFontColor', dropDownSelectedFontColor)
  143. pickerDropdownPanleContent.style.setProperty('--dropDownHoverBackgroundColor', dropDownHoverBackgroundColor)
  144. // 选中项字体颜色
  145. const selectedEl = pickerDropdownPanleContent.querySelector('.selected')
  146. if (selectedEl) {
  147. selectedEl.style.color = dropDownSelectedFontColor
  148. }
  149. // 选择过的,需要将选中颜色重置
  150. const pickerItemEl = document.querySelectorAll(`.time-picker-popper-${code} .el-time-spinner__item`)
  151. pickerItemEl.forEach((el) => {
  152. el.style.color = dropDownFontColor
  153. })
  154. }
  155. })
  156. },
  157. mouseenter () {
  158. if (this.config.customize.value) {
  159. setTimeout(() => {
  160. // 清空图标
  161. const timePickerCloseIcon = document.querySelector(`.time-picker-${this.innerConfig.code} .el-icon-circle-close`)
  162. if (timePickerCloseIcon) {
  163. timePickerCloseIcon.style.fontSize = this.innerConfig.customize.fontSize + 'px'
  164. }
  165. }, 25)
  166. }
  167. }
  168. }
  169. }
  170. </script>
  171. <style lang="scss">
  172. .basic-component-time-picker {
  173. color: '';
  174. // 清空图标
  175. .el-icon-circle-close {
  176. width: 100% !important;
  177. height: 100% !important;
  178. display: flex !important;
  179. align-items: center !important;
  180. }
  181. // 时间选择器
  182. .el-icon-time {
  183. display: flex !important;
  184. align-items: center !important;
  185. }
  186. .el-time-spinner {
  187. margin-bottom: 0px !important;
  188. .el-time-spinner__item {
  189. &:hover {
  190. color: var(--dropDownHoverFontColor) !important;
  191. background-color: var(--dropDownHoverBackgroundColor) !important;
  192. }
  193. }
  194. .active {
  195. color: var(--dropDownSelectedFontColor) !important;
  196. &:hover {
  197. color: var(--dropDownSelectedFontColor) !important;
  198. background-color: transparent !important;
  199. }
  200. }
  201. }
  202. .el-time-panel__content::before {
  203. content: "";
  204. top: 50%;
  205. position: absolute;
  206. margin-top: -15px;
  207. height: 32px;
  208. z-index: 1;
  209. left: 0;
  210. right: 0;
  211. box-sizing: border-box;
  212. padding-top: 6px;
  213. text-align: left;
  214. border-top: 1px solid var(--dropDownFontColor);
  215. border-bottom: 1px solid var(--dropDownFontColor);
  216. }
  217. .popper__arrow {
  218. border-bottom-color: var(--dropDownBackgroundColor) !important;
  219. &::after {
  220. top: 0px !important;
  221. border-bottom-color: var(--dropDownBackgroundColor) !important;
  222. }
  223. }
  224. .cancel {
  225. color: var(--dropDownFontColor) !important;
  226. }
  227. .confirm {
  228. color: var(--dropDownSelectedFontColor);
  229. }
  230. .el-time-panel__footer {
  231. border-color: 1px solid var(--dropDownFontColor) !important;
  232. }
  233. }
  234. </style>
  235. <style lang="scss" scoped>
  236. .basic-component-time-picker {
  237. width: 100%;
  238. height: 100%;
  239. .el-input--mini ::v-deep .el-input__inner {
  240. height: 100% !important;
  241. line-height: 100% !important;
  242. }
  243. .el-tag.el-tag--info {
  244. color: var(--bs-el-text) !important;
  245. }
  246. }
  247. ::v-deep .el-input__inner {
  248. height: 100% !important;
  249. line-height: 100% !important;
  250. }
  251. </style>