From 972086094199bbda2646afae30ca701b35a666e5 Mon Sep 17 00:00:00 2001
From: Jo <479214531@qq.com>
Date: Thu, 25 Nov 2021 22:18:07 +0800
Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E4=B8=8B=E8=BD=BD=E7=AD=89bu?=
=?UTF-8?q?g=E4=BF=AE=E5=A4=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/layouts/header/index.vue | 18 +--
src/layouts/navbar/index.vue | 6 +
src/pages/index/list/index.vue | 249 +++++++++++++++++++++++++++++----
src/router/permission.js | 18 ++-
4 files changed, 244 insertions(+), 47 deletions(-)
diff --git a/src/layouts/header/index.vue b/src/layouts/header/index.vue
index b4f8c10..ec7feb0 100644
--- a/src/layouts/header/index.vue
+++ b/src/layouts/header/index.vue
@@ -146,18 +146,12 @@ export default {
this.showSetting = false
},
toIndex() {
- this.$route.path === '/index/list'
- ? location.reload()
- : this.$refs.nav.jump({
- index: '/index/list',
- title: '首页'
- })
- },
- toSearch() {
- this.$refs.nav.jump({
- index: '/index/list',
- title: '首页'
- })
+ if (this.$route.path === '/index/list') {
+ location.reload()
+ } else {
+ this.$refs.nav.toIndex()
+ this.showSetting = true
+ }
},
toLogin() {
this.$refs.nav.jump({
diff --git a/src/layouts/navbar/index.vue b/src/layouts/navbar/index.vue
index c435e1e..3836e79 100644
--- a/src/layouts/navbar/index.vue
+++ b/src/layouts/navbar/index.vue
@@ -102,6 +102,12 @@ export default {
this.active = item.index
this.$router.push(item.index).catch(err => { })
},
+ toIndex() {
+ this.$router.push('/index')
+ this.isManager = false
+ this.setManager(true)
+ this.initMenu()
+ },
// 获取权限列表
getPer() {
this.$get(`${this.api.getPermissions}?platformId=${Setting.platformId}`).then(res => {
diff --git a/src/pages/index/list/index.vue b/src/pages/index/list/index.vue
index 5f131eb..504ead0 100644
--- a/src/pages/index/list/index.vue
+++ b/src/pages/index/list/index.vue
@@ -25,7 +25,7 @@
-
+
@@ -176,6 +176,34 @@
+
+
+
+
+ 全选
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -183,6 +211,9 @@
import { mapState } from 'vuex'
import Setting from '@/setting'
import util from '@/libs/util'
+import axios from 'axios'
+let startTimeLimit = ''
+let endTimeLimit = ''
export default {
name: 'index',
data() {
@@ -198,7 +229,43 @@ export default {
active: '',
previewVisible: false,
previewHead: [],
- previewData: []
+ previewData: [],
+ downloadVisible: false,
+ curRow: {},
+ checkAllFields: false,
+ fields: [],
+ fieldsList: [],
+ startTime: '',
+ endTime: '',
+ startTimeLimit: '',
+ startTimeDisabled: false,
+ endTimeLimit: '',
+ endTimeDisabled: false,
+ timeDefault: '',
+ timeOptions: {
+ disabledDate(time) {
+ return time.getTime() < startTimeLimit || time.getTime() > endTimeLimit
+ },
+ },
+ frequency: '',
+ frequencyList: [
+ {
+ id: 1,
+ name: '日频'
+ }, {
+ id: 2,
+ name: '周频'
+ }, {
+ id: 3,
+ name: '月频'
+ }, {
+ id: 4,
+ name: '季频'
+ }, {
+ id: 5,
+ name: '年频'
+ },
+ ]
}
},
computed: {
@@ -226,7 +293,20 @@ export default {
getData(){
if (this.keyword) {
this.$post(`${this.api.getTableByCondition}?showName=${this.keyword}&pageNum=${this.page}&pageSize=${this.pageSize}`).then(res => {
- this.listData = res.data.records
+ const list = res.data.records
+ list.map(e => {
+ // 开始结束时间只显示日期
+ const startTime = e.startTime ? e.startTime.slice(0, 10) : ''
+ const endTime = e.endTime ? e.endTime.slice(0, 10) : ''
+ if (startTime && endTime) {
+ e.timeRange = startTime + ' ~ ' + endTime
+ } else if (startTime) {
+ e.timeRange = startTime
+ } else if (endTime) {
+ e.timeRange = e.endTime
+ }
+ })
+ this.listData = list
this.total = res.data.total
}).catch(res => {})
} else {
@@ -255,6 +335,30 @@ export default {
this.$refs.table.clearSelection()
this.getData()
},
+
+ clearKeyword() {
+ this.keyword = ''
+ this.listData = []
+ },
+ toData(row){
+ // 登录了才能查看数据,否则直接跳转到登录页
+ if(this.token){
+ if (this.routes.find(e => e.path === '/data/list')) {
+ this.$router.push(`/data?typeId=${row.categoryTwoId}`)
+ } else {
+ this.keyword = row.categoryTwo
+ }
+ }else{
+ let route = this.$router.resolve({
+ path: '/login'
+ })
+ window.open(route.href)
+ }
+ },
+ toPart(i){
+ this.active = i
+ document.querySelector(`#part${i}`).scrollIntoView()
+ },
preview(row) {
// 登录后才能预览,否则直接跳转到登录页
if(this.token){
@@ -293,14 +397,7 @@ export default {
download(row){
// 登录了才能下载,否则直接跳转到登录页
if(this.token){
- // 查询是否有下载权限
- this.$get(`${this.api.isDownload}`,{
- tableId: row.id,
- schoolId: this.schoolId,
- }).then(res => {
- // 跳转到数据页去下载
- this.$router.push(`/data?download=true&id=${row.id}&name=${row.name}&showName=${row.showName}`)
- }).catch(res => {})
+ this.showDownload(row)
}else{
let route = this.$router.resolve({
path: '/login'
@@ -308,28 +405,124 @@ export default {
window.open(route.href)
}
},
- clearKeyword() {
- this.keyword = ''
- this.listData = []
+ checkAllFieldsChange(val) {
+ this.fields = val ? this.fieldsList.map(n => n.comment) : []
},
- toData(row){
- // 登录了才能查看数据,否则直接跳转到登录页
- if(this.token){
- if (this.routes.find(e => e.path === '/data/list')) {
- this.$router.push(`/data?typeId=${row.categoryTwoId}`)
+ showDownload(row) {
+ // 查询是否购买了该数据,只有购买了才能下载
+ this.$get(`${this.api.isDownload}`, {
+ tableId: row.id,
+ schoolId: this.schoolId,
+ }).then(res => {
+ this.curRow = row
+ this.downloadVisible = true
+ // 限制数据可选择的开始结束时间
+ if (row.startTime) {
+ startTimeLimit = new Date(row.startTime).getTime()
} else {
- this.keyword = row.categoryTwo
+ // 如果没有开始时间,则禁止选择开始时间
+ this.startTimeDisabled = true
}
- }else{
- let route = this.$router.resolve({
- path: '/login'
+ if (row.endTime) {
+ endTimeLimit = new Date(row.endTime).getTime()
+ this.timeDefault = row.endTime
+ } else {
+ // 如果没有结束时间,则禁止选择结束时间
+ this.endTimeDisabled = true
+ }
+
+ this.$get(`${this.api.previewData}?tableName=${row.name}&tableId=${row.id}`).then(res => {
+ let comment = res.comment
+ let fieldsList = []
+ comment.map(n => {
+ n.field != 'id' && n.field != 'operation_time' && fieldsList.push(n)
})
- window.open(route.href)
- }
+ this.fieldsList = fieldsList
+ }).catch(res => { })
+ }).catch(res => { })
},
- toPart(i){
- this.active = i
- document.querySelector(`#part${i}`).scrollIntoView()
+ closeDownload() {
+ this.checkAllFields = false
+ this.fields = []
+ this.startTime = ''
+ this.endTime = ''
+ this.frequency = ''
+ },
+ confirmDown() {
+ let fields = this.fields
+ if (!fields.length) return util.warningMsg('请选择字段')
+ if (!this.startTime) return util.warningMsg('请选择开始时间')
+ if (!this.endTime) return util.warningMsg('请选择结束时间')
+ if (!this.frequency) return util.warningMsg('请选择数据频率')
+ let invalid = false
+
+ if (this.startTime && this.endTime) {
+ let startTime = new Date(this.startTime)
+ let endTime = new Date(this.endTime)
+ let frequency = this.frequency
+
+ // 只要选择的不是日频,则要判断选择的日期区间有没有包含这段频率对应的完整交易日段
+ // 比如选的是周频,则判断选择的时间区间有没有包含一段完整的星期交易日,即星期1~5,
+ // 选的是月频的话,则判断选择的时间区间有没有包含一个完整的月份,即30天;年份同理
+ if (frequency == 2) {
+ let week = []
+ while (startTime <= endTime) {
+ let weekNum = startTime.getDay()
+ if (weekNum == 0) weekNum = 7
+ week.push(weekNum)
+ startTime.setTime(startTime.getTime() + 86400000)
+ }
+ // 如果没有包含1~5,则提示请选择完整区间,下面同理
+ for (let i = 1; i <= 5; i++) {
+ if (!week.includes(i)) {
+ invalid = true
+ break
+ }
+ }
+ } else if (frequency == 3) {
+ if ((endTime.getTime() - startTime.getTime()) / 86400000 < 30) invalid = true
+ } else if (frequency == 4) {
+ if ((endTime.getTime() - startTime.getTime()) / 86400000 < 90) invalid = true
+ } else if (frequency == 5) {
+ if ((endTime.getTime() - startTime.getTime()) / 86400000 < 365) invalid = true
+ }
+ }
+
+ if (invalid) return util.warningMsg('请选择完整区间')
+
+ let newFields = []
+ let fieldsList = this.fieldsList
+ fields.map(n => {
+ newFields.push(fieldsList.find(e => e.comment == n).field)
+ })
+ let msgObj = util.successMsg('数据正在生成中,请稍等片刻,生成后会自动下载,您可以先访问其他页面。', 5000)
+ this.downloadVisible = false
+
+ let startTime = this.startTime ? this.startTime : ''
+ let endTime = this.endTime ? this.endTime : ''
+ let frequency = this.frequency
+ axios.get(`${this.api.downloadData}?tableName=${this.curRow.name}&table_id=${this.curRow.id}&fields=${newFields.join()}&startTime=${startTime}&endTime=${endTime}&frequency=${frequency}`, {
+ headers: {
+ token: this.token
+ },
+ responseType: 'blob'
+ }).then((res) => {
+ msgObj.close()
+ if (res.data.type != 'multipart/form-data') return util.warningMsg('数据总数为零!')
+ // 统一调用该方法去下载excel
+ util.downloadFileDirect(`${this.curRow.showName}.xls`, new Blob([res.data]))
+
+ // 下载记录
+ this.$get(`${this.api.downloadRecord}?tableId=${this.curRow.id}&fields=${newFields.join()}` + (startTime ? `&startTime=${startTime}` : '') + (endTime ? `&endTime=${endTime}` : '') + `&frequency=${frequency}`).then(res => { }).catch(res => { })
+
+ // 下载次数+1
+ this.$post(this.api.saveRecord, {
+ tableId: this.curRow.id,
+ type: 1,
+ }).then(res => { }).catch(res => { })
+ }).catch(res => {
+ msgObj.close()
+ })
}
}
};
diff --git a/src/router/permission.js b/src/router/permission.js
index 1b19e30..77c3ef0 100644
--- a/src/router/permission.js
+++ b/src/router/permission.js
@@ -19,14 +19,18 @@ router.beforeEach((to, from, next) => {
// 如果是管理员则需要从获取的路由权限里判断当前访问页面是否有权限访问,如果没权限访问则跳转到403
if((mg && atob(decodeURI(mg)) === 'true') || (to.query.mg && atob(decodeURI(to.query.mg)) === 'true')){
if(routes.length){
- if(routes.find(n => n.name == toPath) || toPath == '/setting/person' || toPath == '/setting/download'){
- if(!to.query.mg){
- next({
- path: toPath,
- query: {mg}
- })
- }else{
+ if(routes.find(n => n.name == toPath) || toPath == '/setting/person' || toPath == '/setting/download' || toPath == '/index/list'){
+ if (toPath === '/index/list') {
next()
+ } else {
+ if(!to.query.mg){
+ next({
+ path: toPath,
+ query: {mg}
+ })
+ }else{
+ next()
+ }
}
}else{
if(to.path != '/403'){