| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- import {
- defineStore
- } from 'pinia';
- import {
- getDictionaryDataAll,
- getGroupSelector,
- getRoleSelector,
- } from '@/api/common'
- export const useBaseStore = defineStore({
- id: ' app-base',
- state: () => ({
- dictionaryList: [],
- groupList: [],
- roleList: [],
- relationData: {},
- }),
- getters: {
- getDictionaryList() {
- return this.dictionaryList
- },
- getRelationData() {
- return this.relationData
- },
- },
- actions: {
- setDictionaryList(dictionaryList) {
- this.dictionaryList = dictionaryList || []
- },
- setGroupList(groupList) {
- this.groupList = groupList
- },
- setRoleList(roleList) {
- this.roleList = roleList
- },
- updateRelationData(val) {
- this.relationData = val
- },
- getDictionaryDataAll() {
- return new Promise((resolve, reject) => {
- if (this.dictionaryList.length) {
- resolve(this.dictionaryList)
- } else {
- getDictionaryDataAll().then(res => {
- this.setDictionaryList(res.data.list)
- resolve(res.data.list)
- }).catch(error => {
- reject(error)
- })
- }
- })
- },
- getDictionaryData(info) {
- return new Promise(async resolve => {
- let list = [],
- data = [],
- json = []
- if (!this.dictionaryList.length) {
- list = await this.getDictionaryDataAll()
- } else {
- list = this.dictionaryList
- }
- if (info.sort) {
- data = list.filter(o => o.enCode === info.sort)[0]
- if (!info.id) {
- json = data?.dictionaryList || []
- } else {
- let rowData = [];
- if (!data.isTree) {
- rowData = data.dictionaryList.fliter(o => o.id == info.id)
- } else {
- const findData = list => {
- for (let i = 0; i < list.length; i++) {
- const e = list[i];
- if (e.id == info.id) {
- rowData[0] = e
- break
- }
- if (e.children && e.children.length) {
- findData(e.children)
- }
- }
- }
- findData(data.dictionaryList)
- }
- if (rowData.length) {
- json = rowData[0]
- } else {
- json = {
- id: "",
- fullName: ""
- };
- }
- }
- }
- resolve(json)
- })
- },
- getDicDataSelector(value, key = 'id') {
- return new Promise(async resolve => {
- let list = [],
- data = {},
- json = [];
- if (!this.dictionaryList.length) {
- list = await this.getDictionaryDataAll()
- } else {
- list = this.dictionaryList
- }
- if (!value) return resolve([])
- let arr = list.filter(o => o[key] === value);
- if (!arr.length) return resolve([])
- data = arr[0];
- json = data.dictionaryList;
- resolve(json)
- })
- },
- getGroupList() {
- return new Promise((resolve, reject) => {
- if (!this.groupList.length) {
- getGroupSelector().then(res => {
- this.setGroupList(res.data)
- resolve(res.data)
- }).catch(error => {
- reject(error)
- })
- } else {
- resolve(this.groupList)
- }
- })
- },
- getRoleList() {
- return new Promise((resolve, reject) => {
- if (!this.roleList.length) {
- getRoleSelector().then(res => {
- this.setRoleList(res.data.list)
- resolve(res.data.list)
- }).catch(error => {
- reject(error)
- })
- } else {
- resolve(this.roleList)
- }
- })
- },
- },
- });
|