新增加一个

This commit is contained in:
daihh
2023-01-30 19:30:12 +08:00
parent cc9eb8a0c2
commit 065298b91a
2 changed files with 178 additions and 11 deletions

169
api/boe/boeUserbasic.js Normal file
View File

@@ -0,0 +1,169 @@
import config from '@/config/index.js'
import {getToken,removeToken} from '@/utils/token.js'
import qs from 'qs'
const ReLoginUrl="/login";
const formatUrl=function(url){
if(url.startsWith('http') || url.startsWith('https')){
//console.log(url,"我拿到的url值我想知道下面有啥方法")
return url;
}else{
return '/userbasic'+url
}
}
const formRequest=function(method,url,data){
let token=getToken();
if(!token){
token='';
}
let headers={
'content-type':'application/x-www-form-urlencoded',
'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==6001){
//uni.removeStorageSync('userInfo');
removeToken();
let loginPath=config.loginPath;
if(loginPath.startsWith('http')){
// #ifdef APP-PLUS
plus.runtime.openURL(loginPath) //这里默认使用外部浏览器打开而不是内部web-view组件打开
// #endif
// #ifdef H5
//window.open(loginPath)
let returnUrl=window.location.protocol+'//'+window.location.host+config.context;
location.href=config.loginPath+"?returnUrl="+encodeURIComponent(returnUrl+'/pages/login/loading');
// #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={
'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==6001){
removeToken();
let loginPath=config.loginPath;
if(loginPath.startsWith('http')){
// #ifdef APP-PLUS
plus.runtime.openURL(loginPath) //这里默认使用外部浏览器打开而不是内部web-view组件打开
// #endif
// #ifdef H5
//window.open(loginPath)
let returnUrl=window.location.protocol+'//'+window.location.host+config.context;
location.href=config.loginPath+"?returnUrl="+encodeURIComponent(returnUrl+'/pages/login/loading');
// #endif
}else{
uni.redirectTo({
url:loginPath
})
}
}else{
resolve(rs.data);
}
}else{
reject("API请求错误");
}
},
fail:function(err){
reject(err);
}
});
});
}
//get请求
const get=function(url){
return formRequest('GET',url,'');
}
//post请求
const post=function(url,data){
if(data){
data=qs.stringify(data);
}
return formRequest('POST',url,data);
}
//postJson请求
const postJson=function(url,json){
return jsonRequest('POST',url,json);
}
//put请求
const put=function(url,data){
if(data){
data=qs.stringify(data);
}
return formRequest('PUT',url,data);
}
//putJson请求
const putJson=function(url,json){
return jsonRequest('PUT',url,json);
}
//patch请求
const patch=function(url,data){
if(data){
data=qs.stringify(data);
}
return formRequest('PATCH',url,data);
}
//patchJson请求
const patchJson=function(url,json){
return jsonRequest('PATCH',url,json);
}
//delete请求
const del=function(url,data){
if(data){
data=qs.stringify(data);
}
return formRequest('DELETE',url,data);
}
export default {
get,
post,
postJson,
put,
putJson,
patch,
patchJson,
del
}

View File

@@ -1,7 +1,5 @@
/**对应用户中心新的接口*/
import config from '@/config/index.js'
import ajax from '../ajax';
const baseURL = '/userbasic';
import ajax from '@/api/boe/boeUserbasic.js'
/**
@@ -9,7 +7,7 @@ const baseURL = '/userbasic';
* organization_id
*/
const userParentOrg = function() {
return ajax.post(baseURL,'/org/userParentOrg',{});
return ajax.post('/org/userParentOrg',{});
}
//https://u-pre.boe.com/userbasic/org/list
@@ -17,20 +15,20 @@ const userParentOrg = function() {
* 根据关键字查询机构
*/
const findOrgsByKeyword = function(keyword) {
return ajax.postJson(baseURL,'/org/list',{keyword});
return ajax.postJson('/org/list',{keyword});
}
const findOrgTreeByOrgId = function(orgId) {
return ajax.postJson(baseURL,'/org/childOrgs',{orgId});
return ajax.postJson('/org/childOrgs',{orgId});
}
const getOrgInfo = function(orgId) {
return ajax.postJson(baseURL,'/org/info',{orgId});
return ajax.postJson('/org/info',{orgId});
}
/**根据用户id获取用户的信息*/
const getUserInfoById = function(id) {
return ajax.postJson(baseURL,'/user/list',{id});
return ajax.postJson('/user/list',{id});
}
/**
@@ -38,7 +36,7 @@ const getUserInfoById = function(id) {
* 获取当前用户受众信息
*/
const getUserCrowds = function() {
return ajax.postJson(baseURL,'/audience/userAudiences',{});
return ajax.postJson('/audience/userAudiences',{});
}
@@ -46,7 +44,7 @@ const getUserCrowds = function() {
* 获取hrbp数据
*/
const getOrgHrbpInfo = function(orgId) {
return ajax.postJson(baseURL,'/org/orgHrbpInfo',{orgId});
return ajax.postJson('/org/orgHrbpInfo',{orgId});
}
/**
@@ -54,7 +52,7 @@ const getOrgHrbpInfo = function(orgId) {
* {newPassword:'',oldPassword:''}
*/
const modifyPassword = function(data) {
return ajax.postJson(baseURL,'/user/resetPassword',data);
return ajax.postJson('/user/resetPassword',data);
}
export default {