| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- 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 {
- AnimationModel,
- AnimationModels,
- } from "@/api";
- import { inRevise } from "bill/utils";
- export type {
- AnimationModelAction,
- AnimationModelFrame,
- AnimationModelPath,
- AnimationModelSubtitle,
- } from '@/api'
- export type { AnimationModel, AnimationModels };
- export const ams = ref<AnimationModels>([]);
- 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 = JSON.parse(JSON.stringify(ams.value))
- };
- 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]),
- isUpdate: (newv) => {
- return inRevise(newv, getBackupAnimationModels())
- },
- save: async () => {
- console.error('savesave')
- await saveAnimationModels();
- },
- });
|