本博客是以下博客系列的第二部分:
向导在上一步只生成了一个起点。现在,我们必须添加额外的文件,大数据是什么意思,我们想在我们的模板。"这个"组件.js"生成的模板中缺少文件,因此让我们从该模板开始。
创建"组件.js.tmpl在文件夹"webapp"
Before.Component中,添加以下内容:
"{{basicSAPUI5ApplicationProject.parameters.namespace名称空间.value}}"
在生成模板的过程中,它将被命名空间替换,它是对模板向导中名称空间字段的引用。
完整文件"组件.js.tmpl": https://github.com/lemaiwo/UI5TemplateWithRouting/blob/master/client/src/templatesapui5withroutingplugin/sapui5withrouting/resources/webapp/Component.js.tmpl
为控制器创建文件夹
为控制器创建文件夹视图
插件的文件夹结构应该是这样的
在文件夹控制器中为基本控制器创建一个模板
再次使用之前对名称空间的引用"。控制器.BaseController"要生成控制器的正确名称
"{{basicSAPUI5ApplicationProject.parameters.namespace名称空间.value}}"
完整文件"的"基本控制器.js.tmpl": https://github.com/lemaiwo/UI5TemplateWithRouting/blob/master/client/src/templatesapui5withroutingplugin/sapui5withrouting/resources/webapp/controller/BaseController.js.tmpl
为客户创建模板应用程序控制器.js在文件夹控制器
中,这里我们将使用对名称空间的引用。但我们第一次添加"formatNamespace"。"formatNamespace"将执行一个handlebar函数,微信淘客,我们将在后面定义它。函数将命名空间中的"."替换为"/"
的完整文件应用程序控制器.js.tmpl":https://github.com/lemaiwo/UI5TemplateWithRouting/blob/master/client/src/templatesapui5withroutingplugin/sapui5withrouting/resources/webapp/controller/App.controller.js.tmpl
为客户创建模板App.view.xml文件在文件夹中再次查看
,在控制器名称中添加对命名空间的引用。给应用程序控件一个ID:
Cod for"App.view.xml文件.tmpl":https://github.com/lemaiwo/UI5TemplateWithRouting/blob/master/client/src/templatesapui5withroutingplugin/sapui5withrouting/resources/webapp/view/App.view.xml.tmpl
在视图文件夹中添加一个文件夹"pages",并添加两个模板视图:
使用名称空间引用连接视图使用正确的控制器:
"{{basicSAPUI5ApplicationProject.parameters.namespace名称空间.value}}"
第1页的完整代码。视图.xml.tmpl": https://github.com/lemaiwo/UI5TemplateWithRouting/blob/master/client/src/templatesapui5withroutingplugin/sapui5withrouting/resources/webapp/view/pages/Page1.view.xml.tmpl
代码"第2页。视图.xml.tmpl": https://github.com/lemaiwo/UI5TemplateWithRouting/blob/master/client/src/templatesapui5withroutingplugin/sapui5withrouting/resources/webapp/view/pages/Page2.view.xml.tmpl
在文件夹"controller"中创建一个文件夹"pages",并创建两个模板控制器
使用名称空间引用创建控制器。在控制器的顶部,添加对basecontroller的引用。我们将使用格式化程序"formatNamespace"将所有"."替换为"/"。
Page1的代码。控制器.js.tmpl": https://github.com/lemaiwo/UI5TemplateWithRouting/blob/master/client/src/templatesapui5withroutingplugin/sapui5withrouting/resources/webapp/controller/pages/Page1.controller.js.tmpl
第二控制器相同
代码"第2页。控制器.js.tmpl": https://github.com/lemaiwo/UI5TemplateWithRouting/blob/master/client/src/templatesapui5withroutingplugin/sapui5withrouting/resources/webapp/controller/pages/Page2.controller.js.tmpl
现在我们要更新"的模板"清单.json"文件。我们将更改rootview并配置两个视图之间的路由。
查找以下行:
将它们更改为以下行:
删除if将viewName更改为"App"
向下滚动到manifest文件的底部,并执行以下更改:
更改viewpath将"mainApp"设置为控件id将第一个目标更改为"Page1"创建"Page2"的第二个目标创建第二条路线将每条路线与目标连接
完整文件清单.json.tmpl": https://github.com/lemaiwo/UI5TemplateWithRouting/blob/master/client/src/templatesapui5withroutingplugin/sapui5withrouting/resources/webapp/manifest.json.tmpl
附加,您可以为I18n创建模板并添加css文件
在I18n文件中添加标题翻译
当您完成所有步骤后,您在webapp文件夹中的完整项目将如下所示:
最后一步,企业管理平台软件,我们需要定义handlebar函数。因此,秒单客返利机器人,我们创建一个文件"共享.js在"sapui5withrouting"(可以不同,查淘客,取决于模板的名称)文件夹中
我拿了共享.js调试SAP Web IDE时从另一个模板中删除文件。您可以在此处找到文件的内容:https://github.com/lemaiwo/UI5TemplateWithRouting/blob/master/client/src/templatesapui5withroutingplugin/sapui5withrouting/shared.js
包括这个"共享.js"sapui5"中的文件带路由.js"文件。(这可能会有所不同,具体取决于您为模板选择的名称)。
在"onBeforeTemplateGenerate"函数中,您调用shared.registerHandlebarHelpers文件()" . 这将注册车把功能。
完整的"sapui5"文件带路由.js": https://github.com/lemaiwo/UI5TemplateWithRouting/blob/master/client/src/templatesapui5withroutingplugin/sapui5withrouting/sapui5withrouting.js
我们需要这个步骤来实现"formatNamspace"功能:
在所有这些步骤之后,它看起来是这样的:
右击"测试模板"包.json"->Run->Run As Feature
这将打开一个新窗口,其中SAP Web IDE处于开发模式
(您必须始终以这种方式测试更改,因为它将重新生成资源.zip用于生成项目的文件。只有在开发模式中刷新SAP Web IDE才不会这样做。)
转到文件->新建->模板中的项目
选择您为模板选择的类别并选择您的模板
填写项目名称和名称
此步骤当前未使用,因此您可以忽略此步骤。(这将在下一个博客中添加)
向导完成后,您将有一个新的项目,看起来像这样。选择项目并点击Run
第一个屏幕将显示标题"Page1"和按钮:
当您点击按钮时,您将进入标题为"Page2"的第二个屏幕