仰望星辰工作室

better-staridc-MNBT

better-staridc-MNBT/ imsetes/js/fn-hs.js 6.4 KB · 210 行 原始文件
Z zfhsh first commit 1 天前
1//显示通知:1为成功,2为信息,3为警告,4为失败,1000是延迟关闭时间
2//msalert(1,'这是文本内容',1000);
3//显示loading,后面两个参数为文字颜色和加载条颜色
4//msloading('这里是文本内容','text-info','text-info');
5//更新loading文字
6//msloadingup('新的文字','文字颜色,必须和显示时的一样');
7//关闭loading
8//msloadingde();
9
10function msloading(text,textcolor="text-info",loadcolor="text-info",idnr="body"){ //显示加载消息
11 lod = $(idnr).lyearloading({
12 opacity: 0.4,
13 spinnerSize: 'lg',
14 spinnerText: text, //文本文字
15 textColorClass: textcolor, //文本文字颜色
16 spinnerColorClass: loadcolor //加载条颜色
17 });
18}
19
20function msloadingde(idnr="body"){ //关闭加载消息
21 var lod = $(idnr).lyearloading({});
22lod.destroy();
23}
24
25function msloadingup(text,textcolor="text-info"){ //更新文字
26 $("span[class='lyear-loading "+textcolor+"']").html(text);
27}
28
29function msalert(icon,text,msds='3000',idnr="body"){
30 if(icon==1){
31 var csicon='mdi mdi-emoticon-outline';
32 var cstype='success';
33 }else if(icon==2){
34 var csicon='mdi mdi-emoticon-cool-outline';
35 var cstype='info';
36 }else if(icon==3){
37 var csicon='mdi mdi-emoticon-neutral-outline';
38 var cstype='warning';
39 }else if(icon==4){
40 var csicon='mdi mdi-emoticon-dead-outline';
41 var cstype='danger';
42 }
43$.notify({
44 icon: csicon,
45 title: null,
46 message: text
47},{
48 element: idnr,
49 position: null,
50 type: cstype, //成功:success 消息:info 警告:warning 失败:danger
51 allow_dismiss: true,
52 newest_on_top: false,
53 showProgressbar: false,
54 placement: {
55 from: "top",
56 align: "center"
57 }, //显示位置
58 offset: 20,
59 spacing: 10,
60 z_index: 1031,
61 delay: msds, //延迟时间
62 timer: 1000,
63 url_target: '_blank',
64 mouse_over: null,
65 animate: {
66 enter: 'animated fadeInDown',
67 exit: 'animated fadeOutUp'
68 },
69 onShow: null,
70 onShown: null,
71 onClose: null,
72 onClosed: null,
73 icon_type: 'class',
74 template: '<div data-notify="container" class="col-xs-11 col-sm-3 alert alert-{0}" role="alert">' +
75 '<button type="button" aria-hidden="true" class="close" data-notify="dismiss">×</button>' +
76 '<span data-notify="icon"></span> ' +
77 '<span data-notify="title">{1}</span> ' +
78 '<span data-notify="message">{2}</span>' +
79 '<div class="progress" data-notify="progressbar">' +
80 '<div class="progress-bar progress-bar-{0}" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;"></div>' +
81 '</div>' +
82 '<a href="{3}" target="{4}" data-notify="url"></a>' +
83 '</div>'
84});
85}
86
87function msalerts(tp=2,tit='提示',cont='提示信息',fn='',fns='',djs=false){
88if(djs!=false){
89var clo='cancelAction|'+djs;
90}else{
91var clo=false;
92}
93var ico='';
94if(tp==1){
95tp='green'
96ico='mdi-checkbox-marked-circle'
97}else if(tp==2){
98tp='blue'
99ico='mdi-comment-processing'
100}else if(tp==3){
101tp='orange'
102ico='mdi-alert'
103}else{
104tp='red'
105ico='mdi-close-circle'
106}
107// 安全:将 fn/fns 字符串转换为函数(仅当非空时)
108// 注意:仅接受简单的"函数名(参数)"或"变量赋值"格式,拒绝包含 ; 或 (){ } 等可疑结构
109var okCallback = null;
110var cancelCallback = null;
111function _msalerts_make_callback(code) {
112 if (typeof code !== 'string') return null;
113 var trimmed = code.trim();
114 if (trimmed === '') return null;
115 // 拒绝可疑字符,仅允许字母数字、下划线、点、字符串、括号、空格、逗号、=、+、-、*、/、'、"、!、<、>、?、&
116 if (!/^[a-zA-Z0-9_.\s\(\),=+\-*/'"!?<>?&]+$/.test(trimmed)) {
117 console.error('回调函数包含非法字符:', trimmed);
118 return null;
119 }
120 try { return new Function(trimmed); } catch(e) { console.error('回调函数无效:', e); return null; }
121}
122okCallback = _msalerts_make_callback(fn);
123cancelCallback = _msalerts_make_callback(fns);
124 $.alert({
125 title: tit,
126 content: cont,
127 icon: 'mdi '+ico,
128 animation: 'scale',
129 closeAnimation: 'scale',
130 autoClose: clo,
131 draggable: true,
132 type:tp,
133 buttons: {
134 okay: {
135 text: '确认',
136 btnClass: 'btn-'+tp,
137 action: function(){
138 if (okCallback) { try { okCallback(); } catch(e) { console.error('确认回调执行失败:', e); } }
139 }
140 },
141 cancelAction: {
142 text: '取消',
143 action: function() {
144 if (cancelCallback) { try { cancelCallback(); } catch(e) { console.error('取消回调执行失败:', e); } }
145 }
146 }
147 }
148 });
149}
150
151
152
153function msalertb(tp=2,tit='提示',cont='提示信息',jrts=false,djs=false){
154if(djs!=false){
155var clo='cancelAction|'+djs;
156}else{
157var clo=false;
158}
159var ico='';
160if(tp==1){
161tp='green'
162ico='mdi-checkbox-marked-circle'
163}else if(tp==2){
164tp='blue'
165ico='mdi-comment-processing'
166}else if(tp==3){
167tp='orange'
168ico='mdi-alert'
169}else{
170tp='red'
171ico='mdi-close-circle'
172}
173var dsrt;
174if(jrts){
175var hcdatar=localStorage.getItem("dast");
176if(hcdatar!=null){
177var hcdata=JSON.parse(hcdatar);
178let dqsjd=new Date().getTime();
179let datebase=(dqsjd-hcdata[0])/1000;
180if(datebase<86400 && cont==hcdata[1]){
181return;
182}
183}
184
185dsrt='<br/><div class="custom-control custom-checkbox custom-control-inline"><input type="checkbox" id="exampleCheck1" name="exampleCheck1" class="custom-control-input"><label class="custom-control-label" for="exampleCheck1">24小时内不再提示</label></div>';
186}
187 $.alert({
188 title: tit,
189 content: cont+dsrt,
190 icon: 'mdi '+ico,
191 animation: 'scale',
192 closeAnimation: 'scale',
193 autoClose: clo,
194 draggable: true,
195 type:tp,
196 buttons: {
197 okay: {
198 text: '我知道了',
199 btnClass: 'btn-'+tp,
200 action: function() {
201 var xsgx=$("#exampleCheck1").prop('checked');
202 if(jrts && xsgx){
203 var rowrj=JSON.stringify(new Array(new Date().getTime(),cont));
204 localStorage.setItem("dast",rowrj); //缓存数据
205 }
206 }
207 }
208 }
209 });
210}