mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-07-15 14:04:41 +08:00
form预览
This commit is contained in:
parent
413e8d9b87
commit
e87eb3c822
@ -36,5 +36,10 @@ namespace OpenAuth.App
|
||||
|
||||
}
|
||||
|
||||
public Form FindSingle(string id)
|
||||
{
|
||||
return Repository.FindSingle(u => u.Id == id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
492
OpenAuth.App/FormUtil.cs
Normal file
492
OpenAuth.App/FormUtil.cs
Normal file
@ -0,0 +1,492 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Infrastructure;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OpenAuth.Repository.Domain;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class FormUtil {
|
||||
|
||||
/**
|
||||
* view
|
||||
*/
|
||||
private static string temp_view = "<div style=\"{0}\"/>{1}</div>";
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 功能: html
|
||||
*/
|
||||
public static string GetHtml(Form form, string action){
|
||||
|
||||
//action=action!=null && !""==(action)?action:"view";
|
||||
|
||||
var tableData =new Dictionary<string, Object>();//表单数据
|
||||
|
||||
string html = form.ContentParse;
|
||||
foreach (var json in form.ContentData.ToList<JObject>())
|
||||
{
|
||||
|
||||
string name = "";
|
||||
string leipiplugins = json.GetValue("leipiplugins").ToString();
|
||||
if ("checkboxs" == (leipiplugins))
|
||||
name = json.GetValue("parse_name").ToString();
|
||||
else
|
||||
name = json.GetValue("name").ToString();
|
||||
|
||||
string temp_html = "";
|
||||
switch (leipiplugins)
|
||||
{
|
||||
case "text":
|
||||
temp_html = GetTextBox(json, tableData, action);
|
||||
break;
|
||||
case "textarea":
|
||||
temp_html = GetTextArea(json, tableData, action);
|
||||
break;
|
||||
case "radios":
|
||||
temp_html = GetRadios(json, tableData, action);
|
||||
break;
|
||||
case "select":
|
||||
temp_html = GetSelect(json, tableData, action);
|
||||
break;
|
||||
case "checkboxs":
|
||||
temp_html = GetCheckboxs(json, tableData, action);
|
||||
break;
|
||||
|
||||
case "qrcode"://二维码
|
||||
temp_html = GetQrcode(json, tableData, action);
|
||||
break;
|
||||
|
||||
case "progressbar"://进度条 (未做处理)
|
||||
/*temp_html = GetProgressbar(json, tableData, action);*/
|
||||
break;
|
||||
default:
|
||||
temp_html = json.GetValue("content").ToString();
|
||||
break;
|
||||
}
|
||||
|
||||
html = html.Replace("{" + name + "}", temp_html);
|
||||
}
|
||||
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
//text
|
||||
private static string GetTextBox(JObject item, Dictionary<string,Object> formData,string action)
|
||||
{
|
||||
string temp = "<input type=\"text\" value=\"{0}\" name=\"{1}\" style=\"{2}\"/>";
|
||||
string name = item.GetValue("name").ToString();
|
||||
|
||||
string value = formData.ContainsKey(name)?formData[name].ToString():null;
|
||||
if (value == null)
|
||||
value = item.GetValue("value") == null ? "" : item.GetValue("value").ToString();
|
||||
string style =item.GetValue("style") == null ? "" : item.GetValue("style").ToString();
|
||||
string temp_html = string.Format(temp, value, name, style);
|
||||
if("view"==(action))
|
||||
return string.Format(temp_view,style,value);
|
||||
else
|
||||
return temp_html;
|
||||
}
|
||||
|
||||
//TextArea
|
||||
private static string GetTextArea(JObject item, Dictionary<string,Object> formData,string action)
|
||||
{
|
||||
string script = "";
|
||||
if (item.GetValue("orgrich") != null && "1"==(item.GetValue("orgrich").ToString()))
|
||||
script = "orgrich=\"true\" ";
|
||||
string name = item.GetValue("name").ToString();
|
||||
|
||||
string value = formData.ContainsKey(name)?formData[name].ToString():null;
|
||||
if (value == null)
|
||||
value = item.GetValue("value")== null ? "" : item.GetValue("value").ToString();
|
||||
string style = item.GetValue("style") == null ? "" : item.GetValue("style").ToString();
|
||||
|
||||
|
||||
string temp = "<textarea name=\"{0}\" id=\"{1}\" style=\"{2}\" {3}>{4}</textarea>";
|
||||
|
||||
string temp_html = string.Format(temp, name, name, style, script, value);
|
||||
|
||||
if("view"==(action))
|
||||
return string.Format(temp_view,style,value);
|
||||
else
|
||||
return temp_html;
|
||||
}
|
||||
|
||||
//Radios
|
||||
private static string GetRadios(JObject item, Dictionary<string,Object> formData,string action)
|
||||
{
|
||||
var radiosOptions = JArray.Parse(item.GetValue("options").ToString());
|
||||
//JArray radiosOptions = item["options"] as JArray;
|
||||
string temp = "<input type=\"radio\" name=\"{0}\" value=\"{1}\" {2}>{3} ";
|
||||
string temp_html = "";
|
||||
string name = item.GetValue("name").ToString();
|
||||
string value = formData.ContainsKey(name)?formData[name].ToString():null;
|
||||
|
||||
string cvalue_="";
|
||||
foreach (var json in radiosOptions)
|
||||
{
|
||||
string cvalue = json["value"].ToString();
|
||||
string Ischecked = "";
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
string check = (json["checked"] != null) ? json["checked"].ToString() : "";
|
||||
if ("checked" == (check) || "true" == (check))
|
||||
{
|
||||
Ischecked = " checked=\"checked\" ";
|
||||
cvalue_ = cvalue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
temp_html += string.Format(temp, name, cvalue, Ischecked, cvalue);
|
||||
}
|
||||
|
||||
if("view"==(action))
|
||||
return string.Format(temp_view," ",cvalue_);
|
||||
else
|
||||
return temp_html;
|
||||
}
|
||||
|
||||
//Checkboxs
|
||||
private static string GetCheckboxs(JObject item, Dictionary<string,Object> formData,string action){
|
||||
string temp_html = "";
|
||||
string temp = "<input type=\"checkbox\" name=\"{0}\" value=\"{1}\" {2}>{3} ";
|
||||
|
||||
string view_value="";//view 查看值
|
||||
|
||||
var checkOptions = JArray.Parse(item.GetValue("options").ToString());
|
||||
foreach (var json in checkOptions)
|
||||
{
|
||||
string name = json["name"].ToString();
|
||||
string value = formData.ContainsKey(name) ? formData[name].ToString() : null;
|
||||
string cvalue = json["value"].ToString();
|
||||
string Ischecked = "";
|
||||
if (value == null)
|
||||
{
|
||||
string check = (json["checked"] != null) ? json["checked"].ToString() : "";
|
||||
if (check == ("checked") || check == ("true"))
|
||||
{
|
||||
Ischecked = " checked=\"checked\" ";
|
||||
view_value += cvalue + " ";//view 查看值
|
||||
}
|
||||
}
|
||||
else if (value != null && value == (cvalue))
|
||||
{
|
||||
Ischecked = " checked=\"checked\" ";
|
||||
view_value += cvalue + " ";//view 查看值
|
||||
}
|
||||
|
||||
temp_html += string.Format(temp, name, cvalue, Ischecked, cvalue);
|
||||
|
||||
}
|
||||
|
||||
if("view"==(action))
|
||||
return string.Format(temp_view," ",view_value);
|
||||
else
|
||||
return temp_html;
|
||||
}
|
||||
|
||||
//Select(比较特殊)
|
||||
private static string GetSelect(JObject item, Dictionary<string,Object> formData, string action)
|
||||
{
|
||||
|
||||
string name = item.GetValue("name").ToString();
|
||||
string value = formData.ContainsKey(name)?formData[name].ToString():null;
|
||||
|
||||
string temp_html =item.GetValue("content").ToString();
|
||||
if (value != null)//用户设置过值
|
||||
{
|
||||
temp_html = temp_html.Replace("selected=\"selected\"", "");
|
||||
value = "value=\"" + value + "\"";
|
||||
string r = value + " selected=\"selected\"";
|
||||
temp_html = temp_html.Replace(value, r);
|
||||
}
|
||||
|
||||
return temp_html;
|
||||
}
|
||||
|
||||
|
||||
//Qrcode 二维码
|
||||
private static string GetQrcode(JObject item, Dictionary<string,Object> formData, string action)
|
||||
{
|
||||
string name = item.GetValue("name").ToString();
|
||||
string value = formData.ContainsKey(name)?formData[name].ToString():null;
|
||||
string temp_html = "";
|
||||
string temp = "";
|
||||
string orgType = item.GetValue("orgtype").ToString();
|
||||
string style = item.GetValue("style").ToString();
|
||||
if ("text"==(orgType))
|
||||
{
|
||||
orgType = "文本";
|
||||
}
|
||||
else if ("url"==(orgType))
|
||||
{
|
||||
orgType = "超链接";
|
||||
}
|
||||
else if ("tel"==(orgType))
|
||||
{
|
||||
orgType = "电话";
|
||||
}
|
||||
string qrcode_value = "";
|
||||
if (item.GetValue("value")!= null)
|
||||
qrcode_value = item.GetValue("value").ToString();
|
||||
//print_R($qrcode_value);exit; //array(value,qrcode_url)
|
||||
if ( "edit"==(action))
|
||||
{
|
||||
temp = orgType + "二维码 <input type=\"text\" name=\"{0}\" value=\"{1}\"/>";
|
||||
temp_html = string.Format(temp, name, value);
|
||||
}
|
||||
else if ("view"==(action))
|
||||
{
|
||||
//可以采用 http://qrcode.leipi.org/
|
||||
|
||||
style = "";
|
||||
if (item.GetValue("orgwidth") != null)
|
||||
{
|
||||
style = "width:" + item.GetValue("orgwidth").ToString() + "px;";
|
||||
}
|
||||
if (item.GetValue("orgheight") != null)
|
||||
{
|
||||
style += "height:" + item.GetValue("orgheight").ToString() + "px;";
|
||||
}
|
||||
temp = "<img src=\"{0}\" title=\"{1}\" style=\"{2}\"/>";
|
||||
temp_html = string.Format(temp_html, name, value, style);
|
||||
|
||||
|
||||
}
|
||||
else if ( "preview"==(action))
|
||||
{
|
||||
style = "";
|
||||
if (item.GetValue("orgwidth")!= null)
|
||||
{
|
||||
style = "width:" + item.GetValue("orgwidth").ToString() + "px;";
|
||||
}
|
||||
if (item.GetValue("orgheight")!= null)
|
||||
{
|
||||
style += "height:" + item.GetValue("orgheight").ToString() + "px;";
|
||||
}
|
||||
temp = "<img src=\"{0}\" title=\"{1}\" style=\"{2}\"/>";
|
||||
temp_html = string.Format(temp_html, name, value, style);
|
||||
}
|
||||
|
||||
return temp_html;
|
||||
}
|
||||
|
||||
////Listctrl
|
||||
//private static string GetListctrl(JObject item, Dictionary<string,Object> formData, string action)
|
||||
// {
|
||||
// string valuetest = "{\"data_110\":[\"1\",\"2\"],\"data_111\":[\"21\",\"22\",\"22\"]}";
|
||||
|
||||
// string name = item.GetValue("name").ToString();
|
||||
// string value = formData.ContainsKey(name)?formData[name].ToString():null;
|
||||
// string temp_html = "";
|
||||
// string orgSum =item.GetValue("orgsum").ToString();
|
||||
// string orgUnit =item.GetValue("orgunit").ToString();
|
||||
// string orgTitle =item.GetValue("orgtitle").ToString();
|
||||
// string title =item.GetValue("title").ToString();
|
||||
// string style =item.GetValue("style").ToString();
|
||||
// string orgcolvalue =item.GetValue("orgcolvalue").ToString();
|
||||
// string orgcoltype =item.GetValue("orgcoltype").ToString();
|
||||
// List<string> listTitle = Arrays.asList(orgTitle.split("`"));
|
||||
// List<string> listSum = Arrays.asList(orgSum.split("`"));
|
||||
// List<string> listUnit = Arrays.asList(orgUnit.split("`"));
|
||||
// List<string> listValue =Arrays.asList(orgcolvalue.split("`"));
|
||||
// List<string> listType =Arrays.asList(orgcoltype.split("`"));
|
||||
// int tdCount = listTitle.size();
|
||||
|
||||
|
||||
// string temp = "<table id=\"" + name + "_table\" bindTable=\"true\" cellspacing=\"0\" class=\"table table-bordered table-condensed\" style=\"" + style + "\"><thead>{0}</thead><tbody>{1}</tbody>{2}</table>";
|
||||
// string btnAdd = "<span class=\"pull-right\"><button class=\"btn btn-small btn-success listAdd\" type=\"button\" tbname=\"" + name + "\">添加一行</button></span>"; //添加按钮
|
||||
// string theader = "<tr><th colspan=\"{0}\">{1}{2}</th></tr>{3}";//头部模版
|
||||
|
||||
// string trTitle = "";//标题
|
||||
// for (int i = 0; i < tdCount; i++)
|
||||
// {
|
||||
// if (i == tdCount - 1)
|
||||
// listTitle.set(i, "操作");
|
||||
// if ("view"==(action) && i == tdCount - 1) continue;//如果是查看最后一列不显示
|
||||
// trTitle += string.Format("<th>{0}</th>", listTitle.get(i));
|
||||
// }
|
||||
// trTitle = "<tr>" + trTitle + "</tr>";
|
||||
|
||||
|
||||
// JObject dataValue=JObject.fromObject(valuetest);
|
||||
|
||||
// int rowCount = dataValue != null ? dataValue.size() : 1;
|
||||
|
||||
|
||||
// stringBuilder sbTr = new stringBuilder();
|
||||
// string tdSum = "";//如果有统计增加一行
|
||||
|
||||
|
||||
// TreeMap<Integer, Float> SumValueDic = new TreeMap<Integer, Float>();
|
||||
// for (int row = 0; row < rowCount; row++)
|
||||
// {
|
||||
|
||||
// JSONArray rowValue = (dataValue != null && dataValue.has(name + row)) ? dataValue.getJSONArray(name + row): null;
|
||||
|
||||
// string tr = "";//默认一行
|
||||
// for (int i = 0; i < tdCount; i++)
|
||||
// {
|
||||
// string tdname = name + "[" + i + "]";
|
||||
// string sum = "1"==(listSum.get(i)) ? "sum=\"" + tdname + "\"" : "";//是否参与统计
|
||||
// string tdValue =( rowValue != null && rowValue.size() > i) ? rowValue.GetValue(i).ToString(): listValue.get(i);
|
||||
// string type = listType.get(i);//类型
|
||||
|
||||
// if (sum != "")//一次循环计算该列的值
|
||||
// {
|
||||
// //region 计算统计值
|
||||
// float tempTdValue = 0;
|
||||
// if (SumValueDic.containsKey(i))
|
||||
// tempTdValue = SumValueDic.get(i);
|
||||
// try
|
||||
// {
|
||||
// float resultTdTemp = 0;
|
||||
// resultTdTemp=Float.parseFloat(tdValue);
|
||||
// //float.TryParse(tdValue, out resultTdTemp);
|
||||
// tempTdValue += resultTdTemp;
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// tdValue = "0";
|
||||
// }
|
||||
// if (SumValueDic.containsKey(i))
|
||||
// SumValueDic.subMap(i, (int) tempTdValue);
|
||||
// else
|
||||
// SumValueDic.put(i, tempTdValue);
|
||||
// //endregion
|
||||
|
||||
// }
|
||||
|
||||
// if (i == tdCount - 1)//最后一列不显示
|
||||
// {
|
||||
// if ("view"==(action)) continue;
|
||||
// //tr += "<td></td>";
|
||||
// else
|
||||
// tr += "<td><a href=\"javascript:void(0);\" class=\"delrow \">删除</a></td>";
|
||||
// //tr += string.Format("<td><a href=\"javascript:void(0);\" class=\"delrow {0}\">删除</a></td>", dataValue != null ? "" : "hide");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if ("view"==(action))
|
||||
// {
|
||||
// tr += string.Format("<td>{0}</td>", tdValue);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if ("text"==(type))
|
||||
// tr += string.Format("<td><input class=\"input-medium\" type=\"text\" value=\"{0}\" name=\"{1}[]\" {2}></td>", tdValue, tdname, sum);
|
||||
// else if ("int"==(type))
|
||||
// tr += string.Format("<td><input class=\"input-medium\" type=\"text\" value=\"{0}\" name=\"{1}[]\" {2}></td>", tdValue, tdname, sum);
|
||||
// else if ("textarea"==(type))
|
||||
// tr += string.Format("<td><textarea class=\"input-medium\" name=\"{0}\" >{1}</textarea></td>", tdname, tdValue, sum);
|
||||
// else if ("calc"==(type))
|
||||
// tr += string.Format("<td><input class=\"input-medium\" type=\"text\" value=\"{0}\" name=\"{1}[]\" {2}></td>", tdValue, tdname, sum);
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (row == 0)//统计的行只有一行
|
||||
// {
|
||||
// //region
|
||||
// if (sum != "")
|
||||
// {
|
||||
// if ("view"==(action))
|
||||
// tdSum += string.Format("<td>合计:value{0}{1}</td>", i, listUnit.get(i));
|
||||
// else
|
||||
// tdSum += string.Format("<td>合计:<input class=\"input-small\" type=\"text\" value=\"value{0}\" name=\"{1}[total]\" {2}\">{3}</td>", i, tdname, sum, listUnit.get(i));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// tdSum += "<td></td>";
|
||||
// }
|
||||
// //endregion
|
||||
|
||||
// }
|
||||
|
||||
// }
|
||||
// sbTr.append(string.Format("<tr class=\"template\">{0}</tr>", tr) );
|
||||
|
||||
// }
|
||||
// /*if(!stringUtils.isBlank(tdSum)){
|
||||
|
||||
// }*/
|
||||
|
||||
// if (!stringUtils.isBlank(tdSum)){
|
||||
// for (Integer i : SumValueDic.keySet()) {
|
||||
// tdSum = tdSum.Replace("value" + i, SumValueDic.get(i).ToString());
|
||||
// tdSum = string.Format("<tbody class=\"sum\"><tr>{0}</tr></tbody>", tdSum);
|
||||
// }
|
||||
// }
|
||||
// if ("view"==(action))
|
||||
// theader = string.Format(theader, tdCount, title, "", trTitle);
|
||||
// else
|
||||
// theader = string.Format(theader, tdCount, title, btnAdd, trTitle);
|
||||
|
||||
// temp_html = string.Format(temp, theader, sbTr.ToString(), tdSum);
|
||||
|
||||
// return temp_html;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 功能: 创建数据sql
|
||||
*/
|
||||
public static string GetSql(Form form,JObject JObject){
|
||||
// 获取字段并处理
|
||||
var jsonArray = JArray.Parse(JObject.GetValue("data").ToString());
|
||||
|
||||
// 数据库名称
|
||||
string data_name="`from_data_"+ form.Id+"`";
|
||||
// 创建数据表
|
||||
StringBuilder sql =new StringBuilder("CREATE TABLE "+data_name+ " (`id` int(64) NOT NULL COMMENT '主键' ,") ;
|
||||
|
||||
string sqlDefault = "";
|
||||
|
||||
foreach (var json in jsonArray)
|
||||
{
|
||||
string name = json["name"].ToString();
|
||||
string type = json["leipiplugins"].ToString();
|
||||
|
||||
sql.Append("`" + name + "` " + field_type_sql(type));//字段拼接
|
||||
|
||||
|
||||
if ("checkboxs" == (type))
|
||||
sqlDefault += field_type_sql_default(data_name, name, "0");
|
||||
else
|
||||
sqlDefault += field_type_sql_default(data_name, name, "''");
|
||||
}
|
||||
|
||||
|
||||
sql.Append("PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci AUTO_INCREMENT=1 ROW_FORMAT=COMPACT;");
|
||||
return sql.ToString()+sqlDefault;
|
||||
|
||||
}
|
||||
//获取控件字段类型 的sql
|
||||
private static string field_type_sql(string leipiplugins)
|
||||
{
|
||||
if ("textarea"==(leipiplugins) || "listctrl"==(leipiplugins))
|
||||
{
|
||||
return " text NULL ,";
|
||||
}
|
||||
else if ("checkboxs"==(leipiplugins))
|
||||
{
|
||||
return " tinyint NOT NULL ,";
|
||||
}
|
||||
else
|
||||
{
|
||||
return " varchar(255) NULL ,";
|
||||
}
|
||||
}
|
||||
private static string field_type_sql_default(string tablename, string field, string defaultValue)
|
||||
{
|
||||
return "alter table "+tablename+" alter column `"+field+"` set default "+defaultValue+";";
|
||||
}
|
||||
}
|
||||
}
|
@ -156,7 +156,9 @@
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<Compile Include="FormUtil.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
@ -20,11 +20,23 @@ namespace OpenAuth.Mvc.Controllers
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult Builder()
|
||||
public ActionResult Preview()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 预览表单
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public string PreviewData(string id)
|
||||
{
|
||||
var form = App.FindSingle(id);
|
||||
|
||||
return FormUtil.GetHtml(form, "");
|
||||
}
|
||||
|
||||
//添加或修改
|
||||
[System.Web.Mvc.HttpPost]
|
||||
[ValidateInput(false)]
|
||||
|
@ -603,7 +603,7 @@
|
||||
<Content Include="json\userface.json" />
|
||||
<Content Include="js\ueditor\formdesign\textfield.html.ajax.bak" />
|
||||
<None Include="Properties\PublishProfiles\default.pubxml" />
|
||||
<Content Include="userJs\formBuilder.js" />
|
||||
<Content Include="userJs\preview.js" />
|
||||
<Content Include="userJs\forms.js" />
|
||||
<Content Include="Views\Home\git.cshtml" />
|
||||
<Content Include="Web.config">
|
||||
@ -627,7 +627,7 @@
|
||||
<Content Include="Views\ModuleManager\Assign.cshtml" />
|
||||
<Content Include="Views\RoleManager\Index.cshtml" />
|
||||
<Content Include="Views\Forms\index.cshtml" />
|
||||
<Content Include="Views\Forms\builder.cshtml" />
|
||||
<Content Include="Views\Forms\Preview.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Areas\FlowManage\Models\" />
|
||||
|
19
OpenAuth.Mvc/Views/Forms/Preview.cshtml
Normal file
19
OpenAuth.Mvc/Views/Forms/Preview.cshtml
Normal file
@ -0,0 +1,19 @@
|
||||
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<title>Preview</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="content"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<script type="text/javascript" src="/layui/layui.js"></script>
|
||||
<script type="text/javascript" src="/userJs/preview.js"></script>
|
@ -1,17 +0,0 @@
|
||||
@section header
|
||||
{
|
||||
<link rel="stylesheet" href="/css/main.css" media="all" />
|
||||
}
|
||||
|
||||
<form method="post" id="saveform" name="saveform" action="">
|
||||
|
||||
</form>
|
||||
|
||||
<button class="layui-btn layui-btn-normal" id="btnSubmit">提交</button>
|
||||
<script type="text/javascript" charset="utf-8" src="/js/ueditor/ueditor.config.js?2023"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="/js/ueditor/ueditor.all.js?2023"> </script>
|
||||
<script type="text/javascript" charset="utf-8" src="/js/ueditor/lang/zh-cn/zh-cn.js?2023"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="/js/ueditor/formdesign/leipi.formdesign.v4.js?2023"></script>
|
||||
|
||||
<script type="text/javascript" src="/layui/layui.js"></script>
|
||||
<script src="/userJs/formBuilder.js?v=23"></script>
|
@ -1,279 +0,0 @@
|
||||
layui.config({
|
||||
base: "/js/"
|
||||
}).use(['form', 'vue', 'ztree', 'layer', 'jquery', 'table', 'droptree', 'openauth'], function () {
|
||||
var form = layui.form,
|
||||
//layer = (parent == undefined || parent.layer === undefined )? layui.layer : parent.layer,
|
||||
layer = layui.layer,
|
||||
$ = layui.jquery;
|
||||
var leipiEditor = UE.getEditor('myFormDesign', {
|
||||
//allowDivTransToP: false,//阻止转换div 为p
|
||||
toolleipi: true,//是否显示,设计器的 toolbars
|
||||
textarea: 'design_content',
|
||||
//这里可以选择自己需要的工具按钮名称,此处仅选择如下五个
|
||||
toolbars: [[
|
||||
'fullscreen', 'source', '|', 'undo', 'redo', '|', 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'removeformat', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', '|', 'fontfamily', 'fontsize', '|', 'indent', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'link', 'unlink', '|', 'horizontal', 'spechars', 'wordimage', '|', 'inserttable', 'deletetable', 'mergecells', 'splittocells']],
|
||||
//focus时自动清空初始化时的内容
|
||||
//autoClearinitialContent:true,
|
||||
//关闭字数统计
|
||||
wordCount: false,
|
||||
//关闭elementPath
|
||||
elementPathEnabled: false,
|
||||
//默认的编辑区域高度
|
||||
initialFrameHeight: 300
|
||||
///,iframeCssUrl:"css/bootstrap/css/bootstrap.css" //引入自身 css使编辑器兼容你网站css
|
||||
//更多其他参数,请参考ueditor.config.js中的配置项
|
||||
});
|
||||
|
||||
leipiFormDesign = {
|
||||
/*执行控件*/
|
||||
exec: function (method) {
|
||||
leipiEditor.execCommand(method);
|
||||
},
|
||||
/*
|
||||
Javascript 解析表单
|
||||
template 表单设计器里的Html内容
|
||||
fields 字段总数
|
||||
*/
|
||||
parse_form: function (template, fields) {
|
||||
//正则 radios|checkboxs|select 匹配的边界 |--| 因为当使用 {} 时js报错
|
||||
var preg = /(\|-<span(((?!<span).)*leipiplugins=\"(radios|checkboxs|select)\".*?)>(.*?)<\/span>-\||<(img|input|textarea|select).*?(<\/select>|<\/textarea>|\/>))/gi, preg_attr = /(\w+)=\"(.?|.+?)\"/gi, preg_group = /<input.*?\/>/gi;
|
||||
if (!fields) fields = 0;
|
||||
|
||||
var template_parse = template, template_data = new Array(), add_fields = new Object(), checkboxs = 0;
|
||||
|
||||
var pno = 0;
|
||||
template.replace(preg, function (plugin, p1, p2, p3, p4, p5, p6) {
|
||||
var parse_attr = new Array(), attr_arr_all = new Object(), name = '', select_dot = '', is_new = false;
|
||||
var p0 = plugin;
|
||||
var tag = p6 ? p6 : p4;
|
||||
//alert(tag + " \n- t1 - "+p1 +" \n-2- " +p2+" \n-3- " +p3+" \n-4- " +p4+" \n-5- " +p5+" \n-6- " +p6);
|
||||
|
||||
if (tag == 'radios' || tag == 'checkboxs') {
|
||||
plugin = p2;
|
||||
} else if (tag == 'select') {
|
||||
plugin = plugin.replace('|-', '');
|
||||
plugin = plugin.replace('-|', '');
|
||||
}
|
||||
plugin.replace(preg_attr, function (str0, attr, val) {
|
||||
if (attr == 'name') {
|
||||
if (val == 'leipiNewField') {
|
||||
is_new = true;
|
||||
fields++;
|
||||
val = 'data_' + fields;
|
||||
}
|
||||
name = val;
|
||||
}
|
||||
|
||||
if (tag == 'select' && attr == 'value') {
|
||||
if (!attr_arr_all[attr]) attr_arr_all[attr] = '';
|
||||
attr_arr_all[attr] += select_dot + val;
|
||||
select_dot = ',';
|
||||
} else {
|
||||
attr_arr_all[attr] = val;
|
||||
}
|
||||
var oField = new Object();
|
||||
oField[attr] = val;
|
||||
parse_attr.push(oField);
|
||||
})
|
||||
/*alert(JSON.stringify(parse_attr));return;*/
|
||||
if (tag == 'checkboxs') /*复选组 多个字段 */ {
|
||||
plugin = p0;
|
||||
plugin = plugin.replace('|-', '');
|
||||
plugin = plugin.replace('-|', '');
|
||||
var name = 'checkboxs_' + checkboxs;
|
||||
attr_arr_all['parse_name'] = name;
|
||||
attr_arr_all['name'] = '';
|
||||
attr_arr_all['value'] = '';
|
||||
|
||||
attr_arr_all['content'] = '<span leipiplugins="checkboxs" title="' + attr_arr_all['title'] + '">';
|
||||
var dot_name = '', dot_value = '';
|
||||
p5.replace(preg_group, function (parse_group) {
|
||||
var is_new = false, option = new Object();
|
||||
parse_group.replace(preg_attr, function (str0, k, val) {
|
||||
if (k == 'name') {
|
||||
if (val == 'leipiNewField') {
|
||||
is_new = true;
|
||||
fields++;
|
||||
val = 'data_' + fields;
|
||||
}
|
||||
|
||||
attr_arr_all['name'] += dot_name + val;
|
||||
dot_name = ',';
|
||||
|
||||
}
|
||||
else if (k == 'value') {
|
||||
attr_arr_all['value'] += dot_value + val;
|
||||
dot_value = ',';
|
||||
|
||||
}
|
||||
option[k] = val;
|
||||
});
|
||||
|
||||
if (!attr_arr_all['options']) attr_arr_all['options'] = new Array();
|
||||
attr_arr_all['options'].push(option);
|
||||
//if(!option['checked']) option['checked'] = '';
|
||||
var checked = option['checked'] != undefined ? 'checked="checked"' : '';
|
||||
attr_arr_all['content'] += '<input type="checkbox" name="' + option['name'] + '" value="' + option['value'] + '" ' + checked + '/>' + option['value'] + ' ';
|
||||
|
||||
if (is_new) {
|
||||
var arr = new Object();
|
||||
arr['name'] = option['name'];
|
||||
arr['leipiplugins'] = attr_arr_all['leipiplugins'];
|
||||
add_fields[option['name']] = arr;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
attr_arr_all['content'] += '</span>';
|
||||
|
||||
//parse
|
||||
template = template.replace(plugin, attr_arr_all['content']);
|
||||
template_parse = template_parse.replace(plugin, '{' + name + '}');
|
||||
template_parse = template_parse.replace('{|-', '');
|
||||
template_parse = template_parse.replace('-|}', '');
|
||||
template_data[pno] = attr_arr_all;
|
||||
checkboxs++;
|
||||
|
||||
} else if (name) {
|
||||
if (tag == 'radios') /*单选组 一个字段*/ {
|
||||
plugin = p0;
|
||||
plugin = plugin.replace('|-', '');
|
||||
plugin = plugin.replace('-|', '');
|
||||
attr_arr_all['value'] = '';
|
||||
attr_arr_all['content'] = '<span leipiplugins="radios" name="' + attr_arr_all['name'] + '" title="' + attr_arr_all['title'] + '">';
|
||||
var dot = '';
|
||||
p5.replace(preg_group, function (parse_group) {
|
||||
var option = new Object();
|
||||
parse_group.replace(preg_attr, function (str0, k, val) {
|
||||
if (k == 'value') {
|
||||
attr_arr_all['value'] += dot + val;
|
||||
dot = ',';
|
||||
}
|
||||
option[k] = val;
|
||||
});
|
||||
option['name'] = attr_arr_all['name'];
|
||||
if (!attr_arr_all['options']) attr_arr_all['options'] = new Array();
|
||||
attr_arr_all['options'].push(option);
|
||||
//if(!option['checked']) option['checked'] = '';
|
||||
var checked = option['checked'] != undefined ? 'checked="checked"' : '';
|
||||
attr_arr_all['content'] += '<input type="radio" name="' + attr_arr_all['name'] + '" value="' + option['value'] + '" ' + checked + '/>' + option['value'] + ' ';
|
||||
|
||||
});
|
||||
attr_arr_all['content'] += '</span>';
|
||||
|
||||
} else {
|
||||
attr_arr_all['content'] = is_new ? plugin.replace(/leipiNewField/, name) : plugin;
|
||||
}
|
||||
//attr_arr_all['itemid'] = fields;
|
||||
//attr_arr_all['tag'] = tag;
|
||||
template = template.replace(plugin, attr_arr_all['content']);
|
||||
template_parse = template_parse.replace(plugin, '{' + name + '}');
|
||||
template_parse = template_parse.replace('{|-', '');
|
||||
template_parse = template_parse.replace('-|}', '');
|
||||
if (is_new) {
|
||||
var arr = new Object();
|
||||
arr['name'] = name;
|
||||
arr['leipiplugins'] = attr_arr_all['leipiplugins'];
|
||||
add_fields[arr['name']] = arr;
|
||||
}
|
||||
template_data[pno] = attr_arr_all;
|
||||
|
||||
|
||||
}
|
||||
pno++;
|
||||
})
|
||||
var parse_form = new Object({
|
||||
'fields': fields,//总字段数
|
||||
'template': template,//完整html
|
||||
'parse': template_parse,//控件替换为{data_1}的html
|
||||
'data': template_data,//控件属性
|
||||
'add_fields': add_fields//新增控件
|
||||
});
|
||||
return JSON.stringify(parse_form);
|
||||
},
|
||||
/*type = save 保存设计 versions 保存版本 close关闭 */
|
||||
fnCheckForm: function (type) {
|
||||
if (leipiEditor.queryCommandState('source'))
|
||||
leipiEditor.execCommand('source');//切换到编辑模式才提交,否则有bug
|
||||
|
||||
if (leipiEditor.hasContents()) {
|
||||
leipiEditor.sync();/*同步内容*/
|
||||
|
||||
|
||||
// return false;
|
||||
//--------------以下仅参考-----------------------------------------------------------------------------------------------------
|
||||
var type_value = '', formid = 0, fields = $("#fields").val(), formeditor = '';
|
||||
|
||||
if (typeof type !== 'undefined') {
|
||||
type_value = type;
|
||||
}
|
||||
//获取表单设计器里的内容
|
||||
formeditor = leipiEditor.getContent();
|
||||
//解析表单设计器控件
|
||||
var parse_form = this.parse_form(formeditor, fields);
|
||||
//alert(parse_form);
|
||||
|
||||
//异步提交数据
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/Forms/AddOrUpdate',
|
||||
//dataType : 'json',
|
||||
data: { 'type': type_value, 'formid': formid, 'parse_form': parse_form },
|
||||
success: function (data) {
|
||||
if (confirm('查看js解析后,提交到服务器的数据,请临时允许弹窗')) {
|
||||
win_parse = window.open('', '', 'width=800,height=600');
|
||||
//这里临时查看,所以替换一下,实际情况下不需要替换
|
||||
data = data.replace(/<\/+textarea/, '<textarea');
|
||||
win_parse.document.write('<textarea style="width:100%;height:100%">' + data + '</textarea>');
|
||||
win_parse.focus();
|
||||
}
|
||||
|
||||
/*
|
||||
if(data.success==1){
|
||||
alert('保存成功');
|
||||
$('#submitbtn').button('reset');
|
||||
}else{
|
||||
alert('保存失败!');
|
||||
}*/
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
alert('表单内容不能为空!')
|
||||
$('#submitbtn').button('reset');
|
||||
return false;
|
||||
}
|
||||
},
|
||||
/*预览表单*/
|
||||
fnReview: function () {
|
||||
if (leipiEditor.queryCommandState('source'))
|
||||
leipiEditor.execCommand('source');/*切换到编辑模式才提交,否则部分浏览器有bug*/
|
||||
|
||||
if (leipiEditor.hasContents()) {
|
||||
leipiEditor.sync(); /*同步内容*/
|
||||
|
||||
alert("你点击了预览,请自行处理....");
|
||||
return false;
|
||||
//--------------以下仅参考-------------------------------------------------------------------
|
||||
|
||||
|
||||
/*设计form的target 然后提交至一个新的窗口进行预览*/
|
||||
document.saveform.target = "mywin";
|
||||
window.open('', 'mywin', "menubar=0,toolbar=0,status=0,resizable=1,left=0,top=0,scrollbars=1,width=" + (screen.availWidth - 10) + ",height=" + (screen.availHeight - 50) + "\"");
|
||||
|
||||
document.saveform.action = "/index.php?s=/index/preview.html";
|
||||
document.saveform.submit(); //提交表单
|
||||
} else {
|
||||
alert('表单内容不能为空!');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$("#btnSubmit").click(function() {
|
||||
leipiFormDesign.fnCheckForm("save");
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
|
@ -396,7 +396,20 @@
|
||||
}
|
||||
editDlg.update(data[0]);
|
||||
}
|
||||
|
||||
, btnPreview:function() {
|
||||
var checkStatus = table.checkStatus('mainList')
|
||||
, data = checkStatus.data;
|
||||
if (data.length != 1) {
|
||||
layer.msg("请选择要预览的行,且同时只能编辑一行");
|
||||
return;
|
||||
}
|
||||
|
||||
layer.open({
|
||||
type: 2,
|
||||
area: ["800px", "700px"],
|
||||
content: '/forms/preview?id=' + data[0].Id
|
||||
});
|
||||
}
|
||||
, search: function () { //搜索
|
||||
mainList({ key: $('#key').val() });
|
||||
}
|
||||
|
14
OpenAuth.Mvc/userJs/preview.js
Normal file
14
OpenAuth.Mvc/userJs/preview.js
Normal file
@ -0,0 +1,14 @@
|
||||
layui.config({
|
||||
base: "/js/"
|
||||
}).use(['form','vue', 'layer', 'jquery', 'table','droptree','queryString'], function () {
|
||||
var form = layui.form,
|
||||
element = layui.element,
|
||||
//layer = (parent == undefined || parent.layer === undefined )? layui.layer : parent.layer,
|
||||
layer = layui.layer,
|
||||
$ = layui.jquery;
|
||||
var id = $.getUrlParam("id");
|
||||
$.get("/forms/previewdata?id=" + id, function (data) {
|
||||
$("#content").html(data);
|
||||
});
|
||||
|
||||
})
|
Loading…
Reference in New Issue
Block a user