Sinestro 2022-04-02 10:55 采纳率: 87.5%
浏览 78
已结题

如何实现按照时间范围查询?

问题遇到的现象和发生背景

使用vue与后端对接,希望实现一个按照时间范围查询的功能
附上后端api

img

问题相关代码,请勿粘贴截图
<template>
  <div class="app-container">
    <!-- 头部 -->
    <el-form :inline="true" ref="queryForm" :model="queryParams">
      <el-form-item prop="inputTime" label="下载时间:">
        <el-date-picker
          @change="change"
          value-format="yyyy-MM-dd"
          v-model="queryParams.inputTime"
          type="daterange"
          range-separator="-"
          start-placeholder="下载时间"
          end-placeholder="失效时间"
          size="small"
          @keyup.enter.native="handleQuery">
        </el-date-picker>
        <!--            -->
      </el-form-item>
      <el-form-item style="margin-left: 40px">
        <el-button size="small" icon="el-icon-search" type="primary" @click="handleQuery">查询</el-button>
        <el-button size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 表格 -->
    <el-table
      v-loading="loading"
      :data="downloadContent"
      border
      height="740"
      style="width: 100%"
      :default-sort="{ prop: 'createTime', order: 'descending' }"
    >
      <el-table-column prop="id" label="序号" type="index" width="70px"></el-table-column>
      <el-table-column prop="resName" label="文件名"></el-table-column>
      <el-table-column prop="dataType" label="下载类型">
          <template slot-scope="scope">
          <dict-tag :options="dataType" :value="scope.row.dataType"/>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="下载时间" sortable></el-table-column>
      <el-table-column prop="dlFileExpireTime" label="失效时间" >
      </el-table-column>
      <el-table-column prop="dlStatus" label="状态">
        <template slot-scope="scope">
          <dict-tag :options="status" :value="scope.row.dlStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="150px">
        <template slot-scope="scope">
          <el-button type="primary" size="mini">查看</el-button>
        <el-button size="mini" v-if="scope.row.status !=1" @click="handleDownload(scope.row)">下载</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script>
import { getToken } from "@/utils/auth";
import { listDownload, downloadFile } from "@/api/user/download";
export default {
  name: "Download",                                                                              
  dicts: ["data_type", "dl_status"],
  data() {
    return {
      startCreateTime: '',
      endCreateTime: '',
      //选中数组
      ids: [],
      //遮罩层
      loading:true,
      //总条目
      total: 1,
      //下载列表数据
      downloadContent: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        inputTime: [],
        startCreateTime: '',
        endCreateTime: '',
      },
      // 文件类型字典
      dataType:[],
      // 文件状态字典
      status:[],
      //页面加载完成事件
      showData: null,
    };
  },
  created() {
       this.getList();
    this.getDicts("data_type").then(response => {
      this.dataType = response.data;
    });
    this.getDicts("dl_status").then(response => {
      this.status = response.data;
    });
  },
  mounted(){
    console.log("页面加载完成")
},
  methods: {
    //   查询事件
      change(val){
        if(val.length>0){
          this.queryParams.startCreateTime =val[0]
          this.queryParams.endCreateTime =val[1]
        }else{
          this.queryParams.startCreateTime =''
          this.queryParams.endCreateTime =''
        };
        console.log(this.queryParams.startCreateTime);
        console.log(this.queryParams.endCreateTime);
      },
    //   查询下载列表
      getList(){
          this.loading = true;
          listDownload(this.queryParams).then(response =>{
            this.downloadContent = response.rows;
            this.downloadContent.forEach(item=>{
             let time = new Date(item.dlFileExpireTime).getTime()
             if(time<= new Date().getTime()){
                item.status=1
              }
            });
            this.total = response.total;
            this.loading = false;
          });
      },

    //   搜索按钮  
      handleQuery(){
        // this.queryParams.startCreateTime = this.queryParams.inputTime[0];
        // this.queryParams.endCreateTime = this.queryParams.inputTime[1];
        this.queryParams.pageNum = 1;
        this.getList();
        // console.log(typeof startCreateTime);
        // console.log(typeof endCreateTime);
        // console.log(this.queryParams.startCreateTime);
        // console.log(this.queryParams.endCreateTime);
      },

    //重置按钮
      resetQuery(){
        this.resetForm("queryForm");
        this.handleQuery();
      },
    //下载按钮
      handleDownload(value){
        // console.log(value);
        // console.log(value.id);
        this.$confirm("是否下载该文件?", "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then((res) => {
          window.location.href = process.env.VUE_APP_BASE_API +"/mydownload/download/download?id=" + value.id + '&Authorization=' + getToken();
          // console.log(process.env.VUE_APP_BASE_API +"/mydownload/download/download?id=" + value.id +'&Authorization:' + getToken());
        });
      },
  }
};
</script>



这是前端的代码

import request from '@/utils/request'

export function listDownload(query) {
  return request({
    url: '/mydownload/download/list',
    method: 'get',
    params: query
  })
}

//下载文件
export function downloadFile(query) {
  return request({
    url: '/mydownload/download/list',
    method: 'get',
    params: query
  })
}


这是接口的代码

运行结果及报错内容

img


这是报错内容

我的解答思路和尝试过的方法

我的思路是希望能把我输入的数组拆成两份,并分别赋予后端的两个字符串startCreateTime和endCreateTime,但是有一个问题就是我的el-date-picker的v-model只能命名为queryParams.startCreateTime,这样子的 话当我把拆分后的数组赋给startCreateTime时两个名字就重复了,我曾经把queryParams.startCreateTime改成过v-model="queryParams.CreateTime"但是会报错

img

img

我想要达到的结果

img


希望能像这样一样达到查找的效果

  • 写回答

4条回答 默认 最新

  • 关注

    传2个时间参数到后台,后台用between条件查询。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 4月18日
  • 已采纳回答 4月10日
  • 修改了问题 4月2日
  • 创建了问题 4月2日

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器