123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504 |
- var iwbfuns;
- function GetFuns(ele) {
- var $table = typeof ele === 'string' ? $('#' + ele) : $(ele);
- return $table.iwbTable('getFuns');
- }
- function LoadTableBackFun(option) {
- if (!option) {
- option = { table: "table" };
- }
- option.table = option.table ? option.table : "table";
- var $table = typeof option.table === 'string' ? $('#' + option.table) : $(option.table);
- if ($table.length < 1) {
- console.log('没有发现表格:', option.table);
- }
- option.lang = option.lang ? option.lang : window.lang;
- $table.iwbTable(option);
- var funs = GetFuns($table);
- return funs;
- }
- function LoadTable(option,isRefresh) {
- if (!option) {
- option = { table: "table" };
- }
- option.table = option.table ? option.table : "table";
- var $table = typeof option.table === 'string' ? $('#' + option.table) : $(option.table);
- if ($table.length < 1) {
- console.log('没有发现表格:', option.table);
- }
- //$table.bootstrapTable('destroy', { silent: true });
- if (isRefresh) {
- $table.iwbTable('destroy');
- $table.iwbTable(option);
- window.iwbfuns = GetFuns($table);
- } else {
- $table.iwbTable(option);
- window.iwbfuns = GetFuns($table);
- }
-
- return $table;
- }
- function LoadTreeTable(option) {
- var $table = !option.table ? $('#table') : typeof option.table === 'string' ? $('#' + option.table) : $(option.table);
- if ($table.length < 1) {
- console.log('没有发现表格:', option.table);
- throw "没有发现表格";
- }
- $.metPageCss('/Content/Libs/bootstrap-table/extensions/treegrid/jquery.treegrid.min.css', "dy-css-treegrid");
- $.metPageJs('/Content/Libs/bootstrap-table/extensions/treegrid/bootstrap-table-treegrid.js', "dy-js-bootstrap-treegrid");
- $.metPageJs('/Content/Libs/bootstrap-table/extensions/treegrid/jquery.treegrid.min.js', "dy-js-treegrid");
- var defaultOption = {
- table: $table,
- rootNo: 0,
- idField: 'no',
- treeShowField: 'name',
- parentIdField: 'parentNo',
- level: "depth",
- customDataField: ['path'],
- height: $(window).height() - 200,
- onLoadSuccess: function () {
- $table.treegrid({
- treeColumn: 1,
- expanderExpandedClass: 'mr-2 iconfont icon-folderopen-fill',
- expanderCollapsedClass: 'mr-2 iconfont icon-folder-fill'
- });
- $(".level-2").closest("tr").treegrid("collapse");
- $("td span.treegrid-expander:not(.iconfont)").addClass("mr-2 iconfont icon-folder");
- abp.ui.clearBusy();
- $("td").off("dblclick").on("dblclick", function () { $($(this).closest("tr")).treegrid("toggle"); });
- }
- };
- option = $.extend({}, defaultOption, option);
- $table.iwbTable(option);
- $(".btn-toolbar .btn-group").find(".btn[data-type]").each(function (i, e) {
- var btnType = $(e).data("type").replace("_", "");
- if (btnType !== "btnRefresh") {
- var btnUrl = $(e).data("url") || "";
- var btnName = $(e).text();
- var btnClass = $(e).attr("class");
- var btnIcon = $(e).find("i").attr("class");
- actions.push({ type: btnType, name: btnName, "class": btnClass, icon: btnIcon, url: btnUrl });
- $(e).remove();
- } else {
- $(e).prop("disabled", false).attr("onclick", "Refresh('" + $(e).data("url") + "')");
- }
- });
- //$(".btn-toolbar").css("display", "block");
- var funs = GetFuns($table);
- var getCustomDataStr = function (row) {
- var str = "";
- if (option.customDataField && option.customDataField.length > 0) {
- for (var i = 0; i < option.customDataField.length; i++) {
- var key = option.customDataField[i];
- str += ',"' + key + '":"' + row[key] + '"';
- }
- }
- return str;
- };
- funs['btnCreate'] = function (url, id) {
- var row;
- if (typeof id === "string" && id !== "") {
- row = $table.bootstrapTable("getRowByUniqueId", id);
- }
- if (row) {
- var dataStr = '{"' + option.parentIdField + '":"' + row[option.idField] + '","' + option.level + '":"' + (row[option.level] + 1) + '"' + getCustomDataStr(row) + '}';
- console.log('create', dataStr);
- BtnCreate({
- table: $table,
- url: url,
- data: JSON.parse(dataStr),
- disabled: option.parentIdField
- });
- } else
- abp.message.warn(abp.localization.iwbZero('SelectRecordOperation'));
- };
- funs['btnUpdate'] = function (url, id) {
- console.log('update', id);
- var row;
- if (typeof id === "string" && id !== "") {
- row = $table.bootstrapTable("getRowByUniqueId", id);
- }
- if (row) {
- BtnUpdate({
- table: $table,
- url: url,
- data: row,
- disabled: option.parentIdField + ',' + option.idField
- }, row);
- } else
- abp.message.warn(abp.localization.iwbZero('SelectRecordOperation'));
- };
- funs['btnDelete'] = function (url, id) {
- console.log('delete', id);
- var row;
- if (typeof id === "string" && id !== "") {
- row = $table.bootstrapTable("getRowByUniqueId", id);
- }
- if (row) {
- BtnDelete({
- table: $table,
- url: url,
- data: row
- }, row);
- } else
- abp.message.warn(abp.localization.iwbZero('SelectRecordOperation'));
- };
- funs['btnMoveUp'] = function (url, id, that) {
- console.log("MoveUp", id);
- var row;
- if (typeof id === "string" && id !== "") {
- row = $table.bootstrapTable("getRowByUniqueId", id);
- }
- if (row) {
- var tr = $(that).closest("tr");
- var funId = tr.data("uniqueid"), parentNo = tr.data("parent");
- var prevs = tr.prevAll().filter("[data-parent='" + parentNo + "']");
- if (prevs.length > 0) {
- var prevId = prevs.first().data("uniqueid");
- //console.log(prevId);
- $.iwbAjax1({ url: url, data: { Id: funId, PrevId: prevId } });
- } else {
- abp.message.warn(abp.localization.iwbZero("RecordAtTop"));
- }
- } else {
- abp.message.warn(abp.localization.iwbZero('SelectRecordOperation'));
- }
- };
- funs['btnMoveDown'] = function (url, id, that) {
- console.log("MoveDown", id);
- var row;
- if (typeof id === "string" && id !== "") {
- row = $table.bootstrapTable("getRowByUniqueId", id);
- }
- if (row) {
- var tr = $(that).closest("tr");
- var funId = $(tr).data("uniqueid"), parentNo = $(tr).data("parent");
- var nexts = tr.nextAll().filter("[data-parent='" + parentNo + "']");
- if (nexts.length > 0) {
- var nextId = nexts.first().data("uniqueid");
- //console.log(nextId);
- $.iwbAjax1({ url: url, data: { Id: funId, NextId: nextId } });
- } else {
- abp.message.warn(abp.localization.iwbZero("RecordAtBottom"));
- }
- } else {
- abp.message.warn(abp.localization.iwbZero("SelectRecordOperation"));
- }
- };
- funs['Refresh'] = function (url) {
- console.log("Refresh");
- $.iwbAjax1({ url: url });
- };
- return funs;
- }
- function RefreshTable(ele, isForce) {
- ele = ele || "table";
- isForce = isForce === undefined;
- var $table = typeof ele === 'string' ? $('#' + ele) : $(ele);
- if ($table.length < 1) {
- console.log('没有发现表格:', ele);
- }
- try {
- $table.iwbTable('refresh', isForce);
- } catch (e) {
- console.log("RefreshTable", e);
- }
- }
- function BtnCreate(option) {
- option = option || {};
- option.table = option.table ? option.table : "table";
- var $table = typeof option.table === 'string' ? $('#' + option.table) : $(option.table);
- var url = option.url || $table.find('.btn-toolbar').find('.btn[data-type="_btnCreate"]').data('url') || $table.find('.btn-toolbar').find('.btn[data-type="btnCreate"]').data('url');
- option.type = 'post';
- $table.iwbTable('defaultCreate', url, option);
- }
- function BtnUpdate(option, row) {
- option = option || {};
- option.table = option.table ? option.table : "table";
- var $table = typeof option.table === 'string' ? $('#' + option.table) : $(option.table);
- var url = option.url || $table.find('.btn-toolbar').find('.btn[data-type="btnUpdate"]').data('url');
- row = row || option.row || $table.bootstrapTable("getSelections")[0];
- option.data = option.data || row;
- option.type = 'post';
- $table.iwbTable('defaultUpdate', url, option, row);
- }
- function BtnDelete(option, row) {
- option = option || {};
- option.table = option.table ? option.table : "table";
- var $table = typeof option.table === 'string' ? $('#' + option.table) : $(option.table);
- var url = option.url || $table.find('.btn-toolbar').find('.btn[data-type="btnDelete"]').data('url');
- row = row || option.row || $table.bootstrapTable("getSelections")[0];
- option.type = 'post';
- $table.iwbTable('defaultDelete', url, option, row);
- }
- function BtnConfirm(message, title, url, rowOrTableId, data) {
- var row;
- if (rowOrTableId) {
- if (typeof rowOrTableId === 'object' && !(rowOrTableId instanceof jQuery)) {
- row = rowOrTableId;
- } else {
- var $table = typeof rowOrTableId === 'string' ? $('#' + rowOrTableId) : $(rowOrTableId);
- row = $table.bootstrapTable("getSelections")[0];
- }
- } else {
- row = $("#table").bootstrapTable("getSelections")[0];
- }
- if (row) {
- data = data || { Id: row.id };
- MsgConfirm(message, title, function () {
- $.iwbAjax({ url: url, data: data, isValidate: false });
- });
- } else
- abp.message.warn(abp.localization.iwbZero('SelectRecordOperation'));
- }
- function MsgConfirm(message, title, callback, opt) {
- abp.message.confirm(message, title, function (isConfirmed) {
- if (isConfirmed && callback) {
- callback(opt);
- }
- });
- }
- function OpenModal(opt) {
- opt = opt || {};
- var ele = opt.modal ? opt.modal : "modal";
- var $modal = typeof ele === 'string' ? $('#' + ele) : $(ele);
- if ($modal.length < 1) {
- console.log('没有发现模态框:', ele);
- }
- try {
- $modal.iwbModal(opt);
- } catch (e) {
- console.log("OpenModal", e);
- }
- }
- function ShowModal(ele) {
- ele = ele || "modal";
- var $modal = typeof ele === 'string' ? $('#' + ele) : $(ele);
- if ($modal.length < 1) {
- console.log('没有发现模态框:', ele);
- }
- try {
- $modal.iwbModal('show');
- } catch (e) {
- console.log("ShowModal", e);
- }
- }
- var queryModalTarget = '';
- function ShowQueryModal(ele, target) {
- ele = ele || "modal";
- queryModalTarget = !target ? '' : target.indexOf('.') === 0 ? target : target.indexOf('#') === 0 ? target : '#' + target;
- var $modal = typeof ele === 'string' ? $('#' + ele) : $(ele);
- if ($modal.length < 1) {
- console.log('没有发现模态框:', ele);
- }
- try {
- $modal.iwbModal('show2');
- } catch (e) {
- console.log("ShowModal", e);
- }
- }
- function ClearSearchValue(target,clear,that) {
- var $target = $(!target ? $(that) : target.indexOf('.') === 0 ? target : target.indexOf('#') === 0 ? target : '#' + target);
- var arr = clear.split(",");
- arr.forEach(function (v) {
- if (v) {
- var vStr = v.indexOf('.') === 0 ? v : v.indexOf('#') === 0 ? v : '#' + v;
- $target.find(vStr).val('');
- }
- });
- }
- function FileUpload(that, opt) { $(that).iwbFileUpload(opt); }
- function FileClear(that) { $(that).iwbFileUpload('clearFile'); }
- function FileShow(that, opt) { $(that).iwbFileShow(opt); }
- function AddDynamicBox(that) {
- var $that = $(that).closest('.iwb-dynamic-box'), html = $that.clone().prop("outerHTML");
- html = html.replace('btn-add', 'btn-delete');
- html = html.replace('AddDynamicBox', 'DeleteDynamicBox');
- html = html.replace('>增加</button', '>删除</button');
- html = html.replace(new RegExp('data-select2-id="[0-9]*"', "g"), '');
- var $html = $(html).addClass('iwb-dynamic-box-delete').removeAttr('data-select2-id');
- $html.find('.select2').remove();
- $html.find('select').val('').select2();
- //$html.find('select').each(function () {
- // var newId = $(this).attr("name") + Math.floor(Math.random() * 100000);
- // $(this).attr('id',newId).attr('name',newId).removeAttr('data-select2-id').val('').select2();
- //});
- $html.find('input').val('');
- $that.parent().append($html);
- return $html;
- }
- function DeleteDynamicBox(that) {
- var $that = $(that).closest('.iwb-dynamic-box');
- $that.remove();
- }
- /*ajax全局设置*/
- $.ajaxSetup({
- type: 'Post',
- timeout: 1000 * 60 * 2,
- //contentType: "application/x-www-form-urlencoded;charset=utf-8",
- contentType: "application/json",
- dataType: "json",
- error: function () {
- abp.ui.clearBusy();
- },
- complete: function (xmlHttpRequest, textStatus) {
- //console.log("Complete - " + textStatus, xmlHttpRequest);
- abp.ui.clearBusy();
- if (textStatus === "timeout") {
- abp.message.error(abp.localization.iwbZero('OpTimeout'));
- console.log("Complete - 操作超时");
- } else if (textStatus !== "success") {
- console.log("Complete - " + textStatus, xmlHttpRequest.responseJSON);
- if (xmlHttpRequest.responseJSON) {
- //var json = xmlHttpRequest.responseJSON;
- } else if (xmlHttpRequest.responseText === "") {
- abp.message.error(abp.localization.iwbZero('OpServerError')).done(function () {
- top.location.reload();
- //top.location.href = "/Account/Login/?ReturnUrl=%2F";
- });
- }
- } else {
- var result = xmlHttpRequest.responseJSON;
- if (result && !result.success && result.error && result.error.message.indexOf('登陆超时') > -1) {
- top.location.reload();
- }
- }
- }
- });
- function OverlayScrollbar(that, opt) {
- var option = $.extend(true,
- {},
- {
- className: "os-theme-thin-dark",
- resize: "n", //[ "none", "both", "horizontal", "vertical" ]shorthand: [ "n", "b", "h", "v" ]
- normalizeRTL: true, //是否应规范化RTL滚动。
- sizeAutoCapable: true,
- clipAlways: true,
- paddingAbsolute: false,
- overflowBehavior: {
- x: "v-h", //[ "hidden", "scroll", "visible-hidden", "visible-scroll" ]shorthand: [ "h", "s", "v-h", "v-s" ]
- y: "s"
- },
- scrollbars: {
- dragScrolling: true,
- clickScrolling: true,
- visibility: "a", //[ "visible", "hidden", "auto" ]shorthand: [ "v", "h", "a" ]
- autoHide: "n", //[ "never", "scroll", "leave", "move" ]shorthand: [ "n", "s", "l", "m" ]
- autoHideDelay: 800
- }
- },
- opt || {});
- return $(that).overlayScrollbars(option);
- }
- // ReSharper disable once NativeTypePrototypeExtending
- String.prototype.format = function (args) {
- var result = this;
- if (arguments.length > 0) {
- var reg;
- if (arguments.length === 1 && typeof args === "object") {
- for (var key in args) {
- if (args.hasOwnProperty(key)) {
- if (args[key] !== undefined) {
- reg = new RegExp("({" + key + "})", "g");
- result = result.replace(reg, args[key]);
- }
- }
- }
- }
- else {
- for (var i = 0; i < arguments.length; i++) {
- if (arguments[i] !== undefined) {
- reg = new RegExp("({[" + i + "]})", "g");
- result = result.replace(reg, arguments[i]);
- }
- }
- }
- }
- return result;
- };
- String.format = function (str) {
- var args = arguments, re = new RegExp("%([1-" + args.length + "])", "g");
- return String(str).replace(re, function ($1, $2) {
- return args[$2];
- }
- );
- };
- //调用方法很简单:
- //element.innerHTML = String.format('<a href="%1" onclick="alert(\’%2\’);">%3</a>', url, msg, text);
- // 对Date的扩展,将 Date 转化为指定格式的String
- // 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
- // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
- // 例子:
- // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
- // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
- // ReSharper disable once NativeTypePrototypeExtending
- Date.prototype.format = function (fmt) {
- var o = {
- "M+": this.getMonth() + 1, //月份
- "d+": this.getDate(), //日
- "h+": this.getHours(), //小时
- "m+": this.getMinutes(), //分
- "s+": this.getSeconds(), //秒
- "q+": Math.floor((this.getMonth() + 3) / 3), //季度
- "S": this.getMilliseconds() //毫秒
- };
- if (/(y+)/.test(fmt))
- fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
- for (var k in o) {
- if (o.hasOwnProperty(k))
- if (new RegExp("(" + k + ")").test(fmt))
- fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
- }
- return fmt;
- };
- function DateFormatter(v, r, i, f) {
- if (!v) {
- return "";
- }
- var date = new Date(v);
- var str = date.format('yyyy-MM-dd');
- r[f] = str;
- return str;
- }
- function DateTimeFormatter(v, r, i, f) {
- if (!v) {
- return "";
- }
- var date = new Date(v);
- var str = date.format('yyyy-MM-dd hh:mm:ss');
- r[f] = str;
- return str;
- }
- $(function () {
- //Configure blockUI
- if ($.blockUI) {
- $.blockUI.defaults.baseZ = 2000;
- }
- $('.iwb-date-time').iwbDate({ language: window.lang });
- $('.iwb-date').iwbDate({ language: window.lang });
- });
|