Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

支付宝小程序出现bug需求各位帮忙

Cannot read property 'showReferpagepath' of undefined![支付宝小程序]
const _my = require("../../__antmove/api/index.js")(my);

// pages/phone/phone.js
import { request } from "../../utils/request.js";
Page({
    data: {
        currentIndex: -1,
        topIndex: 0,
        menu: [],
        left: [],
        right: [],
        classid: 4 //类别:手机,平板,笔记本
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        // console.log("options")
        // console.log("options")
        // console.log("options")
        // console.log(options)
    },

    handlesos(e) {
        let { index, id } = e.currentTarget.dataset; // // console.log(index)

        const { menu } = this.data;
        let left = menu[index].function;
        let right = menu[index].recommend;
        let currentIndex = -1;
        let classid = menu[index].id; // 切换选项
        // console.log(menu,menu[index].recommend,right)
        // right.forEach((v,ind) => {
        //   v.recovershop_img=getApp().data.baseUrl+v.recovershop_img
        // });
        // console.log("激活上方选项卡",index,id,menu[index].id)

        this.setData({
            topIndex: index,
            left,
            right,
            currentIndex,
            classid
        });
    },

    // 左侧菜单切换
    async handleItemTap(e) {
        const { index, fun } = e.currentTarget.dataset;
        const res = await request({
            url: "recoveershopxq",
            data: {
                functionid: fun,
                classid: this.data.classid
            }
        }); // console.log("左侧菜单点击测试结果",{functionid:fun,classid:this.data.classid}, res)

        let right = res.data.data;
        right.forEach((v, ind) => {
            v.recovershop_img = getApp().data.baseUrl + v.recovershop_img;
        });
        this.setData({
            currentIndex: index,
            right
        });
    },

    tuijian() {
        let right = this.data.menu[this.data.topIndex].recommend;
        let currentIndex = -1; // right.forEach((v,ind) => {
        // v.recovershop_img=getApp().data.baseUrl+v.recovershop_img
        // // console.log(v.recovershop_img)
        // });

        this.setData({
            currentIndex,
            right
        });
    },

    async getrecover(id) {
        const res = await request({
            url: "recoveershop"
        });
        let menu = res.data.data;
        menu.forEach((v, ind) => {
            v.recommend.forEach((v2, ind2) => {
                v2.recovershop_img = getApp().data.baseUrl + v2.recovershop_img;
            });
        });
        let left = menu[id].function;
        let right = menu[id].recommend; // console.log(menu,right)

        this.setData({
            menu,
            left,
            right,
            classid: menu[id].id
        });
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {
        let fromPage = getCurrentPages()[0].__displayReporter.showReferpagepath;

        let istrue = fromPage.indexOf("/index") < 0;
        let istrue2 = fromPage.indexOf("/yindao") < 0;
        let isgujia = fromPage.indexOf("/gujia") < 0;
        console.log(fromPage);

        if (!istrue || !istrue2 || isgujia) {
            if (parseInt(_my.getStorageSync("topIndex"))) {
                var id = parseInt(_my.getStorageSync("topIndex")); //若id为0,就是默认页设置的

                this.setData({
                    topIndex: id
                });
                this.getrecover(id);
            } else {
                var id = parseInt(0); //若id为0,就是默认页设置的

                this.setData({
                    topIndex: id
                });
                this.getrecover(id);
            }
        } else {
            this.getrecover(this.data.topIndex);
        }

        this.setData({
            currentIndex: -1
        });
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        // console.log("onShow")
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {},

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {},

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {},

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {},

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {}
});
const utils = require('../../api/utils');
const { warnLife } = utils;
const config = require('../../api/config');
const createNode = require('./relation');
const Relations = require('../../api/relations');
const processRelationHandle = require('./processRelation');
const { connectNodes, antmoveAction } = require('./utils');
const selectComponent = require('./selectComponent');
const {
    watchShakes,
    getUrl
} = require('../utils');


module.exports = {
    processTransformationPage (_opts, options) {
        _opts = Object.assign(_opts, options);

        _opts.onLoad = function (res) {
            this.selectComponentApp = new selectComponent(this);
            this.selectComponentApp.connect();
            // 初始化节点树
            createNode.call(this, null, null, null, true);
            processRelations(this, Relations);
            if (typeof options.data === 'function') {
                options.data = options.data();
            }

            getUrl();
            this.createSelectorQuery = function() {
                return my.createSelectorQuery()
            }
            if (options.onLoad) {
                options.onLoad.call(this, res);
            }
        };

        _opts.onReady = function (param) {
            let ast = null;
            if (this.$node) {
                ast = this.$node.getRootNode();
            }
            ast && processRelationNodes(ast);
            if (options.onReady) {
                options.onReady.call(this, param);
            }
            if (ast) {
                ast.isPageReady = true;
            }
        };
        _opts.onShow = function (param) {
            if (config.env === "development" && config.useRuntimeLog) {
                watchShakes();
            }
            if (options.onShow) {
                options.onShow.call(this, param);
            }
        };
        if (options.onResize) {
            _opts.events = options.events || {};
            _opts.events.onResize = function (e) {
                const {size} = e;
                const {windowHeight, windowWidth} =  size;
                let deviceOrientation = 'landscape';
                let resizeObj = {}
                if (windowHeight > windowWidth) {
                    deviceOrientation = 'portrait';
                }

                let {screenWidth, screenHeight} = my.getSystemInfoSync();
                size.screenWidth = screenWidth;
                size.screenHeight = screenHeight;

                resizeObj = {
                    deviceOrientation,
                    size
                }

                /**
                * 组件所在的页面尺寸变化时执行
                */
               if (this.$node && Array.isArray(this.$node.$children)) {
                    this.$node.$children.forEach((c) => {
                        if (c.$self.antmovePageLifetimes) {
                            c.$self.antmovePageLifetimes(e = resizeObj);
                        }
                    })
                } 

                options.onResize(e = resizeObj);
            }
        };

        _opts.antmoveAction = antmoveAction
    }
};


function processRelationNodes (ast = {}) {
    let $nodes = ast.$nodes;

    /**
     * componentNodes onPageReady
     */
    Object.keys($nodes)
        .forEach(function (item) {
            let node = $nodes[item];
            connectNodes(node, ast);

            if (node.$self && typeof node.$self.onPageReady === 'function') {
                node.$self.onPageReady();
            }
        });

    ast.mountedHandles
        .forEach(function (fn, i) {
            fn();
        });
    ast.mountedHandles = [];
}


function processRelations (ctx, relationInfo = {}) {
    let route = ctx.route;
    route = route.replace(//node_modules/[a-z-]+/[a-z-]+/, '')

    if (route[0] !== '/') route = '/' + route;

    let info = relationInfo[route] || relationInfo[route.substring(1)];
    if (info) {
        processRelationHandle(info, function (node) {
            let id = node.$id;
            if (id === 'saveChildRef0') {
                ctx[id] = function () {};
                node.$index = 0;
                node.$route = route;
                createNode.call(ctx, ctx, null, node);
                return false;
            }
            ctx[id] = function (ref) {
                if (!ref) return false;
                ctx.$antmove = ctx.$antmove || {};
                if (ctx.$antmove[id] === undefined) {
                    ctx.$antmove[id] = 0;
                } else {
                    ctx.$antmove[id] += 1;
                }
                ctx.selectComponentApp.preProcesscomponents(ref);
                node.$index = ctx.$antmove[id];
                node.$route = route;
                createNode.call(ctx, ref, null, node);
            };
        });
    } else {
        console.warn('Missing nodes relation of ', route);
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.5k users

...