修改请求逻辑

v1.4.0
于肖磊 2025-08-08 18:48:19 +08:00
parent 381abcea60
commit a492eb0a7d
5 changed files with 29 additions and 23 deletions

View File

@ -1,13 +1,22 @@
import { get_type } from '@/utils/common';
import request from '@/utils/request';
import { isEmpty } from 'lodash';
class CommonAPI {
/** 链接初始化接口 */
static getInit() {
return request({
url: `diyapi/init`,
method: 'post',
});
if (get_type() == 'shop') {
return request({
url: `?s=plugins/index/pluginsname/shop/pluginscontrol/diyapi/pluginsaction/init.html`,
method: 'post',
});
} else {
return request({
url: `diyapi/init`,
method: 'post',
});
}
}
/** 动态接口 */
static getDynamicApi(url: string, data: any, is_header: boolean = false) {

View File

@ -4,14 +4,14 @@ class UploadAPI {
/** 分类查询接口*/
static getTree() {
return api_request({
url: `?s=attachmentapi/attachmentcategory`,
url: `?s=attachmentapi/category`,
method: 'post',
});
}
/** 分类新增,修改接口 */
static saveTree(data: any) {
return api_request({
url: `?s=attachmentapi/attachmentcategorysave`,
url: `?s=attachmentapi/categorysave`,
method: 'post',
data,
});
@ -19,7 +19,7 @@ class UploadAPI {
/** 分类删除接口 */
static delTree(data: any) {
return api_request({
url: `?s=attachmentapi/attachmentcategorydelete`,
url: `?s=attachmentapi/categorydelete`,
method: 'post',
data,
});
@ -27,7 +27,7 @@ class UploadAPI {
/** 附件移动分类 */
static moveTree(data: any) {
return api_request({
url: `?s=attachmentapi/attachmentmovecategory`,
url: `?s=attachmentapi/movecategory`,
method: 'post',
data,
});
@ -36,7 +36,7 @@ class UploadAPI {
// 附件列表
static getAttachmentList(data: any) {
return api_request({
url: `?s=attachmentapi/attachmentlist`,
url: `?s=attachmentapi/list`,
method: 'post',
data,
});
@ -44,7 +44,7 @@ class UploadAPI {
// 附件名称修改
static saveAttachmentName(data: any) {
return api_request({
url: `?s=attachmentapi/attachmentsave`,
url: `?s=attachmentapi/save`,
method: 'post',
data,
});
@ -52,7 +52,7 @@ class UploadAPI {
// 附件删除
static delAttachment(data: any) {
return api_request({
url: `?s=attachmentapi/attachmentdelete`,
url: `?s=attachmentapi/delete`,
method: 'post',
data,
});
@ -60,7 +60,7 @@ class UploadAPI {
// 附件上传
static uploadAttachment(data: any, progress: any) {
return api_request({
url: `?s=attachmentapi/attachmentupload`,
url: `?s=attachmentapi/upload`,
method: 'post',
data,
headers: {
@ -72,7 +72,7 @@ class UploadAPI {
// 扫码上传
static uploadQrcode(data: any) {
return api_request({
url: `?s=attachmentapi/attachmentscanuploaddata`,
url: `?s=attachmentapi/scanuploaddata`,
method: 'post',
data,
});
@ -80,7 +80,7 @@ class UploadAPI {
// 提取链接 --------附件远程下载
static getAttachmentCatch(data: any) {
return api_request({
url: `?s=attachmentapi/attachmentcatch`,
url: `?s=attachmentapi/catch`,
method: 'post',
data,
});

View File

@ -39,17 +39,16 @@ const service = axios.create({
// 请求拦截器
service.interceptors.request.use(
async (config: InternalAxiosRequestConfig) => {
const new_url = get_type() == 'shop' && config.url?.includes('diyapi/init') ? '?s=plugins/index/pluginsname/shop/pluginscontrol/diyapi/pluginsaction/init.html' : config.url;
// 如果是本地则使用静态tonken如果是线上则使用cookie的token
const symbol = new_url?.includes('?') ? '&' : '?';
const symbol = config.url?.includes('?') ? '&' : '?';
if (import.meta.env.VITE_APP_BASE_API_PHP == '/dev-api') {
let temp_data = await import(import.meta.env.VITE_APP_BASE_API_PHP == '/dev-api' ? '../../temp.d' : '../../temp_pro.d');
config.url = new_url + symbol + 'token=' + temp_data.default.temp_token;
config.url = config.url + symbol + 'token=' + temp_data.default.temp_token;
} else {
// 如果是shop认为是多商户插件使用user_info的cookie
const cookie = get_type() == 'shop' ? get_cookie('user_info') : get_cookie('admin_info');
if (cookie && cookie !== null && cookie !== 'null') {
config.url = new_url + '&token=' + (JSON.parse(cookie) !== 'null' ? JSON.parse(cookie)?.token : '');
config.url = config.url + '&token=' + (JSON.parse(cookie) !== 'null' ? JSON.parse(cookie)?.token : '');
}
}
// 判断是否是包含不需要认证的接口

View File

@ -49,7 +49,6 @@ export const get_type = () => {
if (url.indexOf('type/') != -1) {
new_type = url.substring(url.indexOf('type/') + 5);
// 去除字符串的.html
// 去除字符串的.html
const dot_data = new_type.split('.')[0];
if (dot_data != '') {
new_type = dot_data.split('/')[0];

View File

@ -35,16 +35,15 @@ const service = axios.create({
// 请求拦截器
service.interceptors.request.use(
async (config: InternalAxiosRequestConfig) => {
const new_url = get_type() == 'shop' && config.url?.includes('diyapi/init') ? '?s=plugins/index/pluginsname/shop/pluginscontrol/diyapi/pluginsaction/init.html' : config.url;
const symbol = new_url ?.includes('?') ? '&' : '?';
const symbol = config.url?.includes('?') ? '&' : '?';
if (import.meta.env.VITE_APP_BASE_API == '/dev-admin') {
let temp_data = await import(import.meta.env.VITE_APP_BASE_API == '/dev-admin' ? '../../temp.d' : '../../temp_pro.d');
config.url = new_url + symbol + 'token=' + temp_data.default.temp_token;
config.url = config.url + symbol + 'token=' + temp_data.default.temp_token;
} else {
// 如果是shop认为是多商户插件使用user_info的cookie
const cookie = get_type() == 'shop' ? get_cookie('user_info') : get_cookie('admin_info');
if (cookie && cookie !== null && cookie !== 'null') {
config.url = new_url + '&token=' + (JSON.parse(cookie) !== 'null' ? JSON.parse(cookie)?.token : '');
config.url = config.url + '&token=' + (JSON.parse(cookie) !== 'null' ? JSON.parse(cookie)?.token : '');
}
}
// 判断是否是包含不需要认证的接口