mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 13:39:24 +08:00
feat(client): allows to store client information into session storage (#5424)
* feat(client): allows to store client information into session storage * fix: test error --------- Co-authored-by: chenos <chenlinxh@gmail.com>
This commit is contained in:
parent
156d99c724
commit
5108c8fe7c
@ -18,19 +18,20 @@ export default defineConfig({
|
|||||||
devtool: process.env.NODE_ENV === 'development' ? 'source-map' : false,
|
devtool: process.env.NODE_ENV === 'development' ? 'source-map' : false,
|
||||||
favicons: [`${appPublicPath}favicon/favicon.ico`],
|
favicons: [`${appPublicPath}favicon/favicon.ico`],
|
||||||
metas: [{ name: 'viewport', content: 'initial-scale=0.1' }],
|
metas: [{ name: 'viewport', content: 'initial-scale=0.1' }],
|
||||||
links: [
|
links: [{ rel: 'stylesheet', href: `${appPublicPath}global.css` }],
|
||||||
{ rel: 'stylesheet', href: `${appPublicPath}global.css` },
|
|
||||||
],
|
|
||||||
headScripts: [
|
headScripts: [
|
||||||
{
|
{
|
||||||
src: `${appPublicPath}browser-checker.js`,
|
src: `${appPublicPath}browser-checker.js`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
content: isDevCmd ? '' : `
|
content: isDevCmd
|
||||||
|
? ''
|
||||||
|
: `
|
||||||
window['__webpack_public_path__'] = '{{env.APP_PUBLIC_PATH}}';
|
window['__webpack_public_path__'] = '{{env.APP_PUBLIC_PATH}}';
|
||||||
window['__nocobase_public_path__'] = '{{env.APP_PUBLIC_PATH}}';
|
window['__nocobase_public_path__'] = '{{env.APP_PUBLIC_PATH}}';
|
||||||
window['__nocobase_api_base_url__'] = '{{env.API_BASE_URL}}';
|
window['__nocobase_api_base_url__'] = '{{env.API_BASE_URL}}';
|
||||||
window['__nocobase_api_client_storage_prefix__'] = '{{env.API_CLIENT_STORAGE_PREFIX}}';
|
window['__nocobase_api_client_storage_prefix__'] = '{{env.API_CLIENT_STORAGE_PREFIX}}';
|
||||||
|
window['__nocobase_api_client_storage_type__'] = '{{env.API_CLIENT_STORAGE_TYPE}}';
|
||||||
window['__nocobase_ws_url__'] = '{{env.WS_URL}}';
|
window['__nocobase_ws_url__'] = '{{env.WS_URL}}';
|
||||||
window['__nocobase_ws_path__'] = '{{env.WS_PATH}}';
|
window['__nocobase_ws_path__'] = '{{env.WS_PATH}}';
|
||||||
`,
|
`,
|
||||||
@ -66,7 +67,7 @@ export default defineConfig({
|
|||||||
target: ['chrome80', 'es2020'],
|
target: ['chrome80', 'es2020'],
|
||||||
},
|
},
|
||||||
codeSplitting: {
|
codeSplitting: {
|
||||||
jsStrategy: 'depPerChunk'
|
jsStrategy: 'depPerChunk',
|
||||||
},
|
},
|
||||||
chainWebpack(config, { env }) {
|
chainWebpack(config, { env }) {
|
||||||
if (env === 'production') {
|
if (env === 'production') {
|
||||||
|
@ -13,6 +13,9 @@ import devDynamicImport from '../.plugins/index';
|
|||||||
|
|
||||||
export const app = new Application({
|
export const app = new Application({
|
||||||
apiClient: {
|
apiClient: {
|
||||||
|
storageType:
|
||||||
|
// @ts-ignore
|
||||||
|
window['__nocobase_api_client_storage_type__'] || process.env.API_CLIENT_STORAGE_TYPE || 'localStorage',
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
storagePrefix:
|
storagePrefix:
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
@ -291,6 +291,7 @@ function buildIndexHtml(force = false) {
|
|||||||
const data = fs.readFileSync(tpl, 'utf-8');
|
const data = fs.readFileSync(tpl, 'utf-8');
|
||||||
const replacedData = data
|
const replacedData = data
|
||||||
.replace(/\{\{env.APP_PUBLIC_PATH\}\}/g, process.env.APP_PUBLIC_PATH)
|
.replace(/\{\{env.APP_PUBLIC_PATH\}\}/g, process.env.APP_PUBLIC_PATH)
|
||||||
|
.replace(/\{\{env.API_CLIENT_STORAGE_TYPE\}\}/g, process.env.API_CLIENT_STORAGE_TYPE)
|
||||||
.replace(/\{\{env.API_CLIENT_STORAGE_PREFIX\}\}/g, process.env.API_CLIENT_STORAGE_PREFIX)
|
.replace(/\{\{env.API_CLIENT_STORAGE_PREFIX\}\}/g, process.env.API_CLIENT_STORAGE_PREFIX)
|
||||||
.replace(/\{\{env.API_BASE_URL\}\}/g, process.env.API_BASE_URL || process.env.API_BASE_PATH)
|
.replace(/\{\{env.API_BASE_URL\}\}/g, process.env.API_BASE_URL || process.env.API_BASE_PATH)
|
||||||
.replace(/\{\{env.WS_URL\}\}/g, process.env.WEBSOCKET_URL || '')
|
.replace(/\{\{env.WS_URL\}\}/g, process.env.WEBSOCKET_URL || '')
|
||||||
@ -327,6 +328,7 @@ exports.initEnv = function initEnv() {
|
|||||||
APP_PORT: 13000,
|
APP_PORT: 13000,
|
||||||
API_BASE_PATH: '/api/',
|
API_BASE_PATH: '/api/',
|
||||||
API_CLIENT_STORAGE_PREFIX: 'NOCOBASE_',
|
API_CLIENT_STORAGE_PREFIX: 'NOCOBASE_',
|
||||||
|
API_CLIENT_STORAGE_TYPE: 'localStorage',
|
||||||
DB_DIALECT: 'sqlite',
|
DB_DIALECT: 'sqlite',
|
||||||
DB_STORAGE: 'storage/db/nocobase.sqlite',
|
DB_STORAGE: 'storage/db/nocobase.sqlite',
|
||||||
// DB_TIMEZONE: '+00:00',
|
// DB_TIMEZONE: '+00:00',
|
||||||
|
@ -8,7 +8,7 @@ const path = require('path');
|
|||||||
console.log('VERSION: ', packageJson.version);
|
console.log('VERSION: ', packageJson.version);
|
||||||
|
|
||||||
function getUmiConfig() {
|
function getUmiConfig() {
|
||||||
const { APP_PORT, API_BASE_URL, API_CLIENT_STORAGE_PREFIX, APP_PUBLIC_PATH } = process.env;
|
const { APP_PORT, API_BASE_URL, API_CLIENT_STORAGE_TYPE, API_CLIENT_STORAGE_PREFIX, APP_PUBLIC_PATH } = process.env;
|
||||||
const API_BASE_PATH = process.env.API_BASE_PATH || '/api/';
|
const API_BASE_PATH = process.env.API_BASE_PATH || '/api/';
|
||||||
const PROXY_TARGET_URL = process.env.PROXY_TARGET_URL || `http://127.0.0.1:${APP_PORT}`;
|
const PROXY_TARGET_URL = process.env.PROXY_TARGET_URL || `http://127.0.0.1:${APP_PORT}`;
|
||||||
const LOCAL_STORAGE_BASE_URL = 'storage/uploads/';
|
const LOCAL_STORAGE_BASE_URL = 'storage/uploads/';
|
||||||
@ -41,6 +41,7 @@ function getUmiConfig() {
|
|||||||
'process.env.WS_PATH': process.env.WS_PATH,
|
'process.env.WS_PATH': process.env.WS_PATH,
|
||||||
'process.env.API_BASE_URL': API_BASE_URL || API_BASE_PATH,
|
'process.env.API_BASE_URL': API_BASE_URL || API_BASE_PATH,
|
||||||
'process.env.API_CLIENT_STORAGE_PREFIX': API_CLIENT_STORAGE_PREFIX,
|
'process.env.API_CLIENT_STORAGE_PREFIX': API_CLIENT_STORAGE_PREFIX,
|
||||||
|
'process.env.API_CLIENT_STORAGE_TYPE': API_CLIENT_STORAGE_TYPE,
|
||||||
'process.env.APP_ENV': process.env.APP_ENV,
|
'process.env.APP_ENV': process.env.APP_ENV,
|
||||||
'process.env.VERSION': packageJson.version,
|
'process.env.VERSION': packageJson.version,
|
||||||
'process.env.WEBSOCKET_URL': process.env.WEBSOCKET_URL,
|
'process.env.WEBSOCKET_URL': process.env.WEBSOCKET_URL,
|
||||||
|
@ -267,6 +267,7 @@ export class MemoryStorage extends Storage {
|
|||||||
|
|
||||||
interface ExtendedOptions {
|
interface ExtendedOptions {
|
||||||
authClass?: any;
|
authClass?: any;
|
||||||
|
storageType?: 'localStorage' | 'sessionStorage' | 'memory';
|
||||||
storageClass?: any;
|
storageClass?: any;
|
||||||
storagePrefix?: string;
|
storagePrefix?: string;
|
||||||
}
|
}
|
||||||
@ -300,10 +301,10 @@ export class APIClient {
|
|||||||
if (typeof instance === 'function') {
|
if (typeof instance === 'function') {
|
||||||
this.axios = instance;
|
this.axios = instance;
|
||||||
} else {
|
} else {
|
||||||
const { authClass, storageClass, storagePrefix = 'NOCOBASE_', ...others } = instance || {};
|
const { authClass, storageType, storageClass, storagePrefix = 'NOCOBASE_', ...others } = instance || {};
|
||||||
this.storagePrefix = storagePrefix;
|
this.storagePrefix = storagePrefix;
|
||||||
this.axios = axios.create(others);
|
this.axios = axios.create(others);
|
||||||
this.initStorage(storageClass);
|
this.initStorage(storageClass, storageType);
|
||||||
if (authClass) {
|
if (authClass) {
|
||||||
this.auth = new authClass(this);
|
this.auth = new authClass(this);
|
||||||
}
|
}
|
||||||
@ -317,14 +318,20 @@ export class APIClient {
|
|||||||
this.interceptors();
|
this.interceptors();
|
||||||
}
|
}
|
||||||
|
|
||||||
private initStorage(storage?: any) {
|
private initStorage(storage?: any, storageType = 'localStorage') {
|
||||||
if (storage) {
|
if (storage) {
|
||||||
this.storage = new storage(this);
|
this.storage = new storage(this);
|
||||||
} else if (typeof localStorage !== 'undefined') {
|
return;
|
||||||
this.storage = localStorage;
|
|
||||||
} else {
|
|
||||||
this.storage = new MemoryStorage();
|
|
||||||
}
|
}
|
||||||
|
if (storageType === 'localStorage' && typeof localStorage !== 'undefined') {
|
||||||
|
this.storage = localStorage;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (storageType === 'sessionStorage' && typeof sessionStorage !== 'undefined') {
|
||||||
|
this.storage = sessionStorage;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.storage = new MemoryStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
interceptors() {
|
interceptors() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user