开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 12576|回复: 2
收起左侧

[易语言纯源码] Route 脚本

[复制链接]
头像被屏蔽
结帖率:100% (4/4)
发表于 2020-11-16 05:54:46 | 显示全部楼层 |阅读模式   湖南省怀化市
本帖最后由 Nameker 于 2020-11-16 06:18 编辑

        Route = {
                Router:{},
                find:function(link)
                {
                        let path = 'Route.Router';
                        let parent = null;
                        let key = null;
                        if (link) {
                                route  = link.split('.')
                                route.forEach(function(keys,index,array){
                                        const regex = /([a-zA-Z0-9\u4e00-\u9fa5]+)?([?<=\[](\d+)[?=\]])?/gm;
                                        if (regexdata = regex.exec(keys)) {
                                                if (typeof regexdata[1] != 'undefined') {
                                                        if (index == array.length - 1) {
                                                                parent = path;
                                                                key = regexdata[1];
                                                        }
                                                        path += `[${JSON.stringify(regexdata[1])}]`
                                                        Class = new Function('return Object.prototype.toString.call('+path+')')()
                                                        switch(Class)
                                                        {
                                                                case '[object Object]':
                                                                break;
                                                                case '[object Array]':
                                                                break;
                                                                case '[object String]':
                                                                break;
                                                                case '[object Undefined]':
                                                                new Function('return '+  path + ' =  {}')()
                                                                break;
                                                                default:
                                                                break;
                                                        }
                                                }
                                                if (typeof regexdata[3] != 'undefined') {
                                                        if (index == array.length - 1) {
                                                                parent = path;
                                                                key = regexdata[3];

                                                        }
                                                        path += `[${parseInt(regexdata[3])}]`
                                                        Class = new Function('return Object.prototype.toString.call('+path+')')()

                                                        switch(Class)
                                                        {
                                                                case '[object Object]':
                                                                break;
                                                                case '[object Array]':
                                                                break;
                                                                case '[object String]':
                                                                break;
                                                                case '[object Undefined]':
                                                                new Function('return '+  path + ' =  {}')()
                                                                break;
                                                                default:
                                                                break;
                                                        }
                                                }
                                        }
                                })
                        } else {
                                parent = path;
                                key = parent;
                                Class = new Function('return Object.prototype.toString.call('+path+')')()
                                        switch(Class)
                                        {
                                                case '[object Object]':
                                                break;
                                                case '[object Array]':
                                                break;
                                                case '[object String]':
                                                new Function('return '+  path + ' =  {}')()
                                                break;
                                                case '[object Undefined]':
                                                new Function('return '+  path + ' =  {}')()
                                                break;
                                                default:
                                                break;
                                        }
                        }
                        let parenttype = new Function('return Object.prototype.toString.call('+parent+')')()
                        let type = new Function('return Object.prototype.toString.call('+path+')')()
                        return {'parent':parent,'parenttype':parenttype,'path':path,'key':key,'type':type}
                },

                load:function(link,data)
                {
                        route = this.find(link || '');
                        new Function(route.path + ' = ' +  JSON.stringify(data))()
                },
                free:function(link)
                {
                        route = this.find(link || '');
                        remove = function(route,type,keys)
                         {
                                if (route.parenttype=='[object Array]')
                                {
                                        new Function('route.parent.splice('+route.keys+',1)')
                                } else if(route.parenttype=='[object Object]')
                                {
                                        new Function('delete ' + route.path)()
                                }
                         }
                        new Function('remove('+JSON.stringify(route)+')')()
                },
                route:function(link,data)
                {
                        route = this.find(link || '');
                        if (Object.prototype.toString.call(data) == '[object Undefined]') {
                                value = new Function( 'return ' + route.path )()
                                if (Object.prototype.toString.call(value) == '[object Object]' || Object.prototype.toString.call(value) == '[object Array]') {
                                        return JSON.stringify(JSON.stringify(value))
                                } else {
                                        return value
                                }
                        } else {
                                new Function(route.path + ' = ' +  JSON.stringify(data || {}))()
                        }
                },
                count:function(link)
                {
                        route = this.find(link || '');
                        count  = function (data) {
                                i = 0;
                                for(keys in data){
                                        i++;
                                }
                                return i;
                        }
                        return new Function( 'return count(' + route.path+')' )()
                },
        }

        console.log(Route.route('',''))
        console.log(Route.route())
        Route.route('this.data',[])
        Route.route('this.data[0]','逸豪方明')
        Route.route('this.data[1]','逸豪方明')
        Route.route('this.data[2]','逸豪方明')
        Route.route('this.data[3]','逸豪方明')
        console.log(Route.route())
.版本 2
.支持库 spec

.程序集 Route, , 公开
.程序集变量 JsrtRuntime, Jsrt_Runtime
.程序集变量 JsrtContext, Jsrt_Context

.子程序 _初始化, , , 当基于本类的对象被创建后,此方法会被自动调用

.判断开始 (JsrtRuntime.Create () ≠ #JsNoError)
    JsrtRuntime.Dispose ()
.switch (JsrtRuntime.CreateContext (JsrtContext) ≠ #JsNoError)
    JsrtRuntime.Dispose ()
.switch (JsrtContext.SetCurrentContext () = #JsNoError)
    JsrtContext.RunScript (#Route)
.默认
    JsrtRuntime.Dispose ()
    调试输出 (“XRoute Error!”)
.判断结束


.子程序 _销毁, , , 当基于本类的对象被销毁前,此方法会被自动调用

JsrtRuntime.Dispose ()

.子程序 load, Jsrt_Value, 公开
.参数 link, 文本型, 可空
.参数 data, 文本型, 可空
.局部变量 JsrtValue, Jsrt_Value
.局部变量 Code, 整数型

Code = JsrtContext.RunScript (“Route.load('” + link + “',” + data + “)”, , , JsrtValue)
.if (Code ≠ #JsNoError)
    调试输出 (取程序名称 (1), “Error”, Code)
.如果真结束
return (JsrtValue)

.子程序 free, Jsrt_Value, 公开
.参数 link, 文本型, 可空
.参数 data, 文本型, 可空
.局部变量 JsrtValue, Jsrt_Value
.局部变量 Code, 整数型

Code = JsrtContext.RunScript (“Route.free('” + link + “',” + data + “)”, , , JsrtValue)
.if (Code ≠ #JsNoError)
    调试输出 (取程序名称 (1), “Error”, Code)
.如果真结束
return (JsrtValue)

.子程序 Route, Jsrt_Value, 公开
.参数 link, 文本型, 可空
.参数 data, 文本型, 可空
.局部变量 JsrtValue, Jsrt_Value
.局部变量 Code, 整数型

.判断开始 (是否为空 (link))
    Code = JsrtContext.RunScript (“Route.route()”, , , JsrtValue)
.switch (是否为空 (data))
    Code = JsrtContext.RunScript (“Route.route('” + link + “')”, , , JsrtValue)
.默认
    Code = JsrtContext.RunScript (“Route.route('” + link + “',” + data + “)”, , , JsrtValue)
.判断结束
.if (Code ≠ #JsNoError)
    调试输出 (取程序名称 (1), “Error”, Code)
.如果真结束
return (JsrtValue)

.子程序 count, Jsrt_Value, 公开
.参数 link, 文本型, 可空
.局部变量 JsrtValue, Jsrt_Value
.局部变量 Code, 整数型

Code = JsrtContext.RunScript (“Route.count('” + link + “')”, , , JsrtValue)
.if (Code ≠ #JsNoError)
    调试输出 (取程序名称 (1), “Error”, Code)
.如果真结束
return (JsrtValue)


1.png

评分

参与人数 2好评 +2 精币 +3 收起 理由
wxfhf520 + 1 支持开源~!感谢分享
冰点 + 1 + 3 支持开源~!感谢分享

查看全部评分


结帖率:83% (10/12)

签到天数: 2 天

发表于 2020-11-16 09:46:38 | 显示全部楼层   山东省枣庄市
支持开源~!感谢分享

能不能把文件上传一下
回复 支持 反对

使用道具 举报

结帖率:100% (7/7)

签到天数: 16 天

发表于 2020-11-16 09:06:16 | 显示全部楼层   湖北省武汉市
支持开源~!感谢分享
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 793400750,邮箱:wp@125.la
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表