mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-10-13 21:33:42 +08:00
23 lines
589 B
TypeScript
23 lines
589 B
TypeScript
import type { PiniaPluginContext } from 'pinia';
|
|
import { cloneDeep } from 'lodash-es';
|
|
import { SetupStoreId } from '@/enum';
|
|
|
|
/**
|
|
* The plugin reset the state of the store which is written by setup syntax
|
|
*
|
|
* @param context
|
|
*/
|
|
export function resetSetupStore(context: PiniaPluginContext) {
|
|
const setupSyntaxIds = Object.values(SetupStoreId) as string[];
|
|
|
|
if (setupSyntaxIds.includes(context.store.$id)) {
|
|
const { $state } = context.store;
|
|
|
|
const defaultStore = cloneDeep($state);
|
|
|
|
context.store.$reset = () => {
|
|
context.store.$patch(defaultStore);
|
|
};
|
|
}
|
|
}
|