• element UI DatePicker 日期选择器 点击时间点可选限制范围前后十五天


    1. "timeRange" type="datetimerange" align="right" :default-time='defaultTime'
    2. value-format="yyyy-MM-dd HH:mm:dd" range-separator="至" start-placeholder="开始日期"
    3. end-placeholder="结束日期" :picker-options="pickerOptions" @change="handleChangeTime"
    4. :clearable="false">

    设置:picker-options="pickerOptions"

    然后在data里面设置

    1. pickerOptions: {
    2. onPick: ({
    3. maxDate,
    4. minDate
    5. }) => {
    6. this.selectDate = minDate.getTime()
    7. if (maxDate) {
    8. this.selectDate = ''
    9. }
    10. },
    11. disabledDate: (time) => {
    12. if (this.selectDate !== '') {
    13. const one = (15 * 24 * 3600 - 1) * 1000 // 00:00:0023:59:59
    14. const minTime = this.selectDate - one
    15. const maxTime = this.selectDate + one
    16. return time.getTime() < minTime || time.getTime() > maxTime
    17. }
    18. }
    19. }

    源代码

    1. <script>
    2. import * as echarts from 'echarts';
    3. export default {
    4. name: 'EChartsComponent',
    5. data() {
    6. return {
    7. chart: null,
    8. // 时间筛选
    9. time: [],
    10. selectDate: '',
    11. defaultTime: ['00:00:00', '23:59:59'],
    12. timeRange: [],
    13. pickerOptions: {
    14. onPick: ({
    15. maxDate,
    16. minDate
    17. }) => {
    18. this.selectDate = minDate.getTime()
    19. if (maxDate) {
    20. this.selectDate = ''
    21. }
    22. },
    23. disabledDate: (time) => {
    24. if (this.selectDate !== '') {
    25. const one = (15 * 24 * 3600 - 1) * 1000 // 00:00:00 到23:59:59
    26. const minTime = this.selectDate - one
    27. const maxTime = this.selectDate + one
    28. return time.getTime() < minTime || time.getTime() > maxTime
    29. }
    30. }
    31. }
    32. };
    33. },
    34. mounted() {
    35. this.chart = echarts.init(this.$refs.chart);
    36. this.drawChart();
    37. },
    38. methods: {
    39. // 获取数据
    40. async getTableData() {
    41. let params = {
    42. startTime: this.time?.[0],
    43. endTime: this.time?.[1],
    44. }
    45. console.log('请求参数@@@@', params);
    46. // let {
    47. // code,
    48. // total,
    49. // rows
    50. // } = await integralUserVOList(params)
    51. // if (code == 200) {
    52. // this.table_data = rows
    53. // this.total = total
    54. // console.log('当前的数据', this.table_data);
    55. // }
    56. },
    57. drawChart() {
    58. const option = {
    59. title: {
    60. text: ''
    61. },
    62. tooltip: {
    63. trigger: 'axis',
    64. axisPointer: {
    65. type: 'cross',
    66. label: {
    67. backgroundColor: '#fff'
    68. }
    69. }
    70. },
    71. legend: {
    72. data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine']
    73. },
    74. toolbox: {
    75. feature: {
    76. saveAsImage: {}
    77. }
    78. },
    79. grid: {
    80. left: '3%',
    81. right: '4%',
    82. bottom: '3%',
    83. containLabel: true
    84. },
    85. xAxis: [{
    86. type: 'category',
    87. boundaryGap: false,
    88. data: ['10/11', '10/12', '10/13', '10/13', '10/14', '10/16', '17']
    89. }],
    90. yAxis: [{
    91. show: false,
    92. type: 'value'
    93. }],
    94. series: [{
    95. name: '',
    96. type: 'line',
    97. stack: 'Total',
    98. color: '#F35555',
    99. areaStyle: {
    100. opacity: 0.8,
    101. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
    102. offset: 0,
    103. color: '#F35555'
    104. },
    105. {
    106. offset: 1,
    107. color: '#FFFFFF'
    108. }
    109. ])
    110. },
    111. emphasis: {
    112. focus: 'series'
    113. },
    114. data: [0.000026, 0.000056, 0.000076, 0.000086, 0.000096, 0.000097, 0.000099]
    115. }]
    116. };
    117. this.chart.setOption(option);
    118. },
    119. },
    120. };
    121. script>
    122. <style scoped lang="scss">
    123. .promotion-page {
    124. padding: 16px;
    125. .promotion-box {
    126. padding: 16px;
    127. min-width: 1280px;
    128. width: 100%;
    129. background: #FFFFFF;
    130. box-shadow: 0px 1px 4px 1px #E5E9F2;
    131. border-radius: 5px 5px 5px 5px;
    132. }
    133. }
    134. // 盒子的标题
    135. .title {
    136. margin-bottom: 0;
    137. text-align: left;
    138. font-size: 24px;
    139. font-weight: 500;
    140. color: #31394d;
    141. font-weight: bold;
    142. }
    143. ::v-deep {
    144. .el-range-editor--medium .el-range__icon,
    145. .el-range-editor--medium .el-range__close-icon {
    146. line-height: 20px !important;
    147. }
    148. }
    149. // 时间筛选
    150. .time-box {
    151. display: flex;
    152. align-items: center;
    153. margin-top: 30px;
    154. padding-left: 56px;
    155. .time-span {
    156. padding-right: 10px;
    157. }
    158. // 深度选择
    159. .date {
    160. height: 28px;
    161. width: 380px;
    162. .el-input__icon {
    163. font-size: 12px;
    164. height: 24px;
    165. line-height: 24px;
    166. }
    167. .el-range-separator {
    168. font-size: 12px;
    169. height: 24px;
    170. line-height: 24px;
    171. }
    172. }
    173. }
    174. .echarts_piece {
    175. margin-left: 56px;
    176. margin-top: 32px;
    177. display: flex;
    178. width: 300px;
    179. justify-content: space-between;
    180. // border: 1px solid red ;
    181. .echarts_piece_t span {
    182. display: block;
    183. }
    184. .echarts_piece_t span:nth-child(1) {
    185. font-size: 36px;
    186. font-weight: bold;
    187. }
    188. .echarts_piece_t span:nth-child(2) {
    189. color: #999999;
    190. font-size: 14px;
    191. }
    192. }
    193. style>

  • 相关阅读:
    【SpringMVC】运行过程
    CEAC之《职业素养》
    LeetCode通关:连刷十四题,回溯算法完全攻略
    OA系统都能为企业带来什么
    【Mybatis 源码】 Mybatis 是如何解析配置文件中的内容 -- settings
    LabVIEW比较LabVIEW类对象 LabVIEW接口
    sklearn基础篇(六)-- 决策树(decision tree)
    2.4GHz WiFi速率测试指导及Omnipeek 空口log分析
    AN动画基础——缓动动画
    带联网功能的RFID宿舍门禁(六)-两年后的再次总结
  • 原文地址:https://blog.csdn.net/Leijiang0504/article/details/134201757