123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- /**
- * 时间格式化
- *
- * 用法: (new Date).format('Y-m-d H:i:s');
- * @link http://jacwright.com/projects/javascript/date_format/
- */
- Date.prototype.format=function(e){var t="";var n=Date.replaceChars;for(var r=0;r<e.length;r++){var i=e.charAt(r);if(r-1>=0&&e.charAt(r-1)=="\\"){t+=i}else if(n[i]){t+=n[i].call(this)}else if(i!="\\"){t+=i}}return t};Date.replaceChars={shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],longMonths:["January","February","March","April","May","June","July","August","September","October","November","December"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],longDays:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],d:function(){return(this.getDate()<10?"0":"")+this.getDate()},D:function(){return Date.replaceChars.shortDays[this.getDay()]},j:function(){return this.getDate()},l:function(){return Date.replaceChars.longDays[this.getDay()]},N:function(){return this.getDay()+1},S:function(){return this.getDate()%10==1&&this.getDate()!=11?"st":this.getDate()%10==2&&this.getDate()!=12?"nd":this.getDate()%10==3&&this.getDate()!=13?"rd":"th"},w:function(){return this.getDay()},z:function(){var e=new Date(this.getFullYear(),0,1);return Math.ceil((this-e)/864e5)},W:function(){var e=new Date(this.getFullYear(),0,1);return Math.ceil(((this-e)/864e5+e.getDay()+1)/7)},F:function(){return Date.replaceChars.longMonths[this.getMonth()]},m:function(){return(this.getMonth()<9?"0":"")+(this.getMonth()+1)},M:function(){return Date.replaceChars.shortMonths[this.getMonth()]},n:function(){return this.getMonth()+1},t:function(){var e=new Date;return(new Date(e.getFullYear(),e.getMonth(),0)).getDate()},L:function(){var e=this.getFullYear();return e%400==0||e%100!=0&&e%4==0},o:function(){var e=new Date(this.valueOf());e.setDate(e.getDate()-(this.getDay()+6)%7+3);return e.getFullYear()},Y:function(){return this.getFullYear()},y:function(){return(""+this.getFullYear()).substr(2)},a:function(){return this.getHours()<12?"am":"pm"},A:function(){return this.getHours()<12?"AM":"PM"},B:function(){return Math.floor(((this.getUTCHours()+1)%24+this.getUTCMinutes()/60+this.getUTCSeconds()/3600)*1e3/24)},g:function(){return this.getHours()%12||12},G:function(){return this.getHours()},h:function(){return((this.getHours()%12||12)<10?"0":"")+(this.getHours()%12||12)},H:function(){return(this.getHours()<10?"0":"")+this.getHours()},i:function(){return(this.getMinutes()<10?"0":"")+this.getMinutes()},s:function(){return(this.getSeconds()<10?"0":"")+this.getSeconds()},u:function(){var e=this.getMilliseconds();return(e<10?"00":e<100?"0":"")+e},e:function(){return"Not Yet Supported"},I:function(){var e=null;for(var t=0;t<12;++t){var n=new Date(this.getFullYear(),t,1);var r=n.getTimezoneOffset();if(e===null)e=r;else if(r<e){e=r;break}else if(r>e)break}return this.getTimezoneOffset()==e|0},O:function(){return(-this.getTimezoneOffset()<0?"-":"+")+(Math.abs(this.getTimezoneOffset()/60)<10?"0":"")+Math.abs(this.getTimezoneOffset()/60)+"00"},P:function(){return(-this.getTimezoneOffset()<0?"-":"+")+(Math.abs(this.getTimezoneOffset()/60)<10?"0":"")+Math.abs(this.getTimezoneOffset()/60)+":00"},T:function(){var e=this.getMonth();this.setMonth(0);var t=this.toTimeString().replace(/^.+ \(?([^\)]+)\)?$/,"$1");this.setMonth(e);return t},Z:function(){return-this.getTimezoneOffset()*60},c:function(){return this.format("Y-m-d\\TH:i:sP")},r:function(){return this.toString()},U:function(){return this.getTime()/1e3}};
- /**
- * 微乐游戏后台核心类定义
- *
- * @author DongHai Hsing <xingdonghai@gmail.com>
- * @link http://www.xingdonghai.cn/
- * @copyright Copyright © 2016 WeiLe Inc.
- * @package com.weile
- * @since 0.1
- * @version 0.1
- */
- (function(window) {
- var WeiLe = function() {
- return WeiLe.prototype.init();
- };
- WeiLe.prototype = {
- V : { //全局变量, 调用方式 weile.V.variable
- },
- F : { //函数库, 调用方式 weile.F.func()
- },
- D : { //Dom操作函数, 调用方式 weile.D.func()
- },
- C : { //类库, 调用方式 weile.C.class
- },
- init : function() { //初始化
- return this;
- }
- };
- window.weile = new WeiLe();
- })(window);
- /**
- * 微乐游戏后台全局函数定义类
- *
- * @author DongHai Hsing <xingdonghai@gmail.com>
- * @link http://www.xingdonghai.cn/
- * @copyright Copyright © 2013 WeiLe Inc.
- * @package com.weile.admin
- * @since 0.1
- * @version 0.1
- */
- weile.F = (function() {
- //JSON响应状态解析提示数组
- var _JSON_RESPONSE_MSG_DEFINE = {};
- return {
- modalConfig : {remote : false},
- /**
- * alert提示框
- * 该方法可传入最多4个参数:
- * 第一个字符串参数为提示信息
- * 第二个字符串参数为提示框标题
- * 传入的布尔值参数为返回值
- * 传入的可调用函数为点击OK或隐藏时触发的回调事件
- *
- * @author DongHai Hsing <xingdonghai@gmail.com>
- * @return boolean
- */
- alert : function() {
- var msg = '',
- title = '系统提示',
- ret = false,
- callback = function() {};
- for (var i = 0, len = arguments.length; i < len; i++) {
- switch (typeof arguments[i]) {
- case 'string':
- if ('' == msg)
- msg = arguments[i];
- else
- title = arguments[i];
- break;
- case 'boolean':
- ret = arguments[i];
- break;
- case 'function':
- callback = arguments[i];
- break;
- }
- }
- if ('undefined' == typeof jQuery.fn.modalmanager) {
- var html = '<div id="_global_modal_alert" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="_global_modal_alert_label" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button><h3 id="_global_modal_alert_label">' + title + '</h3></div><div class="modal-body"><p>' + msg + '</p></div><div class="modal-footer"><button data-dismiss="modal" class="btn green">OK</button></div></div></div></div>';
- $(html).modal(this.modalConfig).on('shown.bs.modal', function() {
- var radios = $('#_global_modal_alert input[type=radio]:not(.toggle, .star, .make-switch)');
- if (radios.size() > 0) {
- radios.each(function () {
- if (0 == $(this).parents('.checker').size()) {
- $(this).show();
- $(this).uniform();
- }
- });
- }
- }).on('hidden.bs.modal', function() {$('#_global_modal_alert').remove();}).one('hide', function() {$(this).focus();callback();});
- } else {
- var html = '<div id="_global_modal_alert" class="modal fade" tabindex="-1" data-focus-on="input:first"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button><h4 class="modal-title">' + title + '</h4></div><div class="modal-body">' + msg + '</div><div class="modal-footer"><button type="button" data-dismiss="modal" class="btn green">OK</button></div></div>';
- $(html).modal(this.modalConfig).one('hide', callback);
- }
- return ret;
- },
- /**
- * confirm提示框
- *
- * 属性 _CONFIRM_STATE 用于保存confirm提示框的点击结果
- *
- * @author DongHai Hsing <xingdonghai@gmail.com>
- * @param function func 单击确定时执行的回调函数
- * @param string s 提示信息字符串
- */
- //_CONFIRM_STATE : false,
- confirm : function(func, s) {
- s = s || '确认要执行该操作吗?';
- if ('string' == typeof func)
- func = new Function(func);
- bootbox.confirm({
- message : s,
- callback : (function(func) {
- return function(result) {
- if (result)
- func(result);
- };
- })(func),
- buttons: {
- confirm: {
- label: '确定'
- },
- cancel: {
- label: '取消'
- }
- },
- backdrop : false
- });
- /*this._CONFIRM_STATE = false;
- s = s || '确认要执行该操作吗?';
- var html = '<div id="static" class="modal fade" tabindex="-1" data-backdrop="static" data-keyboard="true"><div class="modal-dialog"><div class="modal-content"><div class="modal-body"><p>' + s + '</p></div><div class="modal-footer"><button type="button" data-dismiss="modal" class="btn">取消</button><button type="button" data-dismiss="modal" class="btn green" onclick="weile.F._CONFIRM_STATE = true;">确定</button></div></div></div></div>';
- if ('string' == typeof func)
- func = new Function(func);
- $(html).modal({remote : false}).one('hide', (function(o, func) {
- return function() {
- $(o).focus();
- if (weile.F._CONFIRM_STATE && func)
- func();
- };
- })(this, func));*/
- },
- /**
- * 在指定区间内随机出一个整数
- *
- * @author DongHai Hsing <xingdonghai@gmail.com>
- * @param integer min 最小值
- * @param integer max 最大值
- * @return integer
- */
- rangeRandom : function(min, max) {
- return Math.floor(Math.random() * (max - min + 1) + min);
- },
- /**
- * 解析JSON字符串
- *
- * @author DongHai Hsing <xingdonghai@gmail.com>
- * @return object
- */
- parseJSON : function(data) {
- try {
- return (new Function('return ' + data))();
- } catch (e) {
- return {};
- }
- },
- /**
- * JSON通信信息解析
- *
- * @author DongHai Hsing <xingdonghai@gmail.com>
- * @param json data
- * @return json
- */
- parseJsonResponse : function(data) {
- if (!data || 'object' != typeof data || !data.state)
- return data;
- _JSON_RESPONSE_MSG_DEFINE = $.extend({
- 51 : 'system error',
- 501 : 'parameter error',
- 502 : 'missing parameter',
- 511 : 'invalid app_id',
- 512 : 'api not exist',
- 513 : 'permission failed',
- 514 : 'api has been deprecated',
- 515 : 'invalid version',
- 521 : 'auth faild',
- 522 : 'request has expired',
- 523 : 'not open',
- 524 : 'invalid token',
- 611 : 'failed',
- 621 : ''
- }, _JSON_RESPONSE_MSG_DEFINE);
- if ('undefined' != typeof _JSON_RESPONSE_MSG_DEFINE[data.state] && '' != _JSON_RESPONSE_MSG_DEFINE[data.state])
- data.msg = _JSON_RESPONSE_MSG_DEFINE[data.state];
- switch (data.state) {
- case 501:
- if (data.data && 'undefined' != typeof data.data['name'])
- data.msg += ' : ' + data.data['name'];
- break;
- case 502:
- if (data.data && 'undefined' != typeof data.data['name'])
- data.msg += ' : ' + data.data['name'];
- break;
- default:
- }
- return data;
- },
- /**
- * 设置JSON响应状态解析提示数组
- *
- * @author DongHai Hsing <xingdonghai@gmail.com>
- * @param json data
- * @return json
- */
- setJsonResponseMsgDefine : function(data) {
- if ('obect' == typeof data)
- _JSON_RESPONSE_MSG_DEFINE = $.extend(_JSON_RESPONSE_MSG_DEFINE, data);
- },
- /**
- * JavaScript打开新窗口
- *
- * @access public
- */
- windowOpen : function(url) {
- if (!/^http[s]?:/.test(url))
- url = window.location.protocol + '//' + window.location.host + url;
- return window.open(url, '_blank', 'left=0,top=0,width='+ (screen.availWidth - 10) +',height='+ (screen.availHeight-50) +',scrollbars,resizable=yes,fullscreen=yes');
- },
- /**
- * 创建option元素
- *
- * @access public
- */
- createOption : function(value, text, selected) {
- var option = document.createElement('option');
- option.appendChild(document.createTextNode(text));
- option.setAttribute('value', value);
- option.setAttribute('title', text);
- if (selected)
- option.setAttribute('selected', true);
- return option;
- },
- /**
- * 地区筛选器
- *
- * @access public
- * @param string url 获取数据的url
- * @param string type_or_region 当前地区值的类型 或 6位地区代码. 当为类型时, 值可以是province_id或是city_id; 当值为6位地区代码时, 表示通过该地区代码自动联动选择值
- * @param string default_value 默认值, 6位地区代码
- * @param string parent
- */
- regionSelecter: function(url, type_or_region, default_value, parent) {
- //设置参数
- var the = this,
- _def_value = -1;
- parent = parent || document;
- //如果type_or_region传入的是一个6位地区代码, 那么表示该调用为初始化调用, 重新为实参赋值
- if (/^\d{6}$/.test(type_or_region)) {
- default_value = type_or_region;
- type_or_region = 'province_id';
- //设置省份列表默认选中值
- var _tmp = default_value.substr(0, 2) + '0000';
- $('select[name=province_id]', parent).val(_tmp);
- if ('function' == typeof $('select[name=province_id]', parent).select2)
- $('select[name=province_id]', parent).select2('val', _tmp);
- } else if (0 == type_or_region) {
- $('select[name=province_id]', parent).val(0);
- $('select[name=city_id]', parent).val(0);
- $('select[name=area_id]', parent).val(0);
- if ('function' == typeof $('select[name=province_id]', parent).select2)
- $('select[name=province_id]', parent).select2('val', 0);
- if ('function' == typeof $('select[name=city_id]', parent).select2)
- $('select[name=city_id]', parent).select2('val', 0);
- if ('function' == typeof $('select[name=area_id]', parent).select2)
- $('select[name=area_id]', parent).select2('val', 0);
- return ;
- }
- //如果定义了选项默认值则在生成表单列表时自动选中
- if ('undefined' != typeof default_value) {
- switch (type_or_region) {
- case 'province_id':
- _def_value = default_value.substr(0, 4) + '00';
- break;
- case 'city_id':
- _def_value = default_value;
- break;
- }
- }
- //定义请求参数
- var data = {type : type_or_region};
- data[type_or_region] = $('select[name=' + type_or_region + ']', parent).val();
- if (!data[type_or_region])
- data[type_or_region] = '0';
- //处理默认值
- $.ajax({
- 'url': url,
- 'type': 'post',
- 'dataType': 'json',
- 'cache': false,
- 'data': data,
- success: function (data) {
- if (data) {
- if (data.state) {
- bootbox.alert(data.msg);
- } else {
- var D = data.data;
- for (var name in D) {
- var select = $('select[name=' + name + ']', parent),
- _selected = -1;
- if (select.length) {
- select = select[0];
- select.length = 0;
- select.innerHTML = '';
- if ('city_id' == name) {
- if ($('select[name=area_id]', parent).length) {
- $('select[name=area_id]', parent)[0].length = 0;
- $('select[name=area_id]', parent)[0].innerHTML = '';
- $('select[name=area_id]', parent)[0].appendChild(the.createOption(0, ' 地区 ', true));
- $('select[name=area_id]', parent).select2({
- placeholder: '请选择',
- allowClear: true
- });
- }
- select.appendChild(the.createOption(0, ' 城市 '));
- } else {
- select.appendChild(the.createOption(0, ' 地区 '));
- }
- for (var i in D[name]) {
- select.appendChild(the.createOption(i, '[' + i + '] ' + D[name][i], _def_value == i));
- if (_def_value == i) //如果某值被选中, 那么将该值缓存
- _selected = i;
- }
- $('select[name=' + name + ']', parent).select2({
- placeholder : '请选择',
- allowClear : true
- });
- //如果有被选中的值且当前为城市列表则自动联选下一级
- if (-1 != _selected && 'city_id' == name) {
- the.regionSelecter(url, 'city_id', default_value);
- }
- }
- break;
- }
- }
- } else {
- bootbox.alert('加载失败');
- }
- },
- });
- },
- /**
- * 取消文本选择
- */
- emptySelection : function() {
- if (window.getSelection) {
- if (window.getSelection().empty) { // Chrome
- window.getSelection().empty();
- } else if (window.getSelection().removeAllRanges) { // Firefox
- window.getSelection().removeAllRanges();
- }
- } else if (document.selection) { // IE?
- document.selection.empty();
- }
- }
- };
- })();
- /**
- * 微乐游戏后台全局函数定义类
- *
- * @author DongHai Hsing <xingdonghai@gmail.com>
- * @link http://www.xingdonghai.cn/
- * @copyright Copyright © 2016 WeiLe Inc.
- * @package com.weile
- * @since 0.1
- * @version 0.1
- */
- weile.D = (function() {
- return {
- };
- })();
|