From 90ccbf25b6e3c8c128e2df6a5f0e22059d62b52b Mon Sep 17 00:00:00 2001 From: yelvye Date: Thu, 11 Jul 2019 17:39:40 +0800 Subject: [PATCH] DuerOS-Cloud-1780 Change-Id: Ibecf6c343f2b818c58125705c4de383ece57e9f4 --- CHANGELOG.md | 3 + samples/DPL/Bot.php | 379 ++++++++++++++++ samples/DPL/README.md | 35 ++ samples/DPL/doc/demo1.json | 50 +++ samples/DPL/doc/demo2.json | 72 +++ samples/DPL/doc/demo3.json | 123 +++++ samples/DPL/doc/demo4.json | 101 +++++ samples/DPL/doc/demo5.json | 96 ++++ samples/DPL/doc/demo6.json | 121 +++++ samples/DPL/doc/demo7.json | 424 ++++++++++++++++++ samples/DPL/doc/demo7_1.json | 368 +++++++++++++++ samples/DPL/doc/launch.json | 176 ++++++++ samples/DPL/doc/update.json | 111 +++++ samples/DPL/index.php | 23 + .../DPL/Commands/AnimationCommand.php | 145 ++++++ .../DPL/Commands/AutoPageCommand.php | 42 ++ src/Directive/DPL/Commands/BaseCommand.php | 54 +++ .../DPL/Commands/ControlMediaCommand.php | 57 +++ .../DPL/Commands/ParallelCommand.php | 60 +++ src/Directive/DPL/Commands/ScrollCommand.php | 44 ++ .../DPL/Commands/ScrollToIndexCommand.php | 61 +++ .../DPL/Commands/SendEventCommand.php | 34 ++ .../DPL/Commands/SequentialCommand.php | 71 +++ src/Directive/DPL/Commands/SetPageCommand.php | 58 +++ .../DPL/Commands/SetStateCommand.php | 54 +++ .../DPL/Commands/UpdateComponentCommand.php | 45 ++ src/Directive/DPL/Document.php | 74 +++ src/Directive/DPL/ExecuteCommands.php | 68 +++ src/Directive/DPL/RenderDocument.php | 65 +++ src/Response.php | 21 +- 30 files changed, 3034 insertions(+), 1 deletion(-) create mode 100644 samples/DPL/Bot.php create mode 100644 samples/DPL/README.md create mode 100644 samples/DPL/doc/demo1.json create mode 100644 samples/DPL/doc/demo2.json create mode 100644 samples/DPL/doc/demo3.json create mode 100644 samples/DPL/doc/demo4.json create mode 100644 samples/DPL/doc/demo5.json create mode 100644 samples/DPL/doc/demo6.json create mode 100644 samples/DPL/doc/demo7.json create mode 100644 samples/DPL/doc/demo7_1.json create mode 100644 samples/DPL/doc/launch.json create mode 100644 samples/DPL/doc/update.json create mode 100644 samples/DPL/index.php create mode 100644 src/Directive/DPL/Commands/AnimationCommand.php create mode 100644 src/Directive/DPL/Commands/AutoPageCommand.php create mode 100644 src/Directive/DPL/Commands/BaseCommand.php create mode 100644 src/Directive/DPL/Commands/ControlMediaCommand.php create mode 100644 src/Directive/DPL/Commands/ParallelCommand.php create mode 100644 src/Directive/DPL/Commands/ScrollCommand.php create mode 100644 src/Directive/DPL/Commands/ScrollToIndexCommand.php create mode 100644 src/Directive/DPL/Commands/SendEventCommand.php create mode 100644 src/Directive/DPL/Commands/SequentialCommand.php create mode 100644 src/Directive/DPL/Commands/SetPageCommand.php create mode 100644 src/Directive/DPL/Commands/SetStateCommand.php create mode 100644 src/Directive/DPL/Commands/UpdateComponentCommand.php create mode 100644 src/Directive/DPL/Document.php create mode 100644 src/Directive/DPL/ExecuteCommands.php create mode 100644 src/Directive/DPL/RenderDocument.php diff --git a/CHANGELOG.md b/CHANGELOG.md index e2ae903..3f88341 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,3 +78,6 @@ #2.1.19 * 增加Buy指令 + +#2.1.20 +* 增加DPL相关API diff --git a/samples/DPL/Bot.php b/samples/DPL/Bot.php new file mode 100644 index 0000000..a7e37ea --- /dev/null +++ b/samples/DPL/Bot.php @@ -0,0 +1,379 @@ + "https://dbp-dict.bj.bcebos.com/video2.mp4", + "index" => "video_list_1", + "name" => "葡萄酒", + "desc" => "人生就像一杯酒", + ], + [ + "src" => "https://dbp-dict.bj.bcebos.com/video4.mp4", + "index" => "video_list_2", + "name" => "初夏", + "desc" => "最美人间四月天", + ], + [ + "src" => "https://dbp-dict.bj.bcebos.com/video3.mp4", + "index" => "video_list_3", + "name" => "海", + "desc" => "我要和你一起看日出, 面向大海", + ], + [ + "src" => "https://dbp-dict.bj.bcebos.com/video4.mp4", + "index" => "video_list_4", + "name" => "心动的感觉", + "desc" => "你知道我对你不仅仅是喜欢", + ], + [ + "src" => "https://dbp-dict.bj.bcebos.com/video5.mp4", + "index" => "video_list_5", + "name" => "冷月", + "desc" => "曾经有一个美丽的女孩追求过我,但是我没有接受,现在后悔了", + ], + [ + "src" => "https://dbp-dict.bj.bcebos.com/video6.mp4", + "index" => "video_list_6", + "name" => "给大家讲一个笑话吧", + "desc" => "你就是一个笑话", + ], + [ + "src" => "https://dbp-dict.bj.bcebos.com/video7.mp4", + "index" => "video_list_7", + "name" => "加班,加班", + "desc" => "很可以", + ] + ]; + + public function __construct($postData = []) { + parent::__construct($postData); + + $this->addHandler('LaunchRequest', function(){ + $this->waitAnswer(); + return [ + 'outputSpeech' => 'DPL演示' + ]; + }); + + $this->addHandler('#dpl_demo1', function () { + $this->waitAnswer(); + $this->setExpectSpeech(false); + $directive = $this->genDPLDirective('./doc/demo1.json'); + if ($directive) { + return [ + 'directives' => [$directive], + 'outputSpeech' => '简单图片' + ]; + } + }); + + //事件监听 + $this->addEventListener('UserEvent', 'handleUserEvent'); + + $this->addDefaultEventListener(function () { + $this->waitAnswer(); + $this->setExpectSpeech(false); + }); + + //demo2 长文本 + $this->addHandler('#dpl_demo2', function () { + $this->waitAnswer(); + $this->setExpectSpeech(false); + $directive = $this->genDPLDirective('./doc/demo2.json'); + if ($directive) { + return [ + 'directives' => [$directive], + 'outputSpeech' => '长文本' + ]; + } + }); + + //demo3 短文本 + $this->addHandler('#dpl_demo3', function () { + $this->waitAnswer(); + $this->setExpectSpeech(false); + $directive = $this->genDPLDirective('./doc/demo3.json'); + return [ + 'directives' => [$directive], + 'outputSpeech' => '短文本' + ]; + }); + + //demo4 右图详情 + $this->addHandler('#dpl_demo4', function() { + $this->waitAnswer(); + $this->setExpectSpeech(false); + $directive = $this->genDPLDirective('./doc/demo3.json'); + return [ + 'directives' => [$directive], + 'outputSpeech' => '右图详情' + ]; + }); + + //demo5 左图详情 + $this->addHandler('#dpl_demo5', function (){ + $this->waitAnswer(); + $this->setExpectSpeech(false); + $directive = $this->genDPLDirective('./doc/demo5.json'); + return [ + 'directives' => [$directive], + 'outputSpeech' => '左图详情' + ]; + }); + + //demo6 横向列表 + $this->addHandler('#dpl_demo6', function () { + $this->waitAnswer(); + $this->setExpectSpeech(false); + $directive = $this->genDPLDirective('./doc/demo6.json'); + return [ + 'directives' => [$directive], + 'outputSpeech' => '横向列表' + ]; + }); + + $this->addHandler('#dpl_demo7', function () { + $this->waitAnswer(); + $this->setExpectSpeech(false); + $directive = $this->genDPLDirective('./doc/demo7.json'); + return [ + 'directives' => [$directive], + 'outputSpeech' => '视频相册' + ]; + }); + + //pull_scrollView + $this->addHandler('#pull_scrollview', function () { + $this->waitAnswer(); + $this->setExpectSpeech(false); + $executeCommands = new ExecuteCommands(); + $scrollCommand = new ScrollCommand(); + $scrollCommand->setDistance("200dp"); + $scrollCommand->setComponentId("demo_pull_scrollview_compid"); + $executeCommands->setCommands($scrollCommand); + return [ + 'directives' => [$executeCommands], + 'outputSpeech' => '滑动窗口滑动' + ]; + }); + + //选择播放第几个 + $this->addHandler('#video_play', function (){ + $this->waitAnswer(); + $this->setExpectSpeech(false); + $index = $this->getSlot('index'); + $index = $index - 1 >= 0 ? $index - 1 : 0; + $executeCommands = new ExecuteCommands(); + $updateComponentCommand = new UpdateComponentCommand(); + $doc = new Document(); + $doc->getDocumentFromPath('./doc/update.json'); + $content = $doc->getData(); + $content['mainTemplate']['items'][0]['items'][0]['src'] = self::$VideoList[$index]['src']; + $content['mainTemplate']['items'][0]['items'][1]['items'][0]['text'] = self::$VideoList[$index]['name']; + $doc->initDocument($content); + $updateComponentCommand->setDocument($doc); + $updateComponentCommand->setComponentId("replaceComponentId"); + $executeCommands->setCommands($updateComponentCommand); + return [ + 'directives' => [$executeCommands], + 'outputSpeech' => '正在播放' . self::$VideoList[$index]['name'] + ]; + }); + + //move_list + //向上滑动列表 + $this->addHandler('#move_list', function() { + $this->waitAnswer(); + $this->setExpectSpeech(false); + $direction = $this->getSlot('direction') ? $this->getSlot('direction') : '下'; + $distance = '100dp'; + if (in_array($direction, ['下', '后'])) { + $distance = '-100dp'; + } + $executeCommands = new ExecuteCommands(); + $scrollCommand = new ScrollCommand(); + $scrollCommand->setComponentId('demo_list_compid'); + $scrollCommand->setDistance($distance); + $executeCommands->setCommands($scrollCommand); + return [ + 'directives' => [$executeCommands], + 'outputSpeech' => '向' . $direction . '滑动列表' + ]; + }); + //go_list_top + //回到列表顶部 + $this->addHandler('#go_list_top', function (){ + $this->waitAnswer(); + $this->setExpectSpeech(false); + $executeCommands = new ExecuteCommands(); + $scrollToIndexCommand = new ScrollToIndexCommand(); + $scrollToIndexCommand->setComponentId('demo_list_compid'); + $scrollToIndexCommand->setAlign('first'); + $scrollToIndexCommand->setIndex(1); + $executeCommands->setCommands($scrollToIndexCommand); + return [ + 'directives' => [$executeCommands], + 'outputSpeech' => '回到列表顶部' + ]; + }); + + //move_page + //翻页 + $this->addHandler('#move_page', function() { + $this->waitAnswer(); + $this->setExpectSpeech(false); + $direction = $this->getSlot('direction') ? $this->getSlot('direction') : '下'; + $val = 1; + if (in_array($direction, ['右', '后'])) { + $val = -1; + } + $executeCommands = new ExecuteCommands(); + $setPageCommand = new SetPageCommand(); + $setPageCommand->setComponentId('demo_move_page_compid'); + $setPageCommand->setPosition('relative'); + $setPageCommand->setValue($val); + $executeCommands->setCommands($setPageCommand); + return [ + 'directives' => [$executeCommands], + 'outputSpeech' => '向' . $direction . '翻页' + ]; + }); + + //视频暂停 + $this->addHandler('#pause_video', function () { + $this->waitAnswer(); + $this->setExpectSpeech(false); + //demo_video_compid + $controlMediaCommand = new ControlMediaCommand(); + $controlMediaCommand->setComponentId('demo_video_compid'); + $controlMediaCommand->setCommand('pause'); + $executeCommands = new ExecuteCommands(); + $executeCommands->setCommands($controlMediaCommand); + return [ + 'directives' => [$executeCommands], + 'outputSpeech' => '视频暂停播放' + ]; + }); + + //视频继续播放 + $this->addHandler('#video_continue', function (){ + $this->waitAnswer(); + $this->setExpectSpeech(false); + //demo_video_compid + $controlMediaCommand = new ControlMediaCommand(); + $controlMediaCommand->setComponentId('demo_video_compid'); + $controlMediaCommand->setCommand('play'); + $executeCommands = new ExecuteCommands(); + $executeCommands->setCommands($controlMediaCommand); + return [ + 'directives' => [$executeCommands], + 'outputSpeech' => '视频继续播放' + ]; + }); + + //收藏 + $this->addHandler('#favourite_video', function() { + $this->waitAnswer(); + $this->setExpectSpeech(false); + $setStateCommand = new SetStateCommand(); + $setStateCommand->setComponentId("demo_image_compid"); + $setStateCommand->setState("src"); + $setStateCommand->setValue("https://dbp-dict.bj.bcebos.com/dpl%2F%E5%BF%83.png"); + $animationCommand = new AnimationCommand(); + $animationCommand->setComponentId("demo_image_compid"); + $animationCommand->setFrom("40dp"); + $animationCommand->setTo("10dp"); + $animationCommand->setEasing("ease-in"); + $animationCommand->setAttribute("height"); + $animationCommand->setDuration(500); + $animationCommand->setRepeatCount('9'); + $animationCommand->setRepeatMode('reverse'); + $executeCommands = new ExecuteCommands(); + $executeCommands->setCommands([$setStateCommand, $animationCommand]); + return [ + 'directives' => [$executeCommands], + 'outputSpeech' => '视频收藏' + ]; + + }); + + } + + /** + * 生成DPL.RenderDocument指令 + * + * @param {string} $pathUrl 文档路径 + * @return RenderDocument + */ + public function genDPLDirective($pathUrl) { + $document = new Document(); + $renderDocument = new RenderDocument(); + $doc = $document->getDocumentFromPath($pathUrl); + $document->initDocument($doc); + $renderDocument->setDocument($document); + return $renderDocument; + } + + public function handleUserEvent($event) { + $this->waitAnswer(); + $this->setExpectSpeech(false); + $componentId = $event['payload']['componentId']; + $executeCommands = new ExecuteCommands(); + if ($event['payload']['source']['type'] === 'Image' && strpos($componentId, 'video_list') !== false) { + $index = substr($componentId, strlen($componentId) -1 , 1); + $index = intval($index); + $setStateCommand = new SetStateCommand(); + $setStateCommand->setComponentId("test_video_videoId1"); + $setStateCommand->setState('src'); + $setStateCommand->setValue(self::$VideoList[$index]); + + $updateComponentCommand = new UpdateComponentCommand(); + $doc = new Document(); + $content = $doc->getDocumentFromPath('./doc/update.json'); + $content['mainTemplate']['items'][0]['src'] = self::$VideoList[$index - 1]['src']; + $content['mainTemplate']['items'][1]['items'][0]['text'] = self::$VideoList[$index - 1]['name']; + $doc->initDocument($content); + $updateComponentCommand->setDocument($doc); + $updateComponentCommand->setComponentId("demo_video_compid"); + $executeCommands->setCommands($setStateCommand); + $executeCommands->setCommands($updateComponentCommand); + return [ + 'directives' => [$executeCommands], + 'outputSpeech' => '播放新视频' + ]; + } + else if ($event['payload']['source']['type'] === 'Pager' && $componentId === 'demo_move_page_compid') { + $controlMediaCommand = new ControlMediaCommand(); + $controlMediaCommand->setComponentId('demo_video_compid'); + if ($event['payload']['source']['value'] === '0' || $event['payload']['source']['value'] === '2') { + $controlMediaCommand->setCommand('pause'); + } + else if ($event['payload']['source']['value'] === '1') { + $controlMediaCommand->setCommand('play'); + } + $executeCommands->setCommands($controlMediaCommand); + return [ + 'directives' => [$executeCommands], + 'outputSpeech' => '切换视频状态' + ]; + } + } +} + + + + diff --git a/samples/DPL/README.md b/samples/DPL/README.md new file mode 100644 index 0000000..1da5038 --- /dev/null +++ b/samples/DPL/README.md @@ -0,0 +1,35 @@ +# 说明 +这个DPL的样例比较完整的展示了DPL的页面构建以及交互的实现,涉及11种组件(9种基础组件+2种复合组件)和8种常见的交互Command。 +组件:Text、Image、Container、Frame、List、Pager、ScrollView、Audio、Video、Header、Footer。 +交互Command: AutoPage、SetPage、Scroll、ScrollToIndex、Animation、ControlMedia、SendEvent、SetState、Parallel。 +页面交互的部分支持:页面点击和通过query控制 +后续组件变更时候会定期更新此demo, 使用前请先配置好列表中的意图,运行服务后在小度在家有屏系列产品上体验。 + +## 如何运行demo +#### 1. 在DBP技能开发平台创建一个技能 如: 技能名称:DPL例子, 调用名称:上海,调用名称在调试模式下可以自定义。 +#### 2. 给新建技能创建demo中需要的意图,demo中一共有14个意图, 具体配置可以如下: +在配置意图之前需要配置一个自定义词典:pageDirection, 词条: 上、下、左(前)、右(后) + +| 意图中文名 | 意图标识名 |常用表达| +| :--------: | :-----: | :----: | +| 简单图片 | dpl_demo1 | 简单图片 | +| 长文本 | dpl_demo2 | 长文本 | +| 短文本 | dpl_demo3 | 短文本 | +| 右图详情 | dpl_demo4 | 右图 | +| 左图详情 | dpl_demo5 | 左图详情/左图 | +| 横向列表 | dpl_demo6 | 横向列表 | +| 视频相册 | dpl_demo7 | 视频相册 | +| 回到列表顶部 | go_list_top | 回到列表顶部/返回列表顶部 | +| 收藏这个视频 | favourite_video| 收藏/喜欢/收藏这个视频 | +| 下拉查看更多 | pull_scrollview | 滚动/继续滚动/下拉 | +| 视频继续播放 | video_continue | 继续播放/播放 | +| 暂停播放 | pause_video | 暂停/暂停播放 | +| 滑动列表(引用pageDirection词典) | move_list | 向下滑动列表/向上滑动列表 | +| 左右翻页 | move_page | 向左翻页/向右翻页 | + + +#### 3. 运行demo, composer require dueros/bot-sdk ,配置nginx +#### 4. 将demo服务地址配置到技能WebService下的部署地址处 +#### 5. 在小度在家或者小度在家1S上绑定自己的开发者账户,进行如下操作: + 1.打开技能调试模式 2.打开上海 3. query:简单图片/长文本/短文本/右图/左图详情/横向列表/视频相册 + diff --git a/samples/DPL/doc/demo1.json b/samples/DPL/doc/demo1.json new file mode 100644 index 0000000..7c82aed --- /dev/null +++ b/samples/DPL/doc/demo1.json @@ -0,0 +1,50 @@ +{ + "type":"DPL", + "version":"1.0", + "mainTemplate":{ + "parameters":[ + "payload" + ], + "items":[ + { + "type":"Audio", + "src":"https://duerstatic.bj.bcebos.com/swan%2Fdbp%2Fgametest%2Faudio2.mp3", + "looping":true, + "autoPlay":true, + "audioType":"music" + }, + { + "type":"Image", + "position":"absolute", + "top":"0dp", + "left":"0dp", + "src":"https://dbp-dict.bj.bcebos.com/dpl%2Fbg-img4.png", + "height":"100%", + "width":"100%" + }, + { + "type":"Container", + "width":"100%", + "height":"100%", + "items":[ + { + "type":"Header", + "headerTitle":"简单图片", + "headerImage":"https://dbp-dict.bj.bcebos.com/dpl%2F%E7%8B%97.png", + "hasBackIcon":true + }, + { + "type":"Image", + "src":"https://dbp-dict.bj.bcebos.com/dpl%2F1.jpeg", + "width":"90%", + "height":"75%", + "position":"absolute", + "left":"45dp", + "top":"100dp", + "border-radius":"10dp" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/samples/DPL/doc/demo2.json b/samples/DPL/doc/demo2.json new file mode 100644 index 0000000..95ab40f --- /dev/null +++ b/samples/DPL/doc/demo2.json @@ -0,0 +1,72 @@ +{ + "type":"DPL", + "version":"1.0", + "dataSource": { + "title": "徒劳的寒鸦", + "content": "宙斯想要为鸟类立一个王,指定一个日期,要求众鸟全都按时出席,以便选他们之中最美丽的为王。众鸟都跑到河里去梳洗打扮。寒鸦知道自己没一处漂亮,便来到河边,捡起众鸟脱落下的羽毛,小心翼翼地全插在自己身上,再用胶粘住。指定的日期到了,所有的鸟都一齐来到宙斯面前。宙斯一眼就看见花花绿绿的寒鸦,在众鸟之中显得格外漂亮,准备立他为王。众鸟十分气愤,纷纷从寒鸦身上拔下本属于自己的羽毛。于是,寒鸦身上美丽的羽毛一下全没了,又变成了一只丑陋的寒鸦了。" + }, + "styles": { + "baseAbsolutePositionStyle": { + "values" : { + "position": "absolute", + "left": "0dp", + "top": "0dp", + "height":"100%", + "width":"100%" + } + }, + "storyContentStyle": { + "values": { + "font-size":"30dp", + "line-height":"40dp", + "font-style":"normal", + "letter-spacing":"0.6dp" + } + }, + "backgroundImageStyle": { + "extend": ["baseAbsolutePositionStyle"], + "values": {} + }, + "mainBodyStyle": { + "extend": "baseAbsolutePositionStyle" + } + }, + "mainTemplate":{ + "parameters":[ + "payload" + ], + "items":[ + { + "type":"Image", + "src":"https://dbp-dict.bj.bcebos.com/dpl%2Fbg-img4.png", + "style": "backgroundImageStyle" + }, + { + "type":"Container", + "style": "mainBodyStyle", + "items":[ + { + "type":"Header", + "headerTitle": "${payload.title}", + "headerImage": "https://dbp-dict.bj.bcebos.com/dpl%2Fh3.png", + "hasBackIcon": true + }, + { + "type":"Container", + "height":"80%", + "width":"80%", + "margin-left": "10%", + "margin-top": "80dp", + "items":[ + { + "type":"Text", + "text":"${payload.content}", + "style": "storyContentStyle" + } + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/samples/DPL/doc/demo3.json b/samples/DPL/doc/demo3.json new file mode 100644 index 0000000..9489d57 --- /dev/null +++ b/samples/DPL/doc/demo3.json @@ -0,0 +1,123 @@ +{ + "type":"DPL", + "version":"1.0", + "dataSource": { + "firstText": "firewood dog | Chinese Pastoral Dog", + "secondText": "has a large number", + "thirdText": "Country of origin: China", + "bottomText": "widely distributed in China and has a large number", + "hint": "Chinese Pastoral Dog" + }, + "styles": { + "backgroundImageStyle": { + "values": { + "height":"100%", + "width":"100%", + "position": "absolute", + "left": "0dp", + "top": "0dp" + } + }, + "mainBodyStyle": { + "extend": "backgroundImageStyle", + "values": { + "flex-direction":"row" + } + }, + "firstTextStyle": { + "values": { + "color":"blue", + "font-size":"35dp", + "margin-top":"90dp", + "margin-left":"10%", + "line-height":"40dp" + } + }, + "secondTextStyle": { + "values": { + "font-size":"25dp", + "margin-top":"20dp", + "margin-left":"10%", + "line-height":"40dp" + } + }, + "thirdTextStyle": { + "values": { + "font-size":"25dp", + "margin-top":"80dp", + "margin-left":"10%", + "line-height":"40dp" + } + }, + "bottomTextStyle": { + "values": { + "font-size":"30dp", + "margin-top":"30dp", + "margin-left":"10%", + "line-height":"40dp" + } + } + }, + "mainTemplate":{ + "parameters":[ + "payload" + ], + "items":[ + { + "type":"Image", + "style": "backgroundImageStyle", + "src":"https://d2o906d8ln7ui1.cloudfront.net/images/BT6_Background.png" + }, + { + "type":"Container", + "width":"100%", + "height":"100%", + "items":[ + { + "type":"Header", + "headerImage":"https://dbp-dict.bj.bcebos.com/dpl/header2.png" + }, + { + "type":"Container", + "style": "mainBodyStyle", + "items":[ + { + "type":"Container", + "width":"100%", + "height":"100%", + "items":[ + { + "type":"Text", + "text":"${payload.firstText}", + "style": "firstTextStyle" + }, + { + "type":"Text", + "text":"${payload.secondText}", + "style": "secondTextStyle" + }, + { + "type":"Text", + "text":"${payload.thirdText}", + "style": "thirdTextStyle" + }, + { + "type":"Text", + "text":"${payload.bottomText}", + "style": "bottomTextStyle" + } + ] + } + ] + }, + { + "type": "Footer", + "hints": [ + "${payload.hint}" + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/samples/DPL/doc/demo4.json b/samples/DPL/doc/demo4.json new file mode 100644 index 0000000..cec0178 --- /dev/null +++ b/samples/DPL/doc/demo4.json @@ -0,0 +1,101 @@ +{ + "type":"DPL", + "version":"1.0", + "mainTemplate": { + "parameters":[ + "payload" + ], + "items":[ + { + "type":"Image", + "position": "absolute", + "left": "0dp", + "top": "0dp", + "height":"100%", + "width":"100%", + "src":"https://dbp-dict.bj.bcebos.com/dpl%2Fbg-img4.png" + }, + { + "type":"Container", + "width":"100%", + "height":"100%", + "position": "absolute", + "left": "0dp", + "top": "0dp", + "items":[ + { + "type":"Header", + "headerImage":"https://dbp-dict.bj.bcebos.com/dpl/header-icon.png" + }, + { + "type":"Container", + "flex-direction":"row", + "width":"100%", + "height":"100%", + "position":"absolute", + "items":[ + { + "type":"Container", + "width":"65%", + "height":"100%", + "items":[ + { + "type":"Text", + "text":"柴犬 | 中华田园犬", + "color":"blue", + "font-size":"30dp", + "letter-spacing":"0.5dp", + "margin-top":"100dp", + "margin-left":"10%", + "line-height":"40dp" + }, + { + "type":"Text", + "text":"在国内数量很多", + "font-size":"25dp", + "letter-spacing":"0.5dp", + "margin-top":"20dp", + "margin-left":"10%", + "line-height":"40dp" + }, + { + "type":"Text", + "text":"产地: 中国", + "font-size":"25dp", + "letter-spacing":"0.5dp", + "margin-top":"80dp", + "margin-left":"10%", + "line-height":"40dp" + }, + { + "type":"Text", + "text":"柴犬又称为中华田园犬,在国内分布广泛且数量众多,性情温和对主人忠诚,在农村很多人家都会饲养柴犬", + "font-size":"30dp", + "letter-spacing":"0.5dp", + "margin-top":"30dp", + "margin-left":"10%", + "line-height":"40dp" + } + ] + }, + { + "type":"Image", + "height":"350dp", + "width":"280dp", + "margin-left":"10dp", + "margin-top":"105dp", + "src":"https://dbp-dict.bj.bcebos.com/dpl%2F4.jpeg" + } + ] + }, + { + "type":"Footer", + "hints":[ + "右图" + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/samples/DPL/doc/demo5.json b/samples/DPL/doc/demo5.json new file mode 100644 index 0000000..893a736 --- /dev/null +++ b/samples/DPL/doc/demo5.json @@ -0,0 +1,96 @@ +{ + "type":"DPL", + "version":"1.0", + "mainTemplate":{ + "parameters":[ + "payload" + ], + "items":[ + { + "type":"Image", + "height":"100%", + "width":"100%", + "position": "absolute", + "left": "0dp", + "top": "0dp", + "src":"https://dbp-dict.bj.bcebos.com/dpl%2Fbg-img4.png" + }, + { + "type":"Container", + "width":"100%", + "height":"100%", + "position": "absolute", + "left": "0dp", + "top": "0dp", + "items":[ + { + "type":"Header", + "headerImage":"https://dbp-dict.bj.bcebos.com/dpl/header-icon.png" + }, + { + "type":"Container", + "flex-direction":"row", + "width":"100%", + "height":"100%", + "items":[ + { + "type":"Image", + "height":"350dp", + "width":"270dp", + "border-radius": "5%", + "margin-left":"35dp", + "margin-top":"40dp", + "src":"https://dbp-dict.bj.bcebos.com/dpl%2F4.jpeg" + }, + { + "type":"Container", + "width":"65%", + "height":"100%", + "items":[ + { + "type":"Text", + "text":"Chinese Pastoral Dog", + "font-size":"25dp", + "margin-top":"40dp", + "margin-left":"7%", + "line-height":"20dp" + }, + { + "type":"Text", + "text":"Country of origin: China", + "font-size":"25dp", + "margin-top":"30dp", + "margin-left":"7%", + "line-height":"20dp" + }, + { + "type":"Text", + "text":"The firewood dog, also known as the Chinese Pastoral Dog, is widely distributed in China and has a large number. It is mild in temperament and loyal to its owner. Many families in the countryside raise firewood dogs.", + "font-size":"25dp", + "margin-top":"30dp", + "margin-left":"7%", + "line-height":"80dp" + }, + { + "type":"Text", + "text":"• Chinese Pastoral Dog is endemic to China", + "font-size":"20dp", + "margin-top":"15dp", + "margin-left":"7%", + "line-height":"40dp" + } + ] + } + ] + }, + { + "type":"Footer", + "hints":[ + "Chinese Pastoral Dog" + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/samples/DPL/doc/demo6.json b/samples/DPL/doc/demo6.json new file mode 100644 index 0000000..37d577a --- /dev/null +++ b/samples/DPL/doc/demo6.json @@ -0,0 +1,121 @@ +{ + "type":"DPL", + "version":"1.0", + "dataSource": { + "listData": [ + { + "src":"https://dbp-dict.bj.bcebos.com/dpl%2F1.jpeg", + "desc":"心心" + }, + { + "src":"https://dbp-dict.bj.bcebos.com/dpl/details2.png", + "desc":"美酒" + }, + { + "src":"https://dbp-dict.bj.bcebos.com/dpl%2F3.jpeg", + "desc":"猫咪" + }, + { + "src":"https://dbp-dict.bj.bcebos.com/dpl%2F4.jpeg", + "desc":"奶狗" + }, + { + "src":"https://dbp-dict.bj.bcebos.com/dpl/details1.png", + "desc":"美食" + } + ] + }, + "styles": { + "listStyle": { + "values": { + "height":"100%", + "width":"100%", + "direction":"horizontal" + } + }, + "listItemTextStyle": { + "values": { + "font-size":"30dp", + "letter-spacing":"0.6dp", + "margin-top":"10dp" + } + }, + "listItemImageStyle": { + "values": { + "width":"200dp", + "height":"260dp", + "border-radius":"5%" + } + } + }, + "layouts": { + "listItemLayout": { + "parameters": [ + "listItemData" + ], + "item": [ + { + "type":"Container", + "height":"100%", + "width":"100%", + "margin-left":"30dp", + "margin-top": "100dp", + "items":[ + { + "type":"Image", + "style": "listItemImageStyle", + "src":"${listItemData.src}" + }, + { + "type":"Text", + "style": "listItemTextStyle", + "text":"${listItemData.desc}" + } + ] + } + ] + } + }, + "mainTemplate":{ + "parameters":[ + "payload" + ], + "items":[ + { + "type":"Image", + "height":"100%", + "width":"100%", + "position": "absolute", + "left": "0dp", + "top": "0dp", + "src":"https://dbp-dict.bj.bcebos.com/dpl%2Fbg-img4.png" + }, + { + "type":"Container", + "width":"100%", + "height":"100%", + "position": "absolute", + "left": "0dp", + "top": "0dp", + "items":[ + { + "type":"Header", + "headerImage":"https://dbp-dict.bj.bcebos.com/dpl/header-icon.png", + "headerTitle":"横向列表" + }, + { + "type":"List", + "style": "listStyle", + "data": "${payload.listData}", + "items":[ + { + "type": "listItemLayout", + "listItemData": "${data}" + } + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/samples/DPL/doc/demo7.json b/samples/DPL/doc/demo7.json new file mode 100644 index 0000000..17aab8e --- /dev/null +++ b/samples/DPL/doc/demo7.json @@ -0,0 +1,424 @@ +{ + "type":"DPL", + "version":"1.0", + "resources": [ + { + "description": "custom defined colors", + "colors": { + "defaultColor": "red" + } + }, + { + "description": "custom defined dimensions", + "dimensions": { + "defaultHeight": "100%", + "defaultWidth": "100%" + } + } + ], + "dataSource": { + "listData": [ + { + "src": "https://dbp-dict.bj.bcebos.com/video2.mp4", + "image": "https://dbp-dict.bj.bcebos.com/dpl%2Fimg4.png", + "index": "video_list_1", + "name": "葡萄酒", + "desc": "人生就像一杯酒" + }, + { + "src": "https://dbp-dict.bj.bcebos.com/video4.mp4", + "image": "https://dbp-dict.bj.bcebos.com/6.jpeg", + "index": "video_list_2", + "name": "初夏", + "desc": "最美人间四月天" + }, + { + "src": "https://dbp-dict.bj.bcebos.com/video3.mp4", + "image": "https://dbp-dict.bj.bcebos.com/5.jpeg", + "index": "video_list_3", + "name": "海", + "desc": "我要和你一起看日出, 面向大海" + }, + { + "src": "https://dbp-dict.bj.bcebos.com/video4.mp4", + "image": "https://dbp-dict.bj.bcebos.com/7.jpeg", + "index": "video_list_4", + "name": "心动的感觉", + "desc": "你知道我对你不仅仅是喜欢" + }, + { + "src": "https://dbp-dict.bj.bcebos.com/video5.mp4", + "image": "https://dbp-dict.bj.bcebos.com/dpl%2Fimg2.png", + "index": "video_list_5", + "name": "冷月", + "desc": "曾经有一个美丽的女孩追求过我,但是我没有接受,现在后悔了" + }, + { + "src": "https://dbp-dict.bj.bcebos.com/video6.mp4", + "image": "https://dbp-dict.bj.bcebos.com/5.jpeg", + "index": "video_list_6", + "name": "给大家讲一个笑话吧", + "desc": "你就是一个笑话" + }, + { + "src": "https://dbp-dict.bj.bcebos.com/video7.mp4", + "image": "https://dbp-dict.bj.bcebos.com/6.jpeg", + "index": "video_list_7", + "name": "加班,加班", + "desc": "很可以" + } + ], + "bottomText": "从创立之初,百度便将“让人们最平等便捷地获取信息,找到所求”作为自己的使命,成立以来,公司秉承“用户至上”的理念,不断坚持技术创新,致力于为用户提供“简单可依赖”的互联网搜索产品及服务,其中包括:以网络搜索为主的功能性搜索;以贴吧为主的社区搜索,针对各区域、行业所需的垂直搜索;以及门户频道、IM等,全面覆盖了中文网络世界所有的搜索需求。根据第三方权威数据,在中国,百度PC端和移动端市场份额总量达73.5%,覆盖了中国97.5%的网民,拥有6亿用户,日均响应搜索60亿次。在面对用户的搜索产品不断丰富的同时,百度还创新性地推出了基于搜索的营销推广服务,并成为最受企业青睐的互联网营销推广平台。中国已有数十万家企业使用了百度的搜索推广服务,不断提升着企业自身的品牌及运营效率。为推动中国数百万中小网站的发展,百度借助超大流量的平台优势,联合所有优质的各类网站,建立了世界上最大的网络联盟,使各类企业的搜索推广、品牌营销的价值、覆盖面均大面积提升。与此同时,各网站也在联盟大家庭的互助下,获得最大的生存与发展机会。移动互联网时代来临,百度在业界率先实现移动化转型,迎来更为广阔的发展机遇。通过开放地连接传统行业的3600行,百度从“连接人和信息”延伸到“连接人和服务”,让网民直接通过百度移动产品获得服务。目前,百度正通过持续的商业模式和产品、技术创新,推动金融、医疗、教育、汽车、生活服务等实体经济的各行业与互联网深度融合发展,为推动经济创新发展,转变经济发展方式发挥积极作用。作为一家以技术为信仰的高科技公司,百度将技术创新作为立身之本,着力于互联网核心技术突破与人才培养,在搜索、人工智能、云计算、大数据等技术领域处于全球领先水平。百度认为,互联网发展正迎来第三幕——人工智能,这也是百度重要的技术战略方向。百度建有世界一流的研究机构——百度研究院,广揽海内外顶尖技术英才,致力于人工智能等相关前沿技术的研究与探索,着眼于从根本上提升百度的信息服务水平。目前,百度人工智能研究成果已全面应用于百度产品,让数亿网民从中受益;同时,百度还将语音、图像、机器翻译等难度高、投入大的领先技术向业界开放,以降低大众创业、万众创新的门槛,进一步释放创业创新活力。作为国内的一家知名企业,百度也一直秉承“弥合信息鸿沟,共享知识社会”的责任理念,坚持履行企业公民的社会责任。成立来,百度利用自身优势积极投身公益事业,先后投入巨大资源,为盲人、少儿、老年人群体打造专门的搜索产品, 解决了特殊群体上网难问题,极大地弥补了社会信息鸿沟问题。此外,在加速推动中国信息化进程、净化网络环境、搜索引擎教育及提升大学生就业率等方面,百度也一直走在行业领先的地位。2011年初,百度还捐赠成立百度基金会,围绕知识教育、环境保护、灾难救助等议题,更加系统规范地管理和践行公益事业。百度已经成为中国最具价值的品牌之一。在2016年MIT Technology Review 《麻省理工科技评论》评选的全球最聪明50家公司中,百度的排名超越其他科技公司高踞第二。而“亚洲最受尊敬企业”、“全球最具创新力企业”、“中国互联网力量之星”等一系列荣誉称号的获得,也无一不向外界展示着百度成立数年来的成就。百度从不满足于自身取得的成绩,也从未停止发展的步伐,自2005年在纳斯达克上市以来,截至2015年,百度的市值已达 800亿美元。如今,百度已经发展成一家国际性企业,在日本、巴西、埃及中东地区、越南、泰国、印度尼西亚建立分公司, 未来,百度将覆盖全球50%以上的国家,为全球提供服务。多年来,百度董事长兼CEO李彦宏,率领百度人所形成的“简单可依赖”的核心文化,深深地植根于百度。这是一个充满朝气、求实坦诚的公司,以技术改变生活,推动人类的文明与进步,促进中国经济的发展为己任,正朝着更为远大的目标而迈进" + }, + "styles": { + "bottomTextStyle": { + "values": { + "margin-left": "60dp", + "margin-top": "20dp", + "font-size": "15dp", + "line-height": "20dp", + "max-lines": 2, + "text-overflow": "ellipsis", + "color": "@defaultColor" + } + }, + "listContainerStyle": { + "values": { + "width": "@defaultWidth", + "height": "@defaultHeight", + "margin-top": "30dp", + "padding-left": "15%", + "flex-direction": "row" + } + } + }, + "layouts": { + "listBottomContainerLayout": { + "parameters": [ + "name", + "desc" + ], + "item": [ + { + "type": "Container", + "width": "200dp", + "height": "100dp", + "flex-direction": "column", + "items": [ + { + "type": "Text", + "margin-left": "60dp", + "font-size": "25dp", + "text": "${name}" + }, + { + "type": "Text", + "style": "bottomTextStyle", + "text": "${desc}" + } + ] + } + ] + }, + "listItemLayout": { + "parameters": [ + "listItemData" + ], + "item": [ + { + "type": "Container", + "onClick": [ + { + "type": "SetState", + "componentId": "demo_video_compid", + "state": "src", + "value": "${listItemData.src}" + }, + { + "type": "SetState", + "componentId": "demo_video_compid", + "state": "autoplay", + "value": true + }, + { + "type": "Animation", + "componentId": "${listItemData.index}", + "from": "90dp", + "to": "120dp", + "easing": "ease-in", + "attribute": "height", + "duration": 500, + "repeatCount": "1", + "repeatMode": "reverse" + }, + { + "type": "SetState", + "componentId": "demo_text_compid", + "state": "text", + "value": "${listItemData.name}" + }, + { + "type": "SetState", + "componentId": "demo_image_compid", + "state": "src", + "value": "https://dbp-dict.bj.bcebos.com/dpl%2F%E7%81%B0%E5%BF%83.png" + }, + { + "type": "ControlMedia", + "componentId": "demo_video_compid", + "command": "play" + } + ], + "style": "listContainerStyle", + "items": [ + { + "type": "Image", + "componentId": "${listItemData.index}", + "onClick": [ + { + "type": "SendEvent" + } + ], + "height": "90dp", + "weight": "100dp", + "src": "${listItemData.image}" + }, + { + "type": "listBottomContainerLayout", + "name": "${listItemData.name}", + "desc": "${listItemData.desc}" + } + ] + } + ] + } + }, + "mainTemplate":{ + "parameters":[ + "payload" + ], + "items":[ + { + "type":"Image", + "position":"absolute", + "top":"0dp", + "left":"0dp", + "src":"https://dbp-dict.bj.bcebos.com/dpl%2Fbg-img4.png", + "height": "@defaultHeight", + "width": "@defaultWidth" + }, + { + "type":"Container", + "position":"absolute", + "top":"0dp", + "left":"0dp", + "height": "@defaultHeight", + "width": "@defaultWidth", + "items": [ + { + "type":"Header", + "headerTitle":"视频相册", + "headerImage":"https://dbp-dict.bj.bcebos.com/dpl/header-icon.png", + "hasBackIcon": true + }, + { + "type": "Pager", + "onPageChanged": [ + { + "type": "SendEvent" + } + ], + "componentId": "demo_move_page_compid", + "height": "@defaultHeight", + "width": "@defaultWidth", + "direction": "horizontal", + "firstItem":[ + { + "type": "Container", + "width": "100%", + "height": "100%", + "margin-top": "80dp", + "flex-direction": "column", + "items": [ + { + "type": "Image", + "width": "70%", + "height": "275dp", + "margin-left": "13%", + "src": "https://dbp-dict.bj.bcebos.com/dpl%2Fimg2.png" + }, + { + "type": "Text", + "margin-top": "15dp", + "margin-left": "37%", + "line-height": "40dp", + "text": "欢迎来到视频相册" + } + ] + } + ], + "items": [ + { + "type": "Container", + "height": "@defaultHeight", + "width": "@defaultWidth", + "flex-direction": "row", + "items": [ + { + "type": "List", + "componentId": "demo_list_compid", + "direction": "vertical", + "width": "45%", + "height": "100%", + "data": "${payload.listData}", + "items": [ + { + "type": "listItemLayout", + "listItemData": "${data}" + } + ] + }, + { + "type": "Container", + "componentId": "replaceComponentId", + "width": "60%", + "height": "@defaultHeight", + "flex-direction": "column", + "padding-left": "10dp", + "items": [ + { + "type": "Video", + "width": "80%", + "height": "70%", + "componentId": "demo_video_compid", + "src": "https://dbp-dict.bj.bcebos.com/video2.mp4", + "backVisible":true, + "controls":true, + "fullScreen":true, + "loop":true, + "autoplay": false, + "nextEnable":false, + "nextVisible":false, + "noProgressBar":true, + "noSwitcher": false, + "prevEnable": false, + "prevVisible": false, + "bar-visible": true, + "onPlay": [ + { + "type": "SendEvent" + } + ], + "onPause": [ + { + "type": "SendEvent" + } + ], + "onNext": [ + { + "type": "SendEvent" + } + ], + "onPrevious": [ + { + "type": "SendEvent" + } + ], + "onEnd": [ + { + "type": "SendEvent" + } + ] + }, + { + "type": "Container", + "flex-direction": "row", + "width": "100%", + "height": "70dp", + "items": [ + { + "type": "Text", + "componentId": "demo_text_compid", + "color": "red", + "font-size": "20dp", + "margin-top": "15dp", + "text": "葡萄酒" + }, + { + "type": "Image", + "componentId": "demo_image_compid", + "onClick": [ + { + "type": "SendEvent" + }, + { + "type": "SetState", + "componentId": "demo_image_compid", + "state": "src", + "value": "https://dbp-dict.bj.bcebos.com/dpl%2F%E5%BF%83.png" + }, + { + "type": "Animation", + "componentId": "demo_image_compid", + "from": "40dp", + "to": "10dp", + "easing": "ease-in", + "attribute": "height", + "duration": 500, + "repeatCount": "3", + "repeatMode": "reverse" + } + ], + "width": "40dp", + "height": "40dp", + "margin-top": "12dp", + "margin-left": "350dp", + "src": "https://dbp-dict.bj.bcebos.com/dpl%2F%E7%81%B0%E5%BF%83.png" + } + ] + } + ] + } + ] + } + ], + "lastItem": [ + { + "type": "Container", + "width": "100%", + "height": "100%", + "padding-top": "1%", + "align-items": "center", + "items": [ + { + "type": "Text", + "line-height": "50dp", + "color": "red", + "text": "喜欢我们的相册么?" + }, + { + "type": "ScrollView", + "componentId": "demo_pull_scrollview_compid", + "direction": "vertical", + "width": "87%", + "height": "68%", + "margin-top": "15dp", + "items": [ + { + "type": "Text", + "color": "#18773d", + "letter-spacing": "0.5dp", + "font-size": "25dp", + "text": "${payload.bottomText}" + } + ] + } + ] + } + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/samples/DPL/doc/demo7_1.json b/samples/DPL/doc/demo7_1.json new file mode 100644 index 0000000..ac2ab65 --- /dev/null +++ b/samples/DPL/doc/demo7_1.json @@ -0,0 +1,368 @@ +{ + "type":"DPL", + "version":"1.0", + "mainTemplate":{ + "parameters":[ + "payload" + ], + "items":[ + { + "type":"Image", + "position":"absolute", + "top":"0dp", + "left":"0dp", + "src":"https://dbp-dict.bj.bcebos.com/dpl%2Fbg-img4.png", + "height":"100%", + "width":"100%" + }, + { + "type":"Container", + "position":"absolute", + "top":"0dp", + "left":"0dp", + "width":"100%", + "height":"100%", + "items": [ + { + "type":"Header", + "headerTitle":"视频相册", + "headerImage":"https://dbp-dict.bj.bcebos.com/dpl/header-icon.png", + "hasBackIcon": true + }, + { + "type": "Pager", + "onPageChanged": [ + { + "type": "SendEvent" + } + ], + "componentId": "demo_move_page_compid", + "width": "100%", + "height": "100%", + "direction": "horizontal", + "firstItem":[ + { + "type": "Container", + "width": "100%", + "height": "100%", + "margin-top": "80dp", + "flex-direction": "column", + "items": [ + { + "type": "Image", + "width": "70%", + "height": "275dp", + "margin-left": "13%", + "src": "https://dbp-dict.bj.bcebos.com/dpl%2Fimg2.png" + }, + { + "type": "Text", + "margin-top": "15dp", + "margin-left": "37%", + "line-height": "40dp", + "text": "欢迎来到视频相册" + } + ] + } + ], + "items": [ + { + "type": "Container", + "width": "100%", + "height": "100%", + "backgroung-color": "red", + "flex-direction": "row", + "items": [ + { + "type": "List", + "componentId": "demo_list_compid", + "direction": "vertical", + "width": "45%", + "height": "100%", + "data": [ + { + "src": "https://dbp-dict.bj.bcebos.com/video2.mp4", + "image": "https://dbp-dict.bj.bcebos.com/dpl%2Fimg4.png", + "index": "video_list_1", + "name": "葡萄酒", + "desc": "人生就像一杯酒" + }, + { + "src": "https://dbp-dict.bj.bcebos.com/video4.mp4", + "image": "https://dbp-dict.bj.bcebos.com/6.jpeg", + "index": "video_list_2", + "name": "初夏", + "desc": "最美人间四月天" + }, + { + "src": "https://dbp-dict.bj.bcebos.com/video3.mp4", + "image": "https://dbp-dict.bj.bcebos.com/5.jpeg", + "index": "video_list_3", + "name": "海", + "desc": "我要和你一起看日出, 面向大海" + }, + { + "src": "https://dbp-dict.bj.bcebos.com/video4.mp4", + "image": "https://dbp-dict.bj.bcebos.com/7.jpeg", + "index": "video_list_4", + "name": "心动的感觉", + "desc": "你知道我对你不仅仅是喜欢" + }, + { + "src": "https://dbp-dict.bj.bcebos.com/video5.mp4", + "image": "https://dbp-dict.bj.bcebos.com/dpl%2Fimg2.png", + "index": "video_list_5", + "name": "冷月", + "desc": "曾经有一个美丽的女孩追求过我,但是我没有接受,现在后悔了" + }, + { + "src": "https://dbp-dict.bj.bcebos.com/video6.mp4", + "image": "https://dbp-dict.bj.bcebos.com/5.jpeg", + "index": "video_list_6", + "name": "给大家讲一个笑话吧", + "desc": "你就是一个笑话" + }, + { + "src": "https://dbp-dict.bj.bcebos.com/video7.mp4", + "image": "https://dbp-dict.bj.bcebos.com/6.jpeg", + "index": "video_list_7", + "name": "加班,加班", + "desc": "很可以" + } + ], + "items": [ + { + "type": "Container", + "onClick": [ + { + "type": "SetState", + "componentId": "demo_video_compid", + "state": "src", + "value": "${data.src}" + }, + { + "type": "SetState", + "componentId": "demo_video_compid", + "state": "autoplay", + "value": true + }, + { + "type": "Animation", + "componentId": "${data.index}", + "from": "90dp", + "to": "120dp", + "easing": "ease-in", + "attribute": "height", + "duration": 500, + "repeatCount": "1", + "repeatMode": "reverse" + }, + { + "type": "SetState", + "componentId": "demo_text_compid", + "state": "text", + "value": "${data.name}" + }, + { + "type": "SetState", + "componentId": "demo_image_compid", + "state": "src", + "value": "https://dbp-dict.bj.bcebos.com/dpl%2F%E7%81%B0%E5%BF%83.png" + }, + { + "type": "ControlMedia", + "componentId": "demo_video_compid", + "command": "play" + } + ], + "width": "100%", + "height": "100%", + "margin-top": "30dp", + "padding-left": "15%", + "flex-direction": "row", + "items": [ + { + "type": "Image", + "componentId": "${data.index}", + "onClick": [ + { + "type": "SendEvent" + } + ], + "height": "90dp", + "weight": "100dp", + "src": "${data.image}" + }, + { + "type": "Container", + "width": "200dp", + "height": "100dp", + "flex-direction": "column", + "items": [ + { + "type": "Text", + "margin-left": "60dp", + "font-size": "25dp", + "text": "${data.name}" + }, + { + "type": "Text", + "margin-left": "60dp", + "margin-top": "20dp", + "font-size": "15dp", + "line-height": "20dp", + "max-lines": 2, + "text-overflow": "ellipsis", + "color": "red", + "text": "${data.desc}" + } + ] + } + ] + } + ] + }, + { + "type": "Container", + "componentId": "replaceComponentId", + "width": "60%", + "height": "100%", + "flex-direction": "column", + "padding-left": "10dp", + "items": [ + { + "type": "Video", + "width": "80%", + "height": "70%", + "componentId": "demo_video_compid", + "src": "https://dbp-dict.bj.bcebos.com/video2.mp4", + "backVisible":true, + "controls":true, + "fullScreen":true, + "loop":true, + "autoplay": false, + "nextEnable":false, + "nextVisible":false, + "noProgressBar":true, + "noSwitcher": false, + "prevEnable": false, + "prevVisible": false, + "bar-visible": true, + "onPlay": [ + { + "type": "SendEvent" + } + ], + "onPause": [ + { + "type": "SendEvent" + } + ], + "onNext": [ + { + "type": "SendEvent" + } + ], + "onPrevious": [ + { + "type": "SendEvent" + } + ], + "onEnd": [ + { + "type": "SendEvent" + } + ] + }, + { + "type": "Container", + "flex-direction": "row", + "width": "100%", + "height": "70dp", + "items": [ + { + "type": "Text", + "componentId": "demo_text_compid", + "color": "red", + "font-size": "20dp", + "margin-top": "15dp", + "text": "葡萄酒" + }, + { + "type": "Image", + "componentId": "demo_image_compid", + "onClick": [ + { + "type": "SendEvent" + }, + { + "type": "SetState", + "componentId": "demo_image_compid", + "state": "src", + "value": "https://dbp-dict.bj.bcebos.com/dpl%2F%E5%BF%83.png" + }, + { + "type": "Animation", + "componentId": "demo_image_compid", + "from": "40dp", + "to": "10dp", + "easing": "ease-in", + "attribute": "height", + "duration": 500, + "repeatCount": "3", + "repeatMode": "reverse" + } + ], + "width": "40dp", + "height": "40dp", + "margin-top": "12dp", + "margin-left": "350dp", + "src": "https://dbp-dict.bj.bcebos.com/dpl%2F%E7%81%B0%E5%BF%83.png" + } + ] + } + ] + } + ] + } + ], + "lastItem": [ + { + "type": "Container", + "width": "100%", + "height": "100%", + "padding-top": "1%", + "align-items": "center", + "items": [ + { + "type": "Text", + "line-height": "50dp", + "color": "red", + "text": "喜欢我们的相册么?" + }, + { + "type": "ScrollView", + "componentId": "demo_pull_scrollview_compid", + "direction": "vertical", + "width": "87%", + "height": "68%", + "margin-top": "15dp", + "items": [ + { + "type": "Text", + "color": "#18773d", + "letter-spacing": "0.5dp", + "font-size": "25dp", + "text": "从创立之初,百度便将“让人们最平等便捷地获取信息,找到所求”作为自己的使命,成立以来,公司秉承“用户至上”的理念,不断坚持技术创新,致力于为用户提供“简单可依赖”的互联网搜索产品及服务,其中包括:以网络搜索为主的功能性搜索;以贴吧为主的社区搜索,针对各区域、行业所需的垂直搜索;以及门户频道、IM等,全面覆盖了中文网络世界所有的搜索需求。根据第三方权威数据,在中国,百度PC端和移动端市场份额总量达73.5%,覆盖了中国97.5%的网民,拥有6亿用户,日均响应搜索60亿次。在面对用户的搜索产品不断丰富的同时,百度还创新性地推出了基于搜索的营销推广服务,并成为最受企业青睐的互联网营销推广平台。中国已有数十万家企业使用了百度的搜索推广服务,不断提升着企业自身的品牌及运营效率。为推动中国数百万中小网站的发展,百度借助超大流量的平台优势,联合所有优质的各类网站,建立了世界上最大的网络联盟,使各类企业的搜索推广、品牌营销的价值、覆盖面均大面积提升。与此同时,各网站也在联盟大家庭的互助下,获得最大的生存与发展机会。移动互联网时代来临,百度在业界率先实现移动化转型,迎来更为广阔的发展机遇。通过开放地连接传统行业的3600行,百度从“连接人和信息”延伸到“连接人和服务”,让网民直接通过百度移动产品获得服务。目前,百度正通过持续的商业模式和产品、技术创新,推动金融、医疗、教育、汽车、生活服务等实体经济的各行业与互联网深度融合发展,为推动经济创新发展,转变经济发展方式发挥积极作用。作为一家以技术为信仰的高科技公司,百度将技术创新作为立身之本,着力于互联网核心技术突破与人才培养,在搜索、人工智能、云计算、大数据等技术领域处于全球领先水平。百度认为,互联网发展正迎来第三幕——人工智能,这也是百度重要的技术战略方向。百度建有世界一流的研究机构——百度研究院,广揽海内外顶尖技术英才,致力于人工智能等相关前沿技术的研究与探索,着眼于从根本上提升百度的信息服务水平。目前,百度人工智能研究成果已全面应用于百度产品,让数亿网民从中受益;同时,百度还将语音、图像、机器翻译等难度高、投入大的领先技术向业界开放,以降低大众创业、万众创新的门槛,进一步释放创业创新活力。作为国内的一家知名企业,百度也一直秉承“弥合信息鸿沟,共享知识社会”的责任理念,坚持履行企业公民的社会责任。成立来,百度利用自身优势积极投身公益事业,先后投入巨大资源,为盲人、少儿、老年人群体打造专门的搜索产品, 解决了特殊群体上网难问题,极大地弥补了社会信息鸿沟问题。此外,在加速推动中国信息化进程、净化网络环境、搜索引擎教育及提升大学生就业率等方面,百度也一直走在行业领先的地位。2011年初,百度还捐赠成立百度基金会,围绕知识教育、环境保护、灾难救助等议题,更加系统规范地管理和践行公益事业。百度已经成为中国最具价值的品牌之一。在2016年MIT Technology Review 《麻省理工科技评论》评选的全球最聪明50家公司中,百度的排名超越其他科技公司高踞第二。而“亚洲最受尊敬企业”、“全球最具创新力企业”、“中国互联网力量之星”等一系列荣誉称号的获得,也无一不向外界展示着百度成立数年来的成就。百度从不满足于自身取得的成绩,也从未停止发展的步伐,自2005年在纳斯达克上市以来,截至2015年,百度的市值已达 800亿美元。如今,百度已经发展成一家国际性企业,在日本、巴西、埃及中东地区、越南、泰国、印度尼西亚建立分公司, 未来,百度将覆盖全球50%以上的国家,为全球提供服务。多年来,百度董事长兼CEO李彦宏,率领百度人所形成的“简单可依赖”的核心文化,深深地植根于百度。这是一个充满朝气、求实坦诚的公司,以技术改变生活,推动人类的文明与进步,促进中国经济的发展为己任,正朝着更为远大的目标而迈进" + } + ] + } + ] + } + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/samples/DPL/doc/launch.json b/samples/DPL/doc/launch.json new file mode 100644 index 0000000..9b8ab5e --- /dev/null +++ b/samples/DPL/doc/launch.json @@ -0,0 +1,176 @@ +{ + "type":"DPL", + "version":"1.0", + "mainTemplate":{ + "parameters":[ + "payload" + ], + "items":[ + { + "type":"Image", + "position":"absolute", + "top":"0dp", + "left":"0dp", + "src":"https://d2o906d8ln7ui1.cloudfront.net/images/BT7_Background.png", + "height":"100%", + "width":"100%" + }, + { + "type":"Header", + "headerTitle":"DPL示例", + "headerImage":"https://dbp-dict.bj.bcebos.com/dpl/header-icon.png", + "hasBackIcon":true + }, + { + "type":"Container", + "width":"100%", + "height":"100%", + "padding-top": "10%", + "padding-left": "10%", + "flex-direction": "row", + "position":"absolute", + "top":"0dp", + "left":"0dp", + "items":[ + { + "type": "ScrollView", + "componentId": "demo_launch_scrollview_compid", + "direction": "vertical", + "width": "40%", + "height": "400dp", + "margin-top": "15dp", + "items": [ + { + "type": "Text", + "color": "#18773d", + "letter-spacing": "0.5dp", + "font-size": "20dp", + "text": "这个DPL的样例比较完整的展示了DPL的页面构建以及交互的实现,涉及11种组件(9种基础组件+2种复合组件)和8种常见的交互Command。组件: Text、Image、Container、Frame、List、Pager、ScrollView、Audio、Video、Header、Footer。交互Command: AutoPage、SetPage、Scroll、ScrollToIndex、Animation、ControlMedia、SendEvent、SetState、Parallel。页面交互的部分支持:页面点击和通过query控制后续组件变更时候会定期更新此demo, 使用前请先配置好列表中的意图,运行服务后在小度在家有屏系列产品上体验。" + }, + { + "type": "Text", + "color": "#18773d", + "letter-spacing": "0.5dp", + "font-size": "20dp", + "margin-top": "10dp", + "text": "如何运行demo" + }, + { + "type": "Text", + "color": "#18773d", + "letter-spacing": "0.5dp", + "font-size": "20dp", + "margin-top": "20dp", + "text": "1. 在DBP技能开发平台创建一个技能 如: 技能名称:DPL例子, 调用名称:上海,调用名称在调试模式下可以自定义。" + }, + { + "type": "Text", + "color": "#18773d", + "letter-spacing": "0.5dp", + "font-size": "20dp", + "margin-top": "20dp", + "text": "2. 给新建技能创建demo中需要的意图,demo中一共有14个意图" + }, + { + "type": "Text", + "color": "#18773d", + "letter-spacing": "0.5dp", + "font-size": "20dp", + "margin-top": "20dp", + "text": "3. 进入DPL_CFC, npm install 下载安装依赖" + }, + { + "type": "Text", + "color": "#18773d", + "letter-spacing": "0.5dp", + "font-size": "20dp", + "margin-top": "20dp", + "text": "4. 将demo服务地址配置" + }, + { + "type": "Text", + "color": "#18773d", + "letter-spacing": "0.5dp", + "font-size": "20dp", + "margin-top": "20dp", + "text": "5. 在小度在家或者小度在家1S上绑定自己的开发者账户,进行如下操作:" + }, + { + "type": "Text", + "color": "#18773d", + "letter-spacing": "0.5dp", + "font-size": "20dp", + "margin-top": "20dp", + "text": "打开技能调试模式 --> 打开上海 --> query:简单图片/长文本/短文本/右图/左图详情/横向列表/视频相册" + } + ] + }, + { + "type": "Pager", + "componentId": "demo_launch_pager_compid", + "width": "45%", + "margin-left": "5%", + "height": "300dp", + "onLoaded": [ + { + "type": "AutoPage", + "componentId": "demo_launch_pager_compid", + "durationInMillisecond": 1000 + } + ], + "items": [ + { + "type": "Frame", + "width": "100%", + "height": "400dp", + "border-radius": "50%", + "padding-top": "22%", + "padding-left": "8%", + "background-color": "#FFB6C1", + "items": [ + { + "type": "Text", + "font-size": "25dp", + "text": "在DBP技能开发平台创建技能 如技能名称:DPL例子,调用名称:上海,调用名称在调试模式下可以自定义。" + } + ] + }, + { + "type": "Frame", + "width": "100%", + "height": "400dp", + "border-radius": "50%", + "padding-top": "30%", + "padding-left": "8%", + "background-color": "#FF83FA", + "items": [ + { + "type": "Text", + "font-size": "25dp", + "text": "给新建技能创建demo中需要的意图,demo中一共有14个意图" + } + ] + }, + { + "type": "Frame", + "width": "100%", + "height": "400dp", + "padding-top": "30%", + "padding-left": "15%", + "border-radius": "50%", + "background-color": "#FFEC8B", + "items": [ + { + "type": "Text", + "font-size": "25dp", + "text": "部署CFC或者WebService" + } + ] + } + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/samples/DPL/doc/update.json b/samples/DPL/doc/update.json new file mode 100644 index 0000000..858db85 --- /dev/null +++ b/samples/DPL/doc/update.json @@ -0,0 +1,111 @@ +{ + "type": "DPL", + "version": "1.0", + "mainTemplate": { + "parameters": [ + "payload" + ], + "items": [ + { + "type": "Container", + "componentId": "replaceComponentId", + "width": "60%", + "height": "100%", + "flex-direction": "column", + "padding-left": "10dp", + "items": [ + { + "type": "Video", + "width": "80%", + "height": "70%", + "componentId": "demo_video_compid", + "src": "https://dbp-dict.bj.bcebos.com/video2.mp4", + "backVisible":true, + "controls":true, + "fullScreen":true, + "loop":true, + "nextEnable":false, + "nextVisible":false, + "noProgressBar":true, + "noSwitcher": false, + "prevEnable": false, + "prevVisible": false, + "bar-visible": true, + "onPlay": [ + { + "type": "SendEvent" + } + ], + "onPause": [ + { + "type": "SendEvent" + } + ], + "onNext": [ + { + "type": "SendEvent" + } + ], + "onPrevious": [ + { + "type": "SendEvent" + } + ], + "onEnd": [ + { + "type": "SendEvent" + } + ] + }, + { + "type": "Container", + "flex-direction": "row", + "width": "100%", + "height": "70dp", + "items": [ + { + "type": "Text", + "componentId": "demo_text_compid", + "color": "red", + "font-size": "20dp", + "margin-top": "15dp", + "text": "视频标题" + }, + { + "type": "Image", + "componentId": "demo_image_compid", + "onClick": [ + { + "type": "SendEvent" + }, + { + "type": "SetState", + "componentId": "demo_image_compid", + "state": "src", + "value": "https://dbp-dict.bj.bcebos.com/dpl%2F%E5%BF%83.png" + }, + { + "type": "Animation", + "componentId": "demo_image_compid", + "from": "40dp", + "to": "10dp", + "easing": "ease-in", + "attribute": "height", + "duration": 500, + "repeatCount": "3", + "repeatMode": "reverse" + } + ], + "width": "40dp", + "height": "40dp", + "margin-top": "12dp", + "margin-left": "350dp", + "src": "https://dbp-dict.bj.bcebos.com/dpl%2F%E7%81%B0%E5%BF%83.png" + } + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/samples/DPL/index.php b/samples/DPL/index.php new file mode 100644 index 0000000..267aa3d --- /dev/null +++ b/samples/DPL/index.php @@ -0,0 +1,23 @@ +log->markStart('all_t'); +$ret = $demo->run(); +//$demo->log->markEnd('all_t'); + +//打印日志 +//$demo->log->notice($demo->log->getField('url_t')); +//$demo->log->notice(); +print $ret; diff --git a/src/Directive/DPL/Commands/AnimationCommand.php b/src/Directive/DPL/Commands/AnimationCommand.php new file mode 100644 index 0000000..9b93de6 --- /dev/null +++ b/src/Directive/DPL/Commands/AnimationCommand.php @@ -0,0 +1,145 @@ +data = [ + 'attribute' => '', + 'from' => '', + 'to' => '', + 'easing' => 'linear', + 'duration' => 1000, + 'repeatCount' => 'infinite', + 'repeatMode' => 'restart', + 'onComplete' => [] + ]; + } + + /** + * @desc 设置动画属性 + * @param string $attribute 文本内容 + */ + public function setAttribute($attribute) { + if (is_string($attribute)) { + $this->data['attribute'] = $attribute; + } + } + + /** + * @desc 设置动画作用属性的起始值 + * @param string $from 动画作用属性的起始值 + */ + public function setFrom($from) { + if ($from) { + $this->data['from'] = $from; + } + } + + /** + * @desc 设置动画作用属性的结束值 + * @param string $to 动画作用属性的结束值 + */ + public function setTo($to) { + if ($to) { + $this->data['to'] = $to; + } + } + + /** + * @desc 设置描述动画执行的速度的类型 + * @param string $easing 描述动画执行的速度的类型 + */ + public function setEasing($easing) { + if (strpos($easing,'cubic-bezier') !== false) { + $this->data['easing'] = $easing; + } + if (in_array($easing, self::$easingArr)) { + $this->data['easing'] = $easing; + } + } + + /** + * @desc 设置动画执行的时间 + * @param number $duration 动画执行的时间 + */ + public function setDuration($duration) { + if (is_numeric($duration)) { + $this->data['duration'] = $duration; + } + } + + /** + * @desc 设置动画重复的次数 + * @param string $repeatCount 动画重复的次数 + */ + public function setRepeatCount($repeatCount) { + if ($repeatCount) { + $this->data['repeatCount'] = $repeatCount; + } + } + + /** + * @desc 设置动画重复方式 + * @param string $repeatMode 动画重复方式 + */ + public function setRepeatMode($repeatMode) { + if (in_array($repeatMode, self::$repeatModeArr)) { + $this->data['repeatMode'] = $repeatMode; + } + } + + /** + * @desc 设置动画结束后需要触发的commands, 如果repeatCount为infinite, 将不会触发onComplete + * @param BaseCommand|array $commands 动画结束后需要触发的commands + */ + public function addCompleteCommands($commands) { + if ($commands instanceof BaseCommand) { + $this->data['onComplete'] = [$commands->getData()]; + } + + if (is_array($commands)) { + foreach ($commands as $command) { + if ($command instanceof BaseCommand) { + $this->data['onComplete'][] = $command->getData(); + } + } + } + } +} + + diff --git a/src/Directive/DPL/Commands/AutoPageCommand.php b/src/Directive/DPL/Commands/AutoPageCommand.php new file mode 100644 index 0000000..881d463 --- /dev/null +++ b/src/Directive/DPL/Commands/AutoPageCommand.php @@ -0,0 +1,42 @@ +data['durationInMillisecond'] = $durationMs; + } + } +} + + diff --git a/src/Directive/DPL/Commands/BaseCommand.php b/src/Directive/DPL/Commands/BaseCommand.php new file mode 100644 index 0000000..c5f5be1 --- /dev/null +++ b/src/Directive/DPL/Commands/BaseCommand.php @@ -0,0 +1,54 @@ +data['type'] = $type; + $this->data['componentId'] = ''; + } + + /** + * @desc 设置指令绑定的组件id + * @param string $componentId 组件id + */ + public function setComponentId($componentId) { + if ($componentId) { + $this->data['componentId'] = $componentId; + } + } + + /** + * @desc 获取指令的data + * @return array + */ + public function getData() { + return $this->data; + } +} + + diff --git a/src/Directive/DPL/Commands/ControlMediaCommand.php b/src/Directive/DPL/Commands/ControlMediaCommand.php new file mode 100644 index 0000000..6772298 --- /dev/null +++ b/src/Directive/DPL/Commands/ControlMediaCommand.php @@ -0,0 +1,57 @@ +data = [ + 'componentId' => '', + 'command' => '' + ]; + } + + /** + * @desc 设置Command + * @param string $command 名称 + */ + public function setCommand($command) { + if (in_array($command, self::$commands)) { + $this->data['command'] = $command; + } + } +} + + diff --git a/src/Directive/DPL/Commands/ParallelCommand.php b/src/Directive/DPL/Commands/ParallelCommand.php new file mode 100644 index 0000000..49a971f --- /dev/null +++ b/src/Directive/DPL/Commands/ParallelCommand.php @@ -0,0 +1,60 @@ +data['delayInMilliseconds'] = $delayMs; + } + } + + /** + * @desc 设置并行执行的指令集合 + * @param BaseCommand|array $commands 指令集合 + */ + public function setCommands($commands) { + if ($commands instanceof BaseCommand) { + $this->data['commands'] = [$commands->getData()]; + } + if (is_array($commands)) { + foreach ($commands as $command) { + if ($command instanceof BaseCommand) { + $this->data['commands'][] = $command->getData(); + } + } + }; + } +} + + diff --git a/src/Directive/DPL/Commands/ScrollCommand.php b/src/Directive/DPL/Commands/ScrollCommand.php new file mode 100644 index 0000000..5686154 --- /dev/null +++ b/src/Directive/DPL/Commands/ScrollCommand.php @@ -0,0 +1,44 @@ +data['distance'] = $distance; + } + } +} + + diff --git a/src/Directive/DPL/Commands/ScrollToIndexCommand.php b/src/Directive/DPL/Commands/ScrollToIndexCommand.php new file mode 100644 index 0000000..eba4ade --- /dev/null +++ b/src/Directive/DPL/Commands/ScrollToIndexCommand.php @@ -0,0 +1,61 @@ +data['index'] = $index; + } + } + + /** + * @desc 设置滚动后视图的位置 + * @param string $align 视图的位置 + */ + public function setAlign($align) { + if (in_array($align, self::$alignArr)) { + $this->data['align'] = $align; + } + } +} + + diff --git a/src/Directive/DPL/Commands/SendEventCommand.php b/src/Directive/DPL/Commands/SendEventCommand.php new file mode 100644 index 0000000..c36dcb3 --- /dev/null +++ b/src/Directive/DPL/Commands/SendEventCommand.php @@ -0,0 +1,34 @@ +data['delayInMilliseconds'] = $delayMs; + } + } + + /** + * @desc 设置滚动的距离 + * @param number $repeatCount 重复执行次数 + */ + public function setRepeatCount($repeatCount) { + if (is_numeric($repeatCount)) { + $this->data['repeatCount'] = $repeatCount; + } + } + + /** + * @desc 设置Command动作项 + * @param array $commands 指令项 + */ + public function setCommands($commands) { + if ($commands instanceof BaseCommand) { + $this->data['commands'] = [$commands->getData()]; + } + if (is_array($commands)) { + foreach ($commands as $command) { + if ($command instanceof BaseCommand) { + $this->data['commands'][] = $command->getData(); + } + } + } + } +} + + diff --git a/src/Directive/DPL/Commands/SetPageCommand.php b/src/Directive/DPL/Commands/SetPageCommand.php new file mode 100644 index 0000000..c7e551d --- /dev/null +++ b/src/Directive/DPL/Commands/SetPageCommand.php @@ -0,0 +1,58 @@ +data['position'] = $position; + } + } + + /** + * @desc 设置切换步长 + * @param number $value 步长 + */ + public function setValue($value) { + if (is_numeric($value)) { + $this->data['value'] = $value; + } + } +} + + diff --git a/src/Directive/DPL/Commands/SetStateCommand.php b/src/Directive/DPL/Commands/SetStateCommand.php new file mode 100644 index 0000000..0282acd --- /dev/null +++ b/src/Directive/DPL/Commands/SetStateCommand.php @@ -0,0 +1,54 @@ +data['state'] = $state; + } + } + + /** + * @desc 设置属性值 + * @param string $value 属性值 + */ + public function setValue($value) { + if ($value) { + $this->data['value'] = $value; + } + } +} + + diff --git a/src/Directive/DPL/Commands/UpdateComponentCommand.php b/src/Directive/DPL/Commands/UpdateComponentCommand.php new file mode 100644 index 0000000..c788255 --- /dev/null +++ b/src/Directive/DPL/Commands/UpdateComponentCommand.php @@ -0,0 +1,45 @@ +data['document'] = $doc->getData(); + } + } +} + + diff --git a/src/Directive/DPL/Document.php b/src/Directive/DPL/Document.php new file mode 100644 index 0000000..39a2fb9 --- /dev/null +++ b/src/Directive/DPL/Document.php @@ -0,0 +1,74 @@ +data = []; + if (is_array($doc)) { + $this->data = $doc; + } + } + + /** + * @desc 从path中读取document配置文件生成文档对象 + * @param string $path 绝对路径 + */ + public function getDocumentFromPath($path) { + $doc = json_decode(file_get_contents($path), true); + $this->data = $doc; + } + + /** + * @desc 获取data + * @return array 返回文档对象数据 + */ + public function getData() { + return $this->data; + } + + /** + * @desc 初始化文档对象数据 + * @param array $data 初始化数据 + */ + public function initDocument($data) { + if (is_array($data)) { + $this->data = $data; + } + } + + /** + * @desc 设置模版渲染停留时间 + * @param number $duration 初始化数据 + */ + public function setDocumentDuration($duration) { + if (is_numeric('number')) { + $this->data['duration'] = $duration; + } + } +} + + diff --git a/src/Directive/DPL/ExecuteCommands.php b/src/Directive/DPL/ExecuteCommands.php new file mode 100644 index 0000000..071d0fd --- /dev/null +++ b/src/Directive/DPL/ExecuteCommands.php @@ -0,0 +1,68 @@ +data['token'] = $this->genToken(); + } + + /** + * @desc 设置token + * @param string $token + */ + public function setToken($token) { + if (is_string($token)) { + $this->data['token'] = $token; + } + } + + /** + * @desc 设置指令 + * @param BaseCommand|array $commands 指令对象集合 + */ + public function setCommands($commands) { + if (!isset($this->data['commands'])) { + $this->data['commands'] = []; + } + + if ($commands instanceof BaseCommand) { + $this->data['commands'] = [$commands->getData()]; + } + if (is_array($commands)) { + foreach ($commands as $command) { + if ($command instanceof BaseCommand) { + $this->data['commands'][] = $command->getData(); + } + } + } + } +} + + diff --git a/src/Directive/DPL/RenderDocument.php b/src/Directive/DPL/RenderDocument.php new file mode 100644 index 0000000..cffd5d1 --- /dev/null +++ b/src/Directive/DPL/RenderDocument.php @@ -0,0 +1,65 @@ +data['token'] = $this->genToken(); + } + + /** + * @desc 设置token + * @param string $token token + */ + public function setToken($token) { + if (is_string($token)) { + $this->data['token'] = $token; + } + } + + /** + * @desc 设置文档对象 + * @param Document $document 文档对象 + */ + public function setDocument($document) { + if ($document instanceof Document) { + $this->data['document'] = $document->getData(); + } + } + + /** + * @desc 设置数据源 + * @param array dataSources 数据源 + */ + public function setDataSources($dataSources) { + if (is_array($dataSources)) { + $this->data['dataSources'] = $dataSources; + } + } +} + + diff --git a/src/Response.php b/src/Response.php index d053c11..0d79765 100644 --- a/src/Response.php +++ b/src/Response.php @@ -126,7 +126,14 @@ public function build($data){ //directive to data $directives = array_values(array_filter(array_map(function($directive){ if($directive instanceof Directive\BaseDirective) { - return $directive->getData(); + $data = $directive->getData(); + if (isset($data['type']) && $data['type'] === 'DPL.ExecuteCommands') { + $token = $this->getTemplateToken(); + if ($token) { + $data['token'] = $token; + } + } + return $data; } }, $directives))); @@ -296,4 +303,16 @@ public function buildContext(){ } return $context; } + /** + * 自动获取token + * @return string + */ + public function getTemplateToken(){ + $data = $this->request->getData(); + $token = ''; + if (isset($data['context']['Screen']['token'])) { + $token = $data['context']['Screen']['token']; + } + return $token; + } }