1
0
şunun yansıması https://github.com/ialley-workshop-open/uni-halo.git eşitlendi 2026-06-11 12:49:30 +08:00

v1.0.0-beta 源码正式开源

Bu işleme şunda yer alıyor:
小莫唐尼
2022-12-06 15:08:29 +08:00
işleme 636ae7b169
461 değiştirilmiş dosya ile 116817 ekleme ve 0 silme
+38
Dosyayı Görüntüle
@@ -0,0 +1,38 @@
/**
* 功能:请求工具
* 作者:小莫唐尼
* 邮箱:studio@925i.cn
* 时间:2022年07月21日 18:58:03
* 版本:v0.1.0
* 修改记录:
* 修改内容:
* 修改人员:
* 修改时间:
*/
import HaloConfig from '@/config/halo.config.js'
import {
setInterceptors
} from "./interceptors.js";
import Request from "@/js_sdk/luch-request/luch-request";
const http = new Request()
/* 设置全局配置 */
http.setConfig((config) => {
// 如果是在外部浏览器调试或者编译为h5,请注释该行代码
config.baseURL = HaloConfig.apiUrl;
config.header = {
...config.header,
'api-authorization': HaloConfig.apiAuthorization,
ContentType: 'application/json',
dataType: 'json'
}
return config
})
setInterceptors(http)
export {
http
}
+84
Dosyayı Görüntüle
@@ -0,0 +1,84 @@
/**
* 功能:http拦截
* 作者:小莫唐尼
* 邮箱:studio@925i.cn
* 时间:2022年07月21日 19:02:14
* 版本:v0.1.0
* 修改记录:
* 修改内容:
* 修改人员:
* 修改时间:
*/
import {
getAdminAccessToken
} from "@/utils/auth.js";
import {
delCache
} from "@/utils/storage";
export const setInterceptors = (http) => {
http.interceptors.request.use(
(config) => {
// 可使用async await 做异步操作
config.header = {
...config.header
// ... 可以直接加参数
};
if (getAdminAccessToken()) {
config.header['admin-authorization'] = getAdminAccessToken()
}
return config;
},
(config) => {
// 可使用async await 做异步操作
return Promise.reject(config);
}
);
http.interceptors.response.use(
(response) => {
/* 对响应成功做点什么 可使用async await 做异步操作*/
// if (response.data.code !== 200) { // 服务端返回的状态码不等于200,则reject()
// return Promise.reject(response) // return Promise.reject 可使promise状态进入catch
// if (response.config.custom.verification) { // 演示自定义参数的作用
// return response.data
// }
if (response.statusCode == 200) {
return response.data;
} else {
return Promise.reject(response);
}
},
(response) => {
/* 对响应错误做点什么 statusCode !== 200*/
if (!response.data) {
return Promise.reject({
status: 500,
message: 'API接口服务异常!'
})
} else if (response.data.status == 401) {
delCache('APP_ADMIN_LOGIN_TOKEN');
uni.$eShowModal({
title: '提示',
content: '您未登录超管账号或登录已过期,是否重新登录?',
showCancel: true,
cancelText: '否',
cancelColor: '#999999',
confirmText: '是',
confirmColor: '#03a9f4'
}).then(res => {
uni.navigateTo({
url: '/pagesB/login/login'
})
}).catch(err => {
uni.switchTab({
url: '/pages/tabbar/about/about'
})
})
} else {
return Promise.reject(response.data);
}
}
);
};
+29
Dosyayı Görüntüle
@@ -0,0 +1,29 @@
/**
* 封装各种请求方式
*/
import {
http
} from '@/common/http/index.js'
export default {
Get: (url, params, config = {}) => {
return http.get(url, {
params,
...config
})
},
Post: (url, data, config = {}) => {
return http.post(url, data, config)
},
Put: (url, data, config = {}) => {
return http.put(url, data, config)
},
Upload: (url, config = {}) => {
return http.upload(url, config)
},
Delete: (url, data, config = {}) => {
return http.delete(url, data, config)
}
}