mrxy-yk 1.4.3 → 1.6.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/coordinate-pickup/CoordinatePickup.vue.js +26 -24
- package/dist/config/index.d.ts +7 -0
- package/dist/config/index.js +5 -0
- package/dist/element-plus/components/table-column/TableColumn.d.ts +26 -0
- package/dist/index.js +4 -2
- package/dist/utils/amap/index.d.ts +8 -2
- package/dist/utils/amap/index.js +45 -16
- package/dist/utils/amap/type.d.ts +11 -24
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/storage/index.d.ts +69 -0
- package/dist/utils/storage/index.js +140 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ElDialog, ElForm, ElFormItem, ElAutocomplete, ElInput, ElButton, ElCheckbox } from "element-plus/es";
|
|
2
|
-
import { defineComponent, onMounted, watch, nextTick, computed, ref, onUnmounted, openBlock, createBlock, withCtx, createVNode, createElementVNode, toDisplayString, createElementBlock, createCommentVNode, createTextVNode } from "vue";
|
|
2
|
+
import { defineComponent, onMounted, watch, nextTick, computed, ref, shallowRef, onUnmounted, openBlock, createBlock, withCtx, createVNode, createElementVNode, toDisplayString, createElementBlock, createCommentVNode, createTextVNode } from "vue";
|
|
3
3
|
import { ElMessage } from "element-plus";
|
|
4
|
-
import {
|
|
4
|
+
import { useAMapClassicHook } from "../../utils/amap/index.js";
|
|
5
5
|
import { AMapConfig } from "../../config/index.js";
|
|
6
6
|
const _hoisted_1 = { class: "autocomplete-subtitle" };
|
|
7
7
|
const _hoisted_2 = { key: 0 };
|
|
@@ -30,14 +30,14 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
30
30
|
const mapKey = props.mapKey || AMapConfig.mapKey;
|
|
31
31
|
const mapSecret = props.mapSecret || AMapConfig.mapSecret;
|
|
32
32
|
watch(() => props.modelValue, (nv) => {
|
|
33
|
-
if (nv && !map) {
|
|
33
|
+
if (nv && !aMapHook.value.map) {
|
|
34
34
|
nextTick(() => {
|
|
35
35
|
loadAMap();
|
|
36
36
|
});
|
|
37
37
|
} else {
|
|
38
38
|
placeSearch.clear();
|
|
39
39
|
showMarker(props.lnglat, props.address);
|
|
40
|
-
emits("open", map);
|
|
40
|
+
emits("open", aMapHook.value.map);
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
43
|
const changeDialogCustomer = computed({
|
|
@@ -63,28 +63,27 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
63
63
|
emits("update:address", pickupForm.value.address);
|
|
64
64
|
emits("update:modelValue", false);
|
|
65
65
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
const coordinatePickupRef = shallowRef();
|
|
67
|
+
const aMapHook = useAMapClassicHook({
|
|
68
|
+
el: coordinatePickupRef,
|
|
69
|
+
mapStyle: props.mapStyle,
|
|
70
|
+
loaderOptions: {
|
|
71
71
|
key: mapKey,
|
|
72
72
|
secret: mapSecret,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
});
|
|
73
|
+
plugins: ["AMap.PlaceSearch", "AMap.AutoComplete", "AMap.Geocoder"]
|
|
74
|
+
}
|
|
75
|
+
}, loadAMap);
|
|
76
|
+
function loadAMap() {
|
|
77
|
+
const AMap = aMapHook.value.AMap;
|
|
78
|
+
const map = aMapHook.value.map;
|
|
79
|
+
satelliteLayer = new AMap["TileLayer"].Satellite();
|
|
80
|
+
map.on("click", clickHandler);
|
|
81
|
+
autoComplete = new AMap["Autocomplete"]({ city: "全国" });
|
|
82
|
+
placeSearch = new AMap["PlaceSearch"]({ map, city: "全国", autoFitView: true });
|
|
83
|
+
placeSearch.on("markerClick", placeMarkerClick);
|
|
84
|
+
geocoder = new AMap["Geocoder"]();
|
|
85
|
+
showMarker(props.lnglat, props.address);
|
|
86
|
+
emits("open", { map, AMap });
|
|
88
87
|
}
|
|
89
88
|
const clickHandler = async (e) => {
|
|
90
89
|
const { lng, lat } = e.lnglat;
|
|
@@ -93,6 +92,7 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
93
92
|
showMarker(lnglat, address);
|
|
94
93
|
};
|
|
95
94
|
onUnmounted(function() {
|
|
95
|
+
const map = aMapHook.value.map;
|
|
96
96
|
if (map) {
|
|
97
97
|
map.off("click", clickHandler);
|
|
98
98
|
map.destroy();
|
|
@@ -166,6 +166,7 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
166
166
|
}
|
|
167
167
|
let marker = null;
|
|
168
168
|
function showMarker(lnglat, address) {
|
|
169
|
+
const { map, AMap } = aMapHook.value;
|
|
169
170
|
if (lnglat) {
|
|
170
171
|
const position = lnglat.split(",");
|
|
171
172
|
if (marker) {
|
|
@@ -185,6 +186,7 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
185
186
|
let satelliteLayer = null;
|
|
186
187
|
const isSatelliteLayer = ref(false);
|
|
187
188
|
function setSatelliteLayer() {
|
|
189
|
+
const { map } = aMapHook.value;
|
|
188
190
|
if (isSatelliteLayer.value) {
|
|
189
191
|
map.add(satelliteLayer);
|
|
190
192
|
} else {
|
package/dist/config/index.d.ts
CHANGED
|
@@ -37,3 +37,10 @@ export declare const EChartsThemeConfig: {
|
|
|
37
37
|
export declare const PagesConfig: {
|
|
38
38
|
params: (pages: Pages) => any;
|
|
39
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* 加密配置
|
|
42
|
+
*/
|
|
43
|
+
export declare const EncryptConfig: {
|
|
44
|
+
encryptMethod: (str: string) => string;
|
|
45
|
+
decryptMethod: (str: string) => string;
|
|
46
|
+
};
|
package/dist/config/index.js
CHANGED
|
@@ -19,6 +19,10 @@ const PagesConfig = {
|
|
|
19
19
|
return { pageNum: pages.pageNum, pageSize: pages.pageSize };
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
|
+
const EncryptConfig = {
|
|
23
|
+
encryptMethod: (str) => str,
|
|
24
|
+
decryptMethod: (str) => str
|
|
25
|
+
};
|
|
22
26
|
export {
|
|
23
27
|
AMapConfig,
|
|
24
28
|
EChartsThemeConfig,
|
|
@@ -28,6 +32,7 @@ export {
|
|
|
28
32
|
ElUploadImagesGlobal,
|
|
29
33
|
EmptyGlobal,
|
|
30
34
|
EmptyStatusExtendConfig,
|
|
35
|
+
EncryptConfig,
|
|
31
36
|
ExportLinkGlobal,
|
|
32
37
|
PagesConfig
|
|
33
38
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { TableColumnCtx } from 'element-plus';
|
|
2
|
+
import { VNode, DefineComponent, ComponentOptionsMixin, PublicProps, ComponentProvideOptions } from 'vue';
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
emptyStr?: string;
|
|
5
|
+
formatter?: ((row: any, column: TableColumnCtx, cellValue: any, index: number) => VNode) | string;
|
|
6
|
+
};
|
|
7
|
+
declare function __VLS_template(): {
|
|
8
|
+
attrs: Partial<{}>;
|
|
9
|
+
slots: {
|
|
10
|
+
'filter-icon'?(_: any): any;
|
|
11
|
+
expand?(_: any): any;
|
|
12
|
+
header?(_: any): any;
|
|
13
|
+
default?(_: any): any;
|
|
14
|
+
};
|
|
15
|
+
refs: {};
|
|
16
|
+
rootEl: any;
|
|
17
|
+
};
|
|
18
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
19
|
+
declare const __VLS_component: DefineComponent<__VLS_Props, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
|
|
20
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
21
|
+
export default _default;
|
|
22
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
23
|
+
new (): {
|
|
24
|
+
$slots: S;
|
|
25
|
+
};
|
|
26
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,8 @@ import { useEmptyHooks } from "./components/empty/hooks/index.js";
|
|
|
9
9
|
import { MatchUnit } from "./utils/match-unit/index.js";
|
|
10
10
|
import { TransitionFade } from "./utils/transition-fade/index.js";
|
|
11
11
|
import { echarts } from "./utils/echarts/index.js";
|
|
12
|
-
import {
|
|
12
|
+
import { newAMapInfoWindow, newAMapMap, newAMapMarkerCluster, useAMapClassicHook, useAMapLoader } from "./utils/amap/index.js";
|
|
13
|
+
import { StorageUtil } from "./utils/storage/index.js";
|
|
13
14
|
import { Pages } from "./entity/Pages.js";
|
|
14
15
|
import { BigFloat } from "./entity/BigFloat.js";
|
|
15
16
|
import { RejectError } from "./entity/RejectError.js";
|
|
@@ -48,7 +49,6 @@ var index = {
|
|
|
48
49
|
}
|
|
49
50
|
};
|
|
50
51
|
export {
|
|
51
|
-
AMapLoader,
|
|
52
52
|
AMapUtil,
|
|
53
53
|
ArrayUtil,
|
|
54
54
|
BigFloat,
|
|
@@ -77,6 +77,7 @@ export {
|
|
|
77
77
|
PromiseUtil,
|
|
78
78
|
RejectError,
|
|
79
79
|
SetupLifeCycle,
|
|
80
|
+
StorageUtil,
|
|
80
81
|
TableUtil,
|
|
81
82
|
TransitionFade,
|
|
82
83
|
YsVideo,
|
|
@@ -103,6 +104,7 @@ export {
|
|
|
103
104
|
positiveNumberRule,
|
|
104
105
|
positiveNumberTag,
|
|
105
106
|
required,
|
|
107
|
+
useAMapClassicHook,
|
|
106
108
|
useAMapLoader,
|
|
107
109
|
useEChartsRef,
|
|
108
110
|
useEcBarOption,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AMapClassProxy, LoaderOptions,
|
|
1
|
+
import { AMapClassProxy, LoaderOptions, UseAMapHookExample, UseAMapHookOptions } from './type';
|
|
2
2
|
import { AMap } from './@type/index';
|
|
3
3
|
import { TemplateRef, ShallowRef } from 'vue';
|
|
4
4
|
export * from './utils';
|
|
@@ -35,4 +35,10 @@ export declare function newAMapMarkerCluster(options: {
|
|
|
35
35
|
* @param AMap { AMap } AMap存在时可以传入跳过`setAMap`过程
|
|
36
36
|
*/
|
|
37
37
|
export declare function newAMapInfoWindow(options: ConstructorParameters<typeof AMap.InfoWindow>[0], AMap?: AMap): AMapClassProxy<AMap.InfoWindow>;
|
|
38
|
-
|
|
38
|
+
/**
|
|
39
|
+
* 常用高德地图配套功能包含地图(Map),聚合标记点(MarkerCluster),信息窗口(InfoWindow)
|
|
40
|
+
* 返回的hook实例需要在onMounted之后才能使用
|
|
41
|
+
* @param options
|
|
42
|
+
* @param callback
|
|
43
|
+
*/
|
|
44
|
+
export declare function useAMapClassicHook(options: UseAMapHookOptions, callback?: (res: ShallowRef<UseAMapHookExample>) => void): ShallowRef<UseAMapHookExample>;
|
package/dist/utils/amap/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import AMapLoader from "@amap/amap-jsapi-loader";
|
|
2
2
|
import { AMapConfig } from "../../config/index.js";
|
|
3
|
-
import { toValue } from "vue";
|
|
3
|
+
import { shallowRef, onMounted, useTemplateRef, onBeforeUnmount, toValue } from "vue";
|
|
4
4
|
async function useAMapLoader(options) {
|
|
5
5
|
const o = options || {};
|
|
6
6
|
const win = window;
|
|
7
7
|
win._AMapSecurityConfig = { securityJsCode: o.secret || AMapConfig.mapSecret };
|
|
8
|
-
return await
|
|
8
|
+
return await AMapLoader.load({
|
|
9
9
|
key: o.key || AMapConfig.mapKey,
|
|
10
10
|
version: "2.0",
|
|
11
11
|
plugins: o.plugins,
|
|
@@ -62,26 +62,55 @@ function newAMapInfoWindow(options, AMap) {
|
|
|
62
62
|
return new AMap2.InfoWindow(o);
|
|
63
63
|
}, AMap);
|
|
64
64
|
}
|
|
65
|
-
|
|
65
|
+
function useAMapClassicHook(options, callback) {
|
|
66
66
|
const o = options;
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
const retRes = shallowRef({});
|
|
68
|
+
let map = null;
|
|
69
|
+
onMounted(async () => {
|
|
70
|
+
const AMap = await useAMapLoader({
|
|
71
|
+
plugins: o.plugins,
|
|
72
|
+
...o?.loaderOptions
|
|
73
|
+
});
|
|
74
|
+
let elRef = shallowRef();
|
|
75
|
+
if (typeof o.el === "string") {
|
|
76
|
+
elRef = useTemplateRef(o.el);
|
|
77
|
+
} else if (o.el) {
|
|
78
|
+
elRef = o.el;
|
|
79
|
+
}
|
|
80
|
+
map = newAMapMap({
|
|
81
|
+
el: elRef.value,
|
|
82
|
+
mapStyle: o.mapStyle,
|
|
83
|
+
opts: o.mapOpts
|
|
84
|
+
}, AMap);
|
|
85
|
+
map.destroy();
|
|
86
|
+
const markerCluster = newAMapMarkerCluster({
|
|
87
|
+
map,
|
|
88
|
+
markerClusterOptions: Object.assign({
|
|
89
|
+
renderMarker: o.renderMarker,
|
|
90
|
+
renderClusterMarker: o.renderClusterMarker
|
|
91
|
+
}, o.markerClusterOpts)
|
|
92
|
+
}, AMap);
|
|
93
|
+
const infoWindow = newAMapInfoWindow({
|
|
94
|
+
isCustom: true,
|
|
95
|
+
content: o.infoWindowContent?.value || void 0
|
|
96
|
+
}, AMap);
|
|
97
|
+
retRes.value = {
|
|
98
|
+
map,
|
|
99
|
+
markerCluster,
|
|
100
|
+
infoWindow,
|
|
101
|
+
AMap
|
|
102
|
+
};
|
|
103
|
+
callback?.(retRes);
|
|
74
104
|
});
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
...o.mapOption
|
|
105
|
+
onBeforeUnmount(() => {
|
|
106
|
+
map.destroy();
|
|
78
107
|
});
|
|
79
|
-
return
|
|
108
|
+
return retRes;
|
|
80
109
|
}
|
|
81
110
|
export {
|
|
82
|
-
AMapLoader,
|
|
83
111
|
newAMapInfoWindow,
|
|
84
112
|
newAMapMap,
|
|
85
113
|
newAMapMarkerCluster,
|
|
114
|
+
useAMapClassicHook,
|
|
86
115
|
useAMapLoader
|
|
87
116
|
};
|
|
@@ -2,7 +2,7 @@ import { AMap, AMapType } from './@type/AMap';
|
|
|
2
2
|
import { LoadOption } from './@type';
|
|
3
3
|
import { MapOptions } from './@type/Map';
|
|
4
4
|
import { RenderMarkerCallbackParams } from './@type/MarkerCluster';
|
|
5
|
-
type PluginsType = 'AMap.MarkerCluster' | 'AMap.Weather' | string
|
|
5
|
+
type PluginsType = 'AMap.MarkerCluster' | 'AMap.Weather' | 'AMap.AutoComplete' | 'AMap.Geocoder' | string
|
|
6
6
|
|
|
7
7
|
export type LoaderOptions = {
|
|
8
8
|
// key 高德地图key(缺省使用全局配置)
|
|
@@ -19,13 +19,19 @@ export type AMapClassProxy<T> = T & { setAMap (AMap: AMap): void }
|
|
|
19
19
|
|
|
20
20
|
// region useAMapHook
|
|
21
21
|
export type UseAMapHookOptions = {
|
|
22
|
-
|
|
22
|
+
// 加载选项
|
|
23
|
+
plugins?: PluginsType[]
|
|
24
|
+
loaderOptions?: LoaderOptions
|
|
25
|
+
// 地图
|
|
26
|
+
el: ShallowRef<HTMLDivElement> | string
|
|
23
27
|
mapStyle?: string
|
|
24
|
-
renderMarker? (e: RenderMarkerCallbackParams): void
|
|
25
|
-
renderClusterMarker? (count: number, marker: AMap.Marker): void
|
|
26
|
-
infoWindowContent: ShallowRef<HTMLDivElement>
|
|
27
28
|
mapOpts?: ConstructorParameters<typeof AMap.Map>[1]
|
|
28
29
|
markerClusterOpts?: ConstructorParameters<typeof AMap.MarkerCluster>[2]
|
|
30
|
+
// 聚合标记
|
|
31
|
+
renderMarker? (e: RenderMarkerCallbackParams): void
|
|
32
|
+
renderClusterMarker? (count: number, marker: AMap.Marker): void
|
|
33
|
+
// 信息窗体
|
|
34
|
+
infoWindowContent?: ShallowRef<HTMLDivElement>
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
export type UseAMapHookExample = {
|
|
@@ -35,22 +41,3 @@ export type UseAMapHookExample = {
|
|
|
35
41
|
AMap: AMap
|
|
36
42
|
}
|
|
37
43
|
// endregion
|
|
38
|
-
|
|
39
|
-
export type LoaderOptions1 = {
|
|
40
|
-
// key 高德地图key(缺省使用全局配置)
|
|
41
|
-
key?: string,
|
|
42
|
-
// secret 高德地图secret(缺省使用全局配置)
|
|
43
|
-
secret?: string,
|
|
44
|
-
// el 地图容器元素
|
|
45
|
-
el: HTMLDivElement,
|
|
46
|
-
// plugins 插件列表
|
|
47
|
-
plugins?: string[],
|
|
48
|
-
// mapStyle 地图样式
|
|
49
|
-
mapStyle?: string,
|
|
50
|
-
// loadOption 加载选项
|
|
51
|
-
loadOption?: LoadOption,
|
|
52
|
-
// mapOption 地图选项
|
|
53
|
-
mapOption?: MapOptions
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export type AMapResolve = { AMap: AMapType, map: AMap.Map }
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
declare class LocalStorage {
|
|
2
|
+
dataset: Map<string, string>;
|
|
3
|
+
getItem(key: string): string;
|
|
4
|
+
setItem(key: string, value: string): void;
|
|
5
|
+
clear(): void;
|
|
6
|
+
removeItem(key: string): void;
|
|
7
|
+
}
|
|
8
|
+
declare class SessionStorage extends LocalStorage {
|
|
9
|
+
}
|
|
10
|
+
export declare class StorageUtil {
|
|
11
|
+
static localStorage: Storage | LocalStorage;
|
|
12
|
+
static sessionStorage: Storage | SessionStorage;
|
|
13
|
+
static init(): void;
|
|
14
|
+
static local: {
|
|
15
|
+
/**
|
|
16
|
+
* 获取localStorage的值 - 解密
|
|
17
|
+
* @param key
|
|
18
|
+
*/
|
|
19
|
+
get(key: string): any;
|
|
20
|
+
/**
|
|
21
|
+
* 设置localStorage的值 - 加密
|
|
22
|
+
* @param key
|
|
23
|
+
* @param value
|
|
24
|
+
*/
|
|
25
|
+
set(key: string, value: any): void;
|
|
26
|
+
remove: (key: string) => void;
|
|
27
|
+
clear: () => void;
|
|
28
|
+
};
|
|
29
|
+
static session: {
|
|
30
|
+
/**
|
|
31
|
+
* 获取sessionStorage的值 - 解密
|
|
32
|
+
* @param key
|
|
33
|
+
*/
|
|
34
|
+
get(key: string): any;
|
|
35
|
+
/**
|
|
36
|
+
* 设置sessionStorage的值 - 加密
|
|
37
|
+
* @param key
|
|
38
|
+
* @param value
|
|
39
|
+
*/
|
|
40
|
+
set(key: string, value: any): void;
|
|
41
|
+
remove: (key: string) => void;
|
|
42
|
+
clear: () => void;
|
|
43
|
+
};
|
|
44
|
+
static cookie: {
|
|
45
|
+
/**
|
|
46
|
+
* 获取cookie
|
|
47
|
+
* @param key
|
|
48
|
+
*/
|
|
49
|
+
get(key: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* 设置cookie
|
|
52
|
+
* @param key
|
|
53
|
+
* @param value
|
|
54
|
+
* @param expires 日期字符串|日期对象|天数
|
|
55
|
+
* @param path
|
|
56
|
+
*/
|
|
57
|
+
set(key: string, value: string, expires?: string | Date | number, path?: string): void;
|
|
58
|
+
/**
|
|
59
|
+
* 获取所有cookie
|
|
60
|
+
*/
|
|
61
|
+
getAll(): Record<string, string>;
|
|
62
|
+
/**
|
|
63
|
+
* 删除cookie
|
|
64
|
+
* @param key
|
|
65
|
+
*/
|
|
66
|
+
remove(key: string): void;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export {};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { EncryptConfig } from "../../config/index.js";
|
|
2
|
+
class LocalStorage {
|
|
3
|
+
dataset = /* @__PURE__ */ new Map();
|
|
4
|
+
getItem(key) {
|
|
5
|
+
return this.dataset.get(key);
|
|
6
|
+
}
|
|
7
|
+
setItem(key, value) {
|
|
8
|
+
this.dataset.set(key, value);
|
|
9
|
+
}
|
|
10
|
+
clear() {
|
|
11
|
+
this.dataset.clear();
|
|
12
|
+
}
|
|
13
|
+
removeItem(key) {
|
|
14
|
+
this.dataset.delete(key);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
class SessionStorage extends LocalStorage {
|
|
18
|
+
}
|
|
19
|
+
class StorageUtil {
|
|
20
|
+
static localStorage = null;
|
|
21
|
+
static sessionStorage = null;
|
|
22
|
+
static init() {
|
|
23
|
+
try {
|
|
24
|
+
this.localStorage = window.localStorage;
|
|
25
|
+
} catch {
|
|
26
|
+
this.localStorage = new LocalStorage();
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
this.sessionStorage = window.sessionStorage;
|
|
30
|
+
} catch {
|
|
31
|
+
this.sessionStorage = new SessionStorage();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
static local = {
|
|
35
|
+
/**
|
|
36
|
+
* 获取localStorage的值 - 解密
|
|
37
|
+
* @param key
|
|
38
|
+
*/
|
|
39
|
+
get(key) {
|
|
40
|
+
const str = StorageUtil.localStorage.getItem(key);
|
|
41
|
+
if (str) {
|
|
42
|
+
return JSON.parse(EncryptConfig.decryptMethod(str));
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* 设置localStorage的值 - 加密
|
|
47
|
+
* @param key
|
|
48
|
+
* @param value
|
|
49
|
+
*/
|
|
50
|
+
set(key, value) {
|
|
51
|
+
StorageUtil.localStorage.setItem(key, EncryptConfig.encryptMethod(JSON.stringify(value)));
|
|
52
|
+
},
|
|
53
|
+
remove: (key) => {
|
|
54
|
+
StorageUtil.localStorage.removeItem(key);
|
|
55
|
+
},
|
|
56
|
+
clear: () => {
|
|
57
|
+
StorageUtil.localStorage.clear();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
static session = {
|
|
61
|
+
/**
|
|
62
|
+
* 获取sessionStorage的值 - 解密
|
|
63
|
+
* @param key
|
|
64
|
+
*/
|
|
65
|
+
get(key) {
|
|
66
|
+
const str = StorageUtil.sessionStorage.getItem(key);
|
|
67
|
+
if (str) {
|
|
68
|
+
return JSON.parse(EncryptConfig.decryptMethod(str));
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
/**
|
|
72
|
+
* 设置sessionStorage的值 - 加密
|
|
73
|
+
* @param key
|
|
74
|
+
* @param value
|
|
75
|
+
*/
|
|
76
|
+
set(key, value) {
|
|
77
|
+
StorageUtil.sessionStorage.setItem(key, EncryptConfig.encryptMethod(JSON.stringify(value)));
|
|
78
|
+
},
|
|
79
|
+
remove: (key) => {
|
|
80
|
+
StorageUtil.sessionStorage.removeItem(key);
|
|
81
|
+
},
|
|
82
|
+
clear: () => {
|
|
83
|
+
StorageUtil.sessionStorage.clear();
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
static cookie = {
|
|
87
|
+
/**
|
|
88
|
+
* 获取cookie
|
|
89
|
+
* @param key
|
|
90
|
+
*/
|
|
91
|
+
get(key) {
|
|
92
|
+
const str = this.getAll()[key];
|
|
93
|
+
return str ? EncryptConfig.decryptMethod(str) : void 0;
|
|
94
|
+
},
|
|
95
|
+
/**
|
|
96
|
+
* 设置cookie
|
|
97
|
+
* @param key
|
|
98
|
+
* @param value
|
|
99
|
+
* @param expires 日期字符串|日期对象|天数
|
|
100
|
+
* @param path
|
|
101
|
+
*/
|
|
102
|
+
set(key, value, expires, path = "/") {
|
|
103
|
+
let cookieStr = `${key}=${EncryptConfig.encryptMethod(value)};path=${path}`;
|
|
104
|
+
if (expires) {
|
|
105
|
+
let date = /* @__PURE__ */ new Date();
|
|
106
|
+
if (typeof expires === "number") {
|
|
107
|
+
date.setTime(date.getTime() + expires * 864e5);
|
|
108
|
+
} else {
|
|
109
|
+
date = new Date(expires);
|
|
110
|
+
}
|
|
111
|
+
cookieStr += ";expires=" + date.toUTCString();
|
|
112
|
+
}
|
|
113
|
+
document.cookie = cookieStr;
|
|
114
|
+
},
|
|
115
|
+
/**
|
|
116
|
+
* 获取所有cookie
|
|
117
|
+
*/
|
|
118
|
+
getAll() {
|
|
119
|
+
const cookieStr = document.cookie;
|
|
120
|
+
const cookieArr = cookieStr.split(";");
|
|
121
|
+
const cookieObj = {};
|
|
122
|
+
cookieArr.forEach((item) => {
|
|
123
|
+
const m = item.split("=");
|
|
124
|
+
cookieObj[m[0].trim()] = m[1];
|
|
125
|
+
});
|
|
126
|
+
return cookieObj;
|
|
127
|
+
},
|
|
128
|
+
/**
|
|
129
|
+
* 删除cookie
|
|
130
|
+
* @param key
|
|
131
|
+
*/
|
|
132
|
+
remove(key) {
|
|
133
|
+
this.set(key, "", -1);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
StorageUtil.init();
|
|
138
|
+
export {
|
|
139
|
+
StorageUtil
|
|
140
|
+
};
|