Applet decline in paging data acquisition package

Possible cases:

1, the data is not a

2, to the last page

3, Request Status: Loading, loaded, no more data

4, the bottom slide, to obtain data, should avoid sending duplicate requests, using the data latch

5, and the throttle stabilization: also disable, countdown, modal prevent duplicate transmission request, etc.

 

Ideas:

1, it is determined whether there is more data

2, set the lock, the lock opening normally captured data, lock off, the request data also proved that, behind the click operation not processed

3, provided a property as determined whether the last page identification,

4, set up a real-time property acquisition url, because every time the page requested data are not the same, so the entire url is different, need to get to the latest url

5, the transmission request returns the result is empty, return a null data object, and returns the result is not empty, determine whether it is the last one, and a final set of attribute values ​​are true / false

6, if there is data, the start stripe number plus the number of requests per acquired

7, data accumulation

8, the lock is released

/ * * 
 * Class does not care about the details tab 
 * When the user invokes the class, data of a next request requires direct return data 
 * Paging state needs to be saved, it should be called to the caller for instance in the form of 
 * / 
Import the Http {} from "./http" ; 

class {the Paging 
    Start 
    COUNT 
    url    // url most primitive url i.e. not covered 
    Locker = to false 
    REQ 
    MoreData = to true    // if there is more data 
    ACC with   // accumulated data, acquired every new and accumulating data to the original data 
    // initial method 
    // REQ incoming object that there may be more than a url also with other parameters 
    / * * 
     * initial constructor 
     * @param req incoming objects, this there may be more than a target url also with other parameters 
     page number of * @param count
     * @Param start from the beginning several check 
     * / 
    constructor (REQ, COUNT, Start = 0 ) {
         the this .start = Start
         the this .count = COUNT
         the this .req = REQ
         the this .url = req.url 
    } 

    / * * 
     * calling the service master method 
     * @returns {Promise <{item: * [], moreData: boolean, accumulator: * [], empty: boolean} | {item: *, moreData: *, accumulator: *, empty: boolean}> } 
     * / 
    the async getMoreData () { 
        // status check of the lock, if the lock is locked, there are other requests not to return to prove, the request will not be other, when the request return result, should release the lock 

        / / determine whether there are data 
        iF (! the this.moreData) {
            return 
        } 
        // check whether the lock, i.e. whether the requested data has been returned 
        IF (! the this ._getLocker ()) {
             return 
        } 
        // real data request 
        const Data = the await the this ._actualGetData ()
         // release lock 
        the this . _releaseLocker ()
         return data 
    } 

    / * * 
     (abnormality processing) * real transmission request, the data structure is determined, the object returns a 
     * @returns {Promise <null | { item: [], moreData: boolean, accumulator: [], empty: Boolean} | {Item: *, MoreData: *, ACC with: *, empty: Boolean}>} 
     * @private 
     * / 
    the async _actualGetData () {
        const req = this._getCurrentReq()
        let paging = await Http.request(req)
        if (!paging) {
            return null
        }
        if (paging.total === 0) {
            return {
                empty: true,
                item: [],
                moreData: false, // 是否为最后一页的标识
                accumulator: []
            }
        }
        this.moreData = this._moreData (paging.total_page, paging.page)
         
     * @returns {*}// determines whether there is more data 
        IF ( the this .moreData) {
             the this .start + = the this .count 
        } 
        the this ._accumulate (paging.items)
         return { 
            empty: to false , 
            Item: paging.items, 
            MoreData: the this .moreData, / / is the last page identification 
            ACC with: the this .accumulator 
        } 
    } 

    / * * 
     * Get the current subject, i.e. the current data object returned 
     * @private 
     * / 
    _getCurrentReq () { 
        the let URL= The this .url 
        const the params = {$ = `Start the this .start & COUNT = $ {} the this .count}`
         IF (url.indexOf ( '?')! == -1 ) {
             // when accessing the address does not contain other parameters, such as V1 = URL / SPU / Latest + '?' + the params 
            URL = + '&' + the params 
        } the else {
             // when accessing the address contains other parameters, such as the url = v1 / spu / latest? other ABC + = '&' + the params 
            URL = + '?' + the params 
        } 
        the this .req.url = URL
         return  the this * 
     * is determined whether the last page, if there is data .req
    } 

    / *
     * @Param total number of pages TotalPage 
     * @param pageNum current page, starts at 0 
     * @Returns Boolean {} 
     * @private 
     * / 
    _moreData (TotalPage, pageNum) { 
        return pageNum <TotalPage -. 1 
    } 

    / * * 
     * accumulated per requested data 
     * @param items requested data returned 
     * @private 
     * / 
    _accumulate (items) { 
        the this .accumulator = the this .accumulator.concat (items) 
    } 

    / * * 
     * to obtain the lock state 
     * @Returns Boolean {} 
     * @ Private 
     * / 
    _getLocker () { 
        // if the lock is locked 
        IF( The this .locker) {
             return  to false 
        } 
        // if the lock is open 
        the this .locker = to true 
        return  to true 
    } 

    / * * 
     * lock release 
     * @private 
     * / 
    _releaseLocker () { 
        the this .locker = to false 
    } 
} 

Export the Paging} {

 

Guess you like

Origin www.cnblogs.com/dgxblogs/p/11959221.html