change mark
This commit is contained in:
		| @@ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "name": "@kevisual/query-mark", |   "name": "@kevisual/query-mark", | ||||||
|   "version": "0.0.2", |   "version": "0.0.1", | ||||||
|   "description": "", |   "description": "", | ||||||
|   "main": "dist/query-mark.js", |   "main": "dist/query-mark.js", | ||||||
|   "types": "dist/query-mark.d.ts", |   "types": "dist/query-mark.d.ts", | ||||||
|   | |||||||
| @@ -2,13 +2,23 @@ import { Query } from '@kevisual/query'; | |||||||
| import type { Result, DataOpts } from '@kevisual/query/query'; | import type { Result, DataOpts } from '@kevisual/query/query'; | ||||||
| import { setBaseResponse } 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; |   query?: Query; | ||||||
|   isBrowser?: boolean; |   isBrowser?: boolean; | ||||||
|   onLoad?: () => void; |   onLoad?: () => void; | ||||||
|   storage?: Storage; | } & T; | ||||||
|   cache: Cache; |  | ||||||
| }; |  | ||||||
| export type QueryMarkData = { | export type QueryMarkData = { | ||||||
|   id?: string; |   id?: string; | ||||||
|   title?: string; |   title?: string; | ||||||
| @@ -20,19 +30,18 @@ export type QueryMarkResult = { | |||||||
|   refreshToken: string; |   refreshToken: string; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| export class QueryMark { | export class QueryMarkBase<T extends SimpleObject = SimpleObject> { | ||||||
|   query: Query; |   query: Query; | ||||||
|   isBrowser: boolean; |   isBrowser: boolean; | ||||||
|   load?: boolean; |   load?: boolean; | ||||||
|   storage: Storage; |   storage: Storage; | ||||||
|   onLoad?: () => void; |   onLoad?: () => void; | ||||||
|  |  | ||||||
|   constructor(opts?: QueryMarkOpts) { |   constructor(opts?: QueryMarkOpts<T>) { | ||||||
|     this.query = opts?.query || new Query(); |     this.query = opts?.query || new Query(); | ||||||
|     this.isBrowser = opts?.isBrowser ?? true; |     this.isBrowser = opts?.isBrowser ?? true; | ||||||
|     this.init(); |     this.init(); | ||||||
|     this.onLoad = opts?.onLoad; |     this.onLoad = opts?.onLoad; | ||||||
|     this.storage = opts?.storage || localStorage; |  | ||||||
|   } |   } | ||||||
|   setQuery(query: Query) { |   setQuery(query: Query) { | ||||||
|     this.query = query; |     this.query = query; | ||||||
| @@ -41,6 +50,7 @@ export class QueryMark { | |||||||
|     this.load = true; |     this.load = true; | ||||||
|     this.onLoad?.(); |     this.onLoad?.(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   async post<T = any>(data: any, opts?: DataOpts) { |   async post<T = any>(data: any, opts?: DataOpts) { | ||||||
|     try { |     try { | ||||||
|       return this.query.post<T>({ path: 'mark', ...data }, opts); |       return this.query.post<T>({ path: 'mark', ...data }, opts); | ||||||
| @@ -51,4 +61,26 @@ export class QueryMark { | |||||||
|       } as any; |       } 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