1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- import { ref, computed } from 'vue';
- import { defineStore } from 'pinia';
- import { AxiosWrapper } from '@/util/axios-wrapper';
- import _ from 'lodash';
- import type { IQueryType, IQueryResult, IQueryParams } from '@/util/types.util';
- const axios = new AxiosWrapper();
- const api = {
- url: `/jcyjdtglpt/v1/api/role`,
- };
- export const RoleStore = defineStore('role', () => {
- const count = ref(0);
- const doubleCount = computed(() => count.value * 2);
- function increment() {
- count.value++;
- }
- const query = async ({ skip = 0, limit = undefined, ...info }: IQueryParams = {}): Promise<IQueryResult> => {
- let cond: IQueryType = {};
- if (skip) cond.skip = skip;
- if (limit) cond.limit = limit;
- cond = { ...cond, ...info };
- const res = await axios.$get(`${api.url}`, cond);
- return res;
- };
- const um = async (): Promise<IQueryResult> => {
- const res = await axios.$get(`${api.url}/um`);
- return res;
- };
- const am = async (): Promise<IQueryResult> => {
- const res = await axios.$get(`${api.url}/am`);
- return res;
- };
- const fetch = async (payload: any): Promise<IQueryResult> => {
- const res = await axios.$get(`${api.url}/${payload}`);
- return res;
- };
- const create = async (payload: any): Promise<IQueryResult> => {
- const res = await axios.$post(`${api.url}`, payload);
- return res;
- };
- const update = async (payload: any): Promise<IQueryResult> => {
- const id = _.get(payload, 'id', _.get(payload, '_id'));
- const res = await axios.$post(`${api.url}/${id}`, payload);
- return res;
- };
- const del = async (payload: any): Promise<IQueryResult> => {
- const res = await axios.$delete(`${api.url}/${payload}`);
- return res;
- };
- return {
- count,
- doubleCount,
- increment,
- query,
- um,
- am,
- fetch,
- create,
- update,
- del,
- };
- });
|