index.ts 4.18 KB
import { defineStore } from 'pinia';
import { Selection } from '@/store/modules/selection/type';

import { SystemConfig } from '@/types/system-config';
import { Tag } from '@/types/tag';
import { Project } from '@/types/project';
import useProjectApi from '@/http/project';
import useUserApi from '@/http/user';
import useTagApi from '@/http/Tag';
import useConfigApi from '@/http/config';
import { User } from '@/utils/model';

const useSelectionStore = defineStore('selection', {
  state: (): Selection => ({ user: [], project: [], tag: [], config: [] }),
  getters: {
    getUserOptions(state): User[] {
      return state.user;
    },
    getProjectOptions(state) {
      return state.project;
    },
    getTagOptions(state) {
      return state.tag;
    },
    projectOptions(state) {
      return state.project;
    },
    getConfigOption(state) {
      return state.config;
    },
    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);
    },
    activityMark(state): SystemConfig | undefined {
      return state.config.find((item) => item.identifier === 'activity_mark');
    },
    activityMarkOptions(state): SystemConfig[] {
      return state.config.filter((item) => item.parent_id === this.activityMark?.id);
    },
    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 || '*';
    },
    activityTagOptions(state): Pick<Tag, 'id' | 'name' | 'type'>[] {
      return state.tag.filter((item) => item.type === 1);
    },
    activityProjectOptions(state): Pick<Project, 'id' | 'name'>[] {
      return state.project;
    },
    activityAuditIds(state): string[] {
      return state.config.find((item) => item.identifier === 'activity_audit_ids')?.content?.split(',') || [];
    },
    appleDemoCover(state): string {
      return state.config.find((item) => item.identifier === 'activity_demo_cover')?.content || '';
    },

    userAuthTag(state) {
      return state.tag.filter((item) => item.type === 4);
    },
  },
  actions: {
    queryUser() {
      useUserApi
        .get({ fetchType: 'all', setColumn: ['id', 'nick_name', 'real_name', 'avatar'], sortBy: 'id', sortType: 'desc' })
        .then(({ data }) => {
          this.user = data;
        });
    },
    queryProject() {
      useProjectApi
        .get({ fetchType: 'all', setColumn: ['id', 'is_can_apply', 'is_can_demo_apply', 'name'], sortBy: 'id', sortType: 'desc' })
        .then(({ data }) => {
          this.project = data;
        });
    },
    queryTag() {
      useTagApi.get({ fetchType: 'all', setColumn: ['id', 'name', 'type'], sortBy: 'weight', sortType: 'desc' }).then(({ data }) => {
        this.tag = data;
      });
    },
    queryConfig() {
      useConfigApi
        .get({
          fetchType: 'all',
          parent_id: '',
          setColumn: ['id', 'parent_id', 'name', 'identifier', 'content'],
          sortBy: 'weight',
          sortType: 'desc',
        })
        .then(({ data }) => {
          this.config = data;
        });
    },
    queryAll() {
      this.queryConfig();
      this.queryUser();
      this.queryProject();
      this.queryTag();
    },
  },
});
export default useSelectionStore;