{"size": 783, "ext": "js", "max_stars_repo_path": "src/components/Dict/Dict.js", "max_stars_repo_name": "izneus/bonfire-admin-vue", "max_stars_repo_stars_event_min_datetime": "2021-07-16T14:39:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T06:40:11.000Z", "max_issues_repo_path": "src/components/Dict/Dict.js", "max_issues_repo_name": "izneus/bonfire-admin-vue", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/components/Dict/Dict.js", "max_forks_repo_name": "izneus/bonfire-admin-vue", "max_forks_repo_forks_event_min_datetime": "2021-11-23T05:29:59.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-23T05:29:59.000Z"}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 26.1, "max_line_length": 63, "alphanum_fraction": 0.5721583653}
import Vue from 'vue'
import { listDictsByDictType } from '@/api/dict'

export default class Dict {
  constructor(dict) {
    this.dict = dict
  }

  async init(names, completeCallback) {
    if (names === undefined || names === null) {
      throw new Error('need Dict names')
    }
    const ps = []
    names.forEach(n => {
      Vue.set(this.dict.dict, n, {})
      Vue.set(this.dict.label, n, {})
      Vue.set(this.dict, n, [])
      ps.push(listDictsByDictType(n).then(resp => {
        this.dict[n].splice(0, 0, ...resp.data.details)
        resp.data.details.forEach(d => {
          Vue.set(this.dict.dict[n], d.dictValue, d)
          Vue.set(this.dict.label[n], d.dictValue, d.dictLabel)
        })
      }))
    })
    await Promise.all(ps)
    completeCallback()
  }
}
