index.vue 8.7 KB

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