Browse Source

首页数据调用

master
453530270@qq.com 3 years ago
parent
commit
90e7b2f321
  1. 54
      src/utils/request.js
  2. 69
      src/views/HomeView.vue
  3. 2
      vue.config.js

54
src/utils/request.js

@ -31,28 +31,40 @@ service.interceptors.request.use(
} }
) )
// 添加响应拦截器 // 接口响应拦截
service.interceptors.response.use( service.interceptors.response.use((response) => {
function (response) { const result = response.data
// console.log(response) return result
// 2xx 范围内的状态码都会触发该函数。 }, (error) => {
// 对响应数据做点什么 // 网络请求出错
// dataAxios 是 axios 返回数据中的 data const errMsg = ((error.response || {}).data || {}).message || '请求出现错误,请稍后再试'
const dataAxios = response.data console.log(errMsg)
// 这个状态码是和后端约定的
const code = dataAxios.reset
if(code!='1'){
return Promise.reject(response)
}
return dataAxios
},
function (error) {
// 超出 2xx 范围的状态码都会触发该函数。
// 对响应错误做点什么
// console.log(error)
return Promise.reject(error) return Promise.reject(error)
} })
)
// 添加响应拦截器
// service.interceptors.response.use(
// function (response) {
// // console.log(response)
// // 2xx 范围内的状态码都会触发该函数。
// // 对响应数据做点什么
// // dataAxios 是 axios 返回数据中的 data
// const dataAxios = response.data.data
// console.log("dataAxios:"+dataAxios)
// // 这个状态码是和后端约定的
// const code = dataAxios.reset
// if(code!='1'){
// return Promise.reject(response)
// }
// return dataAxios
// },
// function (error) {
// // 超出 2xx 范围的状态码都会触发该函数。
// // 对响应错误做点什么
// // console.log(error)
// return Promise.reject(error)
// }
// )
export default service export default service

69
src/views/HomeView.vue

@ -159,30 +159,49 @@ export default {
return { return {
// , // ,
klselt: "d", klselt: "d",
//
kltdata:[],
//
klvdata:[],
} }
}, },
mounted() { mounted() {
this.showorders() this.showorders()
this.cgrs_line() this.cgrs_line()
this.cgchart() this.cgchart()
// //
this.btgetdata() // this.btgetdata(this.klselt)
}, },
// //
methods: { methods: {
// //
btgetdata(){ btgetdata(type){
console.log(type)
let rqtp;
switch(type) {
case 'd':rqtp ="daily";break;
case 'm':rqtp ="monthly";break;
case 'y':rqtp ="yearly";break;
}
// //
btApi.allGroupTimeNum({'granularity':'daily'}).then(res=>{ btApi.allGroupTimeNum({'granularity':rqtp}).then(res=>{
console.log(res) const kldata = res.data.data.allTimeData
}).catch(err=>{ //
console.log("发生错误:") let kltd=new Array;
console.log(err) let tmpkvd=new Array;
const dkeys = res.data.data.dkeys
dkeys.forEach(function(item,idx){
kltd.push(item)
tmpkvd.push(kldata[item].num)
})
this.kltdata = kltd
this.klvdata = tmpkvd
}); });
}, },
// //
selitem(type) { selitem(type) {
this.klselt = type; this.klselt = type;
this.btgetdata(type)
}, },
// //
showorders() { showorders() {
@ -192,35 +211,8 @@ export default {
// //
var option; var option;
// option = { //var data = [100, 200, 100, 200, 100, 200, 250, 50, 30, 130, 150, 110, 120]
// grid: { //leftrightbottom var data = this.klvdata
// left: '3%',
// right: '4%',
// bottom: '3%',
// containLabel: true
// },
// xAxis: {
// type: 'category',
// data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
// },
// yAxis: {
// type: 'value'
// },
// series: [
// {
// data: [120, 200, 150, 80, 70, 110, 130],
// type: 'bar',
// showBackground: true,
// color: "#2626ff",
// backgroundStyle: {
// color: 'rgba(180, 180, 180, 0.2)'
// },
// }
// ]
// };
var data = [100, 200, 100, 200, 100, 200, 250, 50, 30, 130, 150, 110, 120]
// var data = [Math.random() * 300] // var data = [Math.random() * 300]
option = { option = {
// backgroundColor: '#031245', // backgroundColor: '#031245',
@ -275,7 +267,8 @@ export default {
}, },
show: true, show: true,
}, },
data: ['09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '20:00', '21:00', '22:00'], data: this.kltdata,
//data: ['09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '20:00', '21:00', '22:00'],
type: 'category', type: 'category',
}, },
yAxis: { yAxis: {

2
vue.config.js

@ -2,7 +2,7 @@ const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({ module.exports = defineConfig({
// 部署应用时候的基本url // 部署应用时候的基本url
//publicPath: process.env.NODE_ENV === 'production' ? './' : '/', publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
devServer: { devServer: {
proxy: { proxy: {

Loading…
Cancel
Save