修改配置

This commit is contained in:
daihh
2022-11-02 12:38:14 +08:00
parent ed553c5175
commit 086d28decc
10 changed files with 213 additions and 239 deletions

166
api/ajax.js Normal file
View File

@@ -0,0 +1,166 @@
import config from '@/config/index.js'
import {getToken} from '@/utils/token.js'
import qs from 'qs'
const ReLoginUrl="/login";
const formatUrl=function(url){
return url;
// if(url.startsWith('http') || url.startsWith('https')){
// //console.log(url,"我拿到的url值我想知道下面有啥方法")
// return url;
// }else{
// return config.apiBaseUrl+url
// }
}
const formRequest=function(method,url,data){
let token=getToken();
if(!token){
token='';
}
let headers={
'content-type':'application/x-www-form-urlencoded',
'XBOE-Access-Token':token
}
let reUrl=formatUrl(url);
return new Promise(function(resolve, reject){
uni.request({
url: reUrl,
method,
data: data,
xhrFields: {withCredentials: true},
dataType: 'json',
header: headers,
success:function(rs,statusCode){
if(rs.statusCode==200){
if(rs.data.status==401 || rs.data.status==402){
let loginPath=config.loginPath;
if(loginPath.startsWith('http')){
// #ifdef APP-PLUS
plus.runtime.openURL(loginPath) //这里默认使用外部浏览器打开而不是内部web-view组件打开
// #endif
// #ifdef H5
//window.open(loginPath)
location.href=loginPath
// #endif
}else{
uni.redirectTo({
url:loginPath
})
}
}else{
resolve(rs.data);
}
}else{
reject("API请求错误");
}
},
fail:function(err){
reject(err);
}
});
});
}
const jsonRequest=function(method,url,data){
let token=getToken();
if(!token){
token='';
}
let headers={
'XBOE-Access-Token':token
}
let reUrl=formatUrl(url);
return new Promise(function(resolve, reject){
uni.request({
url: reUrl,
method,
data: data,
xhrFields: {withCredentials: true},
dataType: 'json',
header: headers,
success:function(rs,statusCode){
if(rs.statusCode==200){
if(rs.data.status==401 || rs.data.status==402){
let loginPath=config.loginPath;
if(loginPath.startsWith('http')){
// #ifdef APP-PLUS
plus.runtime.openURL(loginPath) //这里默认使用外部浏览器打开而不是内部web-view组件打开
// #endif
// #ifdef H5
//window.open(loginPath)
location.href=loginPath
// #endif
}else{
uni.redirectTo({
url:loginPath
})
}
}else{
resolve(rs.data);
}
}else{
reject("API请求错误");
}
},
fail:function(err){
reject(err);
}
});
});
}
//get请求
const get=function(baseURL,url){
return formRequest('GET',baseURL+url,'');
}
//post请求
const post=function(baseURL,url,data){
if(data){
data=qs.stringify(data);
}
return formRequest('POST',baseURL+url,data);
}
//postJson请求
const postJson=function(baseURL,url,json){
return jsonRequest('POST',baseURL+url,json);
}
//put请求
const put=function(baseURL,url,data){
if(data){
data=qs.stringify(data);
}
return formRequest('PUT',baseURL+url,data);
}
//putJson请求
const putJson=function(baseURL,url,json){
return jsonRequest('PUT',baseURL+url,json);
}
//patch请求
const patch=function(baseURL,url,data){
if(data){
data=qs.stringify(data);
}
return formRequest('PATCH',baseURL+url,data);
}
//patchJson请求
const patchJson=function(baseURL,url,json){
return jsonRequest('PATCH',baseURL+url,json);
}
//delete请求
const del=function(baseURL,url,data){
if(data){
data=qs.stringify(data);
}
return formRequest('DELETE',baseURL+url,data);
}
export default {
get,
post,
postJson,
put,
putJson,
patch,
patchJson,
del
}

View File

@@ -1,6 +1,6 @@
// import ajax from '@/utils/xajax.js'
import config from '@/config/index.js'
import ajax from '../ajax';
const baseURL = process.env.VUE_APP_CESOURCE_BASE_API;
const baseURL = config.socialApiBaseUrl;
/**

View File

@@ -1,6 +1,7 @@
// import ajax from '@/utils/xajax.js'
import config from '@/config/index.js'
import ajax from '../ajax';
const baseURL = process.env.VUE_APP_CESOURCE_BASE_API;
const baseURL = config.socialApiBaseUrl;
/**

View File

@@ -1,205 +0,0 @@
// import ajax from '@/utils/xajax.js'
// import ajax from '../cesource/index.js';
import axios from 'axios'
import { getToken } from '@/utils/token'
import ajax from '../ajax';
const baseURL = process.env.VUE_APP_CESOURCE_BASE_API;
/**
* 添加或者编辑
* @param 参数见设计文档
* */
const save=function (data){
return ajax.postJson(baseURL,'/xboe/subgroup/m/noteinfo/save',data);
}
/**
* 添加或者编辑
* @param 参数见设计文档
* */
const update=function (data){
return ajax.postJson(baseURL,'/xboe/subgroup/m/noteinfo/update',data);
}
/**
* 详情
* */
const detail=function (id){
return ajax.get(baseURL,'/xboe/subgroup/m/noteinfo/detail?id='+id);
}
/**
* 删除笔记
* */
const del=function (id){
return ajax.get(baseURL,'/xboe/subgroup/m/noteinfo/delete?id='+id);
}
/**
* 查询课程笔记
* @param{
* pageIndex
* pageSize
* courseId 课程id
* openType 公开类型
* }
* */
const coursePage=function (query){
return ajax.post(baseURL,'/xboe/subgroup/m/noteinfo/course-page',query);
}
/**
* 查询我的指定课程笔记
* */
const myCourse=function (courseId){
return ajax.get(baseURL,'/xboe/subgroup/m/noteinfo/mycourse?courseId='+courseId);
}
/**
* 查询笔记的修改历史
* */
const history=function (noteId){
return ajax.get(baseURL,'/xboe/subgroup/m/noteinfo/modify/history?noteId='+noteId);
}
/**
* 我的笔记
* type 我发布的是1 我导入的是2
* orderType 升序降序
* orderField排序字段
* courseId 课程id
* */
const query=function (data){
return ajax.post(baseURL,'/xboe/subgroup/m/noteinfo/query',data);
}
/**
* 课程列表 应该是当前用户记过笔记的课程
* */
const course=function (){
return ajax.get(baseURL,'/xboe/subgroup/m/noteinfo/course');
}
/**
* 还原
* 笔记id
* */
const restore=function (id){
return ajax.get(baseURL,'/xboe/subgroup/m/noteinfo/restore?id='+id);
}
/**
* 二次查询
* @param{
* ids
* }
* */
const ids=function (data){
return ajax.postJson(baseURL,'/xboe/subgroup/m/noteinfo/ids',data);
}
/**
* 导出excel
* @param {
* ids ["",""]
* }
* */
const exportExcel=function (data){
return ajax.postJsonToFile(baseURL,'/xboe/subgroup/m/noteinfo/exportExcel',data);
// return ajax.post(baseURL,'/xboe/subgroup/m/noteinfo/exportExcel',data);
}
/**
* 导出excel预览
* @param {
* ids ["",""]
* }
* */
const exportExcelPre=function (data){
return ajax.post(baseURL,'/xboe/subgroup/m/noteinfo/excel-detail',data);
}
/**
* 导出pdf预览
* @param {
* ids ["",""]
* }
* */
const exportPdfPre=function (data){
return ajax.post(baseURL,'/xboe/subgroup/m/noteinfo/pdf-detail',data);
}
/**
* 导出pdf
* @param{
*
* }
* */
const exportPdf=function (udata){
// return ajax.postJson(baseURL,'/xboe/subgroup/m/noteinfo/exportPdf',data);
//return ajax.post(baseURL,'/xboe/subgroup/m/noteinfo/exportPdf',data);
var url = baseURL + '/xboe/subgroup/m/noteinfo/exportPdf';
axios({
method: 'POST',
url: url,
data:udata,
responseType: 'blob',
headers: { 'XBOE-Access-Token':getToken(),'Content-Type':'application/pdf;charset=utf-8'}
}).then(res => {
//resolveBlob(res, mimeMap.zip);
console.log(res);
const aLink = document.createElement('a')
var blob = new Blob([res.request.response], { type: 'application/pdf' })
// //从response的headers中获取filename, 后端response.setHeader("Content-disposition", "attachment; filename=xxxx.docx") 设置的文件名;
//var patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*')
//var contentDisposition = decodeURI(res.headers['content-disposition'])
//var result = patt.exec(contentDisposition)
//var fileName = result[1]
//fileName = fileName.replace(/\"/g, '')
aLink.href = URL.createObjectURL(blob)
aLink.setAttribute('download','我的笔记.pdf') // 设置下载文件名称
document.body.appendChild(aLink)
aLink.click()
document.body.removeChild(aLink)
})
}
/**
* 我的笔记收藏和分享都是这一个,目前只有收藏
* @param{
* paegIndex
* pageSize
* dataType 1收藏 2分享
* orderType 排序顺序 顺序倒叙
* orderField 排序字段
* keyword 关键字查询
* }
* */
const pagelist=function (query){
return ajax.post(baseURL,'/xboe/subgroup/m/noteinfo/pagelist',query);
}
export default {
save,
detail,
del,
coursePage,
myCourse,
history,
pagelist,
query,
course,
update,
restore,
ids,
exportExcel,
exportPdf,
exportExcelPre,
exportPdfPre
}

View File

@@ -1,7 +1,6 @@
// import ajax from '@/utils/xajax.js'
// import ajax from '../cesource/index.js';
import ajax from '../ajax'
const baseURL = process.env.VUE_APP_CESOURCE_BASE_API;
import config from '@/config/index.js'
import ajax from '../ajax';
const baseURL = config.socialApiBaseUrl;
/**

View File

@@ -1,7 +1,8 @@
/**文章模块的相关处理*/
// import ajax from '@/utils/xajax.js'
import ajax from '../ajax'
const baseURL = process.env.VUE_APP_STAT_BASE_API;
import config from '@/config/index.js'
import ajax from '../ajax';
const baseURL = config.statApiBaseUrl;
/**
* 发送事件,具体事件参考后台管理的事件查看
*参数如下:

View File

@@ -1,5 +1,6 @@
import config from '@/config/index.js'
import ajax from '../ajax';
const baseURL = process.env.VUE_APP_CESOURCE_BASE_API;
const baseURL = config.socialApiBaseUrl;
/**

View File

@@ -1,7 +1,6 @@
// import ajax from '@/utils/xajax.js'
// import ajax from '../cesource/index.js'
import config from '@/config/index.js'
import ajax from '../ajax';
const baseURL = process.env.VUE_APP_CESOURCE_BASE_API;
const baseURL = config.socialApiBaseUrl;
/**

View File

@@ -1,6 +1,8 @@
/**系统的一些全局配置变量*/
let apiBaseUrl = '';
let oldApiBaseUrl ='/uboeApi';
let statApiBaseUrl='/statApi';
let socialApiBaseUrl='/socialApi';
let loginPath='/pages/login/login';
let context='/mbile';
let tokenName='';
@@ -10,26 +12,34 @@ let version=1;
if(process.env.NODE_ENV === 'development'){
//本地开发环境
apiBaseUrl = '/systemapi';
apiBaseUrl = '/systemapi';
oldApiBaseUrl = '/uboeApi';
statApiBaseUrl='/statApi';
socialApiBaseUrl='/socialApi';
fileUrl = 'http://localhost:9090/cdn/upload';
loginPath='/pages/login/login';
}else if(process.env.NODE_ENV === 'preview'){
// 预发布环境,当前配置未使用上
apiBaseUrl = '/systemapi';
oldApiBaseUrl = '/uboeApi';
statApiBaseUrl='/statApi';
socialApiBaseUrl='/socialApi';
fileUrl = 'https://u-pre.boe.com/upload';
loginPath='https://u-pre.boe.com/m/preview';
}else if(process.env.NODE_ENV === 'testing'){
// 测试环境
apiBaseUrl = '/systemapi';
oldApiBaseUrl = '/uboeApi';
statApiBaseUrl='/statApi';
socialApiBaseUrl='/socialApi';
fileUrl = 'https://u-pre.boe.com/upload';
loginPath='https://u-pre.boe.com/m/testing';
}else{
// 生产环境
apiBaseUrl = '/systemapi';
oldApiBaseUrl = '/uboeApi';
statApiBaseUrl='/statApi';
socialApiBaseUrl='/socialApi';
fileUrl = 'https://u.boe.com/upload';
loginPath='https://u.boe.com/m/loginuser';
}
@@ -37,6 +47,8 @@ if(process.env.NODE_ENV === 'development'){
export default {
apiBaseUrl:apiBaseUrl,
oldApiBaseUrl:oldApiBaseUrl,
statApiBaseUrl:statApiBaseUrl,
socialApiBaseUrl:socialApiBaseUrl,
context:context,
appId:appId,
loginPath:loginPath,

View File

@@ -89,26 +89,26 @@
"^/uboeApi" : "/api"
}
},
"/statApi": {
// 目标代理服务器地址
"target" : "http://192.168.0.11:9080",
"changeOrigin" : true,
"logLevel" :"debug",
"secure" : false,
"pathRewrite" : {
"^/statApi": ""
}
},
"/socialApi": {
// 目标代理服务器地址
"target": "http://192.168.0.11:9081",
"changeOrigin": true,
"logLevel":"debug",
"secure": false,
"pathRewrite": {
"^/socialApi": ""
}
}
"/statApi": {
// 目标代理服务器地址
"target" : "http://192.168.0.11:9080",
"changeOrigin" : true,
"logLevel" :"debug",
"secure" : false,
"pathRewrite" : {
"^/statApi": ""
}
},
"/socialApi": {
// 目标代理服务器地址
"target": "http://192.168.0.11:9081",
"changeOrigin": true,
"logLevel":"debug",
"secure": false,
"pathRewrite": {
"^/socialApi": ""
}
}
}
},
"optimization" : {