以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  集成照片上传和录入功能  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=178559)

--  作者:一笑
--  发布时间:2022/7/9 18:08:00
--  集成照片上传和录入功能
参考帮助文档照片上传代码,录入代码(蓝色),单独使用都无问题,想在一个页面上实现2个功能,但代码放一起,都不管用,求解,谢谢!
    Case "upload.htm"
        wb.AddForm("","form1","receive.htm")
        With wb.AddInputGroup("form1","ipg2","文件上传")
        With .AddUploader("up128","照片",True)
        .AllowDelete = True \'允许删除
        .Incremental = True \'允许 重复选择文件或连续拍照
        End With
        End With
        With wb.AddButtonGroup("form1","btg2",True)
        .Add("btn1", "确定上传", "button").Attribute= "" \'调用js函数上传
        End With
        wb.AddToast("","tst1", "正在上传",1)
        wb.AddToast("","tst2", "上传成功",0)
        wb.AddToast("","tst3", "上传失败",0).Icon= "warn"
        wb.AppendHTML("<script src=\'./lib/ajaxform.js\'></script>") \'引入脚本文件
        
        If e.PostValues.Count = 0 Then \'生成增加工作网页
            wb.AddForm("","form1","upload.htm")
            With wb.AddInputGroup("form1","ipg1","增加工作")
                .AddInput("责任单位","责任单位","text")
            End With
        Else \'保存新增的工作
            Dim dr As DataRow = DataTables("飞机引进工作单").AddNew()
            Dim nms() As String = {"责任单位"}
            For Each nm As String In nms
                dr(nm) = e.PostValues(nm)
            Next
            dr.Save()
            With wb.AddMsgPage("","msgpage","增加成功", "工作顺利") \'增加工作成功提示信息
                .AddButton("btn1","继续增加","upload.htm").Attribute= "style=\'background-color:LightSeaGreen;\'"
                .AddButton("btn1","返回","upload.htm").Attribute= "style=\'background-color:Aqua;\'"
            End With
        End If
        e.WriteString(wb.Build) \'生成网页
    Case "receive.htm"
        For Each key As String In e.Files.Keys
            For Each fln As String In e.Files(key)
                e.SaveFile(key,fln,"d:\\web\\uploadfiles\\" & fln) \'保存接收到的文件
            Next
        Next
        e.WriteString("OK")
        
End Select

--  作者:tongliaozyr
--  发布时间:2022/7/9 18:10:00
--  
收藏了
--  作者:有点蓝
--  发布时间:2022/7/10 20:38:00
--  

    Case "upload.htm"
        wb.AddForm("", "form1", "receive.htm")
        With wb.AddInputGroup("form1", "ipg2", "文件上传")
            With .AddUploader("up128", "照片", True)
                .AllowDelete = True \'允许删除
                .Incremental = True \'允许 重复选择文件或连续拍照
            End With
        End With
        With wb.AddInputGroup("form1", "ipg1", "增加单位")
            .AddInput("责任单位", "责任单位", "text")
        End With
        With wb.AddButtonGroup("form1", "btg2", True)
            .Add("btn1", "确定上传", "button").Attribute = "" \'调用js函数上传
        End With
        wb.AddToast("", "tst1", "正在上传", 1)
        wb.AddToast("", "tst2", "上传成功", 0)
        wb.AddToast("", "tst3", "上传失败", 0).Icon = "warn"
        wb.AppendHTML("<script src=\'./lib/ajaxform.js\'></script>") \'引入脚本文件
        e.WriteString(wb.Build) \'生成网页
    Case "receive.htm"
        Dim dr As DataRow = DataTables("飞机引进工作单").AddNew()
        Dim nms() As String = {"责任单位"}
        For Each nm As String In nms
            dr(nm) = e.PostValues(nm)
        Next
        For Each key As String In e.Files.Keys
            If key = "up128" Then
                For Each fln As String In e.Files(key)
                    e.SaveFile(key, fln, "d:\\web\\uploadfiles\\" & fln)
                Next
                dr.Lines("照片") = e.Files(key)
            End If
        Next
        dr.Save()
        e.WriteString("OK")
End Select
[此贴子已经被作者于2022/7/10 20:38:36编辑过]

--  作者:一笑
--  发布时间:2022/7/18 10:58:00
--  
在电脑端http://127.0.0.1/测试正常,发布在服务器后,无反应,求解,谢谢!
--  作者:有点蓝
--  发布时间:2022/7/18 11:09:00
--  
服务器也是使用的d:\\web\\目录吗,js 文件有放到服务器了吗
--  作者:一笑
--  发布时间:2022/8/9 10:27:00
--  
参考指南http://www.foxtable.com/mobilehelp/topics/0083.htm,增加TopTips用于在页面顶端临时显示信息功能,增加了代码,但不起作用,求解,谢谢!
Case "upload.htm"
        wb.AddForm("", "form1", "receive.htm").Attribute = ""
        With wb.AddInputGroup("form1", "ipg2", "文件上传")
....
wb.AppendHTML("<script src=\'./lib/valid.js\'></script>"\'引入脚本文件

--  作者:有点蓝
--  发布时间:2022/8/9 10:35:00
--  
贴出完整代码
--  作者:一笑
--  发布时间:2022/8/9 10:52:00
--  
 Case "testupload.htm"
            wb.AddTopTips("","toptip1","请输入安全隐患名称和地点!")
            wb.AddForm("", "form1", "receive.htm").Attribute = "" \'调用函数
            With wb.AddInputGroup("form1","ipg1","安全隐患上报")
                .AddInput("yhm","隐患名称","text")
                .AddInput("yhd","隐患地点","text")
            End With
            
            With wb.AddInputGroup("form1", "ipg4", "安全随手拍")
                With .AddUploader("up128", "照片", True)
                    .AllowDelete = True \'允许删除
                    .Incremental = True \'允许 重复选择文件或连续拍照
                    .Accept = "image/*"   \'允许使用相册和相机
                    .ScaleWidth = 600
                End With
            End With
            With wb.AddButtonGroup("form1", "btg2", False)
                .Add("btn1", "确定上报", "button").Attribute= "" \'调用js函数上传
            End With
            wb.AddToast("", "tst1", "正在上传", 1)
            wb.AddToast("", "tst2", "上传成功", 0)
            wb.AddToast("", "tst3", "上传失败", 0).Icon = "warn"
            wb.AppendHTML("<script src=\'./lib/valid.js\'></script>") \'引入脚本文件
            wb.AppendHTML("<script src=\'./lib/ajaxform.js\'></script>") \'引入脚本文件
            
        Case "receive.htm"
            Dim dr As DataRow = DataTables("安全报告").AddNew()
            dr("安全隐患名称") = e.PostValues("yhm")
            dr("安全隐患地点") = e.PostValues("yhd")
            For Each key As String In e.Files.Keys
                If key = "up128" Then
                    For Each fln As String In e.Files(key)
                        e.SaveFile(key, fln, "d:\\web\\uploadfiles\\" & fln)
                    Next
                    dr.Lines("上传文件") = e.Files(key)
                End If
            Next
            dr.Save()
            e.WriteString("OK")             
    End Select


js代码:
function valid(){
   var v1 = document.getElementById("yhm").value;
   var v2 = document.getElementById("yhd").value;
   if (v1 && v2){return true}
   show("toptip1",2000);
   return false;
}


--  作者:有点蓝
--  发布时间:2022/8/9 11:34:00
--  
我照帮助测试没有问题

Select Case e.Path
    Case "test.htm"
        Dim wb As New WeUI
        wb.AddTopTips("", "toptip1", "请输入姓名和密码!")
        wb.AddForm("", "form1", "t2.htm").Attribute = "onsubmit=\'return valid()\'" \'调用函数
        With wb.AddInputGroup("form1", "ipg1", "用户登录")
            .AddInput("xm", "户名", "text")
            .AddInput("pw", "密码", "password")
        End With
        With wb.AddButtonGroup("form1", "btg1", True)
            .Add("btn1", "确定", "submit")
        End With
        wb.AppendHTML("<script src=\'./lib/valid.js\'></script>") \'引入脚本文件
        e.WriteString(wb.Build)
    Case "t2.htm"
        Dim sb As New StringBuilder
        sb.AppendLine("<meta name=\'viewport\' content=\'width=device-width,initial-scale=1,user-scalable=0\'>")
        For Each key As String In e.PostValues.Keys
            sb.AppendLine(key & ":" & e.PostValues(key) & "</br>")
        Next
        e.WriteString(sb.ToString)
End Select

--  作者:一笑
--  发布时间:2022/8/9 13:54:00
--  
测试了一下:
如果使用 .Add("btn1", "确定", "submit"),TopTips工作,但以下代码不起作用:
            For Each key As String In e.Files.Keys
                If key = "up128" Then
                    For Each fln As String In e.Files(key)
                        e.SaveFile(key, fln, "d:\\web\\uploadfiles\\" & fln)
                    Next
                    dr.Lines("上传文件") = e.Files(key)
                End If
            Next
使用.Add("btn1", "确定上报", "button").Attribute= "" \'调用js函数上传
反义亦然。求解,谢谢!
js代码:
function submitForm(){
    show("tst1",2000);
    var result = submitAjaxForm(\'form1\',\'afterSubmit\');
}

function afterSubmit(result){
    hide("tst1");
    if (result==\'OK\') {
        show("tst2");
        location="upload.htm";
    }
    else{
        show("tst3",2000);
    }
}