class SearchListApiBase { constructor(config = {}) { this.list = [] this.loading = false this.finished = false this.total = -1 this._getParams = config.getParams || (() => {}) // 函数 Hooks this.doQuery = this.runQuery.bind(this) } /** * 统一查询 API 入口 * @param params - 请求参数 * @returns {Promise<{success: boolean, total: number, list: []}>} */ async runQuery(params) { this.loading = true this.finished = false this.list = [] const query = Object.assign({}, params, this._getParams(params)) const result = await this.ajaxQuery(query) if (result.success) { this.list = result.list this.total = result.total } else { this.list = [] this.total = -1 } this.finished = true this.loading = false return result } // 需要覆写的API处理逻辑 async ajaxQuery(params) { return { success: true, list: [], total: -1 } } } export default SearchListApiBase