需求背景:
出于公司机密需要,手机端fiori 访问sap 需要添加水印功能。尝试使用UI Theme Designer
修改主题,发现不太好使,且sap主题只在颜色,尺寸,版式及背景图片和logo做了一些设计。
实现方式:
通过修改服务html页面实现,不管是webgui 还是fiori Lunchpad 在SAP gui 都有一个处理器类方法:
1、tcode:sicf 通过输入服务名称:webgui 找到处理器的START_WEBGUI_PASS1方法
在此类方法里面增强
2、tcode:sicf 通过输入服务名称:flp 找到处理器的SAVE_MEASUREMENT_HTTP方法
在此类方法增强
代码片段:
FORM frm_change_html CHANGING cv_html TYPE string.
DEFINE append_string.
CONCATENATE lv_string &1 cl_abap_char_utilities=>cr_lf INTO lv_string.
END-OF-DEFINITION.
DATA: lv_string TYPE string,
lv_string2 TYPE string,
lv_char TYPE char10.
DATA: lr_table_des TYPE REF TO cl_abap_structdescr.
SELECT * FROM ztits001 WHERE ztext <> '' INTO TABLE @DATA(lt_ztits001).
SORT lt_ztits001 BY zline.
CHECK lt_ztits001[] IS NOT INITIAL.
LOOP AT lt_ztits001 INTO DATA(ls_ztits001).
lv_string = |{ lv_string }{ ls_ztits001-ztext }{ cl_abap_char_utilities=>cr_lf }|.
ENDLOOP.
TRY.
lr_table_des ?= cl_abap_typedescr=>describe_by_data( sy ).
DATA(lt_compdescr) = lr_table_des->components[].
LOOP AT lt_compdescr INTO DATA(ls_compdescr).
lv_char = |&{ ls_compdescr-name }|.
FIND FIRST OCCURRENCE OF lv_char IN lv_string.
CHECK sy-subrc = 0.
ASSIGN COMPONENT ls_compdescr-name OF STRUCTURE sy TO FIELD-SYMBOL(<fs_value>).
CHECK sy-subrc = 0 AND <fs_value> IS ASSIGNED.
lv_string2 = <fs_value>.
REPLACE lv_char IN lv_string WITH lv_string2.
ENDLOOP.
lv_string = |<script>{ lv_string }</script></html>|.
REPLACE '</html>' IN cv_html WITH lv_string.
CATCH cx_sy_conversion_error INTO DATA(exc).
ENDTRY.
ENDFORM.
js水印配置表内容:
1 function WaterMarker(str){
2 var can = document.createElement('canvas');
3 var body = document.body;
4 can.width=200; //画布的宽
5 can.height=120;//画布的高度
6 can.style.display='none';
7 var cans = can.getContext('2d');
8 cans.rotate(-20*Math.PI/180); //画布里面文字的旋转角度
9 cans.font = "15px Microsoft JhengHei"; //画布里面文字的字体
10 cans.fillStyle = "rgba(17, 17, 17, 0.50)";//画布里面文字的颜色
11 cans.textAlign = 'left'; //画布里面文字的水平位置
12 cans.textBaseline = 'Middle'; //画布里面文字的垂直位置
13 cans.fillText(str,10,120); //画布里面文字的间距比例
14 let waterMarkPage = document.createElement('div');
15 waterMarkPage.id = "waterMark"
16 let style = waterMarkPage.style;
17 style.position = 'fixed';
18 style.overflow = "hidden";
19 style.left = 0;
20 style.top = 0;
21 style.opacity = '0.4';
22 style.background = "url(" + can.toDataURL("image/png") + ")";
23 style.zIndex = 999;
24 style.pointerEvents = "none";
25 style.width = '100%';
26 style.height = '100vh';
27 document.body.appendChild(waterMarkPage);
28 }
29 WaterMarker("&UNAME-&DATUM");
配置表截图
最终结果(fiori Lunchpad)