change mark
This commit is contained in:
		| @@ -1,6 +1,6 @@ | ||||
| { | ||||
|   "name": "@kevisual/query-mark", | ||||
|   "version": "0.0.2", | ||||
|   "version": "0.0.1", | ||||
|   "description": "", | ||||
|   "main": "dist/query-mark.js", | ||||
|   "types": "dist/query-mark.d.ts", | ||||
|   | ||||
| @@ -2,13 +2,23 @@ import { Query } from '@kevisual/query'; | ||||
| import type { Result, DataOpts } from '@kevisual/query/query'; | ||||
| import { setBaseResponse } from '@kevisual/query/query'; | ||||
|  | ||||
| export type QueryMarkOpts = { | ||||
| export type SimpleObject = Record<string, any>; | ||||
|  | ||||
| export type SearchOpts = { | ||||
|   page: number; | ||||
|   pageSize: number; | ||||
|   search?: string; | ||||
|   sort?: string; // DESC, ASC | ||||
|   markType?: string; // 类型 | ||||
|   [key: string]: any; | ||||
| }; | ||||
|  | ||||
| export type QueryMarkOpts<T extends SimpleObject = SimpleObject> = { | ||||
|   query?: Query; | ||||
|   isBrowser?: boolean; | ||||
|   onLoad?: () => void; | ||||
|   storage?: Storage; | ||||
|   cache: Cache; | ||||
| }; | ||||
| } & T; | ||||
|  | ||||
| export type QueryMarkData = { | ||||
|   id?: string; | ||||
|   title?: string; | ||||
| @@ -20,19 +30,18 @@ export type QueryMarkResult = { | ||||
|   refreshToken: string; | ||||
| }; | ||||
|  | ||||
| export class QueryMark { | ||||
| export class QueryMarkBase<T extends SimpleObject = SimpleObject> { | ||||
|   query: Query; | ||||
|   isBrowser: boolean; | ||||
|   load?: boolean; | ||||
|   storage: Storage; | ||||
|   onLoad?: () => void; | ||||
|  | ||||
|   constructor(opts?: QueryMarkOpts) { | ||||
|   constructor(opts?: QueryMarkOpts<T>) { | ||||
|     this.query = opts?.query || new Query(); | ||||
|     this.isBrowser = opts?.isBrowser ?? true; | ||||
|     this.init(); | ||||
|     this.onLoad = opts?.onLoad; | ||||
|     this.storage = opts?.storage || localStorage; | ||||
|   } | ||||
|   setQuery(query: Query) { | ||||
|     this.query = query; | ||||
| @@ -41,6 +50,7 @@ export class QueryMark { | ||||
|     this.load = true; | ||||
|     this.onLoad?.(); | ||||
|   } | ||||
|  | ||||
|   async post<T = any>(data: any, opts?: DataOpts) { | ||||
|     try { | ||||
|       return this.query.post<T>({ path: 'mark', ...data }, opts); | ||||
| @@ -51,4 +61,26 @@ export class QueryMark { | ||||
|       } as any; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   async getMarkList(search: SearchOpts, opts?: DataOpts) { | ||||
|     return this.post({ key: 'list', ...search }, opts); | ||||
|   } | ||||
|  | ||||
|   async getMark(id: string, opts?: DataOpts) { | ||||
|     return this.post({ key: 'get', id }, opts); | ||||
|   } | ||||
|  | ||||
|   async updateMark(id: string, data: any, opts?: DataOpts) { | ||||
|     return this.post({ key: 'update', id, ...data }, opts); | ||||
|   } | ||||
| } | ||||
| export class QueryMark extends QueryMarkBase<SimpleObject> { | ||||
|   markType: string; | ||||
|   constructor(opts?: QueryMarkOpts) { | ||||
|     super(opts); | ||||
|     this.markType = opts?.markType || 'simple'; | ||||
|   } | ||||
|   async getMarkList(search: SearchOpts, opts?: DataOpts) { | ||||
|     return this.post({ key: 'list', ...search, markType: this.markType }, opts); | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user