mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-portal.git
synced 2025-12-11 03:46:44 +08:00
首页精品课部分
This commit is contained in:
208
src/api/httpAjax.js
Normal file
208
src/api/httpAjax.js
Normal file
@@ -0,0 +1,208 @@
|
|||||||
|
import axios from 'axios'
|
||||||
|
import qs from 'qs'
|
||||||
|
import {Notification, MessageBox, Message} from 'element-ui'
|
||||||
|
import store from '@/store'
|
||||||
|
import {getToken} from '@/utils/token'
|
||||||
|
import errorCode from '@/utils/errorCode'
|
||||||
|
|
||||||
|
/**
|
||||||
|
*request请求 axios.request(config)
|
||||||
|
*requestJson请求 axios.request(config)
|
||||||
|
*get请求 axios.get(url[, config])
|
||||||
|
*post请求 axios.post(url[, data[, config]])
|
||||||
|
*postJson请求 axios.post(url[, data[, config]])
|
||||||
|
*put请求 axios.put(url[, data[, config]])
|
||||||
|
*putJson请求 axios.put(url[, data[, config]])
|
||||||
|
*patch请求 axios.patch(url[, data[, config]])
|
||||||
|
*patchJson请求 axios.patch(url[, data[, config]])
|
||||||
|
*delete请求 axios.delete(url[, config])
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// const ReLoginUrl=process.env.VUE_APP_LOGIN_URL;
|
||||||
|
const TokenName = 'token';
|
||||||
|
/**axios.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded'**/
|
||||||
|
//只是用于发送json对象数据时使用post,put,patch
|
||||||
|
/**axios.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded'**/
|
||||||
|
//只是用于发送json对象数据时使用post,put,patch
|
||||||
|
//用于普通的发送请求
|
||||||
|
const formRequest = axios.create({
|
||||||
|
//headers:{'Content-Type':'application/x-www-form-urlencoded'},
|
||||||
|
// axios中请求配置有baseURL选项,表示请求URL公共部分
|
||||||
|
// baseURL: process.env.VUE_APP_CESOURCE_BASE_API,
|
||||||
|
//超时
|
||||||
|
timeout: 10000,
|
||||||
|
})
|
||||||
|
//发送json对象的拦截器
|
||||||
|
formRequest.interceptors.request.use(config => {
|
||||||
|
//是否需要设置 token
|
||||||
|
const isToken = (config.headers || {}).isToken === false
|
||||||
|
let curToken = getToken();
|
||||||
|
//curToken='eyJ0eXBlIjoidG9rZW4iLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC91LmJvZS5jb20iLCJpYXQiOjE2NzIzMTE2MTIsImV4cCI6MTY3MjMxODgxMiwiR2l2ZW5OYW1lIjoiYm9ldSIsInVzZXJJZCI6IjZCMDQ5RkFGLUMzMTQtN0NDRi0wRDI4LTBEMjNGNEM0MjUzMSIsInVJZCI6Ijk2NTM0MjAyNzQ5NzYwNzE2OCIsInBlcm1pc3Npb24iOiIifQ==.a4f41376e994c5fcd3ab537ce17572ef4c633863f87785cf7b6ffa353e2ed51c';
|
||||||
|
if (curToken && !isToken) {
|
||||||
|
config.headers[TokenName] = curToken // 让每个请求携带自定义token 请根据实际情况自行修改
|
||||||
|
}
|
||||||
|
return config
|
||||||
|
}, error => {
|
||||||
|
console.log(error)
|
||||||
|
Promise.reject(error)
|
||||||
|
});
|
||||||
|
formRequest.interceptors.response.use(res => {
|
||||||
|
//console.log(res);
|
||||||
|
const code = res.data.status || 200;
|
||||||
|
if (code === 200) {
|
||||||
|
return res.data
|
||||||
|
} else {
|
||||||
|
if (code === 401) {
|
||||||
|
// store.dispatch('LogOut').then(() => {
|
||||||
|
// location.href = this.webBaseUrl + ReLoginUrl;
|
||||||
|
// })
|
||||||
|
console.error('', res.data);
|
||||||
|
return Promise.reject(new Error('接口返回未登录'))
|
||||||
|
} else if (code === 403) {
|
||||||
|
var msg = '当前操作没有权限';
|
||||||
|
Message({message: msg, type: 'error'});
|
||||||
|
return Promise.reject(new Error(msg))
|
||||||
|
} else {
|
||||||
|
//Message({message: res.data.message, type: 'error'});
|
||||||
|
//console.log('err' + res.data.error);
|
||||||
|
return res.data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error => {
|
||||||
|
console.log('err', error)
|
||||||
|
let {message} = error;
|
||||||
|
if (message == "Network Error") {
|
||||||
|
message = "网络异常,请稍后重试";
|
||||||
|
} else if (message.includes("timeout")) {
|
||||||
|
message = "网络异常或接口错误,请求超时";
|
||||||
|
} else if (message.includes("Request failed with status code")) {
|
||||||
|
message = "系统接口" + message.substr(message.length - 3) + "异常";
|
||||||
|
}
|
||||||
|
Message({
|
||||||
|
message: message,
|
||||||
|
type: 'error',
|
||||||
|
duration: 5 * 1000
|
||||||
|
})
|
||||||
|
return Promise.reject(error)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* request请求,可以自定义参数
|
||||||
|
*/
|
||||||
|
const request = formRequest.request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get请求 ,只有url
|
||||||
|
*/
|
||||||
|
const get = function (baseURL, url) {
|
||||||
|
return request({
|
||||||
|
baseURL,
|
||||||
|
url: url,
|
||||||
|
method: 'get',
|
||||||
|
headers: {'Content-Type': 'application/json;charset=utf-8'}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* post请求
|
||||||
|
* @param {Object} url
|
||||||
|
* @param {Object} postData
|
||||||
|
*/
|
||||||
|
const post = function (baseURL, url, postData) {
|
||||||
|
if (postData) {
|
||||||
|
postData = qs.stringify(postData);
|
||||||
|
}
|
||||||
|
return request({
|
||||||
|
baseURL,
|
||||||
|
url: url,
|
||||||
|
method: 'post',
|
||||||
|
data: postData,
|
||||||
|
headers: {'Content-Type': 'application/json;charset=utf-8'}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
//post请求
|
||||||
|
const postForm = function (baseURL, url, data) {
|
||||||
|
return request({
|
||||||
|
baseURL,
|
||||||
|
url,
|
||||||
|
data,
|
||||||
|
method: 'post',
|
||||||
|
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// const postJson=jsonRequest.post;
|
||||||
|
|
||||||
|
const postJson = function (baseURL, url, postData) {
|
||||||
|
return request({
|
||||||
|
baseURL,
|
||||||
|
url: url,
|
||||||
|
method: 'post',
|
||||||
|
data: postData,
|
||||||
|
headers: {'Content-Type': 'application/json;charset=utf-8'},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 导出文件请求定义
|
||||||
|
const postJsonToFile = function (baseURL, url, postData) {
|
||||||
|
return request({
|
||||||
|
baseURL,
|
||||||
|
url: url,
|
||||||
|
method: 'post',
|
||||||
|
data: postData,
|
||||||
|
headers: {'Content-Type': 'application/json;charset=utf-8'},
|
||||||
|
responseType: 'blob'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const getJsonToFile = function (baseURL, url, postData) {
|
||||||
|
return request({
|
||||||
|
baseURL,
|
||||||
|
url: url,
|
||||||
|
method: 'get',
|
||||||
|
data: postData,
|
||||||
|
headers: {'Content-Type': 'application/json;charset=utf-8'},
|
||||||
|
responseType: 'blob'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* put请求
|
||||||
|
*/
|
||||||
|
const put = function (baseURL, url, data) {
|
||||||
|
if (data) {
|
||||||
|
data = qs.stringify(data);
|
||||||
|
}
|
||||||
|
return request({
|
||||||
|
baseURL,
|
||||||
|
url: url,
|
||||||
|
method: 'put',
|
||||||
|
data: data,
|
||||||
|
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const putJson = function (baseURL, url, data) {
|
||||||
|
return request({
|
||||||
|
baseURL,
|
||||||
|
url: url,
|
||||||
|
method: 'put',
|
||||||
|
data: data,
|
||||||
|
headers: {'Content-Type': 'application/json;charset=utf-8'},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default {
|
||||||
|
tokenName: TokenName,
|
||||||
|
request,
|
||||||
|
get,
|
||||||
|
post,
|
||||||
|
postJson,
|
||||||
|
postJsonToFile,
|
||||||
|
put,
|
||||||
|
putJson,
|
||||||
|
getJsonToFile
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
import ajax from '@/utils/xajax.js'
|
import ajax from '@/utils/xajax.js'
|
||||||
import http from '../unionAjax'
|
import http from '../unionAjax'
|
||||||
|
import httpAjax from '../httpAjax'
|
||||||
|
|
||||||
const baseURL = process.env.VUE_APP_MANAGER_API_PATH;
|
const baseURL = process.env.VUE_APP_MANAGER_API_PATH;
|
||||||
|
|
||||||
|
|
||||||
@@ -49,7 +51,7 @@ const courselist=function (data){
|
|||||||
}
|
}
|
||||||
// 精品课信息列表
|
// 精品课信息列表
|
||||||
const qualitylist=function (data){
|
const qualitylist=function (data){
|
||||||
return http.post(baseURL,'/quality/home/qualityItem',data);
|
return httpAjax.post(baseURL,'/quality/home/qualityItem',data);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 首页新课程推荐列表
|
* 首页新课程推荐列表
|
||||||
|
|||||||
@@ -362,7 +362,15 @@ export const constantRoutes = [{
|
|||||||
path: '/500',
|
path: '/500',
|
||||||
component: (resolve) => require(['@/views/error/500'], resolve),
|
component: (resolve) => require(['@/views/error/500'], resolve),
|
||||||
hidden: true
|
hidden: true
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
path: '/quailtyCourse',
|
||||||
|
hidden: true,
|
||||||
|
component: (resolve) => require(['@/views/portal/course/quailtyCourse'], resolve),
|
||||||
|
name: 'course',
|
||||||
|
meta: {title: '精品课课程', keepAlive: true, icon: 'dashboard', noCache: true, affix: false},
|
||||||
|
},
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
const router = new VueRouter({
|
const router = new VueRouter({
|
||||||
|
|||||||
@@ -167,7 +167,7 @@
|
|||||||
<span class="quyer-tag">
|
<span class="quyer-tag">
|
||||||
</span>
|
</span>
|
||||||
<span class="more">
|
<span class="more">
|
||||||
<router-link to="/course">查看更多>></router-link>
|
<router-link to="/quailtyCourse">查看更多>></router-link>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
2198
src/views/portal/course/quailtyCourse.vue
Normal file
2198
src/views/portal/course/quailtyCourse.vue
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user