xxx
This commit is contained in:
parent
bfec2ad8ee
commit
cc650681d2
@ -4,6 +4,7 @@ import { UnifiedViteWeappTailwindcssPlugin as uvtw } from 'weapp-tailwindcss/vit
|
|||||||
import autoImport from 'unplugin-auto-import/vite';
|
import autoImport from 'unplugin-auto-import/vite';
|
||||||
import viteRestart from 'vite-plugin-restart';
|
import viteRestart from 'vite-plugin-restart';
|
||||||
import { visualizer } from 'rollup-plugin-visualizer';
|
import { visualizer } from 'rollup-plugin-visualizer';
|
||||||
|
import { appProvider, buildThemeConfig, createComponents } from '../vite/plugins/index';
|
||||||
import { WeappTailwindcssDisabled, isH5 } from './platform';
|
import { WeappTailwindcssDisabled, isH5 } from './platform';
|
||||||
|
|
||||||
interface VitePluginConfig {
|
interface VitePluginConfig {
|
||||||
@ -14,6 +15,9 @@ export function createVitePlugins({ isProd }: VitePluginConfig): PluginOption[]
|
|||||||
return [
|
return [
|
||||||
// @ts-expect-error TODO uni() 会报错:uni is not a function,暂时使用此方式解决
|
// @ts-expect-error TODO uni() 会报错:uni is not a function,暂时使用此方式解决
|
||||||
uni?.default(),
|
uni?.default(),
|
||||||
|
appProvider(),
|
||||||
|
buildThemeConfig(),
|
||||||
|
createComponents(),
|
||||||
uvtw({
|
uvtw({
|
||||||
rem2rpx: true,
|
rem2rpx: true,
|
||||||
disabled: WeappTailwindcssDisabled,
|
disabled: WeappTailwindcssDisabled,
|
||||||
|
|||||||
112
src/utils/cache/storageCache.ts
vendored
112
src/utils/cache/storageCache.ts
vendored
@ -1,112 +0,0 @@
|
|||||||
import { cacheCipher } from '@/settings/encryptionSetting';
|
|
||||||
import type { EncryptionParams } from '@/utils/cipher';
|
|
||||||
import { AesEncryption } from '@/utils/cipher';
|
|
||||||
import { isNullOrUnDef } from '@/utils/is';
|
|
||||||
|
|
||||||
export interface CreateStorageParams extends EncryptionParams {
|
|
||||||
prefixKey: string
|
|
||||||
hasEncrypt: boolean
|
|
||||||
timeout?: number | null
|
|
||||||
}
|
|
||||||
export function createStorage({
|
|
||||||
prefixKey = '',
|
|
||||||
key = cacheCipher.key,
|
|
||||||
iv = cacheCipher.iv,
|
|
||||||
timeout = null,
|
|
||||||
hasEncrypt = true,
|
|
||||||
}: Partial<CreateStorageParams> = {}) {
|
|
||||||
if (hasEncrypt && [key.length, iv.length].some(item => item !== 16)) {
|
|
||||||
throw new Error('When hasEncrypt is true, the key or iv must be 16 bits!');
|
|
||||||
}
|
|
||||||
|
|
||||||
const encryption = new AesEncryption({ key, iv });
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cache class
|
|
||||||
* Construction parameters can be passed into sessionStorage, localStorage,
|
|
||||||
* @class Cache
|
|
||||||
* @example
|
|
||||||
*/
|
|
||||||
class Storage {
|
|
||||||
private prefixKey?: string;
|
|
||||||
|
|
||||||
private encryption: AesEncryption;
|
|
||||||
|
|
||||||
private hasEncrypt: boolean;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this.prefixKey = prefixKey;
|
|
||||||
this.encryption = encryption;
|
|
||||||
this.hasEncrypt = hasEncrypt;
|
|
||||||
}
|
|
||||||
|
|
||||||
private getKey(key: string) {
|
|
||||||
return `${this.prefixKey}${key}`.toUpperCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set cache
|
|
||||||
* @param {string} key
|
|
||||||
* @param {*} value
|
|
||||||
* @param {*} expire Expiration time in seconds
|
|
||||||
* @memberof Cache
|
|
||||||
*/
|
|
||||||
set(key: string, value: any, expire: number | null = timeout) {
|
|
||||||
try {
|
|
||||||
const stringData = JSON.stringify({
|
|
||||||
value,
|
|
||||||
time: Date.now(),
|
|
||||||
expire: !isNullOrUnDef(expire) ? new Date().getTime() + expire * 1000 : null,
|
|
||||||
});
|
|
||||||
const stringifyValue = this.hasEncrypt ? this.encryption.encryptByAES(stringData) : stringData;
|
|
||||||
uni.setStorageSync(this.getKey(key), stringifyValue);
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`setStorageSync error: ${err}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read cache
|
|
||||||
* @param {string} key
|
|
||||||
* @param {*} def
|
|
||||||
* @memberof Cache
|
|
||||||
*/
|
|
||||||
get<T = any>(key: string, def: any = null): T {
|
|
||||||
const val = uni.getStorageSync(this.getKey(key));
|
|
||||||
if (!val)
|
|
||||||
return def;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const decVal = this.hasEncrypt ? this.encryption.decryptByAES(val) : val;
|
|
||||||
const data = JSON.parse(decVal);
|
|
||||||
const { value, expire } = data;
|
|
||||||
if (isNullOrUnDef(expire) || expire < new Date().getTime()) {
|
|
||||||
this.remove(key);
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
||||||
} catch (e) {
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete cache based on key
|
|
||||||
* @param {string} key
|
|
||||||
* @memberof Cache
|
|
||||||
*/
|
|
||||||
remove(key: string) {
|
|
||||||
uni.removeStorageSync(this.getKey(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete all caches of this instance
|
|
||||||
*/
|
|
||||||
clear(): void {
|
|
||||||
uni.clearStorageSync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new Storage();
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ const ContentType = {
|
|||||||
*/
|
*/
|
||||||
const alovaInstance = createAlova({
|
const alovaInstance = createAlova({
|
||||||
baseURL: BASE_URL,
|
baseURL: BASE_URL,
|
||||||
localCache: null, // 设置为null即可全局关闭全部请求缓存
|
// localCache: null, // 设置为null即可全局关闭全部请求缓存
|
||||||
...AdapterUniapp({
|
...AdapterUniapp({
|
||||||
/* #ifndef APP-PLUS */
|
/* #ifndef APP-PLUS */
|
||||||
mockRequest: isUseMock() ? mockAdapter : undefined, // APP 平台无法使用mock
|
mockRequest: isUseMock() ? mockAdapter : undefined, // APP 平台无法使用mock
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
{ // 指定要从编译中排除的文件列表
|
{
|
||||||
|
// 指定要从编译中排除的文件列表
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ESNext", // 编译出目标语言版本
|
"target": "ESNext", // 编译出目标语言版本
|
||||||
"jsx": "preserve",
|
"jsx": "preserve",
|
||||||
|
|||||||
121
unocss.config.ts
121
unocss.config.ts
@ -1,15 +1,16 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* unocss defineConfig
|
* unocss defineConfig
|
||||||
* @link unocss: https://github.com/unocss/unocss
|
* @link unocss: https://github.com/unocss/unocss
|
||||||
* @link unocss-preset-weapp: https://github.com/MellowCo/unocss-preset-weapp
|
* @link unocss-preset-weapp: https://github.com/MellowCo/unocss-preset-weapp
|
||||||
*/
|
* */
|
||||||
import presetWeapp from 'unocss-preset-weapp';
|
import presetWeapp from 'unocss-preset-weapp'
|
||||||
import { extractorAttributify, transformerClass } from 'unocss-preset-weapp/transformer';
|
import { extractorAttributify, transformerClass } from 'unocss-preset-weapp/transformer'
|
||||||
import { presetIcons } from 'unocss';
|
import { presetIcons } from 'unocss'
|
||||||
|
|
||||||
import transformerDirectives from '@unocss/transformer-directives';
|
import transformerDirectives from '@unocss/transformer-directives'
|
||||||
|
|
||||||
const { presetWeappAttributify, transformerAttributify } = extractorAttributify();
|
const { presetWeappAttributify, transformerAttributify } = extractorAttributify()
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
presets: [
|
presets: [
|
||||||
@ -37,61 +38,61 @@ export default {
|
|||||||
transformerClass(),
|
transformerClass(),
|
||||||
],
|
],
|
||||||
theme: {
|
theme: {
|
||||||
extend: {
|
"extend": {
|
||||||
opacity: {
|
"opacity": {
|
||||||
disabled: 'var(--opacity-disabled)',
|
"disabled": "var(--opacity-disabled)"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
"colors": {
|
||||||
|
"primary": "var(--colors-primary)",
|
||||||
|
"secondary": "var(--colors-secondary)",
|
||||||
|
"accent": "var(--colors-accent)",
|
||||||
|
"success": "var(--colors-success)",
|
||||||
|
"warning": "var(--colors-warning)",
|
||||||
|
"error": "var(--colors-error)",
|
||||||
|
"disable": "var(--colors-disable)",
|
||||||
|
"danger": "var(--colors-danger)",
|
||||||
|
"mark": "var(--colors-mark)",
|
||||||
|
"title": "var(--colors-title)",
|
||||||
|
"subtitle": "var(--colors-subtitle)",
|
||||||
|
"paragraph": "var(--colors-paragraph)",
|
||||||
|
"fontColorblack": "var(--colors-fontColorblack)",
|
||||||
|
"fontColorPrimary": "var(--colors-fontColorPrimary)",
|
||||||
|
"fontColorInverse": "var(--colors-fontColorInverse)",
|
||||||
|
"fontColorGrey": "var(--colors-fontColorGrey)",
|
||||||
|
"fontColorPlaceholder": "var(--colors-fontColorPlaceholder)",
|
||||||
|
"fontColorDisable": "var(--colors-fontColorDisable)",
|
||||||
|
"fontColorBottomText": "var(--colors-fontColorBottomText)",
|
||||||
|
"container": "var(--colors-container)",
|
||||||
|
"page": "var(--colors-page)",
|
||||||
|
"containerInverse": "var(--colors-containerInverse)",
|
||||||
|
"containerHover": "var(--colors-containerHover)",
|
||||||
|
"secondaryHover": "var(--colors-secondaryHover)",
|
||||||
|
"containerMask": "var(--colors-containerMask)",
|
||||||
|
"iconButton": "var(--colors-iconButton)",
|
||||||
|
"borderColor": "var(--colors-borderColor)"
|
||||||
},
|
},
|
||||||
colors: {
|
"fontSize": {
|
||||||
primary: 'var(--colors-primary)',
|
"sm": "var(--fontSize-sm)",
|
||||||
secondary: 'var(--colors-secondary)',
|
"base": "var(--fontSize-base)",
|
||||||
accent: 'var(--colors-accent)',
|
"lg": "var(--fontSize-lg)",
|
||||||
success: 'var(--colors-success)',
|
"title": "var(--fontSize-title)",
|
||||||
warning: 'var(--colors-warning)',
|
"subtitle": "var(--fontSize-subtitle)",
|
||||||
error: 'var(--colors-error)',
|
"paragraph": "var(--fontSize-paragraph)"
|
||||||
disable: 'var(--colors-disable)',
|
|
||||||
danger: 'var(--colors-danger)',
|
|
||||||
mark: 'var(--colors-mark)',
|
|
||||||
title: 'var(--colors-title)',
|
|
||||||
subtitle: 'var(--colors-subtitle)',
|
|
||||||
paragraph: 'var(--colors-paragraph)',
|
|
||||||
fontColorblack: 'var(--colors-fontColorblack)',
|
|
||||||
fontColorPrimary: 'var(--colors-fontColorPrimary)',
|
|
||||||
fontColorInverse: 'var(--colors-fontColorInverse)',
|
|
||||||
fontColorGrey: 'var(--colors-fontColorGrey)',
|
|
||||||
fontColorPlaceholder: 'var(--colors-fontColorPlaceholder)',
|
|
||||||
fontColorDisable: 'var(--colors-fontColorDisable)',
|
|
||||||
fontColorBottomText: 'var(--colors-fontColorBottomText)',
|
|
||||||
container: 'var(--colors-container)',
|
|
||||||
page: 'var(--colors-page)',
|
|
||||||
containerInverse: 'var(--colors-containerInverse)',
|
|
||||||
containerHover: 'var(--colors-containerHover)',
|
|
||||||
secondaryHover: 'var(--colors-secondaryHover)',
|
|
||||||
containerMask: 'var(--colors-containerMask)',
|
|
||||||
iconButton: 'var(--colors-iconButton)',
|
|
||||||
borderColor: 'var(--colors-borderColor)',
|
|
||||||
},
|
},
|
||||||
fontSize: {
|
"borderRadius": {
|
||||||
sm: 'var(--fontSize-sm)',
|
"sm": "var(--borderRadius-sm)",
|
||||||
base: 'var(--fontSize-base)',
|
"base": "var(--borderRadius-base)",
|
||||||
lg: 'var(--fontSize-lg)',
|
"lg": "var(--borderRadius-lg)",
|
||||||
title: 'var(--fontSize-title)',
|
"circle": "var(--borderRadius-circle)"
|
||||||
subtitle: 'var(--fontSize-subtitle)',
|
|
||||||
paragraph: 'var(--fontSize-paragraph)',
|
|
||||||
},
|
},
|
||||||
borderRadius: {
|
"spacing": {
|
||||||
sm: 'var(--borderRadius-sm)',
|
"rowSm": "var(--spacing-rowSm)",
|
||||||
base: 'var(--borderRadius-base)',
|
"rowBase": "var(--spacing-rowBase)",
|
||||||
lg: 'var(--borderRadius-lg)',
|
"rowLg": "var(--spacing-rowLg)",
|
||||||
circle: 'var(--borderRadius-circle)',
|
"colSm": "var(--spacing-colSm)",
|
||||||
},
|
"colBase": "var(--spacing-colBase)",
|
||||||
spacing: {
|
"colLg": "var(--spacing-colLg)"
|
||||||
rowSm: 'var(--spacing-rowSm)',
|
}
|
||||||
rowBase: 'var(--spacing-rowBase)',
|
}
|
||||||
rowLg: 'var(--spacing-rowLg)',
|
}
|
||||||
colSm: 'var(--spacing-colSm)',
|
|
||||||
colBase: 'var(--spacing-colBase)',
|
|
||||||
colLg: 'var(--spacing-colLg)',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import { defineConfig, loadEnv } from 'vite';
|
|||||||
import TransformPages from 'uni-read-pages-vite';
|
import TransformPages from 'uni-read-pages-vite';
|
||||||
import postcssPlugins from './postcss.config';
|
import postcssPlugins from './postcss.config';
|
||||||
import { createVitePlugins, currentPlatform, resolveProxy } from './build';
|
import { createVitePlugins, currentPlatform, resolveProxy } from './build';
|
||||||
import { appProvider, buildThemeConfig, createComponents } from './vite/plugins/index';
|
|
||||||
|
|
||||||
export default defineConfig(async ({ mode }) => {
|
export default defineConfig(async ({ mode }) => {
|
||||||
const root = process.cwd();
|
const root = process.cwd();
|
||||||
@ -49,7 +48,7 @@ export default defineConfig(async ({ mode }) => {
|
|||||||
host: true,
|
host: true,
|
||||||
// open: true,
|
// open: true,
|
||||||
port: Number.parseInt(VITE_PORT!, 10),
|
port: Number.parseInt(VITE_PORT!, 10),
|
||||||
proxy: resolveProxy([[VITE_PROXY_PREFIX, VITE_BASE_URL], [VITE_UPLOAD_PROXY_PREFIX, VITE_UPLOAD_URL]]),
|
proxy: resolveProxy([[VITE_PROXY_PREFIX as string, VITE_BASE_URL as string], [VITE_UPLOAD_PROXY_PREFIX as string, VITE_UPLOAD_URL as string]]),
|
||||||
},
|
},
|
||||||
// 构建配置
|
// 构建配置
|
||||||
build: {
|
build: {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user