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 viteRestart from 'vite-plugin-restart';
|
||||
import { visualizer } from 'rollup-plugin-visualizer';
|
||||
import { appProvider, buildThemeConfig, createComponents } from '../vite/plugins/index';
|
||||
import { WeappTailwindcssDisabled, isH5 } from './platform';
|
||||
|
||||
interface VitePluginConfig {
|
||||
@ -14,6 +15,9 @@ export function createVitePlugins({ isProd }: VitePluginConfig): PluginOption[]
|
||||
return [
|
||||
// @ts-expect-error TODO uni() 会报错:uni is not a function,暂时使用此方式解决
|
||||
uni?.default(),
|
||||
appProvider(),
|
||||
buildThemeConfig(),
|
||||
createComponents(),
|
||||
uvtw({
|
||||
rem2rpx: true,
|
||||
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({
|
||||
baseURL: BASE_URL,
|
||||
localCache: null, // 设置为null即可全局关闭全部请求缓存
|
||||
// localCache: null, // 设置为null即可全局关闭全部请求缓存
|
||||
...AdapterUniapp({
|
||||
/* #ifndef APP-PLUS */
|
||||
mockRequest: isUseMock() ? mockAdapter : undefined, // APP 平台无法使用mock
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{ // 指定要从编译中排除的文件列表
|
||||
{
|
||||
// 指定要从编译中排除的文件列表
|
||||
"compilerOptions": {
|
||||
"target": "ESNext", // 编译出目标语言版本
|
||||
"jsx": "preserve",
|
||||
|
||||
125
unocss.config.ts
125
unocss.config.ts
@ -1,17 +1,18 @@
|
||||
/**
|
||||
|
||||
/**
|
||||
* unocss defineConfig
|
||||
* @link unocss: https://github.com/unocss/unocss
|
||||
* @link unocss-preset-weapp: https://github.com/MellowCo/unocss-preset-weapp
|
||||
*/
|
||||
import presetWeapp from 'unocss-preset-weapp';
|
||||
import { extractorAttributify, transformerClass } from 'unocss-preset-weapp/transformer';
|
||||
import { presetIcons } from 'unocss';
|
||||
* */
|
||||
import presetWeapp from 'unocss-preset-weapp'
|
||||
import { extractorAttributify, transformerClass } from 'unocss-preset-weapp/transformer'
|
||||
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: [
|
||||
// https://github.com/MellowCo/unocss-preset-weapp
|
||||
presetWeapp(),
|
||||
@ -37,61 +38,61 @@ export default {
|
||||
transformerClass(),
|
||||
],
|
||||
theme: {
|
||||
extend: {
|
||||
opacity: {
|
||||
disabled: 'var(--opacity-disabled)',
|
||||
"extend": {
|
||||
"opacity": {
|
||||
"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: {
|
||||
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)',
|
||||
"fontSize": {
|
||||
"sm": "var(--fontSize-sm)",
|
||||
"base": "var(--fontSize-base)",
|
||||
"lg": "var(--fontSize-lg)",
|
||||
"title": "var(--fontSize-title)",
|
||||
"subtitle": "var(--fontSize-subtitle)",
|
||||
"paragraph": "var(--fontSize-paragraph)"
|
||||
},
|
||||
fontSize: {
|
||||
sm: 'var(--fontSize-sm)',
|
||||
base: 'var(--fontSize-base)',
|
||||
lg: 'var(--fontSize-lg)',
|
||||
title: 'var(--fontSize-title)',
|
||||
subtitle: 'var(--fontSize-subtitle)',
|
||||
paragraph: 'var(--fontSize-paragraph)',
|
||||
"borderRadius": {
|
||||
"sm": "var(--borderRadius-sm)",
|
||||
"base": "var(--borderRadius-base)",
|
||||
"lg": "var(--borderRadius-lg)",
|
||||
"circle": "var(--borderRadius-circle)"
|
||||
},
|
||||
borderRadius: {
|
||||
sm: 'var(--borderRadius-sm)',
|
||||
base: 'var(--borderRadius-base)',
|
||||
lg: 'var(--borderRadius-lg)',
|
||||
circle: 'var(--borderRadius-circle)',
|
||||
},
|
||||
spacing: {
|
||||
rowSm: 'var(--spacing-rowSm)',
|
||||
rowBase: 'var(--spacing-rowBase)',
|
||||
rowLg: 'var(--spacing-rowLg)',
|
||||
colSm: 'var(--spacing-colSm)',
|
||||
colBase: 'var(--spacing-colBase)',
|
||||
colLg: 'var(--spacing-colLg)',
|
||||
},
|
||||
},
|
||||
};
|
||||
"spacing": {
|
||||
"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 postcssPlugins from './postcss.config';
|
||||
import { createVitePlugins, currentPlatform, resolveProxy } from './build';
|
||||
import { appProvider, buildThemeConfig, createComponents } from './vite/plugins/index';
|
||||
|
||||
export default defineConfig(async ({ mode }) => {
|
||||
const root = process.cwd();
|
||||
@ -49,7 +48,7 @@ export default defineConfig(async ({ mode }) => {
|
||||
host: true,
|
||||
// open: true,
|
||||
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: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user