1404/11/04- first
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import {computed, ref} from 'vue'
|
||||
import {defineStore} from 'pinia'
|
||||
|
||||
|
||||
export const useConfigStore = defineStore('config', () => {
|
||||
const config = ref()
|
||||
|
||||
async function getConfigData() {
|
||||
|
||||
let temp = window.__APP_CONFIG__
|
||||
config.value = temp.user
|
||||
console.log(config.value)
|
||||
}
|
||||
|
||||
return {
|
||||
config,
|
||||
getConfigData
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,201 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
interface State {
|
||||
/* docGroupsData: Array<GroupItem> | undefined
|
||||
docTypeListData: Array<DocItem> | undefined
|
||||
natureListData: Array<Const> | undefined
|
||||
budgetListData: Array<Const> | undefined
|
||||
projectTypeListData: Array<Const> | undefined
|
||||
userTypeListData: Array<Const> | undefined
|
||||
sectionListData: Array<Const> | undefined
|
||||
projectListData: Array<Customer> | undefined
|
||||
processListData: Array<Process> | undefined
|
||||
provincesListData: Array<Province> | undefined
|
||||
cityListData: Array<City> | undefined
|
||||
usersListData: Array<User> | undefined*/
|
||||
//myInfo: User | undefined
|
||||
// treePermissionData: any
|
||||
networkError: boolean
|
||||
}
|
||||
|
||||
export const useStaticApiListsStore = defineStore('staticApiLists', {
|
||||
state: (): State => {
|
||||
return {
|
||||
/* docGroupsData: undefined,
|
||||
docTypeListData: undefined,
|
||||
natureListData: undefined,
|
||||
budgetListData: undefined,
|
||||
projectTypeListData: undefined,
|
||||
userTypeListData: undefined,
|
||||
usersListData: undefined,
|
||||
sectionListData: undefined,
|
||||
treePermissionData: undefined,
|
||||
processListData: undefined,
|
||||
provincesListData: undefined,
|
||||
projectListData: undefined,
|
||||
cityListData: undefined,*/
|
||||
// myInfo: undefined,
|
||||
networkError: false
|
||||
}
|
||||
},
|
||||
// could also be defined as
|
||||
// state: () => ({ count: 0 })
|
||||
actions: {
|
||||
/* async getDocGroupList() {
|
||||
try {
|
||||
this.docGroupsData = await getDocGroupList()
|
||||
return this.docGroupsData
|
||||
} catch (e) {
|
||||
this.networkError = true
|
||||
}
|
||||
},
|
||||
async getUsersList() {
|
||||
try {
|
||||
this.usersListData = await getUsersList()
|
||||
return this.usersListData
|
||||
} catch (e) {
|
||||
this.networkError = true
|
||||
}
|
||||
},
|
||||
async getDocTypeList() {
|
||||
try {
|
||||
this.docTypeListData = await getDocTypeList()
|
||||
return this.docTypeListData
|
||||
} catch (e) {
|
||||
this.networkError = true
|
||||
}
|
||||
},
|
||||
async getNatureConst() {
|
||||
try {
|
||||
this.natureListData = await getNatureConst()
|
||||
// console.log('hell', this.natureListData)
|
||||
return this.natureListData
|
||||
} catch (e) {
|
||||
this.networkError = true
|
||||
}
|
||||
},
|
||||
async getBudgetConst() {
|
||||
try {
|
||||
this.budgetListData = await getBudgetConst()
|
||||
return this.budgetListData
|
||||
} catch (e) {
|
||||
this.networkError = true
|
||||
}
|
||||
},
|
||||
async getProjectTypeConst() {
|
||||
try {
|
||||
this.projectTypeListData = await getProjectConst()
|
||||
return this.projectTypeListData
|
||||
} catch (e) {
|
||||
this.networkError = true
|
||||
}
|
||||
},
|
||||
async getUserTypeConst() {
|
||||
try {
|
||||
this.userTypeListData = await getUserTypeConst()
|
||||
return this.userTypeListData
|
||||
} catch (e) {
|
||||
this.networkError = true
|
||||
}
|
||||
},
|
||||
async getSectionConst() {
|
||||
try {
|
||||
this.sectionListData = await getSectionConst()
|
||||
return this.sectionListData
|
||||
} catch (e) {
|
||||
this.networkError = true
|
||||
}
|
||||
},
|
||||
async getProcessList() {
|
||||
try {
|
||||
this.processListData = await getProcessList()
|
||||
return this.processListData
|
||||
} catch (e) {
|
||||
this.networkError = true
|
||||
}
|
||||
},
|
||||
async getTreeDataList() {
|
||||
try {
|
||||
this.treePermissionData = await getTreeData()
|
||||
return this.treePermissionData
|
||||
} catch (e) {
|
||||
this.networkError = true
|
||||
}
|
||||
},
|
||||
async getProjectList() {
|
||||
try {
|
||||
this.projectListData = await getProjectList()
|
||||
return this.projectListData
|
||||
} catch (e) {
|
||||
this.networkError = true
|
||||
}
|
||||
},
|
||||
async getProvincesList() {
|
||||
try {
|
||||
this.provincesListData = await getProvinces()
|
||||
return this.provincesListData
|
||||
} catch (e) {
|
||||
this.networkError = true
|
||||
}
|
||||
},
|
||||
async getCityList() {
|
||||
try {
|
||||
this.cityListData = await getAllCities()
|
||||
return this.cityListData
|
||||
} catch (e) {
|
||||
this.networkError = true
|
||||
}
|
||||
},
|
||||
async readyDocGroupList() {
|
||||
return this.docGroupsData ?? (await this.getDocGroupList())
|
||||
},
|
||||
async readyDocTypeList() {
|
||||
return this.docTypeListData ?? (await this.getDocTypeList())
|
||||
},
|
||||
async readyNatureConst() {
|
||||
return this.natureListData ?? (await this.getNatureConst())
|
||||
},
|
||||
async readyBudgetConst() {
|
||||
return this.budgetListData ?? (await this.getBudgetConst())
|
||||
},
|
||||
async readyProjectTypeConst() {
|
||||
return this.projectTypeListData ?? (await this.getProjectTypeConst())
|
||||
},
|
||||
async readyUserTypeConst() {
|
||||
return this.userTypeListData ?? (await this.getUserTypeConst())
|
||||
},
|
||||
async readySectionConst() {
|
||||
return this.sectionListData ?? (await this.getSectionConst())
|
||||
},
|
||||
async readyProcessList() {
|
||||
return this.processListData ?? (await this.getProcessList())
|
||||
},
|
||||
async readyTreeDataList() {
|
||||
return this.treePermissionData ?? (await this.getTreeDataList())
|
||||
},
|
||||
async readyProjectList() {
|
||||
return this.projectListData ?? (await this.getProjectList())
|
||||
},
|
||||
async readyProvincesList() {
|
||||
return this.provincesListData ?? (await this.getProvincesList())
|
||||
},
|
||||
async readyCitiesList() {
|
||||
return this.cityListData ?? (await this.getCityList())
|
||||
},
|
||||
async readyUserList() {
|
||||
console.log('sasasasa', this.usersListData)
|
||||
return this.usersListData ?? (await this.getUsersList())
|
||||
}*/
|
||||
/*async getWholeData() {
|
||||
await this.getDocGroupList()
|
||||
await this.getDocTypeList()
|
||||
await this.getNatureConst()
|
||||
await this.getProjectTypeConst()
|
||||
await this.getBudgetConst()
|
||||
await this.getUserTypeConst()
|
||||
await this.getProjectList()
|
||||
await this.getProcessList()
|
||||
await this.getProvincesList()
|
||||
}*/
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,33 @@
|
||||
import { type ComputedRef, ref } from 'vue'
|
||||
import type { User } from '@/model/user'
|
||||
import { getMyInformation } from '@/api/user'
|
||||
import { get } from 'lodash'
|
||||
export const useUserStore = defineStore('user', () => {
|
||||
const userInfo = ref<User | undefined>(undefined)
|
||||
|
||||
async function getMyInfo() {
|
||||
try {
|
||||
userInfo.value = await getMyInformation()
|
||||
return userInfo.value
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
|
||||
const permissions: ComputedRef<string[]> = computed(() => {
|
||||
const permissions: string[] = get(userInfo.value, 'permission', [])
|
||||
const excludes: string[] = get(userInfo.value, 'exclude', [])
|
||||
return permissions.filter((item) => !excludes.includes(item))
|
||||
})
|
||||
|
||||
function canAccess(permissionKey: string) {
|
||||
if (isAdmin.value) return true
|
||||
return permissions.value.includes(permissionKey)
|
||||
}
|
||||
|
||||
const isAdmin = computed(() => {
|
||||
return userInfo.value?.is_admin
|
||||
})
|
||||
|
||||
return { userInfo, getMyInfo, permissions, canAccess, isAdmin }
|
||||
})
|
||||
Reference in New Issue
Block a user