| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- import { ref } from "vue";
- import { autoSetModeCallback, createTemploraryID } from "./sys";
- import {
- fetchAnimationActions,
- fetchAnimationModels,
- postDeleteAnimationModel,
- postInsertAnimationModel,
- postUpdateAnimationModel,
- } from "@/api";
- import {
- togetherCallback,
- deleteStoreItem,
- addStoreItem,
- updateStoreItem,
- saveStoreItems,
- recoverStoreItems,
- } from "@/utils";
- import type {
- AnimationAction,
- AnimationModel,
- AnimationModels,
- } from "@/api";
- export type {
- AnimationModelAction,
- AnimationModelFrame,
- AnimationModelPath,
- AnimationModelSubtitle,
- } from '@/api'
- export type { AnimationModel, AnimationModels };
- export const ams = ref<AnimationModels>([]);
- export const amActions = ref<AnimationAction[]>([]);
- export const initAnimationActions = async () => {
- amActions.value = await fetchAnimationActions();
- };
- export const createAnimationModel = (
- am: Partial<AnimationModel> = {}
- ): AnimationModel => ({
- id: createTemploraryID(),
- title: `模型`,
- url: "",
- showTitle: true,
- fontSize: 12,
- globalVisibility: true,
- visibilityRange: 12,
- subtitles: [],
- actions: [],
- frames: [],
- paths: [],
- ...am,
- });
- let bcAms: AnimationModels = [];
- export const getBackupAnimationModels = () => bcAms;
- export const backupAnimationModels = () => {
- bcAms = ams.value.map((am) => ({ ...am }));
- };
- export const addAnimationModel = addStoreItem(ams, postInsertAnimationModel);
- export const updateAnimationModels = updateStoreItem(
- ams,
- postUpdateAnimationModel
- );
- export const deleteAnimationModel = deleteStoreItem(ams, ({ id }) =>
- postDeleteAnimationModel(id)
- );
- export const initialAnimationModels = async () => {
- ams.value = await fetchAnimationModels();
- backupAnimationModels();
- };
- export const recoverAnimationModels = recoverStoreItems(
- ams,
- getBackupAnimationModels
- );
- export const saveAnimationModels = saveStoreItems(
- ams,
- getBackupAnimationModels,
- {
- add: addAnimationModel,
- update: updateAnimationModels,
- delete: deleteAnimationModel,
- }
- );
- export const autoSaveAnimationModel = autoSetModeCallback([ams], {
- backup: togetherCallback([backupAnimationModels]),
- recovery: togetherCallback([recoverAnimationModels]),
- save: async () => {
- await saveAnimationModels();
- },
- });
|