|
|
|
|
|
(function (window) {
|
|
|
|
|
|
window._$id = window._$idCard = new Object();
|
|
|
|
|
|
_$id.version = "1.0.0";
|
|
|
|
|
|
_$id.author = "pelli";
|
|
|
|
|
|
_$id.author_email = "pelli_mail@163.com";
|
|
|
|
|
|
|
|
|
|
|
|
var IdCard = {
|
|
|
|
|
|
random: function (start, end) {
|
|
|
|
|
|
return Math.ceil(Math.random() * (end - start) + start);
|
|
|
|
|
|
},
|
|
|
|
|
|
cityArea: function () {
|
|
|
|
|
|
var city_code = [110000, 110100, 110101, 110102, 110105, 110106, 110107, 110108, 110109, 110111, 110112, 110113, 110114, 110115, 110116, 110117, 110200, 110228, 110229, 120000, 120100, 120101, 120102, 120103, 120104, 120105, 120106, 120110, 120111, 120112, 120113, 120114, 120115, 120116, 120117, 120118, 120200, 120225, 130000, 130100, 130101, 130102, 130104, 130105, 130107, 130108, 130109, 130110, 130111, 130121, 130123, 130125, 130126, 130127, 130128, 130129, 130130, 130131, 130132, 130133, 130183, 130184, 130200, 130201, 130202, 130203, 130204, 130205, 130207, 130208, 130209, 130223, 130224, 130225, 130227, 130229, 130281, 130283, 130300, 130301, 130302, 130303, 130304, 130306, 130321, 130322, 130324, 130400, 130401, 130402, 130403, 130404, 130406, 130421, 130423, 130424, 130425, 130426, 130427, 130428, 130429, 130430, 130431, 130432, 130433, 130434, 130435, 130481, 130500, 130501, 130502, 130503, 130521, 130522, 130523, 130524, 130525, 130526, 130527, 130528, 130529, 130530, 130531, 130532, 130533, 130534, 130535, 130581, 130582, 130600, 130601, 130602, 130606, 130607, 130608, 130609, 130623, 130624, 130626, 130627, 130628, 130629, 130630, 130631, 130632, 130633, 130634, 130635, 130636, 130637, 130638, 130681, 130683, 130684, 130700, 130701, 130702, 130703, 130705, 130706, 130721, 130722, 130723, 130724, 130725, 130726, 130727, 130728, 130729, 130730, 130731, 130732, 130733, 130800, 130801, 130802, 130803, 130804, 130821, 130822, 130823, 130824, 130825, 130826, 130827, 130828, 130900, 130901, 130902, 130903, 130921, 130922, 130923, 130924, 130925, 130926, 130927, 130928, 130929, 130930, 130981, 130982, 130983, 130984, 131000, 131001, 131002, 131003, 131022, 131023, 131024, 131025, 131026, 131028, 131081, 131082, 131100, 131101, 131102, 131121, 131122, 131123, 131124, 131125, 131126, 131127, 131128, 131181, 131182, 139000, 139001, 139002, 140000, 140100, 140101, 140105, 140106, 140107, 140108, 140109, 140110, 140121, 140122, 140123, 140181, 140200, 140201, 140202, 140203, 140211, 140212, 140221, 140222, 140223, 140224, 140225, 140226, 140227, 140300, 140301, 140302, 140303, 140311, 140321, 140322, 140400, 140401, 140402, 140411, 140421, 140423, 140424, 140425, 140426, 140427, 140428, 140429, 140430, 140431, 140481, 140500, 140501, 140502, 140521, 140522, 140524, 140525, 140581, 140600, 140601, 140602, 140603, 140621, 140622, 140623, 140624, 140700, 140701, 140702, 140721, 140722, 140723, 140724, 140725, 140726, 140727, 140728, 140729, 140781, 140800, 140801, 140802, 140821, 140822, 140823, 140824, 140825, 140826, 140827, 140828, 140829, 140830, 140881, 140882, 140900, 140901, 140902, 140921, 140922, 140923, 140924, 140925, 140926, 140927, 140928, 140929, 140930, 140931, 140932, 140981, 141000, 141001, 141002, 141021, 141022, 141023, 141024, 141025, 141026, 141027, 141028, 141029, 141030, 141031, 141032, 141033, 141034, 141081, 141082, 141100, 141101, 141102, 141121, 141122, 141123, 141124, 141125, 141126, 141127, 141128, 141129, 141130, 141181, 141182, 150000, 150100, 150101, 150102, 150103, 150104, 150105, 150121, 150122, 150123, 150124, 150125, 150200, 150201, 150202, 150203, 150204, 150205, 150206, 150207, 150221, 150222, 150223, 150300, 150301, 150302, 150303, 150304, 150400, 150401, 150402, 150403, 150404, 150421, 150422, 150423, 150424, 150425, 150426, 150428, 150429, 150430, 150500, 150501, 150502, 150521, 150522, 150523, 150524, 150525, 150526, 150581, 150600, 150601, 150602, 150621, 150622, 150623, 150624, 150625, 150626, 150627, 150700, 150701, 150702, 150703, 150721, 150722, 150723, 150724, 150725, 150726, 150727, 150781, 150782, 150783, 150784, 150785, 150800, 150801, 150802, 150821, 150822, 150823, 150824, 150825, 150826, 150900, 150901, 150902, 150921, 150922, 150923, 150924, 150925, 150926, 150927, 150928, 150929, 150981, 152200, 152201, 152202, 152221, 152222, 152223, 152224, 152500, 152501, 152502, 152522, 152523, 152524, 152525, 152526, 152527, 152528, 152529, 152530, 152531, 152900, 152921, 152922, 152923, 210000, 210100, 210101, 210102, 210103, 210104, 210105, 210106, 210111, 210112, 21
|
|
|
|
|
|
var len = city_code.length;
|
|
|
|
|
|
var code = city_code[this.random(0, len - 1)];
|
|
|
|
|
|
return code;
|
|
|
|
|
|
},
|
|
|
|
|
|
YMD: function () {
|
|
|
|
|
|
// year,month,day
|
|
|
|
|
|
var today = new Date();
|
|
|
|
|
|
var max_y = today.getFullYear();
|
|
|
|
|
|
var Y = this.random(1900, max_y) + "";
|
|
|
|
|
|
var M = this.random(0, 12);
|
|
|
|
|
|
if (M < 10) {
|
|
|
|
|
|
M = "0" + M + "";
|
|
|
|
|
|
}
|
|
|
|
|
|
var D = this.random(0, 30);
|
|
|
|
|
|
if (D < 10) {
|
|
|
|
|
|
D = "0" + D + "";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var ymd = Y + M + D;
|
|
|
|
|
|
return ymd;
|
|
|
|
|
|
},
|
|
|
|
|
|
areaPolice: function () {
|
|
|
|
|
|
var code = this.random(0, 99);
|
|
|
|
|
|
if (code < 10) {
|
|
|
|
|
|
code = "0" + code;
|
|
|
|
|
|
}
|
|
|
|
|
|
return code;
|
|
|
|
|
|
},
|
|
|
|
|
|
sex: function () {
|
|
|
|
|
|
return this.random(0, 9);
|
|
|
|
|
|
},
|
|
|
|
|
|
lastNo: function (str) {
|
|
|
|
|
|
// ISO 7064:1983.MOD 11-2
|
|
|
|
|
|
var weight_factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
|
|
|
|
|
|
var check_code = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
|
|
|
|
|
|
// the last no
|
|
|
|
|
|
var arr = str.split("");
|
|
|
|
|
|
var len = arr.length;
|
|
|
|
|
|
var num = 0;
|
|
|
|
|
|
for (var i = 0; i < len; i++) {
|
|
|
|
|
|
num = num + arr[i] * weight_factor[i];
|
|
|
|
|
|
}
|
|
|
|
|
|
var resisue = num % 11;
|
|
|
|
|
|
var last_no = check_code[resisue];
|
|
|
|
|
|
return last_no;
|
|
|
|
|
|
},
|
|
|
|
|
|
idCard: function () {
|
|
|
|
|
|
var area = this.cityArea();
|
|
|
|
|
|
var ymd = this.YMD();
|
|
|
|
|
|
var police = this.areaPolice();
|
|
|
|
|
|
var sex = this.sex();
|
|
|
|
|
|
|
|
|
|
|
|
var id_code_17 = "" + area + ymd + police + sex;
|
|
|
|
|
|
var last = this.lastNo(id_code_17);
|
|
|
|
|
|
id_code_18 = id_code_17 + last;
|
|
|
|
|
|
|
|
|
|
|
|
return id_code_18;
|
|
|
|
|
|
},
|
|
|
|
|
|
isLegal: function (idcode) {
|
|
|
|
|
|
var code = idcode + "";
|
|
|
|
|
|
var last = idcode[17];
|
|
|
|
|
|
var seventeen = code.substring(0, 17);
|
|
|
|
|
|
var real_last = this.lastNo(seventeen);
|
|
|
|
|
|
|
|
|
|
|
|
var idcard_patter = /^[1-9][0-9]{5}([1][9][0-9]{2}|[2][0][0|1][0-9])([0][1-9]|[1][0|1|2])([0][1-9]|[1|2][0-9]|[3][0|1])[0-9]{3}([0-9]|[X])$/;
|
|
|
|
|
|
|
|
|
|
|
|
var format = idcard_patter.test(idcode);
|
|
|
|
|
|
return last === real_last && format ? true : false;//校验码正确
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_$id.getCardNumber = function () {
|
|
|
|
|
|
return IdCard.idCard();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_$id.checkCardNumber = function (card_code) {
|
|
|
|
|
|
return IdCard.isLegal(card_code);
|
|
|
|
|
|
}
|
|
|
|
|
|
})(window);
|
|
|
|
|
|
|
|
|
|
|
|
(function ($) {
|
|
|
|
|
|
$.getUrlParam = function (name, url) {
|
|
|
|
|
|
url == undefined ? url = window.location.href : "";
|
|
|
|
|
|
if (url.indexOf("?") != -1) {
|
|
|
|
|
|
var arr = url.split("?");
|
|
|
|
|
|
arr = arr[1].split("&");
|
|
|
|
|
|
for (var i = 0; i < arr.length; i++) {
|
|
|
|
|
|
var str = arr[0].split("=");
|
|
|
|
|
|
if (str[0] == name) return str[1];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* $.unserialize
|
|
|
|
|
|
*
|
|
|
|
|
|
* Takes a string in format "param1=value1¶m2=value2" and returns an object { param1: 'value1', param2: 'value2' }. If the "param1" ends with "[]" the param is treated as an array.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Example:
|
|
|
|
|
|
*
|
|
|
|
|
|
* Input: param1=value1¶m2=value2
|
|
|
|
|
|
* Return: { param1 : value1, param2: value2 }
|
|
|
|
|
|
*
|
|
|
|
|
|
* Input: param1[]=value1¶m1[]=value2
|
|
|
|
|
|
* Return: { param1: [ value1, value2 ] }
|
|
|
|
|
|
*
|
|
|
|
|
|
* @todo Support params like "param1[name]=value1" (should return { param1: { name: value1 } })
|
|
|
|
|
|
*/
|
|
|
|
|
|
$.unserialize = function (serializedString) {
|
|
|
|
|
|
var str = decodeURI(serializedString);
|
|
|
|
|
|
var pairs = str.split('&');
|
|
|
|
|
|
var obj = {}, p, idx, val;
|
|
|
|
|
|
for (var i = 0, n = pairs.length; i < n; i++) {
|
|
|
|
|
|
p = pairs[i].split('=');
|
|
|
|
|
|
idx = p[0];
|
|
|
|
|
|
|
|
|
|
|
|
if (idx.indexOf("[]") == (idx.length - 2)) {
|
|
|
|
|
|
var ind = idx.substring(0, idx.length - 2)
|
|
|
|
|
|
if (obj[ind] === undefined) {
|
|
|
|
|
|
obj[ind] = [];
|
|
|
|
|
|
}
|
|
|
|
|
|
obj[ind].push(p[1]);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
obj[idx] = p[1];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return obj;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
$.validator.addMethod("isIdCard", function (value, element) {
|
|
|
|
|
|
return this.optional(element) || _$id.checkCardNumber(value);
|
|
|
|
|
|
}, "请输入正确的身份证号码");
|
|
|
|
|
|
|
|
|
|
|
|
$.validator.addMethod("isMobile", function (value, element) {
|
|
|
|
|
|
return this.optional(element) || isMobile(value);
|
|
|
|
|
|
}, "请输入正确的手机号码");
|
|
|
|
|
|
|
|
|
|
|
|
$.validator.addMethod("alphaDash", function (value, element) {
|
|
|
|
|
|
var reg = /^\w+$/;
|
|
|
|
|
|
return this.optional(element) || reg.test(value);
|
|
|
|
|
|
}, "只能包含字母、数字和下划线");
|
|
|
|
|
|
|
|
|
|
|
|
$.validator.addMethod("passwordStrength", function (value, element) {
|
|
|
|
|
|
return this.optional(element) || passwordStrength(value);
|
|
|
|
|
|
}, "密码长度至少为6个字符,且必须同时包含字母、数字和特殊字符中的两种!");
|
|
|
|
|
|
})(jQuery);
|
|
|
|
|
|
|
|
|
|
|
|
function isMobile(val) {
|
|
|
|
|
|
var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
|
|
|
|
|
|
if (!myreg.test(val)) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function passwordStrength(value) {
|
|
|
|
|
|
if (value.length < 6) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
var ls = 0;
|
|
|
|
|
|
if (value.match(/([a-z])+/)) {
|
|
|
|
|
|
ls++;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (value.match(/([0-9])+/)) {
|
|
|
|
|
|
ls++;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (value.match(/[^a-zA-Z0-9]+/)) {
|
|
|
|
|
|
ls++;
|
|
|
|
|
|
}
|
|
|
|
|
|
return ls >= 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$(function () {
|
|
|
|
|
|
setValidateForm();
|
|
|
|
|
|
setDatePicker();
|
|
|
|
|
|
setDatetimePicker();
|
|
|
|
|
|
setMultipleSelect();
|
|
|
|
|
|
setSelect2();
|
|
|
|
|
|
setSelect2Tag();
|
|
|
|
|
|
setBackBtn();
|
|
|
|
|
|
setUploaders();
|
|
|
|
|
|
fixRadio();
|
|
|
|
|
|
fixCheckbox();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$.fn.datepicker.dates['en'] = {
|
|
|
|
|
|
days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
|
|
|
|
|
|
daysShort: ["日", "一", "二", "三", "四", "五", "六"],
|
|
|
|
|
|
daysMin: ["日", "一", "二", "三", "四", "五", "六"],
|
|
|
|
|
|
months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
|
|
|
|
|
|
monthsShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
|
|
|
|
|
|
today: "今天",
|
|
|
|
|
|
clear: "清除",
|
|
|
|
|
|
format: "yyyy-mm-dd",
|
|
|
|
|
|
titleFormat: "yyyy-mm-dd", /* Leverages same syntax as 'format' */
|
|
|
|
|
|
weekStart: 0
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function setDatePicker(box) {
|
|
|
|
|
|
if (box == undefined) {
|
|
|
|
|
|
var selector = $("[data-plugin=date-picker]");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
var selector = $(box).find("[data-plugin=date-picker]");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
selector.css({"position": "relative"}).datetimepicker({
|
|
|
|
|
|
format: "YYYY-MM-DD",
|
|
|
|
|
|
useStrict: true,
|
|
|
|
|
|
icons: {
|
|
|
|
|
|
time: "fa fa-clock",
|
|
|
|
|
|
date: "fa fa-calendar",
|
|
|
|
|
|
up: "fa fa-arrow-up",
|
|
|
|
|
|
down: "fa fa-arrow-down",
|
|
|
|
|
|
previous: 'fa fa-chevron-left',
|
|
|
|
|
|
next: 'fa fa-chevron-right',
|
|
|
|
|
|
today: 'fa fa-calendar-check-o',
|
|
|
|
|
|
clear: 'fa fa-trash',
|
|
|
|
|
|
close: 'fa fa-remove'
|
|
|
|
|
|
},
|
|
|
|
|
|
debug: false,
|
|
|
|
|
|
locale: "zh-CN"
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function setDatetimePicker(box) {
|
|
|
|
|
|
if (box == undefined) {
|
|
|
|
|
|
var selector = $("[data-plugin=datetime-picker]");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
var selector = $(box).find("[data-plugin=datetime-picker]");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
selector.css({"position": "relative"}).datetimepicker({
|
|
|
|
|
|
format: "YYYY-MM-DD HH:mm",
|
|
|
|
|
|
useStrict: true,
|
|
|
|
|
|
icons: {
|
|
|
|
|
|
time: "fa fa-clock",
|
|
|
|
|
|
date: "fa fa-calendar",
|
|
|
|
|
|
up: "fa fa-arrow-up",
|
|
|
|
|
|
down: "fa fa-arrow-down",
|
|
|
|
|
|
previous: 'fa fa-chevron-left',
|
|
|
|
|
|
next: 'fa fa-chevron-right',
|
|
|
|
|
|
today: 'fa fa-calendar-check-o',
|
|
|
|
|
|
clear: 'fa fa-trash',
|
|
|
|
|
|
close: 'fa fa-remove'
|
|
|
|
|
|
},
|
|
|
|
|
|
debug: false,
|
|
|
|
|
|
locale: "zh-CN"
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function setTimePicker(box) {
|
|
|
|
|
|
if (box == undefined) {
|
|
|
|
|
|
var selector = $("[data-plugin=time-picker]");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
var selector = $(box).find("[data-plugin=time-picker]");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
selector.css({"position": "relative"}).datetimepicker({
|
|
|
|
|
|
format: "HH:mm",
|
|
|
|
|
|
useStrict: true,
|
|
|
|
|
|
icons: {
|
|
|
|
|
|
time: "fa fa-clock",
|
|
|
|
|
|
date: "fa fa-calendar",
|
|
|
|
|
|
up: "fa fa-arrow-up",
|
|
|
|
|
|
down: "fa fa-arrow-down",
|
|
|
|
|
|
previous: 'fa fa-chevron-left',
|
|
|
|
|
|
next: 'fa fa-chevron-right',
|
|
|
|
|
|
today: 'fa fa-calendar-check-o',
|
|
|
|
|
|
clear: 'fa fa-trash',
|
|
|
|
|
|
close: 'fa fa-remove'
|
|
|
|
|
|
},
|
|
|
|
|
|
debug: false,
|
|
|
|
|
|
locale: "zh-CN"
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function setUploaders(box) {
|
|
|
|
|
|
if (window.uploaders == undefined) {
|
|
|
|
|
|
window.uploaders = [];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (box == undefined) {
|
|
|
|
|
|
var selector = $("[data-plugin=uploader]");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
var selector = $(box).find("[data-plugin=uploader]");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
selector.each(function () {
|
|
|
|
|
|
var index = window.uploaders.length;
|
|
|
|
|
|
initUploader(this, index);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function initUploader(obj, index) {
|
|
|
|
|
|
$(obj).wrap("<div class='uploader-wrapper pl-2 pr-2 pt-2 border bg-soft-light' style='border-style: dotted !important;' data-uploader-index='" + index + "'></div>");
|
|
|
|
|
|
var picker_id = "uploader-picker-" + index;
|
|
|
|
|
|
|
|
|
|
|
|
$(obj).attr("data-uploader-index", index);
|
|
|
|
|
|
$(obj).after("<div class='uploader-list' data-uploader-index='" + index + "' ></div>");
|
|
|
|
|
|
$(obj).after("<div data-uploader-index='" + index + "' id='" + picker_id + "'></div>");
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
var uploads = JSON.parse($(obj).val());
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof uploads == "object") {
|
|
|
|
|
|
console.log(uploads);
|
|
|
|
|
|
var ids = [];
|
|
|
|
|
|
for (i in uploads) {
|
|
|
|
|
|
var file = uploads[i];
|
|
|
|
|
|
|
|
|
|
|
|
var li = '<div data-id="' + file.id + '" class="alert alert-success alert-dismissible fade show mb-2" role="alert">' +
|
|
|
|
|
|
'<button type="button" class="close"><span aria-hidden="true">×</span></button>' +
|
|
|
|
|
|
'<a href="/storage/' + (file.folder != "public" ? file.folder : "") + '/' + file.name + '" target="_blank" class="text-success">' + file.original_name + '(' + Math.ceil(file.size / 1000) + 'K)</a>' +
|
|
|
|
|
|
'</div>';
|
|
|
|
|
|
$(".uploader-list[data-uploader-index=" + index + "]").append(li);
|
|
|
|
|
|
$(".uploader-list[data-uploader-index=" + index + "]").children(":last").find(".close").click(function () {
|
|
|
|
|
|
var ids = [];
|
|
|
|
|
|
$(this).parent().siblings("[data-id]").each(function () {
|
|
|
|
|
|
ids.push($(this).attr("data-id"));
|
|
|
|
|
|
});
|
|
|
|
|
|
$('input[data-uploader-index=' + index + ']').val(ids.join(","));
|
|
|
|
|
|
$(this).parent().remove();
|
|
|
|
|
|
});
|
|
|
|
|
|
ids.push(file.id);
|
|
|
|
|
|
}
|
|
|
|
|
|
$(obj).val(ids.join(","));
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
if ($(obj).val() != "" && $(obj).val() != undefined) {
|
|
|
|
|
|
var ids = $(obj).val().split(",");
|
|
|
|
|
|
for (var i = 0; i < ids.length; i++) {
|
|
|
|
|
|
var li = '<div data-id="' + ids[i] + '" class="alert alert-success alert-dismissible fade show mb-2" role="alert">' +
|
|
|
|
|
|
'<button type="button" class="close"><span aria-hidden="true">×</span></button>' +
|
|
|
|
|
|
'<a class="text-success" href="' + ids[i] + '" target="_blank" class="text-success">' + ids[i] + '</a>' +
|
|
|
|
|
|
'</div>';
|
|
|
|
|
|
$(".uploader-list[data-uploader-index=" + index + "]").append(li);
|
|
|
|
|
|
$(".uploader-list[data-uploader-index=" + index + "]").children(":last").find(".close").click(function () {
|
|
|
|
|
|
var ids = [];
|
|
|
|
|
|
$(this).parent().siblings("[data-id]").each(function () {
|
|
|
|
|
|
ids.push($(this).attr("data-id"));
|
|
|
|
|
|
});
|
|
|
|
|
|
$('input[data-uploader-index=' + index + ']').val(ids.join(","));
|
|
|
|
|
|
$(this).parent().remove();
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//more options to set
|
|
|
|
|
|
var _token = $("meta[name=csrf-token]").attr("content");
|
|
|
|
|
|
var options_default = {
|
|
|
|
|
|
uploaderIndex: index,
|
|
|
|
|
|
formData: {
|
|
|
|
|
|
_token: _token
|
|
|
|
|
|
},
|
|
|
|
|
|
// swf文件路径
|
|
|
|
|
|
swf: '/plugins/webuploader/Uploader.swf',
|
|
|
|
|
|
// 文件接收服务端。
|
|
|
|
|
|
server: window.uploaderServer == undefined ? '/admin/upload' : window.uploaderServer,
|
|
|
|
|
|
auto: true,
|
|
|
|
|
|
// 不压缩image, 默认如果是jpeg,文件上传前会压缩一把再上传!
|
|
|
|
|
|
resize: false,
|
|
|
|
|
|
multiple: false,
|
|
|
|
|
|
fileNumLimit: 1
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var options = {};
|
|
|
|
|
|
if ($(obj).attr("data-uploader-multiple")) {
|
|
|
|
|
|
options.multiple = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($(obj).attr("data-uploader-folder") != undefined) {
|
|
|
|
|
|
options.folder = $(obj).attr("data-uploader-folder");
|
|
|
|
|
|
}
|
|
|
|
|
|
options.pick = {
|
|
|
|
|
|
id: "#" + picker_id,
|
|
|
|
|
|
innerHTML: "<button class='btn btn-primary'><i class='la la-upload'></i> 上传文件</button>"
|
|
|
|
|
|
};
|
|
|
|
|
|
options = $.extend(options_default, options);
|
|
|
|
|
|
if (options.folder != undefined) {
|
|
|
|
|
|
options.formData.folder = options.folder;
|
|
|
|
|
|
}
|
|
|
|
|
|
console.log(options);
|
|
|
|
|
|
|
|
|
|
|
|
window.uploaders[index] = WebUploader.create(options);
|
|
|
|
|
|
window.uploaders[index].on('fileQueued', function (file) {
|
|
|
|
|
|
var index = this.options.uploaderIndex;
|
|
|
|
|
|
var li = '<div id="' + file.id + '" class="alert alert-primary alert-dismissible fade show mb-2" role="alert">' +
|
|
|
|
|
|
'<button type="button" class="close"><span aria-hidden="true">×</span></button>' +
|
|
|
|
|
|
'<a>' + file.name + '(' + Math.ceil(file.size / 1000) + 'K)</a>' +
|
|
|
|
|
|
'</div>';
|
|
|
|
|
|
if (this.options.multiple) {
|
|
|
|
|
|
$(".uploader-list[data-uploader-index=" + index + "]").append(li);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$("input[data-uploader-index=" + index + "]").val("");
|
|
|
|
|
|
$(".uploader-list[data-uploader-index=" + index + "]").html(li);
|
|
|
|
|
|
}
|
|
|
|
|
|
$(".uploader-list[data-uploader-index=" + index + "]").children(":last").find(".close").click(function () {
|
|
|
|
|
|
var ids = [];
|
|
|
|
|
|
$(this).parent().siblings("[data-id]").each(function () {
|
|
|
|
|
|
ids.push($(this).attr("data-id"));
|
|
|
|
|
|
});
|
|
|
|
|
|
$('input[data-uploader-index=' + index + ']').val(ids.join(","));
|
|
|
|
|
|
$(this).parent().remove();
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 文件上传失败,显示上传出错。
|
|
|
|
|
|
window.uploaders[index].on('uploadError', function (file) {
|
|
|
|
|
|
var $li = $('#' + file.id), $error = $li.find('div.text-danger');
|
|
|
|
|
|
$li.addClass("alert-danger");
|
|
|
|
|
|
$error.remove();
|
|
|
|
|
|
$error = $('<div class="text-danger"></div>').appendTo($li);
|
|
|
|
|
|
$error.html('上传失败');
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 完成上传完了,成功或者失败,先删除进度条并重置插件以便继续上传。
|
|
|
|
|
|
window.uploaders[index].on('uploadComplete', function (file) {
|
|
|
|
|
|
$('#' + file.id).find('.progress').remove();
|
|
|
|
|
|
window.uploaders[index].reset();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 文件上传成功
|
|
|
|
|
|
window.uploaders[index].on('uploadSuccess', function (file, data) {
|
|
|
|
|
|
var index = this.options.uploaderIndex;
|
|
|
|
|
|
|
|
|
|
|
|
$('#' + file.id).addClass("alert-success").attr("data-id", data.id);
|
|
|
|
|
|
$('#' + file.id).find("a").attr("href", "/storage/" + (data.folder && data.folder != "public" ? data.folder + "/" : "") + data.name).attr("target", "_blank").addClass("text-success");
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof uploaderCallback === "function") {
|
|
|
|
|
|
var res = uploaderCallback(file, data, index);
|
|
|
|
|
|
if (res === true) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
$('input[data-uploader-index=' + index + ']').valid();
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (this.options.multiple) {
|
|
|
|
|
|
var val = $('input[data-uploader-index=' + index + ']').val();
|
|
|
|
|
|
if (val == "") {
|
|
|
|
|
|
$('input[data-uploader-index=' + index + ']').val(data.id);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$('input[data-uploader-index=' + index + ']').val(val + "," + data.id);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$('input[data-uploader-index=' + index + ']').val(data.id);
|
|
|
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
|
|
|
$('input[data-uploader-index=' + index + ']').valid();
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//根据options设置元素本身
|
|
|
|
|
|
$(obj).css({height: 0, padding: 0, margin: 0, border: 0});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function setBackBtn() {
|
|
|
|
|
|
$(".btn-back").click(function () {
|
|
|
|
|
|
backAndReload();
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function setValidateForm(selections) {
|
|
|
|
|
|
if (selections == undefined) {
|
|
|
|
|
|
selections = $("form:not(.needs-no-validation)");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
selections = $(selections);
|
|
|
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
|
|
|
selections.each(function () {
|
|
|
|
|
|
$(this).validate({
|
|
|
|
|
|
errorClass: "text-danger",
|
|
|
|
|
|
errorElement: "div",
|
|
|
|
|
|
errorPlacement: function (e, t) {
|
|
|
|
|
|
return t.parents(".form-group,.controls,.form-fill").first().append(e);
|
|
|
|
|
|
},
|
|
|
|
|
|
// highlight: function (e) {
|
|
|
|
|
|
// return $(e).closest('.form-group').removeClass("text-danger").addClass('text-danger');
|
|
|
|
|
|
// },
|
|
|
|
|
|
success: function (e) {
|
|
|
|
|
|
return e.closest(".form-group,.controls,.form-fill").first().removeClass("text-danger");
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function addCollectionRow(ele) {
|
|
|
|
|
|
var count = parseInt($(ele).closest("table").attr("data-rows"));
|
|
|
|
|
|
var prototype = $(ele).closest("table").attr("data-prototype");
|
|
|
|
|
|
prototype = prototype.replace(/__NAME__/g, count);
|
|
|
|
|
|
$(ele).closest("table").children("tbody").append(prototype);
|
|
|
|
|
|
$(ele).closest("table").attr("data-rows", count + 1);
|
|
|
|
|
|
|
|
|
|
|
|
if ("function" == typeof afterAddCollectionRow) {
|
|
|
|
|
|
afterAddCollectionRow(ele);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function setMultipleSelect() {
|
|
|
|
|
|
$("select.multiple").prop("multiple", true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function setSelect2(box) {
|
|
|
|
|
|
if (box == undefined) {
|
|
|
|
|
|
var selector = $("[data-plugin=select2]");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
var selector = $(box).find("[data-plugin=select2]");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
selector.each(function () {
|
|
|
|
|
|
$(this).select2({
|
|
|
|
|
|
language: {
|
|
|
|
|
|
noResults: function (params) {
|
|
|
|
|
|
return "没有匹配的搜索结果";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function setSelect2Tag(box) {
|
|
|
|
|
|
if (box == undefined) {
|
|
|
|
|
|
var selector = $("[data-plugin=select2-tag]");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
var selector = $(box).find("[data-plugin=select2-tag]");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
selector.select2({
|
|
|
|
|
|
tags: true,
|
|
|
|
|
|
placeholder: "请选择或自行录入",
|
|
|
|
|
|
allowClear: true,
|
|
|
|
|
|
language: {
|
|
|
|
|
|
noResults: function (params) {
|
|
|
|
|
|
return "没有匹配的搜索结果";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function fixRadio() {
|
|
|
|
|
|
$(".radio input").each(function () {
|
|
|
|
|
|
if ($(this).attr("id") == undefined && $(this).siblings("label").attr("for") != undefined) {
|
|
|
|
|
|
$(this).attr("id", $(this).siblings("label").attr("for"));
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function fixCheckbox() {
|
|
|
|
|
|
$(".custom-checkbox input").each(function () {
|
|
|
|
|
|
if ($(this).attr("id") == undefined && $(this).siblings("label").attr("for") != undefined) {
|
|
|
|
|
|
$(this).attr("id", $(this).siblings("label").attr("for"));
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function makeForm(url, paras, autoSubmit) {
|
|
|
|
|
|
var form_id = "make_form_" + Date.parse(new Date());
|
|
|
|
|
|
var form_html = "<form id='" + form_id + "' method='post' action='" + url + "'>";
|
|
|
|
|
|
for (var k in paras) {
|
|
|
|
|
|
if ($.isArray(paras[k])) {
|
|
|
|
|
|
for (var i = 0; i < paras[k].length; i++) {
|
|
|
|
|
|
form_html += "<input type='hidden' name='" + k + "[]' value='" + paras[k][i] + "'>";
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
form_html += "<input type='hidden' name='" + k + "' value='" + paras[k] + "'>";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
form_html += "</form>";
|
|
|
|
|
|
$("body").append(form_html);
|
|
|
|
|
|
|
|
|
|
|
|
if (autoSubmit == undefined) {
|
|
|
|
|
|
autoSubmit = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (autoSubmit == true) {
|
|
|
|
|
|
$("#" + form_id).submit();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return form_id;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function notifySuccess(msg) {
|
|
|
|
|
|
$.toast({
|
|
|
|
|
|
heading: '成功',
|
|
|
|
|
|
text: msg,
|
|
|
|
|
|
icon: 'success',
|
|
|
|
|
|
bgColor: '#5ba035',
|
|
|
|
|
|
textColor: 'white',
|
|
|
|
|
|
position: 'top-center'
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function notifyError(msg) {
|
|
|
|
|
|
$.toast({
|
|
|
|
|
|
heading: '失败',
|
|
|
|
|
|
text: msg,
|
|
|
|
|
|
icon: 'warning',
|
|
|
|
|
|
bgColor: '#bf441d',
|
|
|
|
|
|
textColor: 'white',
|
|
|
|
|
|
position: 'top-center'
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function alertSuccess(msg, callbackFunction) {
|
|
|
|
|
|
var type = 'success';
|
|
|
|
|
|
var color = '#0acf97';
|
|
|
|
|
|
|
|
|
|
|
|
Swal.fire({
|
|
|
|
|
|
title: "成功",
|
|
|
|
|
|
text: msg,
|
|
|
|
|
|
type: type,
|
|
|
|
|
|
showCancelButton: false,
|
|
|
|
|
|
confirmButtonColor: color,
|
|
|
|
|
|
confirmButtonText: "知道了"
|
|
|
|
|
|
}).then(function (t) {
|
|
|
|
|
|
if (!t.value) return;
|
|
|
|
|
|
if (typeof callbackFunction == "function") {
|
|
|
|
|
|
callbackFunction();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function alertInfo(msg, callbackFunction) {
|
|
|
|
|
|
var type = 'info';
|
|
|
|
|
|
var color = '#0acf97';
|
|
|
|
|
|
|
|
|
|
|
|
Swal.fire({
|
|
|
|
|
|
title: "成功",
|
|
|
|
|
|
text: msg,
|
|
|
|
|
|
type: type,
|
|
|
|
|
|
showCancelButton: false,
|
|
|
|
|
|
confirmButtonColor: color,
|
|
|
|
|
|
confirmButtonText: "知道了"
|
|
|
|
|
|
}).then(function (t) {
|
|
|
|
|
|
if (!t.value) return;
|
|
|
|
|
|
if (typeof callbackFunction == "function") {
|
|
|
|
|
|
callbackFunction();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function alertError(msg) {
|
|
|
|
|
|
var type = 'warning';
|
|
|
|
|
|
var color = '#ffbc00';
|
|
|
|
|
|
|
|
|
|
|
|
Swal.fire({
|
|
|
|
|
|
title: "提示",
|
|
|
|
|
|
text: msg,
|
|
|
|
|
|
type: type,
|
|
|
|
|
|
showCancelButton: false,
|
|
|
|
|
|
confirmButtonColor: color,
|
|
|
|
|
|
confirmButtonText: "知道了"
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//popup
|
|
|
|
|
|
function popup() {
|
|
|
|
|
|
//根据传递的参数数量及类型,获取向目标参数传递的值、回调函数、配置修改
|
|
|
|
|
|
var url = arguments[0];
|
|
|
|
|
|
var parameters_index = 1;
|
|
|
|
|
|
var callback_index = 2;
|
|
|
|
|
|
var options_index = 3;
|
|
|
|
|
|
if (typeof arguments[parameters_index] == "function") {
|
|
|
|
|
|
parameters_index = -1;
|
|
|
|
|
|
callback_index = 1;
|
|
|
|
|
|
options_index = 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var parameters = arguments[parameters_index] != undefined ? arguments[parameters_index] : {};
|
|
|
|
|
|
parameters = json2url(parameters, "array");
|
|
|
|
|
|
|
|
|
|
|
|
var callback = arguments[callback_index];
|
|
|
|
|
|
if (typeof callback == "function") {
|
|
|
|
|
|
callback = callback.name;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
callback = 'callbackPopup';
|
|
|
|
|
|
}
|
|
|
|
|
|
parameters.push("callback=" + callback);
|
|
|
|
|
|
url += url.indexOf("?") >= 0 ? "&" : "?";
|
|
|
|
|
|
url += parameters.join("&");
|
|
|
|
|
|
|
|
|
|
|
|
var options = arguments[options_index] != undefined ? arguments[options_index] : {};
|
|
|
|
|
|
options = $.extend({
|
|
|
|
|
|
size: 'lg',
|
|
|
|
|
|
minHeight: "600px"
|
|
|
|
|
|
}, options);
|
|
|
|
|
|
|
|
|
|
|
|
var modal_html = '\
|
|
|
|
|
|
<div class="modal" id="_popup" tabindex="-1" role="dialog">\
|
|
|
|
|
|
<div class="modal-dialog modal-' + options.size + '" role="document">\
|
|
|
|
|
|
<div class="modal-content" style="border-radius: 0;">\
|
|
|
|
|
|
<div class="modal-body" style="padding: 0; ">[!--iframe--]</div>\
|
|
|
|
|
|
</div>\
|
|
|
|
|
|
</div>\
|
|
|
|
|
|
</div>';
|
|
|
|
|
|
|
|
|
|
|
|
var iframe = "<iframe name='iframe_popup' src='" + url + "' frameborder='0' scrolling='auto' width='100%' style='vertical-align:bottom;min-height: " + options.minHeight + ";'></iframe>";
|
|
|
|
|
|
modal_html = modal_html.replace("[!--iframe--]", iframe);
|
|
|
|
|
|
|
|
|
|
|
|
$("body").append(modal_html).dblclick(function () {
|
|
|
|
|
|
closePopup();
|
|
|
|
|
|
});
|
|
|
|
|
|
$("#_popup").modal({
|
|
|
|
|
|
keyboard: false,
|
|
|
|
|
|
backdrop: "static"
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function closePopup() {
|
|
|
|
|
|
$("#_popup").modal("hide").remove();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function callbackPopup(result) {
|
|
|
|
|
|
closePopup();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function json2url(json, type) {
|
|
|
|
|
|
if (typeof json == "string") {
|
|
|
|
|
|
return json;
|
|
|
|
|
|
}
|
|
|
|
|
|
undefined == type ? type = "string" : "";
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
var url = [];
|
|
|
|
|
|
for (var k in json) {
|
|
|
|
|
|
if ($.isArray(json[k])) {
|
|
|
|
|
|
for (var i = 0; i < json[k].length; i++) {
|
|
|
|
|
|
url.push(k + "[]=" + encodeURIComponent(json[k][i]));
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
url.push(k + "=" + encodeURIComponent(json[k]));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
|
case "string":
|
|
|
|
|
|
url = url.join("&");
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
//保持不变
|
|
|
|
|
|
}
|
|
|
|
|
|
return url;
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
alert(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function second2hour(second) {
|
|
|
|
|
|
var hours = Math.floor(second / 3600);
|
|
|
|
|
|
var minutes = Math.floor((second - hours * 3600) / 60);
|
|
|
|
|
|
var seconds = second - hours * 3600 - minutes * 60;
|
|
|
|
|
|
hours < 10 ? hours = "0" + hours : "";
|
|
|
|
|
|
minutes < 10 ? minutes = "0" + minutes : "";
|
|
|
|
|
|
seconds < 10 ? seconds = "0" + seconds : "";
|
|
|
|
|
|
|
|
|
|
|
|
return hours + ":" + minutes + ":" + seconds;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function backAndReload() {
|
|
|
|
|
|
if (document.referrer === '') {
|
|
|
|
|
|
return window.history.go(-1);
|
|
|
|
|
|
}
|
|
|
|
|
|
window.location.href = document.referrer;
|
|
|
|
|
|
}
|