Initial commit

This commit is contained in:
jackyu66git
2026-03-23 11:52:05 +08:00
commit c3c9db3151
267 changed files with 24984 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
//统一设置API接口地址
let urls = {
// 七牛相关API
upload: `/admin-api/infra/file/upload`,
newPageUrl: `/app-api/psychic/news/page`,
newDetailUrl: `/app-api/psychic/news/get`,
loginUrl: `/app-api/oauth/app/login`,
getBanner: `/app-api/psychic/banner/all`,
psychicSave: `/app-api/psychic/save`,
getPsychicListTest: `/app-api/psychic/study/list`,
getSingleDetail: `/app-api/psychic/study/getSingleDetail`,
userChoiceSave: `/app-api/psychic/user-choice/save`,
getResult: `/app-api/psychic/user-choice/getResult`,
myTest: `/app-api/psychic/user-choice/my-test`,
businessScopeList: `/app-api/psychic/doctor-info/business-scope-list`,
getDoctorInfo: `/app-api/psychic/doctor-info/get`,
doctorInfopage: `/app-api/psychic/doctor-info/page`,
focus: `/app-api/psychic/doctor-info/focus`,
cancelFocus: `/app-api/psychic/doctor-info/cancel-focus`,
appointTotalList: `/app-api/psychic/appointment/remain-list`,
dateDetailList: `/app-api/psychic/appointment/date-detail-list`,
getShowInfo: `/app-api/psychic/doctor-info/get-show-info`,
createOrder: `/app-api/psychic/pay/createOrder`,
refund: `/app-api/psychic/pay/refund`,
getSelfInfo: `/app-api/psychic/platform-user/getSelfInfo`,
updateUserInfo: `/app-api/psychic/platform-user/update`,
notReadNum: `/app-api/psychic/platform-user/not-read-num`,
focusToRead: `/app-api/psychic/platform-user/focus-to-read`,
orderToRead: `/app-api/psychic/platform-user/order-to-read`,
userFeedback: `/app-api/psychic/platform-user/user-feedback`,
feedbackFlag: `/app-api/psychic/platform-user/feedback-flag`,
focusAll: `/app-api/psychic/platform-user/focus-all`,
getByCode: `/app-api/psychic/procotol/getByCode`,
// 订单
createZxOrder: `/app-api/psychic/order/create`,
orderList: `/app-api/psychic/order/order-list`,
orderDetail: `/app-api/psychic/order/order-detail`,
getPayParam: `/app-api/psychic/order/get-pay-param`,
cancelOrder: `/app-api/psychic/order/cancel`,
deleteOrder: `/app-api/psychic/order/delete-order`,
}
export {
urls
}
+171
View File
@@ -0,0 +1,171 @@
import { mergeConfig, dispatchRequest, jsonpRequest} from "./utils.js";
export default class request {
constructor(options) {
//请求公共地址
this.baseUrl = options.baseUrl || "";
//公共文件上传请求地址
this.fileUrl = options.fileUrl || "";
// 超时时间
this.timeout = options.timeout || 6000;
// 服务器上传图片默认url
this.defaultUploadUrl = options.defaultUploadUrl || "";
//默认请求头
this.header = options.header || {};
//默认配置
this.config = options.config || {
isPrompt: true,
load: true,
isFactory: true,
resend: 0
};
}
navigateTo(url,data) {
const isLoggedIn = uni.getStorageSync('token'); // 假设 token 保存在本地存储
console.log("isLoggedIn",isLoggedIn)
if (isLoggedIn) {
if(data){
uni.navigateTo({
url: url,
animationType: "pop-in",
success: function(res) {
res.eventChannel.emit('acceptDataFromOpenerPage',data)
}
})
}else{
uni.navigateTo({
"url": url,
"animationType": "pop-in"
});
}
} else {
uni.showModal({
title: '提示',
content: '您还未登录,是否前往登录?',
confirmText: '前往',
success: function (res) {
if (res.confirm) {
uni.navigateTo({
"url":"/pages/login-pop/login-pop?type=2",
"animationType": "pop-in"
})
}
}
});
}
}
//post请求
post(url = '', data = {}, options = {}) {
return this.request({
method: "POST",
data: data,
url: url,
...options
});
}
//get请求
get(url = '', data = {}, options = {}) {
return this.request({
method: "GET",
data: data,
url: url,
...options
});
}
//put请求
put(url = '', data = {}, options = {}) {
return this.request({
method: "PUT",
data: data,
url: url,
...options
});
}
//delete请求
delete(url = '', data = {}, options = {}) {
return this.request({
method: "DELETE",
data: data,
url: url,
...options
});
}
//jsonp请求(只限于H5使用)
jsonp(url = '', data = {}, options = {}) {
return this.request({
method: "JSONP",
data: data,
url: url,
...options
});
}
//接口请求方法
async request(data) {
// 请求数据
let requestInfo,
// 是否运行过请求开始钩子
runRequestStart = false;
try {
if (!data.url) {
throw { errMsg: "【request】缺失数据url", statusCode: 0}
}
// 数据合并
requestInfo = mergeConfig(this, data);
// 代表之前运行到这里
runRequestStart = true;
//请求前回调
if (this.requestStart) {
let requestStart = this.requestStart(requestInfo);
if (typeof requestStart == "object") {
let changekeys = ["data", "header", "isPrompt", "load", "isFactory"];
changekeys.forEach(key => {
requestInfo[key] = requestStart[key];
});
} else {
throw {
errMsg: "【request】请求开始拦截器未通过",
statusCode: 0,
data: requestInfo.data,
method: requestInfo.method,
header: requestInfo.header,
url: requestInfo.url,
}
}
}
let requestResult = {};
if(requestInfo.method == "JSONP"){
requestResult = await jsonpRequest(requestInfo);
} else {
requestResult = await dispatchRequest(requestInfo);
}
//是否用外部的数据处理方法
if (requestInfo.isFactory && this.dataFactory) {
//数据处理
let result = await this.dataFactory({
...requestInfo,
response: requestResult
});
return Promise.resolve(result);
} else {
return Promise.resolve(requestResult);
}
} catch (err){
this.requestError && this.requestError(err);
return Promise.reject(err);
} finally {
// 如果请求开始未运行到,请求结束也不运行
if(runRequestStart){
this.requestEnd && this.requestEnd(requestInfo);
}
}
}
}
+101
View File
@@ -0,0 +1,101 @@
// 获取合并的数据
export const mergeConfig = function(_this, options) {
//判断url是不是链接
let urlType = /^(http|https):\/\//.test(options.url);
let config = Object.assign({
timeout: _this.timeout
}, _this.config, options);
if (options.method == "FILE") {
config.url = urlType ? options.url : _this.fileUrl + options.url;
} else {
config.url = urlType ? options.url : _this.baseUrl + options.url;
}
//请求头
if (options.header) {
config.header = Object.assign({}, _this.header, options.header);
} else {
config.header = Object.assign({}, _this.header);
}
return config;
}
// 请求
export const dispatchRequest = function(requestInfo) {
return new Promise((resolve, reject) => {
let requestAbort = true;
let requestData = {
url: requestInfo.url,
header: requestInfo.header, //加入请求头
success: (res) => {
requestAbort = false;
resolve(res);
},
fail: (err) => {
requestAbort = false;
if(err.errMsg == "request:fail abort"){
reject({
errMsg: "请求超时,请重新尝试",
statusCode: 0,
});
} else {
reject(err);
}
}
};
//请求类型
if (requestInfo.method) {
requestData.method = requestInfo.method;
}
if (requestInfo.data) {
requestData.data = requestInfo.data;
}
// #ifdef MP-WEIXIN || MP-ALIPAY
if (requestInfo.timeout) {
requestData.timeout = requestInfo.timeout;
}
// #endif
if (requestInfo.dataType) {
requestData.dataType = requestInfo.dataType;
}
// #ifndef APP-PLUS || MP-ALIPAY
if (requestInfo.responseType) {
requestData.responseType = requestInfo.responseType;
}
// #endif
// #ifdef H5
if (requestInfo.withCredentials) {
requestData.withCredentials = requestInfo.withCredentials;
}
// #endif
let requestTask = uni.request(requestData);
setTimeout(() => {
if(requestAbort){
requestTask.abort();
}
}, requestInfo.timeout)
})
}
// jsonp请求
export const jsonpRequest = function(requestInfo) {
return new Promise((resolve, reject) => {
let dataStr = '';
Object.keys(requestInfo.data).forEach(key => {
dataStr += key + '=' + requestInfo.data[key] + '&';
});
//匹配最后一个&并去除
if (dataStr !== '') {
dataStr = dataStr.substr(0, dataStr.lastIndexOf('&'));
}
requestInfo.url = requestInfo.url + '?' + dataStr;
let callbackName = "callback" + Math.ceil(Math.random() * 1000000);
// #ifdef H5
window[callbackName] = function(data) {
resolve(data);
}
let script = document.createElement("script");
script.src = requestInfo.url + "&callback=" + callbackName;
document.head.appendChild(script);
// 及时删除,防止加载过多的JS
document.head.removeChild(script);
// #endif
});
}
+2
View File
@@ -0,0 +1,2 @@
import request from "./core/request.js";
export default request;
+204
View File
@@ -0,0 +1,204 @@
import {
sysConsts
} from '../common/sysConsts.js';
import request from "./request";
// 全局配置的请求域名
// const baseUrl = 'http://192.168.100.19:8922'; //线上正式环境888
// const baseUrl = 'https://api-qa.scyuelai.com/'; //qa测试环境
// const baseUrl = 'https://api-zsh-dev.scyuelai.com/' //dev开发环境
// const baseUrl = 'https://local.scyuelai.com/'; //本地测试环境
const baseUrl = "https://miniapp.yuxingu.com.cn" //https://miniapp.yuxingu.com.cn
// const baseUrl = "http://8.137.99.227:8922"
//可以new多个request来支持多个域名请求
let $http = new request({
//接口请求地址
baseUrl: baseUrl,
//服务器本地上传文件地址
fileUrl: baseUrl,
// 服务器上传图片默认url
defaultUploadUrl: "api/common/v1/upload_image",
//设置请求头(如果使用报错跨域问题,可能是content-type请求类型和后台那边设置的不一致)
header: {
'content-type': 'application/json;charset=UTF-8'
},
// 请求超时时间(默认6000
timeout: 20000,
// 默认配置(可不写)
config: {
// 是否自动提示错误
isPrompt: true,
// 是否显示加载动画
load: true,
// 是否使用数据工厂
isFactory: true,
// 加载动画提示文字
loadingText: '加载中',
}
});
//当前接口请求数
let requestNum = 0;
//请求开始拦截器
$http.requestStart = function(options) {
if (options.load) {
if (requestNum <= 0) {
//打开加载动画
uni.showLoading({
title: options.loadingText,
mask: true
});
}
requestNum += 1;
}
// 图片上传大小限制
if (options.method == "FILE" && options.maxSize) {
// 文件最大字节: options.maxSize 可以在调用方法的时候加入参数
const maxSize = options.maxSize;
for (let item of options.files) {
if (item.size > maxSize) {
setTimeout(() => {
uni.showToast({
title: "图片过大,请重新上传",
icon: "none"
});
}, 500);
return false;
}
}
}
//请求前加入token
let myToken = uni.getStorageSync('token')
if (myToken) {
myToken = myToken.replace(/\"/g, "");
options.header['Authorization'] = 'Bearer ' + myToken;
}
return options; // return false 表示请求拦截,不会继续请求
}
//请求结束
$http.requestEnd = function(options) {
//判断当前接口是否需要加载动画
if (options.load) {
requestNum = requestNum - 1;
if (requestNum <= 0) {
uni.hideLoading();
}
}
}
//所有接口数据处理(可在接口里设置不调用此方法)
//此方法需要开发者根据各自的接口返回类型修改,以下只是模板
$http.dataFactory = async function(res) {
// console.log("接口请求数据", {
// url: res.url,
// resolve: res.response,
// header: res.header,
// data: res.data,
// method: res.method,
// });
if (res.response.statusCode && res.response.statusCode == 200) {
let httpData = res.response.data;
if (typeof(httpData) == "string") {
httpData = JSON.parse(httpData);
}
/*********以下只是模板(及共参考),需要开发者根据各自的接口返回类型修改*********/
//判断数据是否请求成功
if (httpData.success || httpData.code == 0) {
// 返回正确的结果(then接受数据)
return Promise.resolve(httpData.data);
} else if (httpData.code == "401" || httpData.code == "1001" || httpData.code == 1100) {
// let content = '此时此刻需要您登录喔~';
// if (!uni.getStorageSync('loginPageAlive')) {
// await gotoLogin().then(()=>{
// })
// }
gotoLogin(res)
// 返回错误的结果(catch接受数据)
return Promise.reject({
statusCode: 0,
errMsg: "【request】" + (httpData.info || httpData.msg)
});
} else { //其他错误提示
if (res.isPrompt) {
setTimeout(() => {
uni.showToast({
title: httpData.info || httpData.msg,
icon: "none",
duration: 3000
});
}, 100)
}
// 返回错误的结果(catch接受数据)
return Promise.reject({
statusCode: 0,
errMsg: "【request】" + (httpData.info || httpData.msg)
});
}
} else if (res.response.statusCode && res.response.statusCode == 401) {
gotoLogin(res)
} else {
// 返回错误的结果(catch接受数据)
return Promise.reject({
statusCode: res.response.statusCode,
errMsg: "【request】数据工厂验证不通过"
});
}
};
// 错误回调
$http.requestError = function(e) {
// e.statusCode === 0 是参数效验错误抛出的
if (e.statusCode === 0) {
throw e;
} else {
setTimeout(() => {
uni.showToast({
title: "网络错误 请检查一下网络",
icon: "none"
});
}, 100)
}
}
//token过期,退出登录
function gotoLogin(res) {
uni.removeStorageSync("token")
uni.removeStorageSync("userinfo")
console.log('res', res)
// uni.navigateTo({
// "url": "/pages/login-pop/login-pop?type=1",
// "animationType": "pop-in"
// })
// return new Promise((resolve, rejict)=>{
// // uni.switchTab({
// // "url":"/pages/login-pop/login-pop",
// // success:(res)=>{
// // // uni.showToast({
// // // title: "登录已失效,请重新登录",
// // // icon: "none"
// // // });
// // uni.showModal({
// // title: '提示',
// // content: '登录已失效,是否重新登录',
// // success: function (res) {
// // if (res.confirm) {
// // uni.navigateTo({
// // "url":"/pageLogin/user-detail/user-detail"
// // })
// // }
// // }
// // });
// // }
// // })
// resolve()
// })
}
export default $http;