附属文件有:basePanel_web.xmltest_web.xmlbackground.png

页面脚本

该脚本在【basePanel_web.xml

创建用户访问的文件,如basePanel_web.xml放在panel路径下

测试访问的网址:http://127.0.0.1/data/ulc/ulc.html?panel=basePanel_web.xml,$token:123

正式访问的网址:https://scadarts11:8081/data/ulc/ulc.html?panel=basePanel_web.xml

内容如下

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
#uses "classes/auth/OaAuthUI"
#uses "panel"

OaAuthUI AuthUI;

/*
需要创建一个Groups为root的用户
如果没有用户,就不能触发点击事件
*/
const string username = "web_embed";
const string password = "web_embed";

/* 保存的内容
1. 需要跳转到哪一个页面(node)
2. token验证(token)
*/
const string DP_WEB_CONTROL = "Message_.";

// 用于存储网页发来的token
string token;

main()
{
// 验证用户信息
AuthUI.setUsername(username);
AuthUI.setPassword(password);

if(AuthUI.getUsername() != "" &&
AuthUI.login() == OaAuthenticationError::None &&
AuthUI.setUiUser())
{
AuthUI.setManagerUser(2);
}
else
{
noticeFailed.visible = true;
}


// 将顶部标题栏去除
titleBar(false);

// 将画面移动到左上角
moveModule(webModule.ModuleName, 0, 0);

// 添加全局变量,防止报错
if(!globalExists("NCC_PT_NODENAMES_GLOBAL"))
{
addGlobal("NCC_PT_NODENAMES_GLOBAL", DYN_LANGSTRING_VAR);
addGlobal("NCC_PT_PANELNUMBER_GLOBAL", DYN_UINT_VAR);
addGlobal("NCC_PT_PARENTNUMBER_GLOBAL", DYN_UINT_VAR);
addGlobal("NCC_PT_DOWNWARDPANEL_GLOBAL", DYN_UINT_VAR);
addGlobal("NCC_PT_UPWARDPANEL_GLOBAL", DYN_UINT_VAR);
addGlobal("NCC_PT_PERMISSIONBIT_GLOBAL", DYN_UINT_VAR);
addGlobal("NCC_PT_FILENAME_GLOBAL", DYN_STRING_VAR);
addGlobal("NCC_PT_PANELTYPE_GLOBAL", DYN_UINT_VAR);
addGlobal("NCC_PT_MODULENAME_GLOBAL", DYN_STRING_VAR);
addGlobal("NCC_PT_SUMALERTNUMBER_GLOBAL", DYN_UINT_VAR);
addGlobal("NCC_PT_MENUBAR_GLOBAL", DYN_UINT_VAR);
addGlobal("NCC_PT_ICONBAR_GLOBAL", DYN_UINT_VAR);
addGlobal("NCC_PT_MODAL_GLOBAL", DYN_BOOL_VAR);
addGlobal("NCC_PT_CENTERED_GLOBAL", DYN_BOOL_VAR);
addGlobal("NCC_PT_PARAMETER_GLOBAL", DYN_STRING_VAR);
addGlobal("NCC_PT_ICONNAME_GLOBAL", DYN_STRING_VAR);
addGlobal("NCC_PT_BACKWARDPANEL_GLOBAL", DYN_UINT_VAR);
addGlobal("NCC_PT_FOREWARDPANEL_GLOBAL", DYN_UINT_VAR);

int error = dpGet("_PanelTopology.nodeName:_online.._value", NCC_PT_NODENAMES_GLOBAL,
"_PanelTopology.panelNumber:_online.._value", NCC_PT_PANELNUMBER_GLOBAL,
"_PanelTopology.parentNumber:_online.._value", NCC_PT_PARENTNUMBER_GLOBAL,
"_PanelTopology.downwardPanel:_online.._value", NCC_PT_DOWNWARDPANEL_GLOBAL,
"_PanelTopology.upwardPanel:_online.._value", NCC_PT_UPWARDPANEL_GLOBAL,
"_PanelTopology.permissionBit:_online.._value", NCC_PT_PERMISSIONBIT_GLOBAL,
"_PanelTopology.fileName:_online.._value", NCC_PT_FILENAME_GLOBAL,
"_PanelTopology.panelType:_online.._value", NCC_PT_PANELTYPE_GLOBAL,
"_PanelTopology.moduleName:_online.._value", NCC_PT_MODULENAME_GLOBAL,
"_PanelTopology.sumAlertNumber:_online.._value", NCC_PT_SUMALERTNUMBER_GLOBAL,
"_PanelTopology.menuBar:_online.._value",NCC_PT_MENUBAR_GLOBAL,
"_PanelTopology.iconBar:_online.._value", NCC_PT_ICONBAR_GLOBAL,
"_PanelTopology.modal:_online.._value", NCC_PT_MODAL_GLOBAL,
"_PanelTopology.centered:_online.._value", NCC_PT_CENTERED_GLOBAL,
"_PanelTopology.parameter:_online.._value", NCC_PT_PARAMETER_GLOBAL,
"_PanelTopology.iconName:_online.._value", NCC_PT_ICONNAME_GLOBAL,
"_PanelTopology.backwardPanel:_online.._value", NCC_PT_BACKWARDPANEL_GLOBAL,
"_PanelTopology.forwardPanel:_online.._value", NCC_PT_FOREWARDPANEL_GLOBAL);
if (error<0)
{
pt_showErrorCeg(error, "");
return;
}
}

// 存储网页传来的token
token = $token;

// 监听函数,监听是否接收到post请求
dpConnect("listenning", 0, DP_WEB_CONTROL);

// 监听函数,监听页面是否切换
string dp;
dp = myUiDpName()+".";
dpConnect("SetBackground",
false,
dp + "RootPanelOrigOn.PanelName:_online.._value",
dp + "RootPanelOrigOn.ModuleName:_online.._value",
dp + "RootPanelOrigOn.FileName:_online.._value");
}

void listenning(string name, string message)
{
mapping m = jsonDecode(message);

// 验证token信息
if(m["token"] != token)
{
return;
}

// 获取跳转页面的名称
string node = m["node"];

// 获取跳转页面的索引,根据这个索引可以查询它的所有信息
int ptIndex = getPTIndex(node);

// 获取对应的pnl或xml文件名称
string path = getPTFileByID(ptIndex);
mapping m = getPTParameter(node);
dyn_string para;
for(int i = 0; i < m.count(); i ++ )
{
para.append(m.keyAt(i) + ":" + m.valueAt(i));
}

// 页面跳转函数
RootPanelOnModule(path,
node,
webModule.ModuleName,
para);
}

void SetBackground(string dpPN, string fNewValuePN, string dpMN, string fNewValueMN, string dpFN, string fNewValueFN)
{
int index = getPTIndex(fNewValuePN);

if(index == 0) return;

if(strpos(fNewValueFN, "ProjectPanels") == -1) return;

string sName;
while(true)
{
try
{
dyn_string sList = getShapes(fNewValueMN, fNewValuePN, "visible");
sName = sList[1];
break;
}
catch
{
DebugTN(__LINE__, getLastException());
}
}

shape sh = getShape(fNewValueMN, fNewValuePN, sName);

shape p = sh.panel;

// 设置背景颜色
p.type = "WebPanel";
string myStyle = "PanelQT[type = \"WebPanel\"] { background-color: rgb(7, 14, 50); }";

p.styleSheet(myStyle);

// 初始化table(防止颜色更改)
myStyle = "PanelQT[type = \"table\"] { background-color: rgb(7, 14, 50); foreground-color: white; }";

p.styleSheet(myStyle);
// p.styleSheet = "PanelQT { background-image: url(pictures:background.png); }";
}

httpServer

该脚本在【test_web.xml

正式内容webclient_http.ctl中,在webclient_http.ctl通过搜索web_switchCB可以定位到对应位置

测试内容如下

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
main()
{
// 开启http服务,(由于测试没有证书,只能开启http服务。在服务器上开启的是https服务)
httpServer(false, 80, 0);

// 当有数据通过post请求发送给http://localhost:80/web_switch的时候
// 会触发web_switchCB监听函数
httpConnect("web_switchCB", "/web_switch", "application/json");
}

const string DP_WEB_MESSAGE = "Message_.";

// 存储node、token
synchronized string web_switchCB(blob content, string user, string ip, dyn_string headerNames, dyn_string headerValues, int connectionIndex)
{
mapping m;
string str;

if(bloblen(content) > 0)
{
blobGetValue(content, 0, str, bloblen(content));
dpSet(DP_WEB_MESSAGE, str);
return "true";
}
else
{
return "false";
}
}

测试脚本(用于发送POST请求)

该脚本在【test_web.xml

post请求给viewstar,将nodetoken存入数据库中。

内容如下

1
2
3
4
5
6
7
8
9
10
11
main()
{
mapping result;
netPost("http://localhost:80/web_switch",
makeMapping("content",
jsonEncode(makeMapping("token", tbTokenName.text, "node", tbNodeName.text)),
"headers",
makeMapping("Content-Type", "application/json")),
result
);
}