Authored by 王涛

Merge branch 'master-v32-lushangqing' into 'master'

日期时间范围组件



See merge request !351
@@ -64,3 +64,11 @@ @@ -64,3 +64,11 @@
64 .userright .roles{ 64 .userright .roles{
65 border: solid 1px rgb(251, 196, 196); 65 border: solid 1px rgb(251, 196, 196);
66 } 66 }
  67 +/*时间范围组件*/
  68 +.drop-active{
  69 + background-color: #ecf5ff;
  70 + color: #66b1ff;
  71 +}
  72 +.select-div{
  73 + margin-left: 10px;
  74 +}
  1 +<el-row class="dataRange-container">
  2 + <el-col :span="24">
  3 + <div class="tabs-div date-flex-div-around">
  4 + <el-col :span="17">
  5 + <el-date-picker
  6 + class="picker-div"
  7 + v-model="dateValue"
  8 + type="datetimerange"
  9 + range-separator="--"
  10 + start-placeholder="开始时间"
  11 + end-placeholder="结束时间"
  12 + format="YYYY-MM-DD hh:mm:ss"
  13 + value-format="YYYY-MM-DD hh:mm:ss"
  14 + :shortcuts="shortcuts"
  15 + @change="changeDate"
  16 + >
  17 + </el-date-picker>
  18 + </el-col>
  19 + <el-col :span="7" class="select-div">
  20 + <!-- <el-select v-model="checkedId" class="m-2" placeholder="聚合频率" size="large">
  21 + <el-option
  22 + v-for="item in frequencyData"
  23 + :key="item.ddicDesc"
  24 + :label="item.ddicName"
  25 + :value="item.ddicDesc"
  26 + @change="changeItem"
  27 + >
  28 + </el-option>
  29 + </el-select>-->
  30 +
  31 + <el-dropdown split-button size="large" type="primary">
  32 + 聚合频率
  33 + <template #dropdown>
  34 + <el-dropdown-menu>
  35 + <el-dropdown-item :class="{'drop-active':checkedId==item.ddicDesc}" v-for="item in frequencyData" @click="changeItem(item.ddicDesc,item.ddicName)"
  36 + :key="item.ddicId"
  37 + :command="item.ddicDesc">
  38 + {{item.ddicName}}
  39 + </el-radio>
  40 + </el-dropdown-item>
  41 + </el-dropdown-menu>
  42 + </template>
  43 + </el-dropdown>
  44 + </el-col>
  45 + </div>
  46 + </el-col>
  47 +</el-row>
  1 +export default {
  2 + name: 'dateRange',
  3 + template: '',
  4 + components: {},
  5 + props: {
  6 + keys:{
  7 + type:String,
  8 + default: 'C620C1D453B79095A64314C8215335D5:KPI7054BC34:cpu'
  9 + },
  10 + dateValueData:{
  11 + type:Array,
  12 + default:[]
  13 + },
  14 + intervalGroup:{
  15 + type:String,
  16 + default:''
  17 + }
  18 + },
  19 + data () {
  20 + return {
  21 +
  22 + }
  23 + },
  24 + setup(props, {attrs, slots, emit}){
  25 + const {proxy} = Vue.getCurrentInstance();
  26 + //接口参数-开始结束时间
  27 + let timeScope=Vue.ref();
  28 + //接口参数-聚合频率
  29 + // let intervalGroup=Vue.ref(60);
  30 + //接口参数-资源id:指标id:flag,资源id:指标id:flag
  31 + let keysVal=props.keys;
  32 + //聚合频率数据
  33 + let frequencyData=Vue.ref([
  34 + {
  35 + name:'5分钟聚合',
  36 + val:5,
  37 + id:'001'
  38 + },{
  39 + name:'15分钟聚合',
  40 + val:15,
  41 + id:'002'
  42 + },{
  43 + name:'1小时聚合',
  44 + val:60,
  45 + id:'003'
  46 + },{
  47 + name:'12小时聚合',
  48 + val:720,
  49 + id:'004'
  50 + },{
  51 + name:'1天聚合',
  52 + val:1440,
  53 + id:'005'
  54 + },{
  55 + name:'不聚合',
  56 + val:0,
  57 + id:'006'
  58 + }
  59 + ])
  60 +
  61 + //自定义选择时间
  62 + let dateValue=Vue.ref();
  63 + //选中的聚合频率
  64 + let checkedId=Vue.ref();
  65 + let commandVal=Vue.ref('聚合频率')
  66 + //聚合频率选择
  67 + const changeItem=(val,name)=>{
  68 + checkedId.value=val;
  69 + commandVal.value=name;
  70 + loadPerformance();
  71 + }
  72 + //时间控件左侧
  73 + let shortcuts=Vue.ref([
  74 + {
  75 + text: '最近30分钟',
  76 + value: () => {
  77 + const end = new Date();
  78 + const start = formatDate(30,'m');
  79 + return [start, end]
  80 + },
  81 + },
  82 + {
  83 + text: '最近1小时',
  84 + value: () => {
  85 + const end = new Date();
  86 + const start = formatDate(1,'h');
  87 + return [start, end]
  88 + },
  89 + },
  90 + {
  91 + text: '最近1天',
  92 + value: () => {
  93 + const end = new Date();
  94 + const start = formatDate(1,'d');
  95 + return [start, end]
  96 + },
  97 + },
  98 + {
  99 + text: '最近3天',
  100 + value: () => {
  101 + const end = new Date();
  102 + const start = formatDate(3,'d');
  103 + return [start, end]
  104 + },
  105 + },
  106 + {
  107 + text: '最近7天',
  108 + value: () => {
  109 + const end = new Date();
  110 + const start = formatDate(7,'d');
  111 + return [start, end]
  112 + },
  113 + },
  114 + {
  115 + text: '最近15天',
  116 + value: () => {
  117 + const end = new Date();
  118 + const start = formatDate(15,'d');
  119 + return [start, end]
  120 + },
  121 + },
  122 + {
  123 + text: '最近1个月',
  124 + value: () => {
  125 + const end = new Date();
  126 + const start = formatDate(1,'M');
  127 + return [start, end]
  128 + },
  129 + },
  130 + {
  131 + text: '最近2个月',
  132 + value: () => {
  133 + const end = new Date();
  134 + const start = formatDate(2,'M');
  135 + return [start, end]
  136 + },
  137 + },
  138 + {
  139 + text: '最近3个月',
  140 + value: () => {
  141 + const end = new Date();
  142 + const start = formatDate(3,'M');
  143 + return [start, end]
  144 + },
  145 + },
  146 + {
  147 + text: '半年内',
  148 + value: () => {
  149 + const end = new Date();
  150 + const start = formatDate(6,'M');
  151 + return [start, end]
  152 + },
  153 + },
  154 + {
  155 + text: '1年内',
  156 + value: () => {
  157 + const end = new Date();
  158 + const start = formatDate(12,'M');
  159 + return [start, end]
  160 + },
  161 + },
  162 + {
  163 + text: '全部',
  164 + value: () => {
  165 + const end = new Date();
  166 + const start = ''
  167 + return [start, end]
  168 + },
  169 + },
  170 + ])
  171 + //开始时间
  172 + let startTime=Vue.ref();
  173 + //结束时间
  174 + let endTime=Vue.ref();
  175 + //相差天数
  176 + let calcDayNum=Vue.ref(0);
  177 + //时间范围改变选中
  178 + const changeDate=(val)=>{
  179 + calcDayNum.value=calcDay(val[0],val[1]);
  180 + getRate(calcCode(calcDayNum.value))
  181 +
  182 + }
  183 + //计算两个日期相差天数
  184 + const calcDay=(start,end)=>{
  185 + let endTime = new Date(end).getTime() / 1000 - parseInt(new Date(start).getTime() / 1000);
  186 + let timeDay = parseInt(endTime / 60 / 60 / 24); //相差天数
  187 + return timeDay;
  188 + }
  189 + //计算需要传参的code值
  190 + const calcCode=(val)=>{
  191 + let code='';
  192 + if(val>0 && val<7){
  193 + code='time_scope_DAY';
  194 + }else if(val>=7 && val<30){
  195 + code='time_scope_WEEK';
  196 + }else if(val>=30 && val<90){
  197 + code='time_scope_MONTH';
  198 + }else if(val>=90 && val<180){
  199 + code='time_scope_QUARTER';
  200 + }else if(val>=180 && val<365){
  201 + code='time_scope_SEMESTER';
  202 + }else if(val>=365){
  203 + code='time_scope_YEAR';
  204 + }
  205 + return code;
  206 + }
  207 +
  208 + //确定
  209 + const sureBtn=()=>{
  210 + let dateValueArr=dateValue.value;
  211 + if(dateValueArr && dateValueArr.length>0){
  212 + timeScope.value=dateValueArr.join(',');
  213 + }else{
  214 + timeScope.value='';
  215 + }
  216 +
  217 + loadPerformance();
  218 +
  219 + }
  220 + //查询性能数据-自定义视图
  221 + const loadPerformance=()=>{
  222 + let params={
  223 + timeScope:timeScope.value,
  224 + intervalGroup:checkedId.value,
  225 + keys:keysVal
  226 + }
  227 + proxy.$http.get(`/api-web/cm-data-range/loadPerformanceCustom`, params, function (res) {
  228 + if(res && res.data){
  229 + emit('callbacksure',res.data)
  230 + }else{
  231 + emit('callbacksure','')
  232 + }
  233 +
  234 + })
  235 + }
  236 + //转换个位数为 00
  237 + let timeFormat =(number)=> {
  238 + return number.length == 1 ? ('0' + number) : number
  239 + }
  240 + //获取时间点 转年月日的方法
  241 + const getDateTime=(newDate)=>{
  242 + let dateTime='';
  243 + let year=newDate.getFullYear();//获取当前年
  244 + let month=timeFormat(newDate.getMonth()+1);//获取当前月
  245 + let day=timeFormat(newDate.getDate());//获取当前日
  246 + let hours=timeFormat(newDate.getHours()+'');//获取当前时
  247 + let minutes=timeFormat(newDate.getMinutes()+'');//获取当前分
  248 + let seconds=timeFormat(newDate.getSeconds()+'');//获取当前秒
  249 + dateTime= year+'-'+month+'-'+day+' '+hours+':'+minutes+':'+seconds;
  250 + return dateTime;
  251 + }
  252 + //获取前n段时间的时间点
  253 + const formatDate=(num,code)=>{
  254 + let m=num;
  255 + let myDate=new Date();
  256 + let lowData='';//当前年月日往前推m个月后获取到的年月日
  257 + if(code=='m'){
  258 + //当前时间前n分钟
  259 + myDate.setMinutes(myDate.getMinutes()-m);
  260 + lowData =getDateTime(myDate); //用了上面转年月日的方法
  261 +
  262 + }else if(code=='h'){
  263 + //当前时间前n小时
  264 + myDate.setHours(myDate.getHours()-m)
  265 + lowData =getDateTime(myDate); //用了上面转年月日的方法
  266 + }else if(code=='d'){
  267 + //当前时间前n天
  268 + myDate.setDate(myDate.getDate() - m);
  269 + lowData =getDateTime(myDate); //用了上面转年月日的方法
  270 + }else if(code=='M'){
  271 + //当前时间前n月
  272 + myDate.setMonth(myDate.getMonth()-m);
  273 + lowData =getDateTime(myDate); //用了上面转年月日的方法
  274 +
  275 + }else{
  276 +
  277 + }
  278 + return lowData;
  279 +
  280 + }
  281 + //判断是否传值进来
  282 + const isDetail=()=>{
  283 + if(props.dateValueData && props.dateValueData.length>0){
  284 + dateValue.value=props.dateValueData
  285 + changeDate(dateValue.value);
  286 + }
  287 + checkedId.value=props.intervalGroup;
  288 + }
  289 +
  290 + //获取聚合频率数据
  291 + const getRate=(defCode)=>{
  292 + let param = {
  293 + ddicName: defCode
  294 + }
  295 + proxy.$http.get(`/api-web/ContrastAnalysis/selectTogetherRate`, param, function (res) {
  296 + if (res && res.data) {
  297 + frequencyData.value = res.data;
  298 +
  299 + }
  300 + sureBtn();
  301 + });
  302 + }
  303 +
  304 + // 挂载完
  305 + Vue.onMounted(() => {
  306 + isDetail();
  307 +
  308 + })
  309 + return {
  310 + commandVal,
  311 + calcDayNum,
  312 + calcDay,
  313 + shortcuts,
  314 + timeScope,
  315 + keysVal,
  316 + startTime,
  317 + endTime,
  318 + frequencyData,
  319 + dateValue,
  320 + changeItem,
  321 + checkedId,
  322 + changeDate,
  323 + sureBtn,
  324 + timeFormat,
  325 + formatDate,
  326 + getDateTime,
  327 + loadPerformance
  328 + }
  329 +
  330 + }
  331 +
  332 +}
@@ -40,7 +40,9 @@ Promise.all([ @@ -40,7 +40,9 @@ Promise.all([
40 //指标类型数 40 //指标类型数
41 .component('cm-kpi-type-tree-input', Vue.defineAsyncComponent(() => myImport('components/common/inputkpitree/index'))) 41 .component('cm-kpi-type-tree-input', Vue.defineAsyncComponent(() => myImport('components/common/inputkpitree/index')))
42 //所属系统 42 //所属系统
43 - .component('cm-biz-type-tree-input', Vue.defineAsyncComponent(() => myImport('components/common/inputbiztypetree/index'))); 43 + .component('cm-biz-type-tree-input', Vue.defineAsyncComponent(() => myImport('components/common/inputbiztypetree/index')))
  44 + //时间范围组件
  45 + .component('cm-date-range', Vue.defineAsyncComponent(() => myImport('components/common/dateRange/index')));
44 46
45 47
46 // // 自定义指令 48 // // 自定义指令