You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
621 B
31 lines
621 B
|
7 months ago
|
const $globalStore = {};
|
||
|
|
const storeModule = {};
|
||
|
|
const uniName = [];
|
||
|
|
const modulesStore = import.meta.glob("../store/**/*.js", {
|
||
|
|
import: "default",
|
||
|
|
eager: true,
|
||
|
|
});
|
||
|
|
|
||
|
|
for (const [, value] of Object.entries(modulesStore)) {
|
||
|
|
const storeId = value.$id;
|
||
|
|
if (storeId) {
|
||
|
|
storeModule[storeId] = value;
|
||
|
|
uniName.includes(storeId)
|
||
|
|
? console.error(`Store的唯一ID${storeId},存在重复`)
|
||
|
|
: uniName.push(storeId);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
const $globalRegisterStore = {
|
||
|
|
install() {
|
||
|
|
Object.entries(storeModule).forEach((item) => {
|
||
|
|
$globalStore[item[0]] = item[1]();
|
||
|
|
});
|
||
|
|
},
|
||
|
|
};
|
||
|
|
|
||
|
|
export {
|
||
|
|
$globalStore,
|
||
|
|
$globalRegisterStore
|
||
|
|
};
|