问题遇到的现象和发生背景
使用vue与后端对接,希望实现一个按照时间范围查询的功能
附上后端api
问题相关代码,请勿粘贴截图
<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
})
}
这是接口的代码
运行结果及报错内容
这是报错内容
我的解答思路和尝试过的方法
我的思路是希望能把我输入的数组拆成两份,并分别赋予后端的两个字符串startCreateTime和endCreateTime,但是有一个问题就是我的el-date-picker的v-model只能命名为queryParams.startCreateTime,这样子的 话当我把拆分后的数组赋给startCreateTime时两个名字就重复了,我曾经把queryParams.startCreateTime改成过v-model="queryParams.CreateTime"但是会报错
我想要达到的结果
希望能像这样一样达到查找的效果