diff --git a/package.json b/package.json index ad485c9..2722ccd 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/query-mark.ts b/src/query-mark.ts index 8e3b7e2..b641730 100644 --- a/src/query-mark.ts +++ b/src/query-mark.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; + +export type SearchOpts = { + page: number; + pageSize: number; + search?: string; + sort?: string; // DESC, ASC + markType?: string; // 类型 + [key: string]: any; +}; + +export type QueryMarkOpts = { 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 { query: Query; isBrowser: boolean; load?: boolean; storage: Storage; onLoad?: () => void; - constructor(opts?: QueryMarkOpts) { + constructor(opts?: QueryMarkOpts) { 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(data: any, opts?: DataOpts) { try { return this.query.post({ 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 { + 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); + } }