|
@@ -1,15 +1,19 @@
|
|
|
import { useCtx } from "@/comm/ctx";
|
|
|
import ListModule from "..";
|
|
|
import { queenApi } from "queenjs";
|
|
|
+import { cloneDeep } from "lodash";
|
|
|
export default ListModule.action({
|
|
|
async getAssetList() {
|
|
|
+ if (this.store.list.length > 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
const { deviceCtrl } = useCtx();
|
|
|
const appDataDir = deviceCtrl.appDataDir;
|
|
|
const currentCategory = localStorage.getItem("category") || "default";
|
|
|
+
|
|
|
const assetsJson = await deviceCtrl.ReadFileText(
|
|
|
`${appDataDir}/screen/assets_${currentCategory}.json`
|
|
|
);
|
|
|
-
|
|
|
if (assetsJson.error) {
|
|
|
const res = await deviceCtrl.WriteFileText(
|
|
|
`${appDataDir}/screen/assets_${currentCategory}.json`,
|
|
@@ -30,4 +34,20 @@ export default ListModule.action({
|
|
|
}
|
|
|
return res.result;
|
|
|
},
|
|
|
+ async delAsset(record: any) {
|
|
|
+ const { deviceCtrl } = useCtx();
|
|
|
+ const list = cloneDeep(this.store.list);
|
|
|
+ list.map((e: any, index: number) => {
|
|
|
+ if (e._id == record._id) {
|
|
|
+ list.splice(index, 1);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.store.list = list;
|
|
|
+ const appDataDir = deviceCtrl.appDataDir;
|
|
|
+ const currentCategory = localStorage.getItem("category") || "default";
|
|
|
+ const res = await deviceCtrl.WriteFileText(
|
|
|
+ `${appDataDir}/screen/assets_${currentCategory}.json`,
|
|
|
+ JSON.stringify(list)
|
|
|
+ );
|
|
|
+ },
|
|
|
});
|