支持ui插件下载&运行

This commit is contained in:
muwoo
2021-12-02 17:55:45 +08:00
parent c2f43bea39
commit 0132a11d7e
32 changed files with 951 additions and 244 deletions

View File

@@ -1,8 +1,73 @@
import { createStore } from "vuex";
import request from "@/assets/request";
const isDownload = (item: any, targets: any[]) => {
let isDownload = false;
targets.some((plugin) => {
if (plugin.name === item.name) {
isDownload = true;
}
return isDownload;
});
return isDownload;
};
export default createStore({
state: {},
mutations: {},
actions: {},
state: {
totalPlugins: [],
localPlugins: [],
},
mutations: {
commonUpdate(state: any, payload) {
Object.keys(payload).forEach((key) => {
state[key] = payload[key];
});
},
},
actions: {
async init({ commit }) {
const totalPlugins = await request.getTotalPlugins();
const localPlugins = (window as any).rubick.getLocalPlugins();
totalPlugins.forEach(
(origin: { isdwonload?: any; name?: any; isloading: boolean }) => {
origin.isdwonload = isDownload(origin, localPlugins);
origin.isloading = false;
}
);
commit("commonUpdate", {
localPlugins,
totalPlugins,
});
},
startDownload({ commit, state }, name) {
const totalPlugins = JSON.parse(JSON.stringify(state.totalPlugins));
totalPlugins.forEach(
(origin: { isdwonload?: any; name?: any; isloading: boolean }) => {
if (origin.name === name) {
origin.isloading = true;
}
}
);
commit("commonUpdate", {
totalPlugins,
});
},
successDownload({ commit, state }, name) {
const totalPlugins = JSON.parse(JSON.stringify(state.totalPlugins));
totalPlugins.forEach(
(origin: { isdwonload?: any; name?: any; isloading: boolean }) => {
if (origin.name === name) {
origin.isloading = false;
origin.isdwonload = true;
}
}
);
commit("commonUpdate", {
totalPlugins,
});
},
},
modules: {},
});