Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

参数变化滚动页面插件 #51

Open
xinglie opened this issue May 14, 2018 · 0 comments
Open

参数变化滚动页面插件 #51

xinglie opened this issue May 14, 2018 · 0 comments

Comments

@xinglie
Copy link
Member

xinglie commented May 14, 2018

//#exclude = define
define('scroll', ['magix', '$'], (require, exports, module) => {
    let Magix = require('magix');
    let $ = require('$');
    let { Router, Vframe } = Magix;
    let checkVframes = (vId, changed, ref) => {
        if (!ref) ref = {};
        let vf = Vframe.get(vId);
        let list = vf.invoke('@{get.scroll.list}');
        if (list && list.length) {
            for (let [node, params] of list) {
                let exist = false;
                for (let e of params) {
                    if (changed[e]) {
                        exist = true;
                        break;
                    }
                }
                if (exist) {
                    let offset = $('#' + vf.id + ' ' + node).offset();
                    if (offset) {
                        window.scrollTo(offset.left + 10, offset.top + 10);
                        ref['@{page.scrolled}'] = true;
                        break;
                    }
                }
            }
        }
        if (!ref['@{page.scrolled}']) {
            let children = vf.children();
            for (let c of children) {
                if (!ref['@{page.scrolled}']) {
                    checkVframes(c, changed, ref);
                }
            }
        }
    };
    Router.on('changed', e => {
        if (!e.force) {
            let vId = Magix.config('rootId');
            checkVframes(vId, e.params);
        }
    });
    Magix.View.merge({
        ctor() {
            this['@{scroll.list}'] = [];
        },
        '@{get.scroll.list}'() {
            return this['@{scroll.list}'];
        },
        scrollIfNeed(node, params) {
            this['@{scroll.list}'].push([node, params]);
        }
    });
});

使用

//...
init(){
    this.scrollIfNeed('table',['page','pageSize']);
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant