news 2026/4/16 18:22:45

SAPUI5 1.71.78老版本的消费restful服务

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
SAPUI5 1.71.78老版本的消费restful服务

为了兼容老浏览器,没用Javascript的现代fetch api,用的jquery

controller.js代码如下

sap.ui.define([ "sap/ui/core/mvc/Controller", "sap/ui/model/json/JSONModel", "sap/m/MessageToast" ], function (Controller, JSONModel, MessageToast) { "use strict"; return Controller.extend("zfiori_stock.controller.StockList", { onInit: function () { // 初始化stock模型 var oStockModel = new JSONModel([]); this.getView().setModel(oStockModel, "stock"); }, /** * 重置查询条件并清空表格数据 */ _resetQuery: function () { this._clearInputs(); // 清空表格数据 var oStockModel = this.getView().getModel("stock"); oStockModel.setData({}); MessageToast.show("查询条件已重置"); }, /** * 清空所有输入框 */ _clearInputs: function () { this.getView().byId("werksInput").setValue(""); this.getView().byId("matnrInput").setValue(""); this.getView().byId("chargInput").setValue(""); this.getView().byId("lgortInput").setValue(""); }, /** * 获取库存数据 * 兼容Android 8平台的老浏览器 */ _fetchStockData: function () { // 后端API信息 var sUrl = "/api/zbakpda?ACTION=GET_STOCK"; // 从输入框获取查询条件 var oRequestData = { "werks": this.getView().byId("werksInput").getValue(), "matnr": this.getView().byId("matnrInput").getValue(), "charg": this.getView().byId("chargInput").getValue(), "lgort": this.getView().byId("lgortInput").getValue() }; // 显示加载提示 MessageToast.show("正在查询数据..."); // 使用jQuery.ajax以兼容老浏览器 jQuery.ajax({ url: sUrl, type: "POST", data: JSON.stringify(oRequestData), headers: { "Content-Type": "application/json", "Accept-Language": "zh" // "Authorization": sAuthHeader }, // 兼容老浏览器的参数设置 dataType: "json", xhrFields: { withCredentials: true }, timeout: 30000, //通过 jQuery.proxy(fn, this),强制绑定了函数执行时的 this 上下文为当前控制器。 success: jQuery.proxy(function (oData) { // 将返回数据绑定到stock模型 var oStockModel = this.getView().getModel("stock"); if (oStockModel) { if (oData.length != 0) { MessageToast.show("库存数据获取成功"); } else { MessageToast.show("返回数据为空"); } oStockModel.setData(oData); } }, this), error: jQuery.proxy(function (xhr, status, error) { console.error("获取库存数据失败:", error); console.error("状态码:", xhr.status); // 友好的错误提示 var sErrorMessage = "获取库存数据失败"; if (xhr.status === 401) { sErrorMessage = "认证失败,请检查账号密码"; } else if (xhr.status === 404) { sErrorMessage = "服务器地址错误"; } else if (xhr.status === 500) { sErrorMessage = "服务器内部错误"; } MessageToast.show(sErrorMessage); }, this) }); } }); });

xml视图代码

<mvc:View controllerName="zfiori_stock.controller.StockList" xmlns="sap.m" xmlns:l="sap.ui.layout" xmlns:mvc="sap.ui.core.mvc"> <Panel class="sapUiResponsiveContentPadding"> <headerToolbar> <Toolbar> <Button text="查询" press="_fetchStockData" icon="sap-icon://search" class="sapUiSmallMarginEnd" /> <Button text="重置" press="_resetQuery" icon="sap-icon://refresh" /> </Toolbar> </headerToolbar> <l:Grid defaultSpan="L6 M6 S6" class="sapUiResponsiveMargin" vSpacing="1"> <l:content> <!-- 工厂 --> <FlexBox class="sapUiTinyMarginBottom" alignItems="Center"> <Label text="工厂:" labelFor="werksInput" width="80px" /> <Input id="werksInput" width="100%" /> </FlexBox> <!-- 库存地点 --> <FlexBox class="sapUiTinyMarginBottom" alignItems="Center"> <Label text="库存地点:" labelFor="lgortInput" width="80px" /> <Input id="lgortInput" width="100%" /> </FlexBox> <!-- 物料 --> <FlexBox class="sapUiTinyMarginBottom" alignItems="Center"> <Label text="物料:" labelFor="matnrInput" width="80px" /> <Input id="matnrInput" width="100%" /> </FlexBox> <!-- 批次 --> <FlexBox class="sapUiTinyMarginBottom" alignItems="Center"> <Label text="批次:" labelFor="chargInput" width="80px" /> <Input id="chargInput" width="100%" /> </FlexBox> </l:content> </l:Grid> <Table id="stockList" class="sapUiResponsiveMargin" width="100%" items="{ path : 'stock>/' }" noDataText="暂无数据"> <columns> <Column minScreenWidth="Phone" demandPopin="true" hAlign="Left"> <Text text="物料编码" /> </Column> <Column minScreenWidth="Phone" demandPopin="true" hAlign="Left"> <Text text="物料描述" /> </Column> <Column minScreenWidth="Tablet" demandPopin="true"> <Text text="工厂" /> </Column> <Column minScreenWidth="Tablet" demandPopin="true"> <Text text="库存地点" /> </Column> <Column minScreenWidth="Tablet" demandPopin="true"> <Text text="库存地点名称" /> </Column> <Column minScreenWidth="Tablet" demandPopin="true"> <Text text="批次" /> </Column> <Column minScreenWidth="Tablet" demandPopin="true"> <Text text="库存数量" /> </Column> <Column minScreenWidth="Tablet" demandPopin="true"> <Text text="单位" /> </Column> </columns> <items> <ColumnListItem> <cells> <Text text="{stock>matnr}" /> <Text text="{stock>maktx}" /> <Text text="{stock>werks}" /> <Text text="{stock>lgort}" /> <Text text="{stock>lgobe}" /> <Text text="{stock>charg}" /> <Text text="{stock>clabs}" /> <Text text="{stock>meins}" /> </cells> </ColumnListItem> </items> </Table> </Panel> </mvc:View>

ui5.yaml配置代理,解决cors跨域

specVersion: "4.0" metadata: name: zfiori_stock type: application server: customMiddleware: - name: ui5-middleware-simpleproxy afterMiddleware: compression mountPath: /api configuration: baseUri: "http://后端ip:port" preserveHostHeader: true ignoreCertErrors: true headers: X-Requested-With: XMLHttpRequest
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/16 10:39:30

vLLM多模态输入:图像、视频与音频处理全解析

vLLM 多模态输入&#xff1a;图像、视频与音频处理全解析 在生成式 AI 快速演进的今天&#xff0c;单一文本推理已无法满足复杂应用场景的需求。从智能客服中的图文问答&#xff0c;到教育平台上的音视频内容理解&#xff0c;再到工业质检中的视觉分析——多模态能力正成为大模…

作者头像 李华
网站建设 2026/4/16 10:44:58

LobeChat能否支持盲文输出?视障人士友好交互模式探索

LobeChat能否支持盲文输出&#xff1f;视障人士友好交互模式探索 在智能对话系统日益普及的今天&#xff0c;AI聊天界面几乎成了数字生活的标配。从客服机器人到个人助手&#xff0c;用户只需敲几下键盘或说一句话&#xff0c;就能获得即时响应。然而&#xff0c;这种“便捷”是…

作者头像 李华
网站建设 2026/4/16 10:40:32

计算机毕业设计 | SpringBoot宠物店 宠物医院管理系统(附源码)

1&#xff0c;绪论 1.1 项目背景 我国已经成为世界第二大经济体&#xff0c;经济实力高速发展以及百姓生活水平的普遍提高&#xff0c;不断地要求企业提供更加多元化的娱乐方式&#xff0c;更加快速和方便的服务&#xff0c;因此对宠物行业也提出了更加严格的要求&#xff0c…

作者头像 李华
网站建设 2026/4/16 11:05:23

YOLO目标检测实战:GPU算力如何提升推理效率

YOLO目标检测实战&#xff1a;GPU算力如何提升推理效率 在一条高速运转的智能制造产线上&#xff0c;每秒都有成百上千个零件经过视觉质检系统。如果检测延迟超过50毫秒&#xff0c;机械臂就无法及时剔除缺陷品——这不仅意味着质量失控&#xff0c;更会造成整条产线停摆。这样…

作者头像 李华
网站建设 2026/4/16 0:27:23

Google 全新的 AI 浏览器 DISCO

https://labs.google/disco 来自Google Chrome Team https://www.youtube.com/GoogleChrome The web is a vast collection of applications and information, making it an incredible engine for discovery and learning. Yet, as our online tasks have grown more compl…

作者头像 李华
网站建设 2026/4/16 12:18:42

本地部署Qwen3-8b大模型完整指南

本地部署 Qwen3-8B 大模型完整指南 在当前生成式 AI 快速发展的浪潮中&#xff0c;越来越多开发者不再满足于调用云端 API&#xff0c;而是希望将大模型真正“握在手中”——既能保障数据隐私&#xff0c;又能深度定制和优化推理流程。阿里云推出的 Qwen3-8B 正是这一趋势下的…

作者头像 李华