Camstar Globally Add VP Restrictions By JS

本文内容仅做参考并不完全通用,测试环境为OpcenterEXCR2410,其中数据均为演示所用无实际意义

将以下工具代码放到指定路径

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/User/PubCommon.js

/**
* @note 公共JS
*/

//禁止粘貼
function _onkeydown(e)
{
var self = null;
if (e) {
self = e;
}
else {
self = window.event;
}
if (self.ctrlKey == true && self.keyCode == '86') {
event.keyCode = 0;
event.returnValue = false;
alert('禁止粘貼');
}
}
var te = null;
//只能输入数字
function _onkeyup(e) {
//te=e;
var txtInput = e.srcElement;
if (!txtInput)
{
txtInput = e.target;
}
var text = txtInput.value;
if (isNaN(parseInt(text)) || text.indexOf(".") > -1)
{
alert("not input no number:" + text);
txtInput.value = '';
return;
}
}
//右键菜单
function _oncontextmenu(e)
{
event.keyCode = 0;
event.returnValue = false;
alert('禁止右鍵');
}
//----------------------------
PubCommon = {
//请求后执行
AfterPostBack:function()
{
if (console && console.log)
console.log("PubCommon.AfterPostBack");
},
//提交前检查控件:function(con){return true}
BeforePostCheckControl: function (con)
{
return true;
},
//提交前检查控件:function(con, other, pageBase){return true}
BeforeSubmitCheckControl: function (con, other, pageBase)
{
return true;
},
//请求完成后
AfterRequestCompleted: function (executor, eventArgs, data)
{
//console.log(data);
}
};
/**
* @note 获取字符串的字节长度
*
* @param str
*/
String.prototype.ByteLength=function()
{
var num = 0;
var arr = this.split("");
for (var i=0;i<arr.length;i++)
{
if (arr[i].charCodeAt(0)< 299)
{
num++;
} else
{
num+=3;
}
}
return num;
}
/**
* @note 按字节长度截取
*
* @param start 指明子字符串的起始位置,该索引从 0 开始起算。
* @param len 指明子字符串的长度
*
*/
String.prototype.SubStringB = function(start, len)
{
//字节数
var num = 0;
var arr = this.split("");
var endi = 0;
var starti = (start > 0 ? -1 : 0);
//最后字符的字节数
var lastNum = 0;
for (var i=0;i<arr.length;i++)
{
if (arr[i].charCodeAt(0)< 299)
{
num++;
lastNum = 1;
} else
{
num+=3;
lastNum = 3;
}
if (start > 0 && starti == -1)
{
if (num == start)
{
starti = i+1;
} else if (num > start)
{
starti = i;
start = num - lastNum;
}
}
//字节数相等
if (num == start + len)
{
endi = i + 1 - starti;
break;
} else if (num > start + len)
{//减去最后开始提前的字符数
endi = i - starti;
break;
}
}
if (endi == 0)
{
endi = arr.length;
}
return this.substr(starti, endi);
}
//初始化
$(function ()
{

//默认页面加载时执行
PubCommon.AfterPostBack();
});

//封装console.log
cmd = {
//支持FF和Opera调试信息
log :function (){
try
{
var msg = '[cmd.log]' + Array.prototype.join.call(arguments, ',');
if (console && console.log)
{
console.log(msg);
if (typeof(arguments[0]) == 'object')
{
console.log(cmd.displayProp(arguments[0]));
} else if (window.opera && window.opera.postError)
{
window.opera.postError(msg);
}
}
}
catch (e)
{
}
},
/**
* 将数组或对象转成字符串信息用于在控制台显示
* console.log(displayProp(obj));
*/
displayProp : function (obj)
{
var names = "";
switch (typeof(obj))
{
case "object":
names += "\n{";
for(var name in obj)
{
names += name+":" + cmd.displayProp(obj[name]) + ",\n";
}
names += "}\n";

break;
case "undefined":
names = "undefined";
break;
case "string":
names = '"'+obj+'"';;
break;
case "function":
names = '"function"';;
break;
default:
names = obj;
}
return names;
},
goto : function (url) {
$(location).attr('href', url);
},
showNavigator : function(){
cmd.log(window.navigator.appCodeName, window.navigator.appMinorVersion,
window.navigator.appName, window.navigator.appVersion,
window.navigator.platform, window.navigator.userAgent);
},
checkPlus : function (){
try
{
plus;
return true;
}
catch (e)
{
cmd.log(e.message);
return false;
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/User/UserJs.aspx

<% @ Page Language="C#" %>
<%@ Import namespace = "System.Text.RegularExpressions" %>
<%@ Import namespace = "System.IO" %>
<%
//Camstar Portal\AJAXMasterPage.master
//获取引用地址
string referUrl = Request.ServerVariables["HTTP_REFERER"];
//UserDll.PubCommon.SaveLog(referUrl);
if (!string.IsNullOrEmpty(referUrl))
{
//文件名
string fileName = string.Empty;
string VPfileName = string.Empty;

//解析服务名
Regex r = new Regex("&ServiceName=([^&]*)");
Match m = r.Match(referUrl);
if (m.Success)
{
fileName = m.Groups[1].Value;
//UserDll.PubCommon.SaveLog(fileName+"21");
}
//解析页面
Regex VPR = new Regex("/([^/]*).aspx");
Match VPM = VPR.Match(referUrl);
//UserDll.PubCommon.SaveLog(m.Success.ToString());
if (VPM.Success)
{
VPfileName = VPM.Groups[1].Value;
//UserDll.PubCommon.SaveLog(fileName+"31");
}
//存在服务文件名
//if (!string.IsNullOrEmpty(fileName))
//{
// //按服务名查找js文件
// string jsFile = Server.MapPath("~/User/" + fileName + ".js");
// if (!string.IsNullOrEmpty(fileName) && File.Exists(jsFile))
// {
// //返回服务名对应js内容
// Response.Write(File.ReadAllText(jsFile));
// }
//}
//存在vp文件名
if (!string.IsNullOrEmpty(VPfileName))
{
//按服务名查找js文件
string jsFile = Server.MapPath("~/User/" + VPfileName + ".js");
if (!string.IsNullOrEmpty(VPfileName) && File.Exists(jsFile))
{
//返回服务名对应js内容
Response.Write(File.ReadAllText(jsFile));
}
}
}
%>

在文件中引用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/AJAXMasterPageResponsive.master

<%-- Copyright Siemens 2019 --%>

<%@ master language="C#" codefile="AJAXMasterPageResponsive.master.cs" autoeventwireup="true" inherits="Camstar.Portal.AJAXMasterPageResponsive" %>
<!doctype html>
<html>
<head runat="server">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>Opcenter Execution</title>
<asp:PlaceHolder runat="server">
<%= this.styleSheetString %>
</asp:PlaceHolder>
</head>
<body class="body-main fullScreen cs-responsive <%=currentTheme%>-theme AJAXMasterResponsive-page">
<div id="mod" class="mod" style="display: none">
<div id="modImage" class="modImage">
<img src="themes/<%=currentTheme%>/images/icons/loading-128x128.gif" alt="" />
</div>
</div>
<form id="AJAXForm" novalidate runat="server" style="height: 100%">
<cwpf:WebPartFrameworkManager ID="WebPartManager" runat="server" EnableClientScript="false" />
<asp:ScriptManager ID="ScriptManager" runat="server" EnablePartialRendering="true" EnableCdn="false" EnableScriptGlobalization="true">
<scripts>
<asp:ScriptReference Name="jquery"/>
<asp:ScriptReference Path="~/Scripts/jquery/jquery.ui.touch-punch.min.js" />
<asp:ScriptReference Name="bootstrap"/>
<asp:ScriptReference Name="camstar"/>
<asp:ScriptReference Name="camstar.webcontrols"/>
<asp:ScriptReference Name="camstar.scripts"/>
<asp:ScriptReference Path="~/Scripts/jquery/tiny_mce/tinymce.min.js" />
<asp:ScriptReference Path="~/Scripts/jquery/datepicker/jquery-ui-timepicker-addon.js" />
<asp:ScriptReference Name="camstar.webcontrols.jqGrid"/>
<asp:ScriptReference Path="~/Scripts/jsPlumb/jsplumb.js" />
<asp:ScriptReference Name="workspaceoverride"/>
<asp:scriptreference path="~/Scripts/User/User.js" />
<asp:scriptreference path="~/User/PubCommon.js" />
<asp:scriptreference path="~/User/UserJs.aspx" />
</scripts>
</asp:ScriptManager>
<cwfw:label runat="server" Visible="false" ID="YesLabel" LabelName="Web_Yes" LabelType="Designer" />
<cwfw:label runat="server" Visible="false" ID="NoLabel" LabelName="Web_No" LabelType="Designer" />
<cwfw:label runat="server" Visible="false" ID="OkLabel" LabelName="OKButton" LabelType="Designer" />
<cwfw:label runat="server" Visible="false" ID="CloseLabel" LabelName="Web_Close" LabelType="Designer" />
<cwfw:label runat="server" Visible="false" ID="MessageTitleLabel" LabelName="ConfirmationMessageTitle" LabelType="Designer" />
<div class="form-container">
<div class="scrollable-panel">
<cwpf:webpartbasezone id="StaticZoneTop" cssclassbrowse="zone-static" runat="server">
<zonetemplate>
<cwpfc:statusbarcontrol ID="StatusBar" runat="server" />
<cwpfc:workflowprogress ID="WorkflowProgressButtonsBar" runat="server" />
</zonetemplate>
</cwpf:webpartbasezone>
<div class="pageTitleMobile">
<span class="pageTitle"></span>
</div>
<div id="DynamicContentDiv" >
<div id="TemplateContentDiv" class="ui-form-contentpanel">
<asp:contentplaceholder id="AJAXContentPlaceHolder" runat="server" />
</div>
</div>
</div>
<cwpfc:SideBar ID="SideBarRight" Side="Right" IsResponsive="true" runat="server" />
<div class="bottom-panel-container">
<div class="bottom-panel">
<cwpf:webpartbasezone id="StaticZoneBottom" cssclassbrowse="zone-static" runat="server">
<ZoneTemplate>
<cwpfc:buttonsbarcontrol ID="ButtonsBar" runat="server" />
<cwpfc:workflownavigationbuttons id="NavigationButtonsBar" runat="server" />
</ZoneTemplate>
</cwpf:webpartbasezone>
</div>
</div>
</div>
<csc:FloatingFrame ID="FloatingFrame" runat="server" />
</form>

<script type="text/javascript">
Sys.Application.add_load(function ()
{
__page = $find("__Page");
window.addEventListener("orientationchange", function (e) {
if (__page)
__page.closePanels(e);
});

var redirectPageFlow = '<%=RedirectPageflow%>';
var redirectPage = '<%=RedirectPage%>';
if (redirectPageFlow.length)
{
__page.pageflow('<%=RedirectPageflow%>', '<%= CallStackKey %>', '<%= ResumeWorkflow %>', '<%= QualityObject %>');
}
else if (redirectPage.length)
{
__page.redirect(redirectPage);
}
else
{
__page.set_virtualPageName('<%= PageName %>');
__page.set_queryString('<%= Query %>');
__page.setFocusOnLoad();
}

// initialize mobile barcode if enabled
if (__page._mobileBarcodeEnabled && __page.isMobilePage())
{
if (!Camstars.Browser.IE) {
InitBarcodeIcons();
}
}
});
</script>
</body>
</html>

示例:设备上料页面添加输入限制

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/User/ahEquipmentMaterialsSetupVP.js

//禁用输入只能扫描
PubCommon.AfterPostBack = function ()
{
var time1 = 0;
var time2 = 0;
var textLengthLast = 0;
var inputEle = document.getElementById('ctl00_WebPartManager_SS_WIPEqpMaterialsSetupWP_WIPEqpMaterialsSetup_MaterialLotNameNew_ctl00');

//var chineseReg = /[\u4e00-\u9fa5]/g;

//禁止粘貼
//inputEle.onkeydown = _onkeydown;

//禁止手动输入
//inputEle.onkeyup = function (e) {
// var text = inputEle.value;
// var textLengthNow = text.length;
// if (textLengthNow > textLengthLast) {
// if (time1 == 0) {
// var gettime1 = new Date();
// time1 = gettime1.getTime();
// }
// else {
// if (textLengthLast == 0 && textLengthNow == 1) {
// var gettime1 = new Date();
// time1 = gettime1.getTime();
// }
// var gettime2 = new Date();
// time2 = gettime2.getTime();
// if (time2 - time1 > 500) {
// inputEle.value = '';
// time1 = 0;
// time2 = 0;
// alert('请扫描条码,不可手动输入,违者记过处理!');
// inputEle.value = '';
// return;
// }
// }
// }
// textLengthLast = textLengthNow;
//}

// 禁止输入中文
//inputEle.oninput = function () {
// var val = inputEle.value;
// if (chineseReg.test(val)) {
// inputEle.value = val.replace(chineseReg, '');
// alert('不允许输入中文,违者罚款一万元!');
// }
//};

document.addEventListener('input', function (e) {
if (e.target &&
e.target.id === 'ctl00_WebPartManager_SS_WIPEqpMaterialsSetupWP_WIPEqpMaterialsSetup_MaterialLotNameNew_ctl00') {

var chineseReg = /[\u4e00-\u9fa5]/g;
if (chineseReg.test(e.target.value)) {
e.target.value = e.target.value.replace(chineseReg, '');
alert('不允许输入中文,违者罚款一万元!');
e.target.value = '';
}
}
});

//禁止右鍵
inputEle.oncontextmenu = _oncontextmenu;

//console.log("车间生产->设备上料.AfterPostBack");
}

//$(function()
//{
// PubCommon.AfterPostBack();
//});

效果如下: