Commit c19da130 by 前端

Merge branch 'v1.0.1' into 'master'

上线合并

See merge request !2
2 parents 9a54ea77 182f7a1b
This diff could not be displayed because it is too large.
{ {
"name": "glsx-common", "name": "glsx-common",
"version": "2.1.0", "version": "2.10.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
......
{ {
"name": "glsx-common", "name": "glsk-common",
"version": "2.10.1", "version": "2.10.9",
"description": "glsx common", "description": "glsk common",
"main": "./dist/glsx-common.js", "main": "./dist/glsk-common.js",
"private": false, "private": false,
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
......
...@@ -7,8 +7,8 @@ import json from '@rollup/plugin-json' ...@@ -7,8 +7,8 @@ import json from '@rollup/plugin-json'
export default { export default {
input: './src/index.js', input: './src/index.js',
output: { output: {
file: './dist/glsx-common.js', file: './dist/glsk-common.js',
name: 'GLSX', name: 'GLSK',
// exports: 'default', // exports: 'default',
format: 'umd' format: 'umd'
}, },
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
import util from './util' import util from './util'
import axios from 'axios' import axios from 'axios'
import qs from 'qs' import qs from 'qs'
import WhiteUrlManager from './whiteUrlManager' // 导入白名单管理器
function Http(options = {}) { function Http(options = {}) {
this.service = axios.create({ this.service = axios.create({
withCredentials: true, withCredentials: true,
...@@ -27,8 +28,14 @@ function Http(options = {}) { ...@@ -27,8 +28,14 @@ function Http(options = {}) {
} }
Http.prototype.create = function () { Http.prototype.create = function () {
this.service.interceptors.request.use( this.service.interceptors.request.use(
config => { async config => {
let { data = {}, sign = true, noSignAttr = [], noSessionId = false } = config let { data = {}, sign = true, noSignAttr = [], noSessionId = false } = config
// 获取白名单并检查接口
const whiteUrl = await WhiteUrlManager.getWhiteUrls()
if (whiteUrl.includes(data?.method)) {
data.sdctag = true
}
if (!noSessionId) { if (!noSessionId) {
data.sessionId = this.customer.sessionId || data.sessionId data.sessionId = this.customer.sessionId || data.sessionId
} }
...@@ -38,8 +45,13 @@ Http.prototype.create = function () { ...@@ -38,8 +45,13 @@ Http.prototype.create = function () {
} }
const method = config.method.toLowerCase() const method = config.method.toLowerCase()
if (method == 'get') { if (method == 'get') {
// config.data = data
config.params = data config.params = data
} else if (method == 'post') { } else if (method == 'post') {
// 将 sdctag
if (data.sdctag) {
config.params = { ...config.params, sdctag: data.sdctag }
}
if (config.headers['Content-Type'] == 'multipart/form-data') { if (config.headers['Content-Type'] == 'multipart/form-data') {
config.data = util.appendFormData(data) config.data = util.appendFormData(data)
} else if (config.headers['Content-Type'] == 'application/json') { } else if (config.headers['Content-Type'] == 'application/json') {
...@@ -97,6 +109,7 @@ Http.prototype.create = function () { ...@@ -97,6 +109,7 @@ Http.prototype.create = function () {
return this.service return this.service
} }
function logout(logout_function) { function logout(logout_function) {
WhiteUrlManager.clearCache()
if (window[logout_function]) { if (window[logout_function]) {
window[logout_function](window.location.href) window[logout_function](window.location.href)
return return
......
/*
* @Descripttion:
* @version: 1.0.0
* @Author: limin
* @Date: 2025-09-09 09:49:02
* @LastEditors: limin
* @LastEditTime: 2025-09-09 09:49:33
* @FilePath: \glsx-common\src\whiteUrlManager.js
*/
// 使用IIFE和闭包来管理白名单状态
const WhiteUrlManager = (() => {
let cachedWhiteUrl = null
let fetchPromise = null
// 返回获取白名单的函数
return {
getWhiteUrls: () => {
// 如果已有缓存,直接返回Promise
if (cachedWhiteUrl) {
return Promise.resolve(cachedWhiteUrl)
}
// 如果已经有一个请求在进行中,返回该Promise
if (fetchPromise) {
return fetchPromise
}
// 创建新的Promise并保存引用
fetchPromise = fetch('https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=glsx-common')
.then(response => response.json())
.then(result => {
cachedWhiteUrl = result.whiteUrl || []
if (Array.isArray(cachedWhiteUrl)) {
// 过滤掉http和https开头的url
cachedWhiteUrl = cachedWhiteUrl.map(url => url.replace(/^https?:/, ''))
}
return cachedWhiteUrl
})
.catch(error => {
console.error('获取配置失败:', error)
cachedWhiteUrl = []
return []
})
.finally(() => {
fetchPromise = null
})
return fetchPromise
}
}
// 添加清除缓存的方法
clearCache: () => {
cachedWhiteUrl = null
fetchPromise = null
return true
}
})()
// 模块加载时立即开始预加载白名单,但不阻塞后续代码执行
WhiteUrlManager.getWhiteUrls()
export default WhiteUrlManager
...@@ -6,8 +6,8 @@ module.exports = { ...@@ -6,8 +6,8 @@ module.exports = {
output: { output: {
path: path.resolve(__dirname, './dist'), path: path.resolve(__dirname, './dist'),
// publicPath: "/dist/", // publicPath: "/dist/",
filename: 'glsx-common.js', filename: 'glsk-common.js',
library: 'glsx-common', library: 'glsk-common',
libraryTarget: 'umd', libraryTarget: 'umd',
umdNamedDefine: true umdNamedDefine: true
}, },
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!