unicloud-db.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. <template>
  2. <uni-cloud-db-element ref="UniCloudDB">
  3. <slot :data="dataList" :loading="loading" :hasMore="hasMore" :pagination="pagination" :error="error" />
  4. </uni-cloud-db-element>
  5. </template>
  6. <script lang="uts">
  7. //#ifdef APP
  8. import { SlotsType } from 'vue'
  9. //#endif
  10. //#ifdef WEB || APP-IOS
  11. let registerFlag = false
  12. //#endif
  13. const EVENT_LOAD = 'load'
  14. const EVENT_ERROR = 'error'
  15. const PAGE_MODE_ADD = 'add'
  16. const PAGE_MODE_REPLACE = 'replace'
  17. const LOAD_MODE_AUTO = 'auto'
  18. const LOAD_MODE_MANUAL = 'manual'
  19. // const LOAD_MODE_ONREADY = 'onready'
  20. type SuccessCallback<T> = (res : T | null) => void | null
  21. type FailCallback = (err : any | null) => void | null
  22. type CompleteCallback = () => void | null
  23. type GetSuccessCallback = SuccessCallback<UniCloudDBGetResult>
  24. type AddSuccessCallback = SuccessCallback<UniCloudDBAddResult>
  25. type RemoveSuccessCallback = SuccessCallback<UniCloudDBRemoveResult>
  26. type UpdateSuccessCallback = SuccessCallback<UniCloudDBUpdateResult>
  27. export type UniCloudDBComponentPaginationType = {
  28. current : number,
  29. size : number,
  30. count : number
  31. }
  32. export type UniCloudDBComponentLoadDataOptions = {
  33. clear ?: boolean | null,
  34. current ?: number | null,
  35. success ?: GetSuccessCallback,
  36. fail ?: FailCallback,
  37. complete ?: CompleteCallback,
  38. }
  39. export type UniCloudDBComponentAddOptions = {
  40. /**
  41. * @default true
  42. */
  43. showToast ?: boolean | null,
  44. toastTitle ?: string | null,
  45. /**
  46. * @default true
  47. */
  48. needLoading ?: boolean | null,
  49. loadingTitle ?: string | null,
  50. success ?: AddSuccessCallback,
  51. fail ?: FailCallback,
  52. complete ?: CompleteCallback,
  53. }
  54. export type UniCloudDBComponentRemoveOptions = {
  55. confirmTitle ?: string | null,
  56. confirmContent ?: string | null,
  57. /**
  58. * @default true
  59. */
  60. needConfirm ?: boolean | null,
  61. /**
  62. * @default true
  63. */
  64. needLoading ?: boolean | null,
  65. loadingTitle ?: string | null,
  66. success ?: RemoveSuccessCallback,
  67. fail ?: FailCallback,
  68. complete ?: CompleteCallback,
  69. }
  70. export type UniCloudDBComponentUpdateOptions = {
  71. /**
  72. * @default true
  73. */
  74. showToast ?: boolean | null,
  75. toastTitle ?: string | null,
  76. confirmTitle ?: string | null,
  77. confirmContent ?: string | null,
  78. /**
  79. * @default true
  80. */
  81. needConfirm ?: boolean | null,
  82. /**
  83. * @default true
  84. */
  85. needLoading ?: boolean | null,
  86. loadingTitle ?: string | null,
  87. success ?: UpdateSuccessCallback,
  88. fail ?: FailCallback,
  89. complete ?: CompleteCallback,
  90. }
  91. function cast_callback<T>(options : any | null) : T | null {
  92. return options as T | null
  93. }
  94. //#ifdef APP-ANDROID
  95. export class UniCloudDBElement extends UniViewElementImpl {
  96. constructor(data : INodeData, pageNode : PageNode) {
  97. super(data, pageNode)
  98. }
  99. //#endif
  100. //#ifdef WEB || APP-IOS
  101. const RealUniElementImpl = typeof UniElementImpl === 'undefined' ? class {} : UniElementImpl
  102. export class UniCloudDBElement extends RealUniElementImpl {
  103. constructor(data : INodeData, pageNode : PageNode) {
  104. super(data, pageNode);
  105. const TagName = 'UNICLOUD-DB';
  106. Object.defineProperty(this, 'tagName', {
  107. value: TagName,
  108. writable: false
  109. });
  110. Object.defineProperty(this, 'nodeName', {
  111. value: TagName,
  112. writable: false
  113. });
  114. }
  115. //#endif
  116. dataList : Array<UTSJSONObject> = []
  117. loadData(options : UTSJSONObject = {}) {
  118. this.onLoadData({
  119. clear: options.getBoolean('clear'),
  120. current: options.getNumber('current'),
  121. success: cast_callback<GetSuccessCallback>(options['success']),
  122. fail: cast_callback<FailCallback>(options['fail']),
  123. complete: cast_callback<CompleteCallback>(options['complete'])
  124. } as UniCloudDBComponentLoadDataOptions)
  125. }
  126. loadMore() {
  127. this.onLoadMore()
  128. }
  129. add(value : UTSJSONObject, options : UTSJSONObject) {
  130. this.onAdd(value, {
  131. showToast: options.getBoolean('showToast') ?? true,
  132. toastTitle: options.getString('toastTitle'),
  133. needLoading: options.getBoolean('needLoading') ?? true,
  134. loadingTitle: options.getString('loadingTitle'),
  135. success: cast_callback<AddSuccessCallback>(options['success']),
  136. fail: cast_callback<FailCallback>(options['fail']),
  137. complete: cast_callback<CompleteCallback>(options['complete'])
  138. } as UniCloudDBComponentAddOptions)
  139. }
  140. // @ts-ignore
  141. remove(id : any, options : UTSJSONObject) {
  142. //#ifdef WEB || APP-IOS
  143. // @ts-ignore
  144. if (arguments.length == 0) {
  145. super.remove()
  146. return
  147. }
  148. //#endif
  149. this.onRemove(id, {
  150. confirmTitle: options.getString('confirmTitle'),
  151. confirmContent: options.getString('confirmContent'),
  152. needConfirm: options.getBoolean('needConfirm') ?? true,
  153. needLoading: options.getBoolean('needLoading') ?? true,
  154. loadingTitle: options.getString('loadingTitle'),
  155. success: cast_callback<RemoveSuccessCallback>(options['success']),
  156. fail: cast_callback<FailCallback>(options['fail']),
  157. complete: cast_callback<CompleteCallback>(options['complete'])
  158. } as UniCloudDBComponentRemoveOptions)
  159. }
  160. update(id : string, value : UTSJSONObject, options : UTSJSONObject) {
  161. this.onUpdate(id, value, {
  162. showToast: options.getBoolean('showToast') ?? true,
  163. toastTitle: options.getString('toastTitle'),
  164. confirmTitle: options.getString('confirmTitle'),
  165. confirmContent: options.getString('confirmContent'),
  166. needConfirm: options.getBoolean('needConfirm') ?? true,
  167. needLoading: options.getBoolean('needLoading') ?? true,
  168. loadingTitle: options.getString('loadingTitle'),
  169. success: cast_callback<UpdateSuccessCallback>(options['success']),
  170. fail: cast_callback<FailCallback>(options['fail']),
  171. complete: cast_callback<CompleteCallback>(options['complete'])
  172. } as UniCloudDBComponentUpdateOptions)
  173. }
  174. onLoadData! : (_ : UniCloudDBComponentLoadDataOptions) => Promise<void>
  175. onLoadMore! : () => void
  176. onAdd! : (value : UTSJSONObject, options : UniCloudDBComponentAddOptions) => void
  177. onUpdate!: (id : string, value : UTSJSONObject, options : UniCloudDBComponentUpdateOptions) => void
  178. onRemove!: (id : any, options : UniCloudDBComponentRemoveOptions) => void
  179. }
  180. export default {
  181. name: 'UniCloudDB',
  182. rootElement: {
  183. name: 'uni-cloud-db-element',
  184. class: UniCloudDBElement
  185. },
  186. slots: Object as SlotsType<{
  187. default : {
  188. data : Array<UTSJSONObject>,
  189. loading : boolean,
  190. hasMore : boolean,
  191. pagination : UniCloudDBComponentPaginationType,
  192. error : UniCloudError | null
  193. }
  194. }>,
  195. props: {
  196. collection: {
  197. type: [String, Object],
  198. default: ''
  199. },
  200. field: {
  201. type: String,
  202. default: ''
  203. },
  204. orderby: {
  205. type: String,
  206. default: ''
  207. },
  208. where: {
  209. type: [String, Object],
  210. default: ''
  211. },
  212. pageData: {
  213. type: String,
  214. default: 'add'
  215. },
  216. pageCurrent: {
  217. type: Number,
  218. default: 1
  219. },
  220. pageSize: {
  221. type: Number,
  222. default: 20
  223. },
  224. getcount: {
  225. type: Boolean,
  226. default: false
  227. },
  228. gettree: {
  229. type: [String, Object],
  230. default: ''
  231. },
  232. gettreepath: {
  233. type: Boolean,
  234. default: false
  235. },
  236. startwith: {
  237. type: String,
  238. default: ''
  239. },
  240. limitlevel: {
  241. type: Number,
  242. default: 10
  243. },
  244. groupby: {
  245. type: String,
  246. default: ''
  247. },
  248. groupField: {
  249. type: String,
  250. default: ''
  251. },
  252. distinct: {
  253. type: Boolean,
  254. default: false
  255. },
  256. pageIndistinct: {
  257. type: Boolean,
  258. default: false
  259. },
  260. foreignKey: {
  261. type: String,
  262. default: ''
  263. },
  264. loadtime: {
  265. type: String,
  266. default: 'auto'
  267. },
  268. manual: {
  269. type: Boolean,
  270. default: false
  271. },
  272. ssrKey: {
  273. type: String,
  274. default: ""
  275. }
  276. },
  277. data() {
  278. return {
  279. //#ifdef WEB
  280. // TODO 修复类型错误
  281. // @ts-ignore
  282. dataList: ssrRef([] as Array<UTSJSONObject>) as Array<UTSJSONObject>,
  283. //#endif
  284. //#ifndef WEB
  285. dataList: [] as Array<UTSJSONObject>,
  286. //#endif
  287. // dataList: [] as Array<UTSJSONObject>,
  288. loading: false,
  289. hasMore: false,
  290. isEnded: false,
  291. pagination: {
  292. current: 1,
  293. size: 20,
  294. count: 0,
  295. } as UniCloudDBComponentPaginationType,
  296. error: null as UniCloudError | null
  297. }
  298. },
  299. //#ifdef WEB || APP-IOS
  300. beforeCreate() {
  301. if (!registerFlag) {
  302. registerFlag = true
  303. // @ts-ignore
  304. typeof customElements !== 'undefined' && customElements.define(
  305. 'uni-cloud-db-element',
  306. UniCloudDBElement,
  307. )
  308. }
  309. },
  310. //#endif
  311. //#ifdef WEB
  312. async serverPrefetch() : Promise<any> {
  313. // @ts-ignore
  314. if (!this.manual && this.loadtime === 'auto') {
  315. // @ts-ignore
  316. return this.loadData({})
  317. }
  318. },
  319. //#endif
  320. created() {
  321. this.pagination.current = this.pageCurrent
  322. this.pagination.size = this.pageSize
  323. this.$watch(
  324. () : any => [
  325. this.pageCurrent,
  326. this.pageSize,
  327. this.collection,
  328. this.field,
  329. this.getcount,
  330. this.orderby,
  331. this.where,
  332. this.groupby,
  333. this.groupField,
  334. this.distinct
  335. ],
  336. (newValue : Array<any>, oldValue : Array<any>) => {
  337. this.pagination.size = this.pageSize
  338. if (newValue[0] !== oldValue[0]) {
  339. this.pagination.current = this.pageCurrent
  340. }
  341. if (this.loadtime == LOAD_MODE_MANUAL) {
  342. return
  343. }
  344. let needReset = false
  345. for (let i = 2; i < newValue.length; i++) {
  346. if (newValue[i] !== oldValue[i]) {
  347. needReset = true
  348. break
  349. }
  350. }
  351. if (needReset) {
  352. this.clear()
  353. this.reset()
  354. }
  355. this.get(null)
  356. }
  357. )
  358. if (!this.manual && this.loadtime == LOAD_MODE_AUTO && this.dataList.length == 0) {
  359. if (typeof this.collection == 'string') {
  360. const collectionString = this.collection as string
  361. if (collectionString.length == 0) {
  362. return
  363. }
  364. } else if (Array.isArray(this.collection)) {
  365. const collectionArray = this.collection as Array<any>
  366. if (collectionArray.length == 0) {
  367. return
  368. }
  369. }
  370. this.get(null)
  371. }
  372. },
  373. mounted() {
  374. const uniCloudDBElement = this.$refs['UniCloudDB'] as UniCloudDBElement
  375. uniCloudDBElement.dataList = this.dataList;
  376. //#ifdef APP
  377. uniCloudDBElement.onLoadData = this.loadData;
  378. uniCloudDBElement.onLoadMore = this.loadMore;
  379. uniCloudDBElement.onAdd = this.add;
  380. uniCloudDBElement.onUpdate = this.update;
  381. uniCloudDBElement.onRemove = this.remove;
  382. //#endif
  383. //#ifdef WEB
  384. uniCloudDBElement.onLoadData = this.loadData.bind(this);
  385. uniCloudDBElement.onLoadMore = this.loadMore.bind(this);
  386. uniCloudDBElement.onAdd = this.add.bind(this);
  387. uniCloudDBElement.onUpdate = this.update.bind(this);
  388. uniCloudDBElement.onRemove = this.remove.bind(this);
  389. //#endif
  390. },
  391. methods: {
  392. async loadData(options : UniCloudDBComponentLoadDataOptions) : Promise<void> {
  393. let clear = (options.clear != null && options.clear == true)
  394. if (clear == true) {
  395. if (this.pageData == PAGE_MODE_REPLACE) {
  396. this.clear()
  397. }
  398. this.reset()
  399. }
  400. await this.get(options)
  401. },
  402. loadMore() {
  403. if (this.isEnded || this.loading) {
  404. return
  405. }
  406. if (this.pageData == PAGE_MODE_ADD) {
  407. this.pagination.current++
  408. }
  409. this.get(null)
  410. },
  411. refresh() {
  412. this.clear()
  413. this.get(null)
  414. },
  415. clear() {
  416. this.isEnded = false
  417. this.dataList.length = 0
  418. },
  419. reset() {
  420. this.pagination.current = 1
  421. },
  422. async get(options? : UniCloudDBComponentLoadDataOptions | null) : Promise<void> {
  423. let loadAfterClear = false
  424. if (options != null && options.clear != null && options.clear == true) {
  425. loadAfterClear = true
  426. }
  427. if (options != null && options.current != null) {
  428. this.pagination.current = options.current!
  429. }
  430. this.error = null
  431. this.loading = true
  432. await this.getExec().then((res : UniCloudDBGetResult) => {
  433. const data = res.data
  434. const count = res.count
  435. this.isEnded = (count != null) ? (this.pagination.current * this.pagination.size >= count) : (data.length < this.pageSize)
  436. this.hasMore = !this.isEnded
  437. if (this.getcount && count != null) {
  438. this.pagination.count = count
  439. }
  440. this._dispatchEvent(EVENT_LOAD, data)
  441. if (loadAfterClear || this.pageData == PAGE_MODE_REPLACE) {
  442. this.dataList = data
  443. } else {
  444. this.dataList.push(...data)
  445. }
  446. options?.success?.(res)
  447. }).catch((err : any | null) => {
  448. this._requestFail(err, null)
  449. options?.fail?.(err)
  450. }).then(() => {
  451. this.loading = false
  452. options?.complete?.()
  453. }, () => {
  454. this.loading = false
  455. options?.complete?.()
  456. })
  457. },
  458. add(value : UTSJSONObject, options : UniCloudDBComponentAddOptions) {
  459. this._needLoading(options.needLoading, options.loadingTitle)
  460. const db = uniCloud.databaseForJQL()
  461. db.collection(this._getMainCollection()).add(value).then<void>((res : UniCloudDBAddResult) => {
  462. options.success?.(res)
  463. this._isShowToast(options.showToast ?? false, options.toastTitle ?? 'add success')
  464. }).catch((err) => {
  465. this._requestFail(err, options.fail)
  466. }).then(() => {
  467. this._requestComplete(options.complete, options.needLoading)
  468. }, () => {
  469. this._requestComplete(options.complete, options.needLoading)
  470. })
  471. },
  472. update(id : string, value : UTSJSONObject, options : UniCloudDBComponentUpdateOptions) {
  473. if (options.needConfirm == true) {
  474. uni.showModal({
  475. title: options.confirmTitle,
  476. content: options.confirmContent,
  477. showCancel: true,
  478. success: (res) => {
  479. if (res.confirm) {
  480. this._update(id, value, options)
  481. }
  482. }
  483. })
  484. } else {
  485. this._update(id, value, options)
  486. }
  487. },
  488. remove(id : any, options : UniCloudDBComponentRemoveOptions) {
  489. const ids = Array.isArray(id) ? (id as Array<any>) : [id]
  490. if (options.needConfirm == true) {
  491. uni.showModal({
  492. title: options.confirmTitle,
  493. content: options.confirmContent,
  494. showCancel: true,
  495. success: (res) => {
  496. if (res.confirm) {
  497. this._remove(ids, options)
  498. }
  499. }
  500. })
  501. } else {
  502. this._remove(ids, options)
  503. }
  504. },
  505. _update(id : string, value : UTSJSONObject, options : UniCloudDBComponentUpdateOptions) {
  506. this._needLoading(options.needLoading, options.loadingTitle)
  507. const db = uniCloud.databaseForJQL()
  508. db.collection(this._getMainCollection()).doc(id).update(value).then((res) => {
  509. options.success?.(res)
  510. this._isShowToast(options.showToast ?? false, options.toastTitle ?? 'update success')
  511. }).catch((err : any | null) => {
  512. this._requestFail(err, options.fail)
  513. }).then(() => {
  514. this._requestComplete(options.complete, options.needLoading)
  515. }, () => {
  516. this._requestComplete(options.complete, options.needLoading)
  517. })
  518. },
  519. _remove(ids : Array<any>, options : UniCloudDBComponentRemoveOptions) {
  520. this._needLoading(options.needLoading, options.loadingTitle)
  521. const db = uniCloud.databaseForJQL()
  522. const dbCommand = db.command
  523. db.collection(this._getMainCollection()).where({
  524. _id: dbCommand.in(ids)
  525. }).remove().then((res) => {
  526. options.success?.(res)
  527. if (this.pageData == PAGE_MODE_REPLACE) {
  528. this.refresh()
  529. } else {
  530. this._removeData(ids)
  531. }
  532. }).catch((err : any | null) => {
  533. this._requestFail(err, options.fail)
  534. }).then(() => {
  535. this._requestComplete(options.complete, options.needLoading)
  536. }, () => {
  537. this._requestComplete(options.complete, options.needLoading)
  538. })
  539. },
  540. _removeData(ids : Array<any>) {
  541. const il = ids.slice(0)
  542. const dl = this.dataList
  543. for (let i = dl.length - 1; i >= 0; i--) {
  544. const index = il.indexOf(dl[i]['_id'])
  545. if (index >= 0) {
  546. dl.splice(i, 1)
  547. il.splice(index, 1)
  548. }
  549. }
  550. },
  551. _isShowToast(showToast : boolean, title : string) {
  552. if (showToast == true) {
  553. uni.showToast({
  554. title: title
  555. })
  556. }
  557. },
  558. _needLoading(needLoading ?: boolean | null, title ?: string | null) {
  559. if (needLoading == true) {
  560. uni.showLoading({
  561. mask: true,
  562. title: title ?? ''
  563. })
  564. }
  565. },
  566. _requestFail(err ?: any | null, callback ?: FailCallback | null) {
  567. callback?.(err)
  568. this.error = err as UniCloudError
  569. this.$emit(EVENT_ERROR, err)
  570. },
  571. _requestComplete(callback ?: CompleteCallback | null, needLoading ?: boolean | null) {
  572. callback?.()
  573. if (needLoading == true) {
  574. uni.hideLoading()
  575. }
  576. },
  577. getExec() : Promise<UniCloudDBGetResult> {
  578. return this.getTemp()
  579. },
  580. getTemp() : Promise<UniCloudDBGetResult> {
  581. let db = uniCloud.databaseForJQL()
  582. let collection = Array.isArray(this.collection) ? db.collection(...(this.collection as Array<any>)) : db.collection(this.collection)
  583. let filter : UniCloudDBFilter | null = null
  584. if (this.foreignKey.length > 0) {
  585. filter = collection.foreignKey(this.foreignKey)
  586. }
  587. if (typeof this.where == 'string') {
  588. const whereString = this.where as string
  589. if (whereString.length > 0) {
  590. filter = (filter != null) ? filter.where(this.where) : collection.where(this.where)
  591. }
  592. } else if (typeof this.where == 'object') {
  593. filter = (filter != null) ? filter.where(this.where) : collection.where(this.where)
  594. }
  595. let query : UniCloudDBQuery | null = null
  596. if (this.field.length > 0) {
  597. query = (filter != null) ? filter.field(this.field) : collection.field(this.field)
  598. }
  599. if (this.groupby.length > 0) {
  600. if (query != null) {
  601. query = query.groupBy(this.groupby)
  602. } else if (filter != null) {
  603. query = filter.groupBy(this.groupby)
  604. }
  605. }
  606. if (this.groupField.length > 0) {
  607. if (query != null) {
  608. query = query.groupField(this.groupField)
  609. } else if (filter != null) {
  610. query = filter.groupField(this.groupField)
  611. }
  612. }
  613. if (this.distinct == true) {
  614. if (query != null) {
  615. query = query.distinct(this.field)
  616. } else if (filter != null) {
  617. query = filter.distinct(this.field)
  618. }
  619. }
  620. if (this.orderby.length > 0) {
  621. if (query != null) {
  622. query = query.orderBy(this.orderby)
  623. } else if (filter != null) {
  624. query = filter.orderBy(this.orderby)
  625. } else {
  626. query = collection.orderBy(this.orderby)
  627. }
  628. }
  629. const size = this.pagination.size
  630. const current = this.pagination.current
  631. const skipSize = size * (current - 1)
  632. if (query != null) {
  633. query = query.skip(skipSize).limit(size)
  634. } else if (filter != null) {
  635. query = filter.skip(skipSize).limit(size)
  636. } else {
  637. query = collection.skip(skipSize).limit(size)
  638. }
  639. const getOptions = {}
  640. const treeOptions = {
  641. limitLevel: this.limitlevel,
  642. startWith: this.startwith
  643. }
  644. if (this.getcount == true) {
  645. getOptions['getCount'] = this.getcount
  646. }
  647. if (typeof this.gettree == 'string') {
  648. const getTreeString = this.gettree as string
  649. if (getTreeString.length > 0) {
  650. getOptions['getTree'] = treeOptions
  651. }
  652. } else if (typeof this.gettree == 'object') {
  653. getOptions['getTree'] = treeOptions
  654. }
  655. if (this.gettreepath == true) {
  656. getOptions['getTreePath'] = treeOptions
  657. }
  658. return query.get(getOptions)
  659. },
  660. _getMainCollection() : string {
  661. if (typeof this.collection === 'string') {
  662. return (this.collection as string).split(',')[0]
  663. }
  664. if (Array.isArray(this.collection)) {
  665. const array = this.collection as Array<any>
  666. const index = array[0] as UTSJSONObject
  667. const collection = index.getString('$db[0].$param[0]')
  668. return collection ?? ''
  669. }
  670. return ''
  671. },
  672. _dispatchEvent(type : string, data : Array<UTSJSONObject>) {
  673. this.$emit(type, data, this.isEnded, {
  674. current: this.pagination.current,
  675. size: this.pagination.size,
  676. count: this.pagination.count
  677. })
  678. }
  679. }
  680. }
  681. </script>