|
@@ -1,12 +1,54 @@
|
|
|
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 projectApi = {
|
|
|
+ url: '/api/util/dbInit/project'
|
|
|
+}
|
|
|
export const useCounterStore = defineStore('counter', () => {
|
|
|
const count = ref(0)
|
|
|
const doubleCount = computed(() => count.value * 2)
|
|
|
function increment() {
|
|
|
count.value++
|
|
|
}
|
|
|
+ // #region project
|
|
|
+ const projectQuery = 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(`${projectApi.url}`, cond)
|
|
|
+ return res
|
|
|
+ }
|
|
|
+ const projectFetch = async (payload: any): Promise<IQueryResult> => {
|
|
|
+ const res = await axios.$get(`${projectApi.url}/${payload}`)
|
|
|
+ return res
|
|
|
+ }
|
|
|
+ const projectCreate = async (payload: any): Promise<IQueryResult> => {
|
|
|
+ const res = await axios.$post(`${projectApi.url}`, payload)
|
|
|
+ return res
|
|
|
+ }
|
|
|
+ const projecUpdate = async (payload: any): Promise<IQueryResult> => {
|
|
|
+ const id = _.get(payload, 'id', _.get(payload, '_id'))
|
|
|
+ const res = await axios.$post(`${projectApi.url}/${id}`, payload)
|
|
|
+ return res
|
|
|
+ }
|
|
|
+ const projecDelete = async (payload: any): Promise<IQueryResult> => {
|
|
|
+ const res = await axios.$delete(`${projectApi.url}/${payload}`)
|
|
|
+ return res
|
|
|
+ }
|
|
|
|
|
|
- return { count, doubleCount, increment }
|
|
|
+ return {
|
|
|
+ count,
|
|
|
+ doubleCount,
|
|
|
+ increment,
|
|
|
+ projectQuery,
|
|
|
+ projectFetch,
|
|
|
+ projectCreate,
|
|
|
+ projecUpdate,
|
|
|
+ projecDelete
|
|
|
+ }
|
|
|
})
|