弘帝企业智能建站系统交流平台

 找回密码
 立即注册
查看: 1171|回复: 1

弘帝系统表单系统通用框架设计脚本JS

[复制链接]
发表于 2020-9-29 14:14:49 | 显示全部楼层 |阅读模式
hondy.form.js
范本:Hondy.Cloud.Agent.JS.Function.JS
适合表单与登陆系统,组合使用见:
弘帝表单系统设计参考CSS:http://wh.ac.cn/forum.php?mod=viewthread&tid=2834&fromuid=1

  1. $(function () {
  2.     $(".empty").click(function () { $(this).parent().prev().val(""); });
  3. });

  4. textLimitCheck = function (thisArea, maxLength) {
  5.     if (thisArea.value.length > maxLength) {
  6.         alert(maxLength + ' 个字限制. \r超出的将自动去除.');
  7.         thisArea.value = thisArea.value.substring(0, maxLength);
  8.         thisArea.focus();
  9.     }
  10.     wordCount.innerText = thisArea.value.length;
  11. };

  12. var file = function (name, title, placeholder, value, regex, help){
  13.     var o = $("form ." + name);
  14.     var maxlength = "";
  15.     var need = "";
  16.     var required = "";
  17.     var readonly = "";
  18.     var pattern = "";
  19.     if (placeholder !== "") { placeholder = " placeholder="" + placeholder + """; }
  20.     if (o.attr("maxlength") !== undefined) { maxlength = " maxlength="" + o.attr("maxlength") + """; }
  21.     if (o.attr("need") !== undefined) {
  22.         if (o.attr("need").indexOf("required") >= 0) { need = "<span class='red'>*</span>"; required = " required"; }
  23.         if (o.attr("need").indexOf("readonly") >= 0) { readonly = " readonly"; }
  24.     }
  25.     if (regex !== "") { pattern = " pattern="" + regex + """; }
  26.     if (value !== "") { value = " value='" + value + "'"; } else { value = ""; }
  27.     o.html("<label class='col-md-2 col-form-label'>" + title + need + "</label><div class='col-md-5'><input type="file" name="" + name + "" class="form-control-file"" + value + placeholder + maxlength + readonly + required + pattern + " /></div><div class='d-flex col-md-5 text-muted align-items-center'>" + help + "</div>");
  28. };

  29. var select = function (name, title, tag, options, sel, help) {
  30.     var o = $("form ." + name);
  31.     o.html("<label class='col-md-2 col-form-label'>" + title + "<span class='red'>*</span></label><div class='col-md-10 row align-items-center'><div class="col-auto"><select name="" + tag + "" class="custom-select">" + option(options, sel) + "</select></div><div class='col-auto text-muted'>" + help + "</div></div>");
  32. };

  33. var option = function (options, sel) {
  34.     var args = "";
  35.     for (var i in options) {
  36.         if (sel === i) { selected = " selected"; } else { selected = ""; }
  37.         args = args + "<option value="" + options[i][0] + """ + selected + ">" + options[i][1] + "</option>";
  38.     }
  39.     return args;
  40. };

  41. var input = function (type, name, title, placeholder, value, regex, help) {
  42.     var o = $("form ." + name);
  43.     var maxlength = "";
  44.     var need = "";
  45.     var required = "";
  46.     var readonly = "";
  47.     var pattern = "";
  48.     if (placeholder !== "") { placeholder = " placeholder="" + placeholder + """; }
  49.     if (o.attr("maxlength") !== undefined) { maxlength = " maxlength="" + o.attr("maxlength") + """; }
  50.     if (o.attr("need") !== undefined) {
  51.         if (o.attr("need").indexOf("required") >= 0) { need = "<span class='red'>*</span>"; required = " required"; }
  52.         if (o.attr("need").indexOf("readonly") >= 0) { readonly = " readonly"; }
  53.     }
  54.     if (regex !== "") { pattern = " pattern="" + regex + """; }
  55.     if (value !== "") { value = " value='" + value + "'"; } else { value = ""; }
  56.     o.html("<label class='col-md-2 col-form-label'>" + title + need + "</label><div class='col-md-5'><input type="" + type + "" name="" + name + "" class="form-control"" + value + placeholder + maxlength + readonly + required + pattern + " /></div><div class='d-flex col-md-5 text-muted align-items-center'>" + help + "</div>");
  57. };

  58. var rang = function (name, title, value, input, unit, help) {
  59.     var o = $("form ." + name);
  60.     var need = "";
  61.     var readonly = "";
  62.     var min = "", max = "", step = "";
  63.     if (o.attr("min") !== undefined) { min = " min='" + o.attr("min") + "'"; }
  64.     if (o.attr("max") !== undefined) { max = " max='" + o.attr("max") + "'"; }
  65.     if (o.attr("step") !== undefined) { step = " step='" + o.attr("step") + "'"; }
  66.     if (o.attr("need") !== undefined) {
  67.         if (o.attr("need").indexOf("required") >= 0) { need = "<span class='red'>*</span>"; }
  68.         if (o.attr("need").indexOf("readonly") >= 0) { readonly = " readonly"; }
  69.     }
  70.     if (value !== "") { var val = " value='" + value + "'"; } else { val = ""; }
  71.     o.html("<label class='col-md-2 col-form-label'>" + title + need + "</label><div class='col-md-5 align-items-center'><input type="range" name="" + name + "" class="custom-range"" + val + min + max + step + readonly + " /></div><div class='col-md-5 row align-items-center'><div class='col-auto'><input name='" + input + "' class="form-control" value='" + value + "' size='2' /></div><div class='text-muted'>" + unit + "</div><div class='col-auto text-muted'>" + help + "</div></div>");
  72.     bind("range", name, input);
  73. };
  74. //list包括内容:string[]={value,title,memo}
  75. var radio = function (name, title, list, value, help) {
  76.     var o = $("form ." + name);
  77.     var need = "";
  78.     var readonly = "";
  79.     if (o.attr("need") !== undefined) {
  80.         if (o.attr("need").indexOf("required") >= 0) { need = "<span class='red'>*</span>"; }
  81.         if (o.attr("need").indexOf("readonly") >= 0) { readonly = " readonly"; }
  82.     }
  83.     var content = "";
  84.     var lst = eval(list);
  85.     for (var i in lst) {
  86.         var id = "";
  87.         var val = "";
  88.         var text = "";
  89.         switch (lst[i].length) {
  90.             case 1:
  91.                 id = name + i;
  92.                 val = " value=" + lst[i];
  93.                 text = lst[i];
  94.                 break;
  95.             case 2:
  96.                 id = name + i;
  97.                 val = " value=" + lst[i][0];
  98.                 text = lst[i][1];
  99.         }
  100.         if (lst[i][0] === value) { check = " checked"; } else { check = ""; }
  101.         content = content + "<input type="radio" name="" + name + """ + val + check + readonly + " id="" + id + "" /><label for="" + id + "" class="mb-0">" + text + "</label>";
  102.     }
  103.     content = "<div class="col-auto">" + content + "</div>";
  104.     o.html("<label class='col-md-2 col-form-label'>" + title + need + "</label><div class='col-md-10 row align-items-center'>" + content + "<div class='col-auto text-muted'>" + help + "</div></div>");
  105. };
  106. var submit = function (name, value) {
  107.     var o = $("form ." + name);
  108.     o.html("<label class='col-md-2 col-form-label'></label><div class="col-md-10"><input type='submit' name = 'submit' value = '" + value + "' class='btn btn-fst'/><input type='reset' name='reset' value='" + common.reset + "' class='btn btn-fst'/></div>");
  109. };

  110. var textarea = function (name, title, placeholder, value, help) {
  111.     var o = $("form ." + name);
  112.     var rows = "";
  113.     var need = "";
  114.     var required = "";
  115.     var readonly = "";
  116.     if (placeholder !== "") { placeholder = " placeholder="" + placeholder + """; }
  117.     if (o.attr("rows") !== undefined) { rows = " rows="" + o.attr("rows") + """; }
  118.     if (o.attr("need") !== undefined) {
  119.         if (o.attr("need").indexOf("required") >= 0) { need = "<span class='red'>*</span>"; required = " required"; }
  120.         if (o.attr("need").indexOf("readonly") >= 0) { readonly = " readonly"; }
  121.     }
  122.     o.html("<label class='col-md-2 col-form-label'>" + title + need + "</label><div class='col-md-10'><textarea name="" + name + "" class="form-control"" + placeholder + rows + readonly + required + ">" + value + "</textarea><div class='d-flex text-muted'>" + help + "</div></div>");
  123. };

  124. var bind = function (type, name, obj) {
  125.     switch (type) {
  126.         case "range":
  127.             $("[name=" + name + "]").change(function () {
  128.                 $("[name=" + obj + "]").val($("[name = " + name + "]").val());
  129.                 price();
  130.             });
  131.             $("[name=" + obj + "]").change(function () {
  132.                 $("[name=" + name + "]").val($("[name = " + obj + "]").val());
  133.                 price();
  134.             });
  135.             break;
  136.     }
  137. };

  138. $.extend({
  139.     send: function (url, args, tar) {
  140.         var body = $(document.body),
  141.             form = $("<form method='post' target='" + tar + "'></form>"),
  142.             input;
  143.         form.attr({ "action": url });
  144.         $.each(args, function (key, value) {
  145.             input = $("<input type='hidden'>");
  146.             input.attr({ "name": key });
  147.             input.val(value);
  148.             form.append(input);
  149.         });

  150.         form.appendTo(document.body);
  151.         form.submit();
  152.         document.body.removeChild(form[0]);
  153.     }
  154. });

  155. var FormDataToJson = function (formData) {
  156.     var objData = {};
  157.     formData.forEach((value, key) => objData[key] = value);
  158.     return JSON.stringify(objData);
  159. };

  160. var regex = {
  161.     name:"^[\u4e00-\u9fa5_a-zA-Z0-9]+[        DISCUZ_CODE_0        ]quot;,
  162.     domain: "^([a-z0-9][a-z0-9\-]*?\.(?:com|cn|net|org|gov|info|la|cc|co|ac.cn)(?:\.(?:cn|jp))?)[        DISCUZ_CODE_0        ]quot;,
  163.     host: "^([a-z0-9][a-z0-9\-\.]*?\.(?:com|cn|net|org|gov|info|la|cc|co|jp|hk|kr))[        DISCUZ_CODE_0        ]quot;,
  164.     ip: "^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})){3}[        DISCUZ_CODE_0        ]quot;,
  165.     int: "^[1-9][0-9]*[        DISCUZ_CODE_0        ]quot;,
  166.     age:"^[1-9][0-9]{0,2}[        DISCUZ_CODE_0        ]quot;,//1-999
  167.     num: "^[1-9][0-9]{1,3}[        DISCUZ_CODE_0        ]quot;,//10-9999
  168.     rate: "^0$|^1$|^0\.[0-9]*[1-9][        DISCUZ_CODE_0        ]quot;
  169. };

  170. var err = function (msg) {
  171.     if (msg === "nologin") { top.href = "/login"; } else { alert(msg); }
  172. };
复制代码

回复

使用道具 举报

 楼主| 发表于 2020-10-20 08:44:46 | 显示全部楼层
最新通知:由于弘帝框架已成,以Hondy.UI设计为准,随时变更。
更完整的参考:hondy.site.user.js.hondy.form.js
最新html.form设计hondy.site.login.template.addition.add.zhg+hondy.site.login.js.hondy.form.js
type=city的使用参考:
json设计参考见:hondy.site.systhemes.js.cityData.js
type=radio的使用参考:
hondy.site.user.profile.zhg
hondy.site.user.js.profile.js
list的表达示:"[[1,'男'],[0,'女']]",记得在语言中设置。




回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|弘帝企业智能建站系统 ( 皖ICP备07503252号 )

GMT+8, 2024-4-27 01:36 , Processed in 0.087721 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表