httprequest代码: 只有登录页的文本框有输入焦点。 其他页面的文本输入框无焦点。
Dim path As String = "foxtableAppTest"
Dim wb As New weui
'身份验证
Dim Verified As Boolean '用于标记用户是否通过了身份验证
Dim UserName As String = e.Cookies("username") '从cookie中获取用户名
Dim Password As String = e.Cookies("password") '从cookie中获取用户密码
If e.Path = "logon.htm" '如果是通过登录页面访问,重新从PostValues中提取用户名和密码
If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password") Then
UserName = e.PostValues("username")
Password = e.PostValues("password")
End If
End If
If UserName = "001" AndAlso Password = "999"
Verified = True
End If
If Verified AndAlso e.Path = "logon.htm" Then '如果用户访问的是登录页,且身份验证成功
wb.AppendCookie("username",UserName) '将用户名和密码写入cookie
wb.AppendCookie("password",Password)
wb.InsertHTML("<meta http-equiv='Refresh' c>") '直接跳转到首页
e.WriteString(wb.Build) '生成网页
Return '必须的
ElseIf Verified = False AndAlso e.Path <> "logon.htm" Then '如果用户身份验证失败,且访问的不是登录页面
wb.InsertHTML("<meta http-equiv='Refresh' c>") '那么直接跳转到登录页面
e.WriteString(wb.Build) '生成网页
Return '必须的
End If
'开始生成网页
Select Case e.path
Case "logon.htm" '登录页面
wb.AddPageTitle("","pageheader","首页","")
If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password") Then '判断是否是验证失败后的重新登录
wb.AddTopTips("","toptip1","用户名或密码错误!").msec = 2000 '如果用户通过登录按钮访问,则给用户一个2秒的提示.
End If
wb.AddForm("","form1","logon.htm")
With wb.AddInputGroup("form1","ipg1")
.AddInput("username","账号","text")
.AddInput("password","密码","password")
End With
With wb.AddInputGroup("form1","ipg12")
.AddInput("扫码号","扫码号","text")
End With
With wb.AddButtonGroup("form1","btg1",True)
.Add("btn1", "登录", "submit")
End With
Case "", "default.htm" '首页
wb.DeleteCookie("ScanGp")
wb.AddPageTitle("","pageheader","首页","")
With wb.AddGrid("","g1")
.Add("c1","车架扫码", "./images/scan.png", "scan.htm") '车架扫码页面
.Add("c2","Dialog", "./images/dev.png").Attribute = ""
.Add("c3","Progress", "./images/dev.png").Attribute = ""
.Add("c4","Panel", "./images/dev.png").Attribute = ""
.Add("c5","Tab", "./images/dev.png").Attribute = """
.Add("c6","退出", "./images/exit.png", "exit.htm") '退出登录
End With
wb.AddToast("","t3","页面待开发",0).Icon = "info"
wb.AddProgress("","t4",False,20)
With wb.AddDialog("","dlg1", "","")
.AddButton("btnOK","确定")
End With
Case "scan.htm"
If e.Cookies.ContainsKey("ScanGp")
Else
wb.AppendCookie("ScanGp",Format(Date.Today,"yyyyMMdd") & Rand.NextString(6))
End If
With wb.AddTabBar("", "tb1", 0)
.AddPage("page1","扫码","./images/scan.png")
.AddPage("page2","清单","./images/list.png")
.AddPage("page3","轨迹","./images/track.png")
.AddPage("page4","设置","./images/order.png")
.AddButton("bt1","返回","./images/exit.png","default.htm")
End With
wb.AppendHTML("<script type='text/javascript' src='/" & path & "/js/common.js'></script>", True)
wb.AppendHTML("<link rel='stylesheet' href='/" & path & "/css/common.css' Type='text/css' charset='utf-8'/>", True)
wb.AppendHTML("<script type='text/javascript' src='/" & path & "/js/ajaxform.js'></script>", True)
'第一个页面,车架扫码
wb.AddForm("page1","form1","addcode.htm")
Dim frs As List(of String) = DataTables("tb_Order").GetValues("OrderID","Status = '1'")
With wb.AddInputGroup("form1","ipg1","扫描号")
.AddSelect("扫码事件","扫码事件","11.正常入库|40.正常出库")
.AddSelect("订单号","订单号",String.Join("|",frs.ToArray))
.AddInput("扫码号","扫码号","Text")
End With
With wb.AddInputGroup("form1","ipg13")
.AddInput("username","账号","text")
.AddInput("password","密码","password")
End With
With wb.AddButtonGroup("form1","btg1",True)
.Add("btn1", "扫一扫", "button").Attribute = " & path & "/plus/barcode_scan.html',true,true);"""
End With
With wb.AddButtonGroup("form1","btg2",False)
'.Add("btn3","提交","button").Attribute = ""
'.Add("btn2", "返回", "button").Attribute = ""
.Add("btn2", "返回", "button","default.htm")
End With
wb.InsertHTML("form1","<div id='p2' style='margin:0.5em'></div>") '插入一个div,用于显示服务器返回的页面
'wb.InsertHTML("<script>function scaned( t, r, f ) {plus.nativeUI.alert('扫描返回的信息如:\n编码:' + t + '\n内容:' + r + '\n图片存放路径(在手机端):' + f);}</script>")
wb.InsertHTML("<script>function scaned( t, r, f ) {document.getElementById('扫码号').value=r;addcode();}</script>")
'wb.InsertHTML("<script>function scaned( t, r, f ) {document.form1.submit();}</script>")
Case "exit.htm" '退出登录
wb.DeleteCookie("username") '清除cookie中原来的用户名和密码
wb.DeleteCookie("password")
wb.InsertHTML("<meta http-equiv='Refresh' c>") '那么直接跳转到登录页面
End Select
e.WriteString(wb.Build) '生成网页