index.ts 2.61 KB
import { defineStore } from 'pinia';
import { Selection } from '@/store/modules/selection/type';
import { AnyObject } from '@/types/global';
import { SystemConfig } from '@/types/system-config';
import axios from 'axios';
import { Tag } from '@/types/tag';

const useSelectionStore = defineStore('selection', {
  state: (): Selection => ({
    user: [],
    project: [],
    tag: [],
    config: [],
  }),
  getters: {
    getUserOptions(state) {
      return state.user;
    },
    getTagOptions(state) {
      return state.tag;
    },
    projectOptions(state) {
      return state.project;
    },
    lyricTool(state): string {
      return state.config.find((item) => item.identifier === 'activity_lyric_tool')?.content || '';
    },
    activityLang(state): SystemConfig | undefined {
      return state.config.find((item) => item.identifier === 'activity_lang');
    },
    activityLangOptions(state): SystemConfig[] {
      return state.config.filter((item) => item.parent_id === this.activityLang?.id);
    },
    activitySpeed(state): SystemConfig | undefined {
      return state.config.find((item) => item.identifier === 'activity_speed');
    },
    activitySpeedOptions(state): SystemConfig[] {
      return state.config.filter((item) => item.parent_id === this.activitySpeed?.id);
    },
    activitySex(state): SystemConfig | undefined {
      return state.config.find((item) => item.identifier === 'activity_sex');
    },
    activitySexOptions(state): SystemConfig[] {
      return state.config.filter((item) => item.parent_id === this.activitySex?.id);
    },
    activityTagOptions(state): Pick<Tag, 'id' | 'name' | 'type'>[] {
      return state.tag.filter((item) => item.type === 1);
    },
    activityAudioAccept(state): string {
      return state.config.find((item) => item.identifier === 'activity_audio_accept')?.content || 'audio/*';
    },
    activityTrackAccept(state): string {
      return state.config.find((item) => item.identifier === 'activity_track_accept')?.content || '*';
    },
    appleDemoCover(state): string {
      return state.config.find((item) => item.identifier === 'activity_demo_cover')?.content || '';
    },
  },
  actions: {
    queryUser(params?: AnyObject) {
      axios.get('/provider/users', { params }).then(({ data }) => {
        this.user = data;
      });
    },
    queryTag(params?: AnyObject) {
      axios.get('/provider/tags',{ params }).then(({ data }) => {
        this.tag = data;
      });
    },
    queryConfig(params?: AnyObject) {
      axios.get('/provider/configs', { params }).then(({ data }) => {
        this.config = data;
      });
    },
  },
});

export default useSelectionStore;