vber.base.js 158 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644
  1. var _LOG = true;
  2. function debug_log() {
  3. if (_LOG) {
  4. console.log(arguments[0], arguments[1] ? arguments[1] : "", arguments[2] ? arguments[2] : "", arguments[3] ? arguments[3] : "", arguments[4] ? arguments[4] : "");
  5. }
  6. }
  7. var abp = abp || {};
  8. let icon = '<i class="fa fa-angle-double-right"></i>';
  9. abp.ui.setBusy = function (elm, opts) {
  10. if (!elm) {
  11. $.blockUI(opts);
  12. } else {
  13. $(elm).block(opts);
  14. }
  15. };
  16. abp.ui.clearBusy = function (elm, opts) {
  17. if (!elm) {
  18. $.unblockUI(opts);
  19. } else {
  20. $(elm).unblock(opts);
  21. }
  22. };
  23. if (typeof jQuery === "undefined") {
  24. throw new Error("jQuery plugins need to be before this file");
  25. }
  26. /*JQuery扩展*/
  27. $.extend({
  28. //表单赋值
  29. formDeserialize: function ($form, data) {
  30. //isSelect2 = isSelect2 === undefined;
  31. if (!data) {
  32. return;
  33. }
  34. let $input = $form.find('input:not([type="radio"]):not([type="checkbox"])');
  35. let $textarea = $form.find("textarea");
  36. let $select = $form.find("select");
  37. let $checkbox = $form.find("input[type='checkbox']");
  38. let $radio = $form.find("input[type='radio']");
  39. $.merge($input, $textarea);
  40. $input.each(function () {
  41. let $input = $form.find($(this));
  42. let name = $input.attr("name");
  43. if (data.hasOwnProperty(name)) {
  44. if ($input.hasClass('flatpickr-input')) {
  45. $input.VbDate("setValue", data[name])
  46. } else {
  47. $input.val(data[name]);
  48. }
  49. }
  50. });
  51. $select.each(function () {
  52. let $select = $form.find($(this));
  53. let name = $select.attr("name");
  54. if (data.hasOwnProperty(name)) {
  55. if (typeof data[name] === "boolean") {
  56. data[name] = data[name] + "";
  57. }
  58. if (data[name] !== "") {
  59. let val = data[name];
  60. $select.val(val);
  61. if ($select.hasClass('ajax-select') && window.ChangAjaxSelectValue) {
  62. window.ChangAjaxSelectValue($select, val);
  63. }
  64. }
  65. }
  66. });
  67. $checkbox.each(function () {
  68. let input = $form.find($(this));
  69. let name = input.attr("name");
  70. if (data.hasOwnProperty(name)) {
  71. $("input[name='" + name + "']").prop("checked", false);
  72. if (typeof data[name] == "string") {
  73. if (data[name] === "True" || data[name] === "1" || data[name] === "true") {
  74. $form.find("input[name='" + name + "']").prop("checked", true);
  75. } else if (data[name].indexOf(",") > 0) {
  76. let arr = data[name].split(',');
  77. for (let i = 0; i < arr.length; i++) {
  78. $form.find("input[name='" + name + "'][value='" + arr[i] + "']").prop("checked", true);
  79. }
  80. }
  81. } else if (typeof data[name] == "object") {
  82. for (let i = 0; i < data[name].length; i++) {
  83. $form.find("input[name='" + name + "'][value='" + data[name][i] + "']").prop("checked", true);
  84. }
  85. }
  86. };
  87. });
  88. $radio.each(function () {
  89. let input = $form.find($(this));
  90. let name = input.attr("name");
  91. if (data.hasOwnProperty(name)) {
  92. $form.find("input[name='" + name + "'][value='" + data[name] + "']").prop("checked", true);
  93. //$("input[name='" + name + "'][value!='" + data[name] + "']").prop("checked", false);
  94. }
  95. });
  96. },
  97. //将form表单元素的值序列化成对象
  98. formSerialize: function ($form) {
  99. let disableEle = $form.find("[disabled]");
  100. disableEle.each(function (i, e) {
  101. $(e).prop("disabled", false);
  102. });
  103. let data = {};
  104. $.each($form.serializeArray(),
  105. function () {
  106. if (data[this['name']]) {
  107. data[this['name']] = data[this['name']] + "," + this['value'];
  108. } else {
  109. data[this['name']] = this['value'];
  110. }
  111. });
  112. disableEle.each(function (i, e) {
  113. $(e).prop("disabled", true);
  114. });
  115. return data;
  116. },
  117. //表单验证
  118. formValidate: function ($form, opt) {
  119. let defaults = {
  120. noValid: false,
  121. form: "form",
  122. modal: "modal",
  123. ignore: ".ignore .iwb-wang-editor"
  124. };
  125. opt = opt || {};
  126. let options = $.extend({}, defaults, opt);
  127. let $modal = options.modal
  128. ? typeof (options.modal) === 'string'
  129. ? $('#' + options.modal)
  130. : $(options.modal)
  131. : null;
  132. $form = $form ? $form : options.form ? $(options.form) : $modal.find('form');
  133. $form.validate(options);
  134. //.settings.ignore = ":disabled";
  135. if (!options.noValid) {
  136. let valid = $form.valid();
  137. debug_log("FormValidate", $form.attr('id'), valid);
  138. return valid;
  139. }
  140. return options.noValid;
  141. },
  142. formatterDate: function (fmt, date, isFix) {
  143. date = date || new Date();
  144. isFix = isFix === undefined ? true : isFix;
  145. let year = date.getFullYear();
  146. let month = date.getMonth() + 1;
  147. fmt = fmt.replace("yyyy", year);
  148. fmt = fmt.replace("yy", year % 100);
  149. fmt = fmt.replace("MM", fix(month));
  150. fmt = fmt.replace("dd", fix(date.getDate()));
  151. fmt = fmt.replace("HH", fix(date.getHours()));
  152. fmt = fmt.replace("mm", fix(date.getMinutes()));
  153. fmt = fmt.replace("ss", fix(date.getSeconds()));
  154. return fmt;
  155. function fix(n) {
  156. return isFix ? (n < 10 ? "0" + n : n) : n;
  157. }
  158. },
  159. blinkTitle: {
  160. start: function (msg) {
  161. msg = msg || abp.localization.iwbZero('NewNotificationRemind');
  162. this.title = document.title;
  163. this.messages = [msg];
  164. if (!this.action) {
  165. try {
  166. this.element = document.getElementsByTagName('title')[0];
  167. this.element.innerHTML = this.title;
  168. this.action = function (ttl) {
  169. this.element.innerHTML = ttl;
  170. };
  171. } catch (e) {
  172. this.action = function (ttl) {
  173. document.title = ttl;
  174. };
  175. delete this.element;
  176. }
  177. this.toggleTitle = function () {
  178. this.index = this.index === 0 ? 1 : 0;
  179. this.action('【' + this.messages[this.index] + '】' + this.title);
  180. };
  181. }
  182. let n = msg.length;
  183. let s = '';
  184. if (this.element) {
  185. let num = msg.match(/\w/g);
  186. if (num) {
  187. let n2 = num.length;
  188. n -= n2;
  189. while (n2 > 0) {
  190. s += " ";
  191. n2--;
  192. }
  193. }
  194. }
  195. while (n > 0) {
  196. s += ' ';
  197. n--;
  198. }
  199. this.messages.push(s);
  200. this.index = 0;
  201. //this.title = this.title.replace("【" + msg + "】", "").replace("【" + s + "】", "");
  202. let _this = this;
  203. this.timer = setInterval(function () {
  204. _this.toggleTitle();
  205. }, 500);
  206. },
  207. stop: function () {
  208. if (this.timer) {
  209. clearInterval(this.timer);
  210. let t = this.title ? this.title : document.title;
  211. this.action(t);
  212. delete this.timer;
  213. delete this.messages;
  214. }
  215. }
  216. },
  217. metPageCss: function (url, id) {
  218. id = id || 'dy-css';
  219. if ($('#' + id).length > 0) {
  220. return;
  221. }
  222. let link = document.createElement('link');
  223. link.type = 'text/css';
  224. link.rel = 'stylesheet';
  225. link.id = id;
  226. link.href = url + '?v=' + Math.floor(Math.random() * 100000);
  227. let flag = document.getElementById('flag');
  228. let head = document.getElementsByTagName('head')[0];
  229. if (flag) {
  230. head.insertBefore(link, flag.nextSibling);
  231. } else {
  232. head.appendChild(link);
  233. }
  234. },
  235. metPageJs: function (src, id) {
  236. id = id || 'dy-js';
  237. if ($('#' + id).length > 0) {
  238. return;
  239. }
  240. let script = document.createElement('script');
  241. script.id = id;
  242. script.type = 'text/javascript';
  243. script.charset = 'UTF-8';
  244. script.src = src + '?v=' + Math.floor(Math.random() * 100000);
  245. $('head').append(script);
  246. },
  247. loadScript: function (url, loadCallback, failCallback) {
  248. /* UrlStates enum */
  249. let urlStates = {
  250. LOADING: 'LOADING',
  251. LOADED: 'LOADED',
  252. FAILED: 'FAILED'
  253. };
  254. /* UrlInfo class */
  255. function UrlInfo() {
  256. this.state = urlStates.LOADING;
  257. this.loadCallbacks = [];
  258. this.failCallbacks = [];
  259. }
  260. UrlInfo.prototype.succeed = function () {
  261. this.state = urlStates.LOADED;
  262. for (let i = 0; i < this.loadCallbacks.length; i++) {
  263. this.loadCallbacks[i]();
  264. }
  265. };
  266. UrlInfo.prototype.failed = function () {
  267. this.state = urlStates.FAILED;
  268. for (let i = 0; i < this.failCallbacks.length; i++) {
  269. this.failCallbacks[i]();
  270. }
  271. };
  272. UrlInfo.prototype.handleCallbacks = function (loadCallback, failCallback) {
  273. switch (this.state) {
  274. case urlStates.LOADED:
  275. loadCallback && loadCallback();
  276. break;
  277. case urlStates.FAILED:
  278. failCallback && failCallback();
  279. break;
  280. case urlStates.LOADING:
  281. this.addCallbacks(loadCallback, failCallback);
  282. break;
  283. }
  284. };
  285. UrlInfo.prototype.addCallbacks = function (loadCallback, failCallback) {
  286. loadCallback && this.loadCallbacks.push(loadCallback);
  287. failCallback && this.failCallbacks.push(failCallback);
  288. };
  289. let urlInfos = {};
  290. let loadScript = function (url, loadCallback, failCallback) {
  291. let urlInfo = urlInfos[url];
  292. if (urlInfo) {
  293. urlInfo.handleCallbacks(loadCallback, failCallback);
  294. return;
  295. }
  296. urlInfos[url] = urlInfo = new UrlInfo();
  297. urlInfo.addCallbacks(loadCallback, failCallback);
  298. $.getScript(url).done(function (script, textStatus) {
  299. urlInfo.succeed(script, textStatus);
  300. }).fail(function (jqXhr, settings, exception) {
  301. urlInfo.failed(jqXhr, settings, exception);
  302. });
  303. };
  304. loadScript(url, loadCallback, failCallback);
  305. },
  306. //jsonTree 转成 array
  307. Json2Array: function (data, opts) {
  308. let defaults = {
  309. id: 'id',
  310. parentId: 'parentId',
  311. children: 'children'
  312. };
  313. let opt = $.extend({}, defaults, opts || {});
  314. let Json2ArrayChild = function (data, dataArray) {
  315. let newData = $.extend([], data);
  316. let children = data[opt.children];
  317. delete newData[opt.children];
  318. dataArray.push(newData);
  319. if (children && children.length > 0) {
  320. children.forEach(function (v) {
  321. Json2ArrayChild(v, dataArray);
  322. });
  323. }
  324. }
  325. let dataArray = [];
  326. let children = data[opt.children];
  327. let newData = $.extend([], data);
  328. delete newData[opt.children];
  329. dataArray.push(newData);
  330. if (children && children.length > 0) {
  331. children.forEach(function (v) {
  332. Json2ArrayChild(v, dataArray);
  333. });
  334. }
  335. return dataArray;
  336. },
  337. //array 转成 JsonTree
  338. Array2Json: function (dataArray, opts) {
  339. let defaults = {
  340. root: '',
  341. id: 'id',
  342. parentId: 'parentId',
  343. children: 'children'
  344. };
  345. let opt = $.extend({}, defaults, opts || {});
  346. let Json2DataChild = function (parentId, dataArray) {
  347. let children = dataArray.filter(function (v) {
  348. return v[opt.parentId] === parentId;
  349. });
  350. if (children && children.length > 0) {
  351. children.forEach(function (v) {
  352. v[opt.children] = Json2DataChild(v[opt.id], dataArray);
  353. });
  354. }
  355. return children;
  356. }
  357. let index = dataArray.findIndex(function (v) {
  358. return v[opt.parentId] === opt.root;
  359. });
  360. let dataJson = dataArray[index];
  361. dataJson[opt.children] = Json2DataChild(dataJson.id, dataArray);
  362. return dataJson;
  363. }
  364. });
  365. $.fn.formDeserialize = function (data) {
  366. $.formDeserialize($(this), data);
  367. }
  368. $.fn.formSerialize = function () {
  369. return $.formSerialize($(this));
  370. }
  371. /*AJAX*/
  372. $.extend({
  373. //ajax
  374. vbAjax: function (url, opt) {
  375. this.defaults = {
  376. async: true,
  377. type: "Post",
  378. contentType: 'application/json; charset=UTF-8',
  379. //contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
  380. data: null,
  381. dataFun: null,
  382. log: _LOG,
  383. dataType: "json",
  384. isAlert: true,
  385. successAlert: false,
  386. isValidate: true,
  387. isRefresh: true,//默认刷新表格
  388. success: null,
  389. error: null,
  390. table: undefined,
  391. modal: undefined,
  392. form: undefined,
  393. errorPlacement: function (error, element) {
  394. element.parent().before(error);
  395. element.focus();
  396. },
  397. rules: {},
  398. blockUI: true
  399. };
  400. if (!opt) {
  401. opt = url;
  402. url = opt.url;
  403. }
  404. let options = $.extend({}, this.defaults, opt);
  405. let $table = !options.table ? undefined : typeof options.table === 'string' ? $('#' + options.table) : $(options.table);
  406. let $modal = !options.modal ? undefined : typeof options.modal === 'string' ? $('#' + options.modal) : $(options.modal);
  407. let $form = !options.form ? ($modal ? $modal.find("form") : undefined) : typeof options.form === 'string' ? $('#' + options.form) : $(options.form);
  408. let isValidated = true;
  409. if (options.isValidate && $form) {
  410. isValidated = $.formValidate($form);
  411. }
  412. if (isValidated) {
  413. if (options.dataFun !== null && typeof options.dataFun === 'function') {
  414. options.data = options.dataFun();
  415. } else {
  416. options.data = options.data ? (typeof options.data === 'function' ? options.data() : options.data) : $form ? $.formSerialize($form) : undefined;
  417. }
  418. let guid = Math.floor(Math.random() * 10000);
  419. let log = options.log;
  420. if (log) {
  421. console.log('[' + guid + ']url:' + url, 'data:', options.data);
  422. }
  423. let success = options.success && typeof options.success === 'function'
  424. ? function (res) {
  425. if (log) { console.log('[' + guid + ']', res); }
  426. options.success(res);
  427. if (options.isRefresh && $table) {
  428. $table.VbTable('refresh', true);
  429. }
  430. if ($modal) {
  431. $modal.VbModal('hide');
  432. }
  433. }
  434. : function (res) {
  435. if (log) { console.log('[' + guid + ']', res); }
  436. if (options.isRefresh && $table) {
  437. $table.VbTable('refresh', true);
  438. }
  439. if ($modal) {
  440. $modal.VbModal('hide');
  441. }
  442. };
  443. let ajaxSuccess = options.isAlert || options.successAlert ? function (res) { abp.message.success(abp.localization.VberZero('OpSuccess')).done(success(res)); } : success;
  444. let data = typeof (options.data) === 'string' ? options.data : JSON.stringify(options.data);
  445. let ajaxOption = {
  446. url: url,
  447. async: options.async,
  448. type: options.type,
  449. contentType: options.contentType,
  450. data: data,
  451. dataType: options.dataType,
  452. success: ajaxSuccess,
  453. error: options.error,
  454. abpHandleError: options.isAlert,
  455. beforeSend: function () {
  456. abp.ajax.blockUI(ajaxOption);
  457. },
  458. blockUI: options.blockUI
  459. };
  460. abp.ajax(ajaxOption);
  461. }
  462. }
  463. });
  464. $.extend({
  465. vbAjax1: function (opt) {
  466. opt = $.extend({}, { isValidate: false }, opt);
  467. $.vbAjax(opt);
  468. },
  469. vbAjax2: function (opt) {
  470. opt = $.extend({}, { isAlert: false }, opt);
  471. $.vbAjax(opt);
  472. },
  473. vbAjax3: function (opt) {
  474. opt = $.extend({}, { isValidate: false, isAlert: false, blockUI: true }, opt);
  475. $.vbAjax(opt);
  476. },
  477. vbAjax4: function (opt) {
  478. opt = $.extend({}, { isValidate: false, isAlert: false, isRefresh: false, blockUI: true }, opt);
  479. $.vbAjax(opt);
  480. },
  481. vbAjax41: function (opt) {
  482. opt = $.extend({}, { isValidate: false, isAlert: false, isRefresh: false, blockUI: false }, opt);
  483. $.vbAjax(opt);
  484. },
  485. vbAjax5: function (opt) {
  486. opt = $.extend({}, { isValidate: false, isAlert: false, successAlert: true, isRefresh: false, blockUI: true }, opt);
  487. $.vbAjax(opt);
  488. },
  489. vbGet: function (opt) {
  490. opt = $.extend({}, { type: 'get', modal: null, form: null }, opt);
  491. $.vbAjax4(opt);
  492. }
  493. });
  494. /*ajax全局设置*/
  495. $.ajaxSetup({
  496. type: 'get',
  497. timeout: 1000 * 60 * 2,
  498. //contentType: "application/x-www-form-urlencoded;charset=utf-8",
  499. contentType: "application/json",
  500. dataType: "json",
  501. error: function () {
  502. abp.ui.clearBusy();
  503. },
  504. complete: function (xmlHttpRequest, textStatus) {
  505. abp.ui.clearBusy();
  506. if (textStatus === "timeout") {
  507. abp.message.error(abp.localization.iwbZero('OpTimeout'));
  508. debug_log("Complete - 操作超时");
  509. } else if (textStatus !== "success") {
  510. debug_log("Complete - " + textStatus, xmlHttpRequest.responseJSON);
  511. if (xmlHttpRequest.responseJSON) {
  512. //let json = xmlHttpRequest.responseJSON;
  513. } else if (xmlHttpRequest.responseText === "") {
  514. abp.message.error(abp.localization.VberZero('OpServerError')).done(function () {
  515. top.location.reload();
  516. //top.location.href = "/Account/Login/?ReturnUrl=%2F";
  517. });
  518. }
  519. } else {
  520. let result = xmlHttpRequest.responseJSON;
  521. if (result && !result.success && result.error && result.error.message.indexOf('登陆超时') > -1) {
  522. top.location.reload();
  523. }
  524. }
  525. }
  526. });
  527. (function (global, factory) {
  528. typeof exports === 'object' && typeof module !== 'undefined'
  529. ? factory(exports)
  530. : typeof define === 'function' && define.amd
  531. ? define(['exports'], factory)
  532. : (global = global || self, factory(global.vber = { a: "1" }));
  533. }(this, (function (exports) {
  534. 'use strict';
  535. let abp = window.abp || {};
  536. let VbTable = function ($) {
  537. const NAME = 'VbTable';
  538. const DATA_KEY = 'Vber.DataTable';
  539. const EVENT_KEY = "." + DATA_KEY;
  540. const JQUERY_NO_CONFLICT = $.fn[NAME];
  541. const ClassName = {
  542. TABLE_BOX: 'table-box',
  543. DATE_RANGE: 'vb-date-range',
  544. SEARCH_FIELD: 'search-filed',
  545. SEARCH_FIELD_TYPE: 'search-filed-type',
  546. SEARCH_EXP_TYPE: 'search-exp-type',
  547. TOOL_MENU_TYPE: 'vb-tool-menu-type',
  548. TOOL_MENU_URL: 'vb-tool-menu-url',
  549. TREE_TD_CONTROL: 'vb-treegrid-control',
  550. TREE_TD_CONTROL_OPEN: 'vb-treegrid-control-open',
  551. };
  552. const Selector = {
  553. TABLE_BOX: `.${ClassName.TABLE_BOX}`,
  554. TOOLBAR_BASE: '[data-kt-table-toolbar="base"]',
  555. TOOLBAR_SELECTED: '[data-kt-table-toolbar="selected"]',
  556. TOOLBAR_SELECTED_COUNT: '[data-kt-table-select="selected_count"]',
  557. SEARCH_GLOBAL: `[data-search-keyWord="global"]`,
  558. SEARCH_ADVANCE: `[data-search-keyWord="advance"]`,
  559. TOOL_MENU_ALL: `[data-vb-tool-menu-type]`,
  560. TOOL_MENU: `[data-vb-tool-menu-type="{0}"]`,
  561. TREE_TD_CONTROL: `td.${ClassName.TREE_TD_CONTROL}`,
  562. TREE_TD_CONTROL_OPEN: `td.${ClassName.TREE_TD_CONTROL_OPEN}`
  563. };
  564. const ALLOW_METHOD = [
  565. "addToolFunctions",
  566. "getToolFunctions",
  567. "create",
  568. "update",
  569. "delete",
  570. "getRow",
  571. "getSelection",
  572. "getSelections",
  573. "getSelectionIds",
  574. "getInstance",
  575. "reRender",
  576. "destroy",
  577. "refresh",
  578. "treeExpandAll",
  579. "treeExpand",
  580. "treeCollapse",
  581. ];
  582. const Default = {
  583. processing: true,
  584. serverSide: true,
  585. scrollCollapse: true,
  586. paging: true,
  587. autoWidth: true,
  588. searching: false,
  589. ordering: true,
  590. orderClasses: true,
  591. rowId: "id",
  592. pagingType: "full_numbers",//分页样式:simple,simple_numbers,full,full_numbers
  593. select: {
  594. style: 'os',
  595. selector: 'td:first-child',
  596. className: 'row-selected'
  597. },
  598. lengthChange: true,
  599. lengthMenu: [25, 50, 100],
  600. clickToSelect: true,
  601. deferRender: false,
  602. drawCallback: undefined,
  603. searchForm: undefined,
  604. searchList: [],
  605. searchFun: null,
  606. onlySearchList: false,
  607. searchValidate: true,
  608. dateRangeSpliter: "至",
  609. order: [],
  610. toolFunctions: [],
  611. onAllCheck: undefined,
  612. onAllUnCheck: undefined,
  613. onCheck: undefined,
  614. onUnCheck: undefined,
  615. onClickRow: undefined,
  616. onDblClickRow: undefined,
  617. modal: 'modal',
  618. form: 'form',
  619. modalDrag: true,
  620. multipleSelect: false,//多选保存分页数据
  621. isTree: false,
  622. left: 12,//tree的子目录偏移
  623. expandDepth: 2,
  624. leafIcon: '<span class="fas fa-folder"></span>',//叶子节点
  625. expandIcon: '<span class="fas fa-folder-plus"></span>',
  626. collapseIcon: '<span class="fas fa-folder-open"></span>',
  627. fnDrawCallback: undefined,
  628. root: null,
  629. field: "id",
  630. parentField: "parentNo",
  631. nameField: "name",
  632. parentNameField: "parentName",
  633. };
  634. let Table = function () {
  635. function Table(element, config) {
  636. this._element = element;
  637. this._config = config;
  638. return this._init();
  639. }
  640. let _proto = Table.prototype, dt, _selectedIdArray = [], treeGridRows = {};
  641. _proto._init = function () {
  642. let _this = this, _config = _this._config, _el = _this._element;
  643. $.fn.dataTable.ext.errMode = "none "
  644. let htmlOptions = _this._getHtmlOption();
  645. if (window.lang && window.lang != "en") {
  646. htmlOptions.language = { url: `/libs-ext/dataTable/language_${window.lang}.json` };
  647. }
  648. let options = $.extend(true, {}, htmlOptions, _config, _config.isTree ? { paging: false, pageSelect: false, dom: "tr" } : {});
  649. debug_log("table_options:", options);
  650. dt = $(_el).DataTable(options);
  651. _config.dataTable = dt;
  652. //_this._initToggleToolbar();
  653. dt.on(`init${EVENT_KEY}`, function () {
  654. _this._onEvent();
  655. _this._drawRender();
  656. })
  657. _this._initToolFunction();
  658. if (_config.isTree) {
  659. _this._initTree();
  660. }
  661. };
  662. _proto._getHtmlOption = function () {
  663. let _this = this, _config = _this._config, _el = _this._element;
  664. let htmlOption = $.extend(true, {}, $(_el).data());
  665. if (htmlOption.url) {
  666. htmlOption.ajax = {
  667. contentType: 'application/json; charset=UTF-8',
  668. url: htmlOption.url,
  669. type: htmlOption.method,
  670. data: (param) => {
  671. return _config.queryParams && typeof _config.queryParams == 'function'
  672. ? _config.queryParams.call(_this, param)
  673. : _this._queryParams(param);
  674. },
  675. dataFilter: (data) => {
  676. return _config.responseHandler && typeof _config.responseHandler == 'function'
  677. ? _config.responseHandler.call(_this, data)
  678. : _this._responseHandler(data);
  679. },
  680. error: function () {
  681. console.error(`Table[${$(_this._element).attr('id')}] load failed`);
  682. $('#table_processing').fadeOut();
  683. abp.message.error("加载出错!");
  684. }
  685. };
  686. }
  687. htmlOption.columns = _config.columnsFunc && typeof _config.columnsFunc == 'function'
  688. ? _config.columnsFunc.call(_this, $.extend(true, {}, $(_el).data()))
  689. : htmlOption.columnsFunc && typeof window[htmlOption.columnsFunc] == "function"
  690. ? window[htmlOption.columnsFunc].call(_this, $.extend(true, {}, $(_el).data()))
  691. : _this._getColumnOption();
  692. htmlOption.rowCallback = htmlOption.rowCallbackFunc && typeof window[htmlOption.rowCallbackFunc] == "function" ?
  693. function (row, data) {
  694. window[htmlOption.rowCallbackFunc].call(_this, row, data);
  695. _this._rowCallback.call(_this, row, data);
  696. } :
  697. function (row, data) {
  698. _this._rowCallback.call(_this, row, data);
  699. };
  700. return htmlOption;
  701. }
  702. _proto._getColumnOption = function () {
  703. let _this = this, _config = _this._config, _el = _this._element;
  704. let columns = [];
  705. let treeColumns = _config.isTree;
  706. let $th = $(_el).find('thead').eq(0).find('th');
  707. if ($th.length) {
  708. $th.each(function () {
  709. let $this = $(this), data = $this.data();
  710. let column = {
  711. data: data.field ? function (item) { return item[data.field] } : null,
  712. orderable: data.sortable ? true : false,
  713. searchable: false
  714. };
  715. column.name = data.field;
  716. if (data.className) {
  717. column.className = data.className;
  718. }
  719. if (data.width) {
  720. column.width = data.width;
  721. }
  722. //if (data.className) {
  723. // column.className = data.className;
  724. //}
  725. if (data.checkBox) {
  726. column.orderable = false;
  727. column.data = "check_state";
  728. column.render = function (data) {
  729. let checked = data ? "checked=\"checked\"" : "";
  730. return `
  731. <div class="form-check form-check-sm form-check-custom form-check-solid">
  732. <input name="check_state" class="form-check-input" type="checkbox" ${checked} value="${data}" />
  733. </div>`;
  734. }
  735. }
  736. if (data.formatter) {
  737. if (window[data.formatter] && typeof window[data.formatter] === "function") {
  738. column.render = function (d, t, r, m) {
  739. let v = t == "display" ?
  740. window[data.formatter].call(this, d, r) :
  741. d;
  742. return v;
  743. };
  744. } else {
  745. column.render = () => data.formatter + "";
  746. }
  747. }
  748. //formatter 后 tip就不能起作用。
  749. if (data.tip && !data.formatter) {
  750. column.render = function (value, type, row, meta) {
  751. if (type === 'display') {
  752. let length = Number(data.tip) && Number(data.tip) > 0 ? Number(data.tip) : 40;
  753. return value.length > length ? `<span data-bs-toggle="tooltip" title="${value}">${value.substr(0, length - 2)}...</span>` : value;
  754. }
  755. return value;
  756. };
  757. }
  758. if (data.tree && treeColumns) {
  759. treeColumns = false;
  760. column.title = '';
  761. column.target = 0;
  762. column.orderable = false;
  763. column.className = ClassName.TREE_TD_CONTROL;
  764. column.data = function (item) {
  765. if (item.children != null && item.children.length > 0) {
  766. return _config.expandIcon;
  767. }
  768. return _config.leafIcon;
  769. }
  770. }
  771. if (data.action) {
  772. // let action = `
  773. //<span href="#" class="btn btn-light-primary py-0 fs-9" data-kt-menu-trigger="click" data-kt-menu-placement="bottom-end" data-kt-menu-flip="top-end" style="line-height:23px;">操作
  774. // <!--Svg Icon | path: icons/duotone/Navigation/Angle-down.svg-->
  775. // <span class="svg-icon svg-icon-5 m-0 ms-1">
  776. // <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1">
  777. // <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
  778. // <polygon points="0 0 24 0 24 24 0 24"></polygon>
  779. // <path d="M6.70710678,15.7071068 C6.31658249,16.0976311 5.68341751,16.0976311 5.29289322,15.7071068 C4.90236893,15.3165825 4.90236893,14.6834175 5.29289322,14.2928932 L11.2928932,8.29289322 C11.6714722,7.91431428 12.2810586,7.90106866 12.6757246,8.26284586 L18.6757246,13.7628459 C19.0828436,14.1360383 19.1103465,14.7686056 18.7371541,15.1757246 C18.3639617,15.5828436 17.7313944,15.6103465 17.3242754,15.2371541 L12.0300757,10.3841378 L6.70710678,15.7071068 Z" fill="#000000" fill-rule="nonzero" transform="translate(12.000003, 11.999999) rotate(-180.000000) translate(-12.000003, -11.999999)"></path>
  780. // </g>
  781. // </svg>
  782. // </span>
  783. //</span>`;
  784. if (data.actionTree) {
  785. column.className = "text-end pe-2";
  786. let treeActionMenu = "";
  787. $(_el).closest(Selector.TABLE_BOX).find(Selector.TOOLBAR_BAS + "," + Selector.TOOLBAR_SELECTED).addClass("d-none").find(Selector.TOOL_MENU_ALL).each(function () {
  788. let btnType = $(this).data(ClassName.TOOL_MENU_TYPE).replace("_", "");
  789. if (btnType !== "btnRefresh" && btnType !== "btnSearch") {
  790. let btnUrl = $(this).data(ClassName.TOOL_MENU_URL) || "";
  791. let btnName = $(this).text();
  792. //let btnClass = $(this).attr("class");
  793. let btnIcon = $(this).find("i").attr("class");
  794. /* treeActionMenu += `<div class="menu-item px-3"><a href="#" class="px-3 ${btnClass}" data-id="{0}" onclick="$('#${_el.id}').VbTable('getToolFunctions')['${btnType}_tree'].call(this,'${btnUrl}','{0}')"> <i class="${btnIcon}"></i>${btnName}</a></div>`;*/
  795. //$(this).remove();
  796. treeActionMenu += `<span class="table-action" onclick="$('#${_el.id}').VbTable('getToolFunctions')['${btnType}_tree'].call(this,'${btnUrl}','{0}')">${btnIcon ? `<i class="${btnIcon}"></i>` : icon}${btnName}</span>`
  797. } else if (btnType !== "btnSearch") {
  798. $(this).prop("disabled", false).attr("onclick", "$.vbAjax1({url: '" + $(this).data(ClassName.TOOL_MENU_URL) + "'});");
  799. }
  800. });
  801. data.actionFormatter = function treeActionFormatter(d, r) {
  802. return treeActionMenu.format(r[_config.rowId]);
  803. };
  804. }
  805. /* let actionMenu = `<div class="menu menu-sub menu-sub-dropdown menu-column menu-rounded menu-gray-600 menu-state-bg-light-primary fw-bold fs-7 w-125px py-4 " data-kt-menu-action="true" kt-hidden-height="120" style="">{0}</div>`;*/
  806. if (data.actionFormatter) {
  807. let actionMenuFunc = typeof data.actionFormatter == "function" ? data.actionFormatter : typeof window[data.actionFormatter] == "function" ? window[data.actionFormatter] : false;
  808. if (actionMenuFunc) {
  809. column.render = function (d, t, r) {
  810. //return t == "display" ? `${action}\r\n${actionMenu.format(actionMenuFunc.call(this, d, r))}` : d;
  811. return t == "display" ? `${actionMenuFunc.call(this, d, r)}` : d;
  812. }
  813. }
  814. }
  815. }
  816. columns.push(column);
  817. });
  818. }
  819. return columns;
  820. };
  821. _proto._queryParams = function (param) {
  822. let _this = this, _config = _this._config;
  823. let queryParam, sort = "";
  824. if (param.order && param.order.length) {
  825. param.order.forEach((v) => {
  826. sort += (sort == "" ? "" : ",") + `${param.columns[v.column].name} ${v.dir}`;
  827. });
  828. }
  829. let $searchForm = _this._getSearchForm();
  830. let searchList = _this._getSearchList();
  831. if (_config.onlySearchList) {
  832. queryParam = {
  833. maxResultCount: params.limit,
  834. skipCount: params.offset,
  835. sorting: params.sort ? params.sort + ' ' + params.order : '',
  836. searchList: searchList
  837. };
  838. } else {
  839. let $search = $searchForm.find(Selector.SEARCH_GLOBAL);
  840. queryParam = {
  841. maxResultCount: param.length > 0 ? param.length : 1000,
  842. skipCount: param.start,
  843. sorting: sort,
  844. keyField: $search.data(ClassName.SEARCH_FIELD),
  845. fieldType: $search.data(ClassName.SEARCH_FIELD_TYPE) ? $search.data(ClassName.SEARCH_FIELD_TYPE) : 0,
  846. expType: $search.data(ClassName.SEARCH_EXP_TYPE) ? $search.data(ClassName.SEARCH_EXP_TYPE) : 0,
  847. keyWords: $search.val(),
  848. SearchList: searchList
  849. }
  850. }
  851. if (_LOG) {
  852. debug_log("table_queryParam", queryParam);
  853. }
  854. return JSON.stringify(queryParam);
  855. };
  856. _proto._getSearchForm = function () {
  857. let _this = this, _config = _this._config;
  858. let $form;
  859. if (_config.searchForm) {
  860. $form = typeof (_config.searchForm) === 'string'
  861. ? $('#' + _config.searchForm)
  862. : $(_config.searchForm);
  863. }
  864. if ($form && $form.length) {
  865. return $form;
  866. }
  867. $form = $(_this._element).closest(Selector.TABLE_BOX).find('form');
  868. return $form;
  869. }
  870. _proto._getSearchList = function () {
  871. let _this = this, _config = _this._config;
  872. let searchList = [];
  873. if (_config.searchFun && typeof _config.searchFun === "function") {
  874. _config.searchFun.call(_this, searchList);
  875. }
  876. if (_config.onlySearchFun) {
  877. return searchList;
  878. }
  879. if (_config.searchList && _config.searchList.length > 0) {
  880. _config.searchList.forEach(function (v) {
  881. if (v.keyWords) {
  882. searchList.push(v);
  883. }
  884. });
  885. }
  886. if (_config.onlySearchList) {
  887. return searchList;
  888. }
  889. let $searchForm = _this._getSearchForm();
  890. $searchForm.find(Selector.SEARCH_ADVANCE).each(function () {
  891. let $this = $(this), keyWords = $this.val();
  892. if (($this.attr('type') == "checkBox" || $this.attr('type') == "radio") && !$this.is(':checked')) {
  893. keyWords = undefined;
  894. }
  895. if (keyWords) {
  896. let field = $this.data(ClassName.SEARCH_FIELD), fieldType = $this.data(ClassName.SEARCH_FIELD_TYPE);
  897. // ReSharper disable once UnknownCssClass
  898. if ($this.hasClass(ClassName.DATE_RANGE)) {
  899. try {
  900. let dates = keyWords.split(` ${_config.dateRangeSpliter} `);
  901. searchList.push({
  902. keyWords: dates[0],
  903. keyField: field,
  904. fieldType: fieldType,
  905. expType: 4
  906. });
  907. if (dates.length === 2) {
  908. let nextDate = new Date(dates[1]);
  909. let newDate = new Date(nextDate.getFullYear(),
  910. nextDate.getMonth(),
  911. nextDate.getDate(),
  912. 23,
  913. 59,
  914. 59,
  915. 999);
  916. //let newDate = new Date(date.getTime() + 24 * 60 * 60 * 1000 - 1);
  917. let date2 = $.formatterDate('yyyy-MM-dd HH:mm:ss', newDate);
  918. searchList.push({
  919. keyWords: date2,
  920. keyField: field,
  921. fieldType: fieldType,
  922. expType: 5
  923. });
  924. }
  925. } catch (e) {
  926. console.log(e);
  927. }
  928. } else {
  929. let expType = $this.data(ClassName.SEARCH_EXP_TYPE)
  930. searchList.push({
  931. keyWords: keyWords,
  932. keyField: field,
  933. fieldType: fieldType,
  934. expType: expType
  935. });
  936. }
  937. }
  938. });
  939. return searchList;
  940. }
  941. _proto._responseHandler = function (res) {
  942. let _this = this, _config = _this._config;
  943. let json = jQuery.parseJSON(res);
  944. let result = {
  945. recordsTotal: 0,
  946. recordsFiltered: 0,
  947. data: []
  948. }
  949. if (json.success) {
  950. if (_config.isTree) {
  951. result.data = _this._toTreeData(json.result.items);
  952. } else {
  953. result.recordsTotal = json.result.totalCount;
  954. result.recordsFiltered = json.result.totalCount;
  955. result.data = json.result.items;
  956. }
  957. } else {
  958. console.log(`Table[${$(_this._element).attr('id')}] load failed`);
  959. if (res.error) {
  960. if (res.error.details) {
  961. return abp.message.error(res.error.details, res.error.message);
  962. } else {
  963. if (res.error.message && res.error.message.indexOf('登陆超时') >= 0) {
  964. return abp.message.error(res.error.message).done(function () {
  965. window.top.location.reload();
  966. });
  967. } else {
  968. return abp.message.error(res.error.message || abp.ajax.defaultError.message);
  969. }
  970. }
  971. }
  972. }
  973. debug_log("table_Data:", result);
  974. return JSON.stringify(result); // return JSON string
  975. }
  976. _proto._toTreeData = function (data) {
  977. let _this = this, _config = _this._config;
  978. let treeData = [];
  979. let f = _config.field ? _config.field : "id",
  980. pf = _config.parentField ? _config.parentField : "parentNo";
  981. function getChildren(parent) {
  982. let children = data.filter(function (v) { return v[pf] == parent[f]; });
  983. parent.children = [];
  984. if (children) {
  985. if (children.length) {
  986. parent.children = children;
  987. children.forEach((v) => { getChildren(v) })
  988. }
  989. //else {
  990. // parent.children.push(children);
  991. // getChildren(children)
  992. //}
  993. }
  994. }
  995. let root = data.filter(function (v) { return v[pf] == _config.root; });
  996. if (root) {
  997. if (root.length) {
  998. root.forEach(v => { treeData.push(v); getChildren(v); })
  999. }
  1000. //else {
  1001. // treeData.push(root);
  1002. // getChildren(root);
  1003. //}
  1004. }
  1005. return treeData;
  1006. }
  1007. _proto._rowCallback = function (row, data) {
  1008. let _this = this, _config = _this._config;
  1009. if (_config.multipleSelect && _config.clickToSelect) {
  1010. if ($.inArray(data.id + "", _selectedIdArray) !== -1) {
  1011. $(row).addClass(_config.select.className);
  1012. $(row).find(' input[type="checkbox"]').prop("checked", true);
  1013. }
  1014. } else {
  1015. _selectedIdArray = [];
  1016. }
  1017. }
  1018. _proto._onEvent = function () {
  1019. let _this = this, _config = _this._config, _el = _this._element;
  1020. let timeOutClick;
  1021. if (_config.onClickRow && typeof _config.onClickRow == "function") {
  1022. $(_el).find('tbody').on(`click${EVENT_KEY}.tr`, 'tr', function () {
  1023. clearTimeout(timeOutClick);
  1024. let __this = this;
  1025. timeOutClick = setTimeout(function () {
  1026. let row = dt.row(__this).data();
  1027. debug_log("table_tr_ckick", __this.id, row);
  1028. _config.onClickRow.call(_this, row);
  1029. }, 200)
  1030. });
  1031. }
  1032. if (_config.onDblClickRow && typeof _config.onDblClickRow == "function") {
  1033. $(_el).find('tbody').on(`dblclick${EVENT_KEY}.tr`, 'tr', function () {
  1034. clearTimeout(timeOutClick);
  1035. let row = dt.row(this).data();
  1036. debug_log("dbckick", this.id, row);
  1037. _config.onDblClickRow.call(_this, row);
  1038. });
  1039. }
  1040. dt.on(`draw${EVENT_KEY}`, function () {
  1041. //if ($(_el).find('tbody tr input[type="checkbox"]:not(:checked)').length) {
  1042. // $(_el).find('thead tr input[type="checkbox"]').prop("checked", false);
  1043. //} else {
  1044. // $(_el).find('thead tr input[type="checkbox"]').prop("checked", true);
  1045. //}
  1046. _this._toggleToolBars();
  1047. _this._drawRender();
  1048. });
  1049. $(_el).on(`resize${EVENT_KEY}`, () => { _this.reRender(); });
  1050. if (_config.checkBox) {
  1051. $(_el).find('thead tr th').on(`click${EVENT_KEY}.init`, 'input[type="checkbox"]', function (e) {
  1052. e.preventDefault();
  1053. e.stopPropagation();
  1054. let checked = this.checked;
  1055. if (checked) {
  1056. if (_config.onAllCheck && typeof _config.onAllCheck == "function") {
  1057. let rows = _this._mapData(dt.rows().data());
  1058. debug_log("table_allcheck", rows)
  1059. _config.onAllCheck.call(_this, rows);
  1060. }
  1061. } else {
  1062. if (_config.onAllUnCheck && typeof _config.onAllUnCheck == "function") {
  1063. let rows = _this._mapData(dt.rows().data());
  1064. debug_log("table_allUncheck", rows)
  1065. _config.onAllUnCheck.call(_this, rows);
  1066. }
  1067. }
  1068. setTimeout(() => {
  1069. const $allTrs = $(_el).find('tbody tr');
  1070. $allTrs.each(function () {
  1071. if (checked) {
  1072. if (!$(this).hasClass(_config.select.className)) {
  1073. $(this).addClass(_config.select.className);
  1074. }
  1075. } else {
  1076. $(this).removeClass(_config.select.className);
  1077. }
  1078. });
  1079. $allTrs.find('input[type="checkbox"]').each(function () {
  1080. let id = $(this).closest('tr').attr('id'), index = $.inArray(id, _selectedIdArray);
  1081. if (checked) {
  1082. $(this).prop("checked", true);
  1083. if (index == -1) {
  1084. _selectedIdArray.push(id);
  1085. }
  1086. } else {
  1087. $(this).prop("checked", false);
  1088. if (index > -1) {
  1089. _selectedIdArray.splice(index, 1);
  1090. }
  1091. }
  1092. });
  1093. if (_config.clickToSelect) {
  1094. _this._toggleToolBars();
  1095. }
  1096. }, 50);
  1097. });
  1098. }
  1099. $(_el).find('tbody').on(`click${EVENT_KEY}.init`, 'tr', function () {
  1100. let __this = this;
  1101. let row = dt.row(this).data();
  1102. setTimeout(() => {
  1103. if (_config.singleSelect) {
  1104. if ($(__this).hasClass(_config.select.className)) {
  1105. $(__this).find('input[name="check_state"][type="checkbox"]')
  1106. .prop("checked", false);
  1107. if (_config.clickToSelect) {
  1108. $(__this).removeClass(_config.select.className);
  1109. }
  1110. _selectedIdArray = [];
  1111. if (_config.onUnCheck && typeof _config.onUnCheck == "function") {
  1112. debug_log("table_tr_uncheck", row)
  1113. _config.onUnCheck.call(_this, row);
  1114. }
  1115. } else {
  1116. $(__this).find('input[name="check_state"][type="checkbox"]')
  1117. .prop("checked", true);
  1118. $(__this).siblings().removeClass(_config.select.className).find('input[name="check_state"][type="checkbox"]')
  1119. .prop("checked", false);
  1120. if (_config.clickToSelect) {
  1121. $(__this).addClass(_config.select.className);
  1122. }
  1123. _selectedIdArray = [__this.id];
  1124. if (_config.onCheck && typeof _config.onCheck == "function") {
  1125. debug_log("table_tr_check", row)
  1126. _config.onCheck.call(_this, row);
  1127. }
  1128. }
  1129. } else {
  1130. let id = __this.id;
  1131. let index = $.inArray(id, _selectedIdArray);
  1132. if (index === -1) {
  1133. _selectedIdArray.push(id);
  1134. $(__this).find('input[name="check_state"][type="checkbox"]').prop('checked', true);
  1135. if (_config.clickToSelect) {
  1136. $(__this).addClass(_config.select.className);
  1137. }
  1138. if (_config.onCheck && typeof _config.onCheck == "function") {
  1139. debug_log("table_tr_check", row)
  1140. _config.onCheck.call(_this, row);
  1141. }
  1142. } else {
  1143. _selectedIdArray.splice(index, 1);
  1144. $(__this).find('input[name="check_state"][type="checkbox"]').prop('checked', false);
  1145. if (_config.clickToSelect) {
  1146. $(__this).removeClass(_config.select.className);
  1147. }
  1148. if (_config.onUnCheck && typeof _config.onUnCheck == "function") {
  1149. debug_log("table_tr_uncheck", row)
  1150. _config.onUnCheck.call(_this, row);
  1151. }
  1152. }
  1153. }
  1154. if (_config.clickToSelect) {
  1155. _this._toggleToolBars();
  1156. }
  1157. }, 50);
  1158. });
  1159. }
  1160. _proto._toggleToolBars = function () {
  1161. let _this = this, _config = _this._config, _el = _this._element;
  1162. const $box = $(_el).closest(Selector.TABLE_BOX),
  1163. $toolbarBase = $box.find(Selector.TOOLBAR_BASE),
  1164. $toolbarSelected = $box.find(Selector.TOOLBAR_SELECTED),
  1165. $selectedCount = $box.find(Selector.TOOLBAR_SELECTED_COUNT);
  1166. if (_config.singleSelect) {
  1167. $selectedCount.parent().addClass('d-none');
  1168. }
  1169. if (_selectedIdArray.length) {
  1170. $selectedCount.html(_selectedIdArray.length);
  1171. $toolbarBase.addClass('d-none');
  1172. $toolbarSelected.removeClass('d-none');
  1173. } else {
  1174. $toolbarBase.removeClass('d-none');
  1175. $toolbarSelected.addClass('d-none');
  1176. }
  1177. if ($(_el).find('tbody tr input[type="checkbox"]:not(:checked)').length) {
  1178. $(_el).find('thead tr input[type="checkbox"]').prop("checked", false);
  1179. } else {
  1180. $(_el).find('thead tr input[type="checkbox"]').prop("checked", true);
  1181. }
  1182. debug_log("table_selectIds", _selectedIdArray);
  1183. }
  1184. _proto._mapData = function (data) {
  1185. let rows = [];
  1186. for (let i = 0; i < data.length; i++) {
  1187. let row = data[i + ""];
  1188. rows.push(row);
  1189. }
  1190. return rows;
  1191. };
  1192. _proto._renderSelectRows = function () {
  1193. let _this = this, _config = _this._config, _el = _this._element;
  1194. if (_config.pageSelect && _selectedIdArray.length) {
  1195. $(_el).find("tbody tr").each(function () {
  1196. let id = $(this).attr('id');
  1197. if (_selectedIdArray.indexOf(id) > -1) {
  1198. $(this).find('input[name="check_state"][type="checkbox"]').prop('checked', true);
  1199. $(this).addClass(_config.select.className);
  1200. }
  1201. });
  1202. }
  1203. }
  1204. _proto._getModalOption = function (url, opt, title, type) {
  1205. let _this = this, _config = _this._config, $table = $(_this._element);
  1206. let modalOpts = $.extend({}, { url: "" });
  1207. modalOpts.opTitle = title;
  1208. modalOpts.draggable = _config.modalDrag;
  1209. modalOpts.fromValidate = true;
  1210. if (!opt) {
  1211. opt = !url || typeof url === "string" ? {} : url;
  1212. }
  1213. if (opt.hasOwnProperty("url")) {
  1214. modalOpts.url = opt.url;
  1215. } else if (typeof url === "string") {
  1216. modalOpts.url = url;
  1217. }
  1218. if (!modalOpts.url) {
  1219. let $tableToolMENU = $table.closest(Selector.TABLE_BOX).find(Selector.TOOL_MENU.format(type));
  1220. modalOpts.url = $tableToolMENU.data([ClassName.TOOL_MENU_URL]);
  1221. }
  1222. modalOpts.modal =
  1223. typeof _config.modal === 'string' ? $("#" + _config.modal) : $(_config.modal);
  1224. modalOpts.table = $table;
  1225. //modalOptions.type = type.toLowerCase().indexOf('btnupdate') === 0 ? 'put' : 'post';
  1226. modalOpts.type = 'post';
  1227. modalOpts = $.extend({}, modalOpts, opt);
  1228. return modalOpts;
  1229. }
  1230. _proto._initToolFunction = function () {
  1231. let _this = this;
  1232. _this.addToolFunctions("btnCreate", function (url) { _this.create(url); });
  1233. _this.addToolFunctions("btnUpdate", function (url) { _this.update(url); });
  1234. _this.addToolFunctions("btnDelete", function (url) { _this.delete(url); });
  1235. _this.addToolFunctions("btnSearch", function () { _this.refresh(true); });
  1236. _this.addToolFunctions("none", function () { console.log("No type"); });
  1237. let $tableToolMenu = $(_this._element).closest(Selector.TABLE_BOX).find(Selector.TOOL_MENU_ALL);
  1238. $tableToolMenu.off().on(`click${EVENT_KEY}.menu`,
  1239. function () {
  1240. let funs = _this.getToolFunctions();
  1241. let type = $(this).data(ClassName.TOOL_MENU_TYPE);
  1242. let index = type.lastIndexOf('_');
  1243. type = index > -1 ? type.substr(index + 1) : type;
  1244. let url = $(this).data(ClassName.TOOL_MENU_URL) || "";
  1245. funs[type] ? funs[type].call(this, url) : funs["none"].call(this);
  1246. });
  1247. };
  1248. _proto._drawRender = function () {
  1249. $(this._element).find('[data-bs-toggle="tooltip"]').each(function () {
  1250. new bootstrap.Tooltip(this, {
  1251. delay: 500
  1252. });
  1253. });
  1254. KTMenu.createInstances('[data-kt-menu-action="true"]')
  1255. };
  1256. _proto._initTree = function () {
  1257. let _this = this, _config = _this._config, _el = _this._element;
  1258. let treeOption = {
  1259. left: _config.left > 0 ? _config.left : 10,
  1260. expandAll: _config.expandAll,
  1261. leafIcon: _config.leafIcon,
  1262. expandIcon: _config.expandIcon,
  1263. collapseIcon: _config.collapseIcon,
  1264. fnDrawCallback: _config.fnDrawCallback
  1265. }
  1266. _config.treeOption = treeOption;
  1267. _this._onTreeEvent();
  1268. _this.addToolFunctions("btnCreate_tree", function (url, id) {
  1269. let row = _this.getRow(id);
  1270. if (row) {
  1271. let data = {};
  1272. data[_config.parentField] = row[_config.field];
  1273. data[_config.parentNameField] = row[_config.nameField];
  1274. _this.create(url, { data: data });
  1275. }
  1276. })
  1277. _this.addToolFunctions("btnUpdate_tree", function (url, id) {
  1278. let row = _this.getRow(id);
  1279. if (row) {
  1280. _this.update(url, { data: row }, row);
  1281. }
  1282. })
  1283. _this.addToolFunctions("btnDelete_tree", function (url, id) {
  1284. let row = _this.getRow(id);
  1285. if (row) {
  1286. _this.delete(url, { data: row }, row);
  1287. }
  1288. })
  1289. _this.addToolFunctions("btnMoveUp_tree", function (url, id) {
  1290. console.log("MoveUp", id);
  1291. let row = _this.getRow(id);
  1292. if (row) {
  1293. let $prev = $('#' + row[_config.rowId]).prev();
  1294. if ($prev.length) {
  1295. let prevRow = _this.getRow($prev.attr('id'));
  1296. if (prevRow && prevRow[_config.parentField] == row[_config.parentField]) {
  1297. $.vbAjax1({ url: url, data: { Id: id, MoveId: prevRow[_config.rowId] }, table: $(_el) });
  1298. return;
  1299. }
  1300. }
  1301. abp.message.warn(abp.localization.VberZero("RecordAtTop"));
  1302. }
  1303. })
  1304. _this.addToolFunctions("btnMoveDown_tree", function (url, id) {
  1305. console.log("MoveDown", id);
  1306. let row = _this.getRow(id);
  1307. if (row) {
  1308. let $next = $('#' + row[_config.rowId]).next();
  1309. if ($next.length) {
  1310. let nextRow = _this.getRow($next.attr('id'));
  1311. if (nextRow && nextRow[_config.parentField] == row[_config.parentField]) {
  1312. $.vbAjax1({ url: url, data: { Id: id, MoveId: nextRow[_config.rowId] }, table: $(_el) });
  1313. return;
  1314. }
  1315. }
  1316. abp.message.warn(abp.localization.VberZero("RecordAtBottom"));
  1317. }
  1318. })
  1319. };
  1320. _proto._resetEvenOddClass = function () {
  1321. let classes = ['odd', 'even'];
  1322. $(dt.table().body()).find('tr').each(function (index, tr) {
  1323. $(tr).removeClass('odd even').addClass(classes[index % 2]);
  1324. });
  1325. };
  1326. _proto._resetTreeGridRows = function (id) {
  1327. let _this = this, treeOption = _this._config.treeOption;
  1328. let subRows = treeGridRows[id];
  1329. if (subRows && subRows.length) {
  1330. subRows.forEach(function (node) {
  1331. let subTrId = $(node).attr('id');
  1332. if (treeGridRows[subTrId]) {
  1333. _this._resetTreeGridRows(subTrId);
  1334. }
  1335. dt.row($(node)).remove();
  1336. $(node).remove();
  1337. });
  1338. delete treeGridRows[id];
  1339. let p_depth = $('#' + id).data('depth') || 0,
  1340. $icon = $(treeOption.expandIcon).css('marginLeft', p_depth * treeOption.left + 'px');
  1341. $('#' + id).find(Selector.TREE_TD_CONTROL_OPEN)
  1342. .removeClass(ClassName.TREE_TD_CONTROL_OPEN)
  1343. .addClass(ClassName.TREE_TD_CONTROL)
  1344. .html($icon);
  1345. }
  1346. };
  1347. _proto._onTreeEvent = function () {
  1348. let _this = this, _config = _this._config;
  1349. //let treeOption = _config.treeOption;
  1350. dt.on(`click${EVENT_KEY}.tree`, Selector.TREE_TD_CONTROL, function (e) {
  1351. _this.treeExpand($(e.target).closest('tr').attr("id"));
  1352. })
  1353. dt.on(`click${EVENT_KEY}.tree`, Selector.TREE_TD_CONTROL_OPEN, function (e) {
  1354. _this.treeCollapse($(e.target).closest('tr').attr("id"));
  1355. })
  1356. dt.on(`draw${EVENT_KEY}.tree`, function () {
  1357. _this._treeExpandAll(_config.expandDepth);
  1358. })
  1359. }
  1360. _proto._treeExpandAll = function (depth, id) {
  1361. let _this = this;
  1362. depth = depth == undefined ? true : depth - 1;
  1363. let children = _this.treeExpand(id || null);
  1364. if (depth && children && children.length) {
  1365. children.forEach(v => {
  1366. _this._treeExpandAll(depth, $(v).attr('id'));
  1367. })
  1368. }
  1369. }
  1370. _proto.treeExpandAll = function () {
  1371. this._treeExpandAll();
  1372. }
  1373. _proto.treeExpand = function (id) {
  1374. let _this = this, _config = _this._config;
  1375. let treeOption = _config.treeOption;
  1376. let $tr = id ? $('#' + id) : $(dt.row(0).node());
  1377. let subRows = treeGridRows[$tr.attr('id')] = []
  1378. let p_depth = $tr.data('depth') || 0;
  1379. let row = dt.row($tr[0]),
  1380. index = row.index(),
  1381. data = row.data();
  1382. debug_log("table_tree_open:", index, data);
  1383. if (data.children && data.children.length) {
  1384. let $td = $tr.find(Selector.TREE_TD_CONTROL),
  1385. //paddingLeft = parseInt($td.css('padding-left'), 10),
  1386. //layer = parseInt($td.find('span').css('margin-left') || 0, 10) / treeOption.left,
  1387. $icon = $(treeOption.collapseIcon);
  1388. $icon.css('marginLeft', p_depth * treeOption.left + 'px');
  1389. $td.removeClass(ClassName.TREE_TD_CONTROL).addClass(ClassName.TREE_TD_CONTROL_OPEN).html($icon);
  1390. let prevRow = row.node();
  1391. p_depth++;
  1392. data.children.forEach(function (item) {
  1393. let node = dt.row.add(item).node();
  1394. $(node).data('depth', p_depth);
  1395. //$(node).attr('parent-index', index);
  1396. //let $childTd = $(node).find(Selector.TREE_TD_CONTROL);
  1397. $(node).find(Selector.TREE_TD_CONTROL).find('span').css('marginLeft', p_depth * treeOption.left + 'px');
  1398. //.next().css('paddingLeft', paddingLeft + left + 'px');
  1399. $(node).insertAfter(prevRow);
  1400. prevRow = node;
  1401. subRows.push(node);
  1402. })
  1403. _this._resetEvenOddClass();
  1404. _this._drawRender();
  1405. }
  1406. return subRows;
  1407. }
  1408. _proto.treeCollapse = function (id) {
  1409. let _this = this, _config = _this._config;
  1410. let treeOption = _config.treeOption;
  1411. let $tr = $('#' + id), $td = $tr.find(Selector.TREE_TD_CONTROL_OPEN),
  1412. //paddingLeft = parseInt($td.css('padding-left'), 10),
  1413. //layer = parseInt($td.find('span').css('margin-left') || 0, 10) / treeOption.left,
  1414. p_depth = $tr.data('depth') || 0,
  1415. $icon = $(treeOption.expandIcon).css('marginLeft', p_depth * treeOption.left + 'px');
  1416. $td.removeClass(ClassName.TREE_TD_CONTROL_OPEN).addClass(ClassName.TREE_TD_CONTROL).html($icon);
  1417. _this._resetTreeGridRows(id);
  1418. _this._resetEvenOddClass();
  1419. }
  1420. _proto.addToolFunctions = function (key, fun) {
  1421. let _this = this;
  1422. let toolFunctions = _this.getToolFunctions();
  1423. toolFunctions[key] = fun;
  1424. _this._config.toolFunctions = toolFunctions;
  1425. };
  1426. _proto.getToolFunctions = function () {
  1427. return this._config.toolFunctions;
  1428. }
  1429. _proto.create = function (url, opt) {
  1430. let _this = this;
  1431. console.log("Add---" + _this._element.id);
  1432. opt = opt || {};
  1433. let modalOpts = _this._getModalOption(url, opt, abp.localization.VberZero('OpCreate'), '_btnCreate');
  1434. let $modal = typeof modalOpts.modal === 'string'
  1435. ? $('#' + modalOpts.modal)
  1436. : $(modalOpts.modal);
  1437. $modal.VbModal(modalOpts);
  1438. }
  1439. _proto.update = function (url, opt, row) {
  1440. let _this = this;
  1441. console.log("Update---" + _this._element.id);
  1442. opt = opt || {};
  1443. row = row || opt.row || _this.getSelection();
  1444. if (row) {
  1445. let modalOptions = _this._getModalOption(url, opt, abp.localization.VberZero('OpUpdate'), 'btnUpdate');
  1446. if (!modalOptions.data) {
  1447. modalOptions.data = row;
  1448. }
  1449. let $modal = typeof (modalOptions.modal) === 'string'
  1450. ? $('#' + modalOptions.modal)
  1451. : $(modalOptions.modal);
  1452. $modal.VbModal(modalOptions);
  1453. }
  1454. }
  1455. _proto.delete = function (url, opt, row) {
  1456. let _this = this;
  1457. console.log("Delete---" + _this._element.id);
  1458. opt = opt || {};
  1459. row = row || opt.row || _this.getSelection();
  1460. if (row) {
  1461. let data = opt.data || { id: row.id };
  1462. abp.message.confirm(abp.localization.VberZero('DeleteConfirmContent'),
  1463. abp.localization.VberZero('DeleteConfirm'),
  1464. function (isConfirmed) {
  1465. if (isConfirmed) {
  1466. $.vbAjax1({
  1467. table: $table,
  1468. url: url + '?' + _this._config.id + '=' + data[_this._config.id],
  1469. data: data
  1470. });
  1471. }
  1472. });
  1473. }
  1474. }
  1475. _proto.destroy = function () {
  1476. let _this = this, $this = $(_this._element);
  1477. $this.removeData(DATA_KEY);
  1478. $this.DataTable('destroy');
  1479. }
  1480. _proto.getSelection = function () {
  1481. return this.getSelections()[0];
  1482. }
  1483. _proto.getSelections = function () {
  1484. let _this = this, _config = _this._config;
  1485. let data = dt.rows("." + _config.select.className).data();
  1486. return _this._mapData(data);
  1487. }
  1488. _proto.getSelectionIds = function () {
  1489. return _selectedIdArray;
  1490. }
  1491. _proto.getRow = function (id) {
  1492. let data = dt.row($("#" + id)).data();
  1493. debug_log("row", id, data);
  1494. return data;
  1495. }
  1496. _proto.getInstance = function () {
  1497. return dt;
  1498. }
  1499. _proto.reRender = function () {
  1500. dt.draw();
  1501. }
  1502. _proto.refresh = function (resetPaging, callback) {
  1503. dt.ajax.reload(callback, resetPaging);
  1504. }
  1505. Table._jQueryInterface = function _jQueryInterface(option) {
  1506. let value, args = Array.prototype.slice.call(arguments, 1);
  1507. this.each(function () {
  1508. let $this = $(this), data = $this.data(DATA_KEY);
  1509. if (typeof option === 'string') {
  1510. if ($.inArray(option, ALLOW_METHOD) < 0) {
  1511. throw new Error("Unknown method: " + option);
  1512. }
  1513. if (!data) {
  1514. return;
  1515. }
  1516. value = data[option].apply(data, args);
  1517. }
  1518. if (!data) {
  1519. let options = $.extend({}, Default, $(this).data(), typeof option === 'object' && option);
  1520. data = new Table(this, options);
  1521. $this.data(DATA_KEY, data);
  1522. }
  1523. });
  1524. return typeof value === 'undefined' ? this : value;
  1525. }
  1526. return Table;
  1527. }();
  1528. /*
  1529. * jQuery API
  1530. * ====================================================
  1531. */
  1532. $.fn[NAME] = Table._jQueryInterface;
  1533. $.fn[NAME].Constructor = Table;
  1534. $.fn[NAME].noConflict = function () {
  1535. $.fn[NAME] = JQUERY_NO_CONFLICT;
  1536. return Table._jQueryInterface;
  1537. };
  1538. return Table;
  1539. }((jQuery));
  1540. let VbModal = function ($) {
  1541. const NAME = 'VbModal';
  1542. const DATA_KEY = 'vb.modal';
  1543. const EVENT_KEY = "." + DATA_KEY;
  1544. const ClassName = {
  1545. CREATE_BOX: "modal-container",
  1546. MODAL: 'modal',
  1547. MODAL_LG: 'modal-lg',
  1548. MODAL_DIALOG: 'modal-dialog',
  1549. MODAL_CONTENT: 'modal-content',
  1550. MODAL_HEADER: 'modal-header',
  1551. MODAL_BODY: 'modal-body',
  1552. MODAL_FOOTER: 'modal-footer',
  1553. BODY: 'body',
  1554. SAVE_BUTTON: 'save-btn',
  1555. CLEAN: 'error valid not-clean invalid valid',
  1556. NOT_CLEAN_TAG: 'not-clear-tag',
  1557. DEFAULT_VALUE: 'default-value',
  1558. AJAX_SELECT: 'ajax-select',
  1559. AJAX_SELECT_SET_VALUE: 'set-value',
  1560. AJAX_SELECT_CODE: 'code-key',
  1561. DRAG_SELECT: "drag-select",
  1562. INVALID_FEEDBACK: "invalid-feedback",
  1563. INVALID_FEEDBACK_SHOW: "invalid-feedback-show"
  1564. }
  1565. const Selector = {
  1566. CREATE_BOX: ".modal-container",
  1567. MODAL_DIALOG: '.modal-dialog',
  1568. MODAL_CONTENT: '.modal-content',
  1569. MODAL_HEADER: '.modal-header',
  1570. MODAL_TITLE: '.modal-title',
  1571. MODAL_TITLE_PRE: '.modal-title .pre',
  1572. MODAL_BODY: '.modal-body',
  1573. MODAL_FOOTER: '.modal-footer',
  1574. MODAL_TAB_LINK: '.tab-auto .nav-item .nav-link',
  1575. SAVE_BUTTON: `.${ClassName.SAVE_BUTTON}`,
  1576. CLEAN: 'input,select,textarea',
  1577. DISABLED: 'input:not(.disabled),select:not(.disabled),textarea:not(.disabled)',
  1578. READONLY: 'input:not(.readonly),select:not(.readonly),textarea:not(.readonly)',
  1579. CLEAN_VALUE: `input:not(.${ClassName.DEFAULT_VALUE}):not([type="checkbox"]):not([type="radio"]):not(.${ClassName.NOT_CLEAN_TAG}),select:not(.${ClassName.DEFAULT_VALUE}):not(.${ClassName.NOT_CLEAN_TAG}),textarea:not(.${ClassName.DEFAULT_VALUE}):not(.${ClassName.NOT_CLEAN_TAG})`,
  1580. NOT_CLEAN_TAG: `.${ClassName.NOT_CLEAN_TAG}`,
  1581. FORM_FIRST: 'input:not(:disabled,[type="hidden"],[readonly="readonly"]):first',
  1582. select2: '.select',
  1583. select2tree: 'select[data-select-tree="true"]',
  1584. AJAX_SELECT: `.${ClassName.AJAX_SELECT}`,
  1585. WANG_EDITOR: 'div.vb-wang-editor',
  1586. INPUT_FILE: 'input[type="file"]',
  1587. SUBMIT_INPUT: '.modal-body input,.modal-body textarea',
  1588. INVALID_FEEDBACK: `.${ClassName.INVALID_FEEDBACK}`
  1589. }
  1590. const JQUERY_NO_CONFLICT = $.fn[NAME];
  1591. const ALLOW_METHOD = [
  1592. 'open',
  1593. 'show',
  1594. 'hide',
  1595. 'create'
  1596. ];
  1597. const WangEditor_DATA_KEY = "WangEditor_DATA_KEY";
  1598. const Default = {
  1599. modal: undefined,
  1600. title: '',
  1601. opTitle: '',
  1602. data: null,
  1603. dataFun: undefined,
  1604. form: null,
  1605. table: undefined,
  1606. rules: {},
  1607. readonly: '',
  1608. disabled: '',
  1609. notClear: '',
  1610. select2: undefined,
  1611. select2tree: undefined,
  1612. url: '',
  1613. type: 'post',
  1614. saveBtn: null,
  1615. save: null,
  1616. success: null,
  1617. showBefore: null,
  1618. showAfter: null,
  1619. isRefresh: true,
  1620. draggable: true,
  1621. backdrop: 'static',
  1622. keyboard: true,
  1623. //kindeditorOption: {},
  1624. content: undefined,
  1625. ajaxSelect: true,
  1626. needForm: true,
  1627. isInit: true,
  1628. }
  1629. let Modal = function () {
  1630. function Modal(element, config, isCreate) {
  1631. this._element = element;
  1632. this._config = config;
  1633. if (!isCreate) {
  1634. this._getModal(config);
  1635. }
  1636. }
  1637. let _proto = Modal.prototype;
  1638. _proto._getModal = function (opts, modal) {
  1639. let _this = this;
  1640. _this._config = $.extend({}, _this._config, opts || {});
  1641. let $modal;
  1642. if (modal) {
  1643. $modal = typeof (modal) === 'string'
  1644. ? $('#' + modal)
  1645. : $(modal);
  1646. } else {
  1647. $modal = _this._config.modalId
  1648. ? $('#' + _this._config.modalId)
  1649. : typeof (_this._config.modal) === 'string'
  1650. ? $('#' + _this._config.modal)
  1651. : $(_this._config.modal);
  1652. }
  1653. if ($(_this._element).hasClass(ClassName.MODAL)) {
  1654. if ($modal.length) {
  1655. _this._element = $modal[0];
  1656. } else {
  1657. $modal = $(_this._element);
  1658. }
  1659. } else {
  1660. if (!$modal.length) {
  1661. throw new Error("未发现模态框!");
  1662. }
  1663. if (!_this._config.modal && !_this._config.modalId) {
  1664. throw new Error("未配置模态框!");
  1665. }
  1666. _this._element = $modal[0];
  1667. }
  1668. return $modal;
  1669. };
  1670. _proto._init = function () {
  1671. let _this = this, _config = _this._config, $modal = $(_this._element);
  1672. _this._clearOldVal();
  1673. $modal.find(Selector.INVALID_FEEDBACK).html("").removeClass(ClassName.INVALID_FEEDBACK_SHOW);
  1674. $modal.find(Selector.CLEAN).removeClass(ClassName.CLEAN);
  1675. $modal.find(Selector.INVALID_FEEDBACK).removeClass(ClassName.INVALID_FEEDBACK_SHOW);
  1676. $modal.find(Selector.DISABLED).prop('disabled', false);
  1677. $modal.find(Selector.READONLY).prop('readonly', false);
  1678. $modal.find(Selector.MODAL_TITLE_PRE).html(_config.opTitle);
  1679. $modal.find(Selector.MODAL_TAB_LINK).eq(0).tab("show");
  1680. _this._setReadonly();
  1681. _this._setDisabled();
  1682. _this._cleanFile();
  1683. $modal.find(Selector.FORM_FIRST).focus();
  1684. };
  1685. _proto._setReadonly = function () {
  1686. let _this = this, _config = _this._config, $modal = $(_this._element);
  1687. if (_config.readonly) {
  1688. let readonly = _config.readonly.split(',');
  1689. for (let i = 0; i < readonly.length; i++) {
  1690. if (readonly[i]) {
  1691. $modal.find(`[name="${readonly[i]}"]`).prop('readonly', true);
  1692. }
  1693. }
  1694. }
  1695. if (_config.no_readonly) {
  1696. let no_readonly = _config.no_readonly.split(',');
  1697. for (let j = 0; j < no_readonly.length; j++) {
  1698. if (no_readonly[j]) {
  1699. $modal.find(`[name="${no_readonly[j]}"]`).prop('readonly', false);
  1700. }
  1701. }
  1702. }
  1703. };
  1704. _proto._setDisabled = function () {
  1705. let _this = this, _config = _this._config, $modal = $(_this._element);
  1706. if (_config.disabled) {
  1707. let disabled = _config.disabled.split(',');
  1708. for (let i = 0; i < disabled.length; i++) {
  1709. if (disabled[i]) {
  1710. $modal.find(`[name="${disabled[i]}"]`).prop('disabled', true);
  1711. }
  1712. }
  1713. }
  1714. if (_config.no_disabled) {
  1715. let no_disabled = _config.no_disabled.split(',');
  1716. for (let j = 0; j < no_disabled.length; j++) {
  1717. if (no_disabled[j]) {
  1718. $modal.find(`[name="${no_disabled[j]}"]`).prop('disabled', true);
  1719. }
  1720. }
  1721. }
  1722. };
  1723. _proto._setSelect2 = function () {
  1724. let _this = this, _config = _this._config, $modal = $(_this._element);
  1725. if (_config.select2) {
  1726. let select2 = _config.select2.split(',');
  1727. for (let i = 0; i < select2.length; i++) {
  1728. $modal.find(`[name="${select2[i]}"]`).select2tree();
  1729. }
  1730. }
  1731. if (_config.select2tree) {
  1732. let tree = _config.select2tree.split(',');
  1733. for (let j = 0; j < tree.length; j++) {
  1734. $modal.find(`[name="${tree[j]}"]`).select2tree();
  1735. }
  1736. }
  1737. $modal.find('select').trigger("change");
  1738. $modal.find('select').off("change.ff").on("change.ff", function () {
  1739. $(this).focus();
  1740. $(this).removeClass(ClassName.CLEAN).parent().find(Selector.INVALID_FEEDBACK).removeClass(ClassName.INVALID_FEEDBACK_SHOW);
  1741. $(this).blur();
  1742. });
  1743. };
  1744. _proto._setData = function () {
  1745. let _this = this, _config = _this._config, $modal = $(_this._element);
  1746. let $form = $modal.find('form');
  1747. $(Selector.AJAX_SELECT).addClass(ClassName.AJAX_SELECT_SET_VALUE);
  1748. $.formDeserialize($form, _config.data);
  1749. };
  1750. _proto._clearOldVal = function () {
  1751. let _this = this, _config = _this._config, $modal = $(_this._element);
  1752. if (_config.notClear) {
  1753. let notClear = _config.notClear.split(',');
  1754. for (let i = 0; i < notClear.length; i++) {
  1755. if (notClear[i]) {
  1756. $modal.find(`[name="${notClear[i]}"]`).addClass(ClassName.NOT_CLEAN_TAG);
  1757. }
  1758. }
  1759. }
  1760. $modal.find(Selector.CLEAN_VALUE).val('');
  1761. $modal.find(Selector.NOT_CLEAN_TAG).removeClass(ClassName.NOT_CLEAN_TAG);
  1762. };
  1763. _proto._initWangEditor = function () {
  1764. let _this = this, $modal = $(_this._element);
  1765. $modal.find(Selector.WANG_EDITOR).each(function () {
  1766. if ($.fn.VbWangEditor) {
  1767. if (!$(this).data('vb.wang_editor')) {
  1768. let config = _this._config.wangEditorOption || {};
  1769. $(this).VbWangEditor(config);
  1770. $(this).data(WangEditor_DATA_KEY, true);
  1771. }
  1772. }
  1773. });
  1774. };
  1775. _proto._setWangEditorData = function () {
  1776. let _this = this, $modal = $(_this._element);
  1777. $modal.find(Selector.WANG_EDITOR).each(function () {
  1778. if ($.fn.VbWangEditor) {
  1779. if ($(this).data('vb.wang_editor')) {
  1780. let val = $modal.find(`[name="${$(this).data('editor-name')}"]`).val();
  1781. $(this).VbWangEditor('setContent', val);
  1782. }
  1783. }
  1784. });
  1785. };
  1786. _proto._cleanFile = function () {
  1787. let _this = this, $modal = $(_this._element);
  1788. $modal.find(Selector.INPUT_FILE).each(function () {
  1789. //TODO
  1790. //$(this).parent().VbFile('cleanFile');
  1791. });
  1792. };
  1793. _proto._draggable = function () {
  1794. let _this = this, _config = _this._config, $modal = $(_this._element);
  1795. if (_config.draggable) {
  1796. /** 拖拽模态框*/
  1797. let dragModal = {
  1798. mouseStartPoint: { 'left': 0, 'top': 0 },
  1799. mouseEndPoint: { 'left': 0, 'top': 0 },
  1800. mouseDragDown: false,
  1801. basePoint: { 'left': 0, 'top': 0 },
  1802. moveTarget: null,
  1803. topLeng: 0
  1804. };
  1805. $modal.off('mousedown.drag' + EVENT_KEY, Selector.MODAL_HEADER).on('mousedown.drag' + EVENT_KEY,
  1806. Selector.MODAL_HEADER,
  1807. function (e) {
  1808. $modal.find(Selector.MODAL_HEADER).css('cursor', 'move');
  1809. //webkit内核和火狐禁止文字被选中
  1810. $('body').addClass(ClassName.DRAG_SELECT);
  1811. //ie浏览器禁止文字选中
  1812. document.body.onselectstart = document.body.ondrag = function () {
  1813. return false;
  1814. };
  1815. if ($(e.target).hasClass('close')) //点关闭按钮不能移动对话框
  1816. return;
  1817. dragModal.mouseDragDown = true;
  1818. dragModal.moveTargetHeader = $(this);
  1819. dragModal.moveTarget = $(this).closest(Selector.MODAL_CONTENT);
  1820. dragModal.mouseStartPoint = { 'left': e.clientX, 'top': e.pageY };
  1821. dragModal.basePoint = dragModal.moveTarget.offset();
  1822. dragModal.topLeng = e.pageY - e.clientY;
  1823. });
  1824. $modal.off(`mouseup.drag${EVENT_KEY}`).on(`mouseup.drag${EVENT_KEY}`,
  1825. function () {
  1826. $modal.find(Selector.MODAL_HEADER).css('cursor', 'default');
  1827. dragModal.mouseDragDown = false;
  1828. dragModal.moveTarget = undefined;
  1829. dragModal.mouseStartPoint = { 'left': 0, 'top': 0 };
  1830. dragModal.basePoint = { 'left': 0, 'top': 0 };
  1831. });
  1832. $modal.off(`mousemove.drag${EVENT_KEY}`).on(`mousemove.drag${EVENT_KEY}`,
  1833. function (e) {
  1834. if (!dragModal.mouseDragDown || dragModal.moveTarget === undefined) return;
  1835. $modal.find(Selector.MODAL_HEADER).css('cursor', 'move');
  1836. let mouseX = e.clientX;
  1837. let mouseY = e.pageY;
  1838. if (mouseX < 0) mouseX = 0;
  1839. if (mouseY < 0) mouseY = 25;
  1840. dragModal.mouseEndPoint = { 'left': mouseX, 'top': mouseY };
  1841. let width = dragModal.moveTarget.width();
  1842. let height = dragModal.moveTargetHeader.height();
  1843. let clientWidth = document.body.clientWidth;
  1844. let clientHeight = document.body.clientHeight;
  1845. if (dragModal.mouseEndPoint.left < dragModal.mouseStartPoint.left - dragModal.basePoint.left) {
  1846. dragModal.mouseEndPoint.left = 0;
  1847. } else if (dragModal.mouseEndPoint.left >=
  1848. clientWidth - width + dragModal.mouseStartPoint.left - dragModal.basePoint.left) {
  1849. dragModal.mouseEndPoint.left = clientWidth - width - 2;
  1850. } else {
  1851. dragModal.mouseEndPoint.left =
  1852. dragModal.mouseEndPoint.left -
  1853. (dragModal.mouseStartPoint.left - dragModal.basePoint.left); //移动修正,更平滑
  1854. }
  1855. if (dragModal.mouseEndPoint.top - (dragModal.mouseStartPoint.top - dragModal.basePoint.top) <
  1856. dragModal.topLeng) {
  1857. dragModal.mouseEndPoint.top = dragModal.topLeng;
  1858. } else if (dragModal.mouseEndPoint.top - dragModal.topLeng >
  1859. clientHeight - height + dragModal.mouseStartPoint.top - dragModal.basePoint.top) {
  1860. dragModal.mouseEndPoint.top = clientHeight - height - 38 + dragModal.topLeng;
  1861. } else {
  1862. dragModal.mouseEndPoint.top = dragModal.mouseEndPoint.top -
  1863. (dragModal.mouseStartPoint.top - dragModal.basePoint.top);
  1864. }
  1865. dragModal.moveTarget.offset(dragModal.mouseEndPoint);
  1866. });
  1867. $modal.off(`hidden.bs.modal${EVENT_KEY}.drag`).on(`hidden.bs.modal${EVENT_KEY}.drag`, function () {
  1868. $modal.find(Selector.MODAL_HEADER).css('cursor', 'default');
  1869. $modal.find(Selector.MODAL_CONTENT).css({ 'top': 0, 'left': 0 });
  1870. $('body').removeClass(ClassName.DRAG_SELECT);
  1871. document.body.onselectstart = document.body.ondrag = null;
  1872. });
  1873. } else {
  1874. $modal.find(Selector.MODAL_HEADER).css('cursor', 'default');
  1875. }
  1876. };
  1877. _proto._showBefore = function () {
  1878. let _this = this, _config = _this._config, $modal = $(_this._element);
  1879. if (_config.showBefore && typeof (_config.showBefore) === 'function') {
  1880. _config.showBefore.call(_this, $modal);
  1881. }
  1882. };
  1883. _proto._showAfter = function () {
  1884. let _this = this, _config = _this._config, $modal = $(_this._element);
  1885. if (_config.showAfter && typeof (_config.showAfter) === 'function') {
  1886. _config.showAfter.call(_this, $modal);
  1887. }
  1888. };
  1889. _proto._shown = function () {
  1890. let _this = this, _config = _this._config, $modal = $(_this._element);
  1891. if (_config.shown && typeof (_config.shown) === 'function') {
  1892. _config.shown.call(_this, $modal);
  1893. }
  1894. };
  1895. _proto._bindEvent = function () {
  1896. let _this = this, _config = _this._config, $modal = $(_this._element);
  1897. $modal.off(`show.bs.modal${EVENT_KEY}`).on(`show.bs.modal${EVENT_KEY}`,
  1898. function () {
  1899. _this._draggable();
  1900. _this._showBefore();
  1901. if (_config.isInit) {
  1902. _this._init();
  1903. }
  1904. _this._initWangEditor();
  1905. _this._setData();
  1906. _this._setSelect2();
  1907. _this._setWangEditorData();
  1908. _this._bindSave();
  1909. $.formValidate($modal.find('form'), { noValid: true });
  1910. _this._showAfter();
  1911. });
  1912. $modal.off(`shown.bs.modal${EVENT_KEY}`).on(`shown.bs.modal${EVENT_KEY}`,
  1913. function () {
  1914. _this._shown();
  1915. });
  1916. };
  1917. _proto._bindSave = function () {
  1918. let _this = this, _config = _this._config, $modal = $(_this._element);
  1919. let $saveBtn = _config.saveBtn
  1920. ? $(_config.saveBtn)
  1921. : $modal.find(Selector.SAVE_BUTTON);
  1922. if (!$saveBtn.length) {
  1923. //throw new Error("未发现保存按钮");
  1924. debug_log("未发现保存按钮");
  1925. return;
  1926. }
  1927. let opt = _this._getSaveOptions(), ajaxSelectFun;
  1928. if (_config.ajaxSelect) {
  1929. ajaxSelectFun = function () {
  1930. $modal.find('select' + Selector.AJAX_SELECT).each(function () {
  1931. let $this = $(this);
  1932. let cKey = $this.data(ClassName.AJAX_SELECT_CODE),
  1933. val = $this.val(),
  1934. name = $this.find("option[value='" + val + "']").text(), ran = Math.floor(Math.random() * 9999);
  1935. debug_log('AjaxSelect[{3}]:{0}-{1}-{2}'.format(cKey, val, name, ran));
  1936. $.vbAjax41({
  1937. url: abp.appUrl + "Query/AddAcInfo",
  1938. data: {
  1939. CodeKey: cKey,
  1940. ValueKey: val,
  1941. NameKey: name
  1942. },
  1943. success: function () {
  1944. debug_log('AjaxSelect[{0}]:Success'.format(ran));
  1945. }
  1946. });
  1947. });
  1948. }
  1949. }
  1950. let save = null;
  1951. if (_config.save && typeof (_config.save) === "function") {
  1952. save = function () { _config.save(opt); };
  1953. } else if (_config.url) {
  1954. save = function () { $.vbAjax(_config.url, opt); };
  1955. }
  1956. let saveFun =
  1957. function () {
  1958. if (save && $.isFunction(save)) {
  1959. save();
  1960. }
  1961. if (ajaxSelectFun && $.isFunction(ajaxSelectFun)) {
  1962. ajaxSelectFun();
  1963. }
  1964. }
  1965. $saveBtn.off('click.save').on('click.save', saveFun);
  1966. $modal.find('.modal-body input').keydown(function (e) {
  1967. if (e.which === 13) {
  1968. if (e.target.tagName.toLocaleLowerCase() === "textarea") {
  1969. e.stopPropagation();
  1970. } else {
  1971. e.preventDefault();
  1972. saveFun.call(_this);
  1973. }
  1974. }
  1975. });
  1976. };
  1977. _proto._getSaveOptions = function () {
  1978. let _this = this, _config = _this._config, $modal = $(_this._element);
  1979. let $form = $modal.find('form');
  1980. if (!$form.length && _config.needForm) {
  1981. throw new Error("未发现表单");
  1982. }
  1983. return {
  1984. url: _config.url,
  1985. type: _config.type,
  1986. table: _config.table,
  1987. success: _config.success,
  1988. form: $form,
  1989. data: null,
  1990. dataFun: _config.dataFun,
  1991. isValidate: _config.fromValidate,
  1992. modal: _config.modal,
  1993. blockUI: true,
  1994. isRefresh: _config.isRefresh,
  1995. isAlert: _config.isAlert
  1996. };
  1997. };
  1998. _proto._show = function ($modal) {
  1999. let _this = this, _config = _this._config;
  2000. $modal.modal({ backdrop: _config.backdrop, keyboard: _config.keyboard });
  2001. $modal.modal('show');
  2002. };
  2003. _proto.open = function (opts, modal) {
  2004. let _this = this;
  2005. let $modal = _this._getModal(opts, modal);
  2006. _this._bindEvent();
  2007. _this._show($modal);
  2008. }
  2009. _proto.show = function (opts, modal) {
  2010. let _this = this;
  2011. let $modal = _this._getModal(opts, modal);
  2012. _this._bindEvent();
  2013. _this._config.isInit = false;
  2014. _this._show($modal);
  2015. };
  2016. _proto.hide = function () {
  2017. let _this = this, $modal = $(_this._element);
  2018. return $modal.modal('hide');
  2019. };
  2020. _proto.create = function (opts) {
  2021. let _this = this, _config = _this._config = $.extend({}, _this._config, opts);
  2022. if (!_config.modalId) {
  2023. if (_config.modal) {
  2024. _config.modalId = typeof (_config.modal) === 'string' ? _config.modal : $(_config.modal).attr('id');
  2025. } else {
  2026. _config.modalId = `modal_${Math.floor(Math.random() * 10000000)}`;
  2027. }
  2028. }
  2029. let dialogClass = _config.modalSize === null ?
  2030. _config.modalSize = "" :
  2031. _config.modalSize ?
  2032. _config.modalSize :
  2033. ClassName.MODAL_LG;
  2034. if (_config.dialogClass) {
  2035. dialogClass += _config.dialogClass;
  2036. }
  2037. let dialogStyle = _config.width ? `max-width:${_config.width}px;` : "";
  2038. if (_config.dialogStyle) {
  2039. dialogStyle += _config.dialogStyle;
  2040. }
  2041. let containerId = `modal-container_${_config.modalId}`;
  2042. if ($('#' + containerId).length) {
  2043. $('#' + containerId).remove();
  2044. }
  2045. let $container = $(`
  2046. <div id="${containerId}" class="${ClassName.CREATE_BOX}">
  2047. <div id="${_config.modalId}" class="modal fade ${_config.modalClass}">
  2048. <div class="${ClassName.MODAL_DIALOG} modal-dialog-centered modal-dialog-scrollable ${dialogClass}" style="${dialogStyle}">
  2049. <div class="${ClassName.MODAL_CONTENT}"></div>
  2050. </div>
  2051. </div>
  2052. </div>`);
  2053. let $modalContent = $container.find(Selector.MODAL_CONTENT);
  2054. if (_config.content) {
  2055. $modalContent.append(_config.content);
  2056. } else if (_config.modalBody) {
  2057. let modalHeader = _config.modalHeader != undefined
  2058. ? _config.modalHeader
  2059. : `<div class="${ClassName.MODAL_HEADER} py-3 ${_config.modalHeaderClass ? _config.modalHeaderClass : ""}"><h4 class="modal-title"><span class="modal-title">${_config.title ? _config.title : ""}</span></h4><div class="btn btn-icon btn-sm btn-active-light-primary ms-2" data-bs-dismiss="modal" aria-label="Close">
  2060. <!--Svg Icon | path: icons/duotone/Navigation/Close.svg-->
  2061. <span class="svg-icon svg-icon-2x">
  2062. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1">
  2063. <g transform="translate(12.000000, 12.000000) rotate(-45.000000) translate(-12.000000, -12.000000) translate(4.000000, 4.000000)" fill="#000000">
  2064. <rect fill="#000000" x="0" y="7" width="16" height="2" rx="1"></rect>
  2065. <rect fill="#000000" opacity="0.5" transform="translate(8.000000, 8.000000) rotate(-270.000000) translate(-8.000000, -8.000000)" x="0" y="7" width="16" height="2" rx="1"></rect>
  2066. </g>
  2067. </svg>
  2068. </span>
  2069. </div></div>`;
  2070. let modalBody = `<div class="${ClassName.MODAL_BODY} ${_config.modalBodyClass}">${_config.modalBody}</div>`;
  2071. let modalFooter = _config.modalFooter != undefined
  2072. ? _config.modalFooter
  2073. : `<div class="${ClassName.MODAL_FOOTER} py-2 ${_config.modalFooterClass ? _config.modalFooterClass : ""}" style="text-align: center;"><button
  2074. <button type="button" class="btn btn-sm btn-light me-5" data-bs-dismiss="modal">取消</button>
  2075. <button type="submit" class="btn btn-sm btn-primary ${ClassName.SAVE_BUTTON}">保存</button>
  2076. </div>`;
  2077. $modalContent.append(modalHeader);
  2078. $modalContent.append(modalBody);
  2079. $modalContent.append(modalFooter);
  2080. }
  2081. $('body').append($container);
  2082. if (!$(_this._element).hasClass(ClassName.MODAL)) {
  2083. _this._element = $('#' + _config.modalId)[0];
  2084. }
  2085. _this.show();
  2086. }
  2087. Modal._jQueryInterface = function _jQueryInterface(option) {
  2088. let value;
  2089. let data = $(this).data(DATA_KEY);
  2090. let args = Array.prototype.slice.call(arguments, 1);
  2091. let _options = $.extend(true, {}, Default, (typeof option == "string" ? {} : option) || {});
  2092. if (typeof option === 'string') {
  2093. if ($.inArray(option, ALLOW_METHOD) < 0) {
  2094. throw new Error("Unknown method: " + option);
  2095. }
  2096. if (!data) {
  2097. data = new Modal($(this), _options, option == "create");
  2098. }
  2099. value = data[option].apply(data, args);
  2100. } else {
  2101. if (!data) {
  2102. data = new Modal($(this), _options);
  2103. $(this).data(DATA_KEY, data);
  2104. }
  2105. data.open(_options);
  2106. }
  2107. return typeof value === 'undefined' ? this : value;
  2108. };
  2109. return Modal;
  2110. }();
  2111. /*
  2112. * jQuery API
  2113. * ====================================================
  2114. */
  2115. $.fn[NAME] = Modal._jQueryInterface;
  2116. $.fn[NAME].Constructor = Modal;
  2117. $.fn[NAME].noConflict = function () {
  2118. $.fn[NAME] = JQUERY_NO_CONFLICT;
  2119. return Modal._jQueryInterface;
  2120. };
  2121. }((jQuery));
  2122. let VbFile = function ($) {
  2123. const NAME = 'VbFile';
  2124. const DATA_KEY = 'vb.File';
  2125. const EVENT_KEY = "." + DATA_KEY;
  2126. const ClassName = {
  2127. FILE_URL: "vb-file-url",
  2128. FILE_TYPE: "vb-file-type",
  2129. MODAL_IMAGE: 'vb-image-modal',
  2130. MODAL_FILE: 'vb-file-modal',
  2131. IMAGE_URL_NAME: 'data-vb-image-url',
  2132. DOWNLOAD: 'download',
  2133. TEMPLINK: 'tempLink-fd',
  2134. TARGET_INFO: "vb-file-target-info",
  2135. TARGET_NAME: "vb-file-target-name",
  2136. TARGET_EXT: "vb-file-target-ext",
  2137. IS_IMAGE: "vb-file-image",
  2138. MAX_SIZE: "vb-file-max-size",
  2139. FILE_BOX: 'vb-file-box',
  2140. FILE_CLEAN_BTN: 'vb-file-btn="clean"',
  2141. VALID_CLASS: "valid",
  2142. INVALID_CLASS: "invalid",
  2143. INVALID_FEEDBACK: "invalid-feedback",
  2144. INVALID_FEEDBACK_SHOW: "invalid-feedback-show"
  2145. }
  2146. const Selector = {
  2147. FILE_UPLOAD: `[data-vb-file="upload"]`,
  2148. FILE_SHOW: `[data-vb-file="show"]`,
  2149. MODAL_IMAGE: `#${ClassName.MODAL_IMAGE}`,
  2150. MODAL_FILE: `#${ClassName.MODAL_FILE}`,
  2151. DOWNLOAD: `#${ClassName.DOWNLOAD}`,
  2152. TEMPLINK: `#${ClassName.TEMPLINK}`,
  2153. FILE_INPUT: 'input[type="file"]',
  2154. FILE_BOX: `[data-${ClassName.FILE_BOX}]`,
  2155. FILE_CLEAN_BTN: `[data-${ClassName.FILE_CLEAN_BTN}]`,
  2156. INVALID_FEEDBACK: `.${ClassName.INVALID_FEEDBACK}`
  2157. }
  2158. const JQUERY_NO_CONFLICT = $.fn[NAME];
  2159. const ALLOW_METHOD = [
  2160. 'show',
  2161. 'showImage',
  2162. 'showOffice',
  2163. 'showFile',
  2164. 'download',
  2165. 'upload',
  2166. 'cleanFile'
  2167. ];
  2168. const Default = {
  2169. url: undefined,
  2170. type: 'img',
  2171. maxSize: 2,
  2172. isImage: false,
  2173. targetInfo: undefined,
  2174. targetName: "fileName",
  2175. targetExt: "fileExt",
  2176. callback: undefined
  2177. }
  2178. let File = function () {
  2179. function File(element, config) {
  2180. this._element = element;
  2181. this._config = config;
  2182. }
  2183. let _proto = File.prototype;
  2184. _proto.show = function () {
  2185. let _this = this, _config = _this._config, _el = _this._element;
  2186. let config = {
  2187. url: _config.url ? _config.url : $(_el).data(ClassName.FILE_URL),
  2188. type: _config.type ? _config.type : $(_el).data(ClassName.FILE_TYPE)
  2189. };
  2190. if (!url) {
  2191. throw new Error("Need URL");
  2192. return;
  2193. }
  2194. switch (config.type.toLowerCase()) {
  2195. case 'img':
  2196. case 'image':
  2197. this.showImage(config.url);
  2198. break;
  2199. case 'office':
  2200. case 'doc':
  2201. case 'docx':
  2202. this.showOffice(config.url);
  2203. break;
  2204. default:
  2205. this.showFile(config.url);
  2206. return;
  2207. }
  2208. };
  2209. _proto.showImage = function (url, config) {
  2210. if (!url) {
  2211. return;
  2212. }
  2213. let _this = this;
  2214. $.metPageCss('/Libs/viewerjs/dist/viewer.min.css', "dy-css-viewer");
  2215. $.metPageJs('/Libs/viewerjs/dist/viewer.min.js', "dy-js-viewer");
  2216. let Viewer = window.Viewer;
  2217. if ($(Selector.MODAL_IMAGE).length > 0) {
  2218. $(Selector.MODAL_IMAGE).remove();
  2219. }
  2220. let urls = url.split(",");
  2221. let $ul = $(`<ul id="${ClassName.MODAL_IMAGE}" style="display:none"></ul>`);
  2222. for (let i = 0; i < urls.length; i++) {
  2223. $ul.append(`<li><img src="${urls[i]}" ${ClassName.IMAGE_URL_NAME}="{urls[i]}" /></li>`);
  2224. }
  2225. $ul.appendTo($('body'));
  2226. let $image = $(Selector.MODAL_IMAGE), imageView;
  2227. let options = $.extend({}, {
  2228. // inline: true,
  2229. url: ClassName.IMAGE_URL_NAME,
  2230. button: true,
  2231. navbar: urls.length > 1,
  2232. title: false,
  2233. toolbar: true,
  2234. ready: function (e) {
  2235. console.log(e.type);
  2236. },
  2237. show: function (e) {
  2238. console.log(e.type);
  2239. },
  2240. shown: function (e) {
  2241. console.log(e.type);
  2242. },
  2243. hide: function (e) {
  2244. console.log(e.type);
  2245. },
  2246. view: function (e) {
  2247. console.log(e.type);
  2248. },
  2249. viewed: function (e) {
  2250. console.log(e.type);
  2251. },
  2252. move: function (e) {
  2253. console.log(e.type);
  2254. },
  2255. moved: function (e) {
  2256. console.log(e.type);
  2257. },
  2258. hidden: function () {
  2259. imageView.destroy();
  2260. $image.remove();
  2261. }
  2262. }, _this._config, config || {}, { url: ClassName.IMAGE_URL_NAME });
  2263. imageView = new Viewer($image[0], options);
  2264. imageView.show();
  2265. //$image.viewer("show");
  2266. $image.css("display", "none");
  2267. };
  2268. _proto.showOffice = function (url, office_url) {
  2269. let _this = this;
  2270. url = (office_url || OFFICEURL) + window.location.host + url;
  2271. _this.showFile(url);
  2272. };
  2273. _proto.showFile = function (url) {
  2274. let _this = this;
  2275. $(document).VbModal('create',
  2276. {
  2277. modal: ClassName.MODAL_FILE,
  2278. title: '文件预览',
  2279. dialogStyle: "min-width: calc(100% - 600px);",
  2280. modalBody: `<div class="modal-body"><iframe src="${url}" width="100%"; style="min-height: calc(100vh - 300px);" frameborder="0"></iframe></div>`,
  2281. modalFooter: `<div class="modal-footer" style="text-align: center;justify-content: center"><button type="button" class="btn btn-default" data-dismiss="modal" style="min-width: 100px;">关闭窗口</button><button id="${ClassName.DOWNLOAD}" type="button" class="btn btn-primary
  2282. " style="min-width: 100px;">下载文件</button></div>`,
  2283. showAfter: function () {
  2284. $(Selector.MODAL_FILE + " " + Selector.DOWNLOAD).off('click.download' + EVENT_KEY).on('click.download' + EVENT_KEY, function () { _this.download(url) });
  2285. }
  2286. });
  2287. };
  2288. _proto.download = function (url) {
  2289. let _this = this;
  2290. url = url || _this.config.url;
  2291. if ($(Selector.TEMPLINK).length > 0) {
  2292. $(Selector.TEMPLINK).remove();
  2293. }
  2294. $('body').append(`<a id="${ClassName.TEMPLINK}" href="${url}" target="_blank" style="display:none"></a>`);
  2295. $(Selector.TEMPLINK)[0].click();
  2296. $(Selector.TEMPLINK).remove();
  2297. };
  2298. _proto.upload = function () {
  2299. let _this = this, $this = $(_this._element), _config = _this._config, $file = _this._getFile();
  2300. let targetInfo = $file.data(ClassName.TARGET_INFO), targetName = $file.data(ClassName.TARGET_NAME), targetExt = $file.data(ClassName.TARGET_EXT), isImage = $file.data(ClassName.IS_IMAGE), maxSize = $file.data(ClassName.MAX_SIZE);
  2301. if (targetInfo) {
  2302. _config.targetInfo = targetInfo;
  2303. }
  2304. if (targetName) {
  2305. _config.targetName = targetName;
  2306. }
  2307. if (targetExt) {
  2308. _config.targetExt = targetExt;
  2309. }
  2310. if (isImage === "true" || isImage === "1" || isImage === "y" || isImage === "Y" || isImage === "True") {
  2311. _config.isImage = true;
  2312. }
  2313. if (maxSize) {
  2314. _config.maxSize = maxSize;
  2315. }
  2316. $file.off('change' + EVENT_KEY).on('change' + EVENT_KEY, function () {
  2317. _this._fileCheck();
  2318. });
  2319. $file.removeClass(ClassName.INVALID_CLASS).removeClass(ClassName.VALID_CLASS);
  2320. $this.closest(Selector.FILE_BOX).parent().find(Selector.INVALID_FEEDBACK).empty().removeClass(ClassName.INVALID_FEEDBACK_SHOW);
  2321. $this.closest(Selector.FILE_BOX).find(Selector.FILE_CLEAN_BTN).off('click' + EVENT_KEY).on('click' + EVENT_KEY, () => { _this.cleanFile(); });
  2322. };
  2323. _proto.cleanFile = function () {
  2324. let _this = this, $this = $(_this._element);
  2325. let $file = _this._getFile();
  2326. let $fileBox = $this.closest(Selector.FILE_BOX);
  2327. $file.removeClass(ClassName.INVALID_CLASS).removeClass(ClassName.VALID_CLASS);
  2328. $this.closest(Selector.FILE_BOX).parent().find(Selector.INVALID_FEEDBACK).empty().removeClass(ClassName.INVALID_FEEDBACK_SHOW);
  2329. $fileBox.find('input').val('');
  2330. $file.after($file.clone().val(""));
  2331. $file.remove();
  2332. $fileBox.find(Selector.FILE_INPUT).off('change' + EVENT_KEY).on('change' + EVENT_KEY, () => { _this._fileCheck(); });
  2333. };
  2334. _proto._fileCheck = function () {
  2335. let _this = this, _config = _this._config;
  2336. let $file = _this._getFile();
  2337. if (_this._checkSize()) {
  2338. let fileName = $file.val().split("\\").pop();
  2339. //$this.closest(Selector.FILE_BOX).addClass(ClassName.FILE_SUCCESS).find("label").text(fileName);
  2340. let file = $file[0].files[0];
  2341. _this._readFile(file);
  2342. if (_config.targetName && _config.targetName !== undefined) {
  2343. let name = fileName.substring(0, fileName.lastIndexOf("."));
  2344. if (!_config.targetName)
  2345. return;
  2346. let targetName = _config.targetName.split(',');
  2347. for (let i = 0; i < targetName.length; i++) {
  2348. $(`[name="${targetName[i]}"]`).val(name);
  2349. }
  2350. }
  2351. if (_config.targetExt && _config.targetExt !== undefined) {
  2352. let ext = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length);
  2353. if (!_config.targetExt)
  2354. return;
  2355. let targetExt = _config.targetExt.split(',');
  2356. for (let j = 0; j < targetExt.length; j++) {
  2357. $(`[name="${targetExt[j]}"]`).val(ext);
  2358. }
  2359. }
  2360. let callback = _config.callback;
  2361. if (callback && typeof (callback) === "function") {
  2362. callback(fileName, file);
  2363. }
  2364. } else {
  2365. //let target = _config.targetInfo ? _config.targetInfo : $file.attr('id').replace('_file', '');
  2366. //$file.addClass(ClassName.INVALID_CLASS);
  2367. //$(`[name="${_config.targetInfo}"]`).closest(Selector.FILE_BOX).parent().find(Selector.INVALID_FEEDBACK).html(abp.localization.VberZero('SelectFile')).addClass(ClassName.INVALID_FEEDBACK_SHOW);
  2368. }
  2369. };
  2370. _proto._checkSize = function () {
  2371. let _this = this, _config = _this._config;
  2372. let $file = _this._getFile();
  2373. let maxsize = _config.maxSize * 1024 * 1024;
  2374. //let errMsg = "上传的附件文件不能超过" + _config.maxSize + "M。";
  2375. //let tipMsg = "您的浏览器暂不支持计算上传文件的大小,确保上传文件不要超过" + _config.maxSize + "M,建议使用IE、FireFox、Chrome浏览器。";
  2376. let errMsg = abp.localization.VberZero('FileUploadErrorMsg', _config.maxSize);
  2377. let tipMsg = abp.localization.VberZero('FileUploadTipMsg', _config.maxSize);
  2378. let browserCfg = {};
  2379. let ua = window.navigator.userAgent;
  2380. if (ua.indexOf("MSIE") >= 1) {
  2381. browserCfg.ie = true;
  2382. } else if (ua.indexOf("Firefox") >= 1) {
  2383. browserCfg.firefox = true;
  2384. } else if (ua.indexOf("Chrome") >= 1) {
  2385. browserCfg.chrome = true;
  2386. }
  2387. try {
  2388. let objFile = $file[0];
  2389. if (objFile.value === "") {
  2390. //layer.alert("请先选择上传文件", { icon: 7, title: "提示信息" });
  2391. return false;
  2392. }
  2393. let filesize;
  2394. if (browserCfg.firefox || browserCfg.chrome) {
  2395. filesize = objFile.files[0].size;
  2396. } else if (browserCfg.ie) {
  2397. let objImg = document.createElement("img");
  2398. objImg.id = "tempImg";
  2399. objImg.style.display = "none";
  2400. document.body.appendChild(objImg);
  2401. objImg.dynsrc = objFile.value;
  2402. filesize = objImg.fileSize;
  2403. } else {
  2404. _this.cleanFile();
  2405. abp.message.warn(tipMsg);
  2406. return false;
  2407. }
  2408. if (filesize === -1) {
  2409. _this.cleanFile();
  2410. abp.message.warn(tipMsg);
  2411. return false;
  2412. } else if (filesize > maxsize) {
  2413. _this.cleanFile();
  2414. abp.message.warn(errMsg);
  2415. return false;
  2416. } else {
  2417. return true;
  2418. }
  2419. } catch (e) {
  2420. _this.cleanFile();
  2421. abp.message.error(e);
  2422. return false;
  2423. }
  2424. };
  2425. _proto._readFile = function (file) {
  2426. let _this = this, _config = _this._config;
  2427. let $file = _this._getFile();
  2428. file = file || $file[0].files[0];
  2429. if (!file) {
  2430. return;
  2431. }
  2432. if (_config.isImage && !/image\/\w+/.test(file.type)) {
  2433. abp.message.warn(abp.localization.VberZero('FileUploadOnlyImage'));
  2434. _this.cleanFile();
  2435. return;
  2436. }
  2437. let reader = new FileReader();
  2438. reader.readAsDataURL(file);
  2439. reader.onload = function () {
  2440. let fileinfo = this.result.substring(this.result.indexOf(',') + 1);
  2441. //let target = _config.targetInfo ? _config.targetInfo : $file.attr('id').replace('_file', '');
  2442. $(`[name="${_config.targetInfo}"]`).val(fileinfo);
  2443. };
  2444. };
  2445. _proto._getFile = function () {
  2446. let _this = this, $this = $(_this._element);
  2447. let $file = $this.closest(Selector.FILE_BOX).find(Selector.FILE_INPUT);
  2448. return $file;
  2449. };
  2450. File._jQueryInterface = function _jQueryInterface(option) {
  2451. let value, args = Array.prototype.slice.call(arguments, 1);
  2452. this.each(function () {
  2453. let data = $(this).data(DATA_KEY);
  2454. let _options = $.extend({}, Default, $(this).data(), typeof option === 'object' && option || {});
  2455. if (!data) {
  2456. data = new File(this, _options);
  2457. $(this).data(DATA_KEY, data);
  2458. }
  2459. if (!option) {
  2460. value = data.show();
  2461. } else if (typeof option === 'string') {
  2462. if ($.inArray(option, ALLOW_METHOD) < 0) {
  2463. throw new Error("Unknown method: " + option);
  2464. }
  2465. value = data[option].apply(data, args);
  2466. }
  2467. });
  2468. return typeof value === 'undefined' ? this : value;
  2469. };
  2470. return File;
  2471. }();
  2472. $(window).on("load" + EVENT_KEY, function () {
  2473. $(Selector.FILE_UPLOAD).each(function () {
  2474. File._jQueryInterface.call($(this), "upload");
  2475. });
  2476. $(Selector.FILE_SHOW).each(function () {
  2477. File._jQueryInterface.call($(this), "show");
  2478. });
  2479. });
  2480. /*
  2481. * jQuery API
  2482. * ====================================================
  2483. */
  2484. $.fn[NAME] = File._jQueryInterface;
  2485. $.fn[NAME].Constructor = File;
  2486. $.fn[NAME].noConflict = function () {
  2487. $.fn[NAME] = JQUERY_NO_CONFLICT;
  2488. return File._jQueryInterface;
  2489. };
  2490. }((jQuery));
  2491. let VbDate = function ($) {
  2492. const NAME = 'VbDate';
  2493. const DATA_KEY = 'vb.date';
  2494. const EVENT_KEY = "." + DATA_KEY;
  2495. const ClassName = {
  2496. }
  2497. const Selector = {
  2498. DATE: `[data-vb-date="date"]`,
  2499. DATETIME: `[data-vb-date="date-time"]`,
  2500. RANGEDATE: `[data-vb-date="r_date"]`,
  2501. RANGEDATETIME: `[data-vb-date="r_date-time"]`,
  2502. }
  2503. const JQUERY_NO_CONFLICT = $.fn[NAME];
  2504. const ALLOW_METHOD = [
  2505. "load",
  2506. "date",
  2507. "dateTime",
  2508. "dateRange",
  2509. "dateTimeRange",
  2510. "setValue",
  2511. ];
  2512. const Default = {
  2513. //altInput: true,
  2514. //altFormat: "Y-m-d",
  2515. //allowInput: true,
  2516. time_24hr: true,
  2517. //wrap: true,//外部元素
  2518. //minDate: undefined,
  2519. //maxDate: undefined,
  2520. //minTime: undefined,
  2521. //maxTime: undefined,
  2522. //showMonths: 1,//显示的月份数
  2523. //mode: undefined,//single,multiple,range
  2524. //noCalendar: true,
  2525. //weekNumbers: false,//显示第多少周
  2526. //enableTime: false,
  2527. //hourIncrement: 1, //调整小时输入的步进(包括滚动)
  2528. //minuteIncrement: 5,//
  2529. //enableSeconds: false,
  2530. //defaultDate: undefined,// ["2025-01-05", "2025-01-10"]
  2531. //defaultHour: undefined,
  2532. //defaultMinute: undefined,
  2533. //dateFormat: "Y-m-d H:i",
  2534. //disable: undefined,//(disable 禁用日期, enable 禁用其余日期) ["2025-01-10", "22025-01-11"] [ { from: "2025-01-05", to: "2025-01-25" },{...}]
  2535. //inline: false,//始终打开状态显示日历
  2536. //position: "auto",
  2537. //preletrow: "<",//箭头图标的HTML,用于切换月份
  2538. //nextArrow: ">"
  2539. }
  2540. let Date = function () {
  2541. function Date(element, config) {
  2542. this._element = element;
  2543. this._config = config;
  2544. }
  2545. let _proto = Date.prototype;
  2546. _proto._getHtmlOption = function () {
  2547. let _this = this, data = $(_this._element).data();
  2548. let htmlOption = {};
  2549. //htmlOption.mode = data.mode;
  2550. htmlOption.defaultDate = data.dateDefaultDate;
  2551. htmlOption.defaultHour = data.dateDefaultHour;
  2552. htmlOption.defaultMinute = data.dateDefaultMinute;
  2553. htmlOption.minDate = data.dateMinDate;
  2554. htmlOption.maxDate = data.dateMaxDate;
  2555. htmlOption.minTime = data.dateMinTime;
  2556. htmlOption.maxTime = data.dateMaxTime;
  2557. //htmlOption.enableTime = data.dateEnableTime;
  2558. htmlOption.dateFormat = data.dateFormat;
  2559. htmlOption.disable = data.dateDisable;
  2560. htmlOption.noCalendar = data.dateNoCalendar;
  2561. htmlOption.inline = data.dateInline;
  2562. htmlOption.showMonths = data.dateShowMonths;
  2563. htmlOption.hourIncrement = data.dateHourIncrement;
  2564. htmlOption.minuteIncrement = data.dateMinuteIncrement;
  2565. htmlOption.enableSeconds = data.dateEnableSeconds;
  2566. return htmlOption;
  2567. };
  2568. _proto._extendOption = function (options) {
  2569. let _this = this, _config = _this._config;
  2570. let opt = $.extend(true, {}, _config, options || {});
  2571. if (opt.noCalendar) {
  2572. opt.enableTime = true;
  2573. opt.dateFormat = "H:i";
  2574. }
  2575. if (!opt.dateFormat) {
  2576. opt.dateFormat = opt.noCalendar ? "" : "Y-m-d";
  2577. if (opt.enableTime) {
  2578. opt.dateFormat = opt.dateFormat ? `${opt.dateFormat} H:i` : "H:i";
  2579. }
  2580. }
  2581. opt.locale = window.lang == "zh-CN" ? "zh" : window.lang;
  2582. _config = opt;
  2583. return opt;
  2584. };
  2585. _proto.date = function (options) {
  2586. let _this = this;
  2587. let opt = $.extend(true, {}, _this._getHtmlOption(), options || {});
  2588. opt.mode = "single";
  2589. opt.enableTime = false;
  2590. opt.dateFormat = "Y-m-d";
  2591. _this.load(opt);
  2592. };
  2593. _proto.dateRange = function (options) {
  2594. let _this = this;
  2595. let opt = $.extend(true, {}, _this._getHtmlOption(), options || {});
  2596. opt.enableTime = false;
  2597. opt.dateFormat = "Y-m-d";
  2598. opt.mode = "range";
  2599. _this.load(opt);
  2600. };
  2601. _proto.dateTime = function (options) {
  2602. let _this = this;
  2603. let opt = $.extend(true, {}, _this._getHtmlOption(), options || {});
  2604. opt.enableTime = true;
  2605. opt.dateFormat = "Y-m-d H:i";
  2606. opt.mode = "single";
  2607. _this.load(opt);
  2608. };
  2609. _proto.dateTimeRange = function (options) {
  2610. let _this = this;
  2611. let opt = $.extend(true, {}, _this._getHtmlOption(), options || {});
  2612. opt.enableTime = true;
  2613. opt.dateFormat = "Y-m-d H:i";
  2614. opt.mode = "range";
  2615. _this.load(opt);
  2616. };
  2617. _proto.load = function (options) {
  2618. let _this = this, _config = _this._config, _el = _this._element;
  2619. let opt = options || _this._getHtmlOption();
  2620. let option = _this._extendOption(opt)
  2621. debug_log("DateTime:", $(_el).attr('name'), option);
  2622. _config.vbDate = $(_el).flatpickr(option);
  2623. }
  2624. _proto.setValue = function (value) {
  2625. let _this = this, _config = _this._config;
  2626. let format = _config.noCalendar ? "Y-m-d H:i" : _config.dateFormat;
  2627. _config.vbDate.setDate(value, true, format);
  2628. debug_log("date_setValue", value, format, $(_this._el).val());
  2629. }
  2630. Date._jQueryInterface = function _jQueryInterface(option) {
  2631. let value, args = Array.prototype.slice.call(arguments, 1);
  2632. this.each(function () {
  2633. let data = $(this).data(DATA_KEY);
  2634. let _options = $.extend({}, Default, $(this).data(), typeof option === 'object' && option || {});
  2635. if (!data) {
  2636. data = new Date(this, _options);
  2637. $(this).data(DATA_KEY, data);
  2638. }
  2639. if (!option) {
  2640. value = data.load();
  2641. } else if (typeof option === 'string') {
  2642. if ($.inArray(option, ALLOW_METHOD) < 0) {
  2643. throw new Error("Unknown method: " + option);
  2644. }
  2645. value = data[option].apply(data, args);
  2646. }
  2647. });
  2648. return typeof value === 'undefined' ? this : value;
  2649. };
  2650. return Date;
  2651. }();
  2652. $(window).on("load" + EVENT_KEY, function () {
  2653. $(Selector.DATE).each(function () {
  2654. Date._jQueryInterface.call($(this), "date");
  2655. });
  2656. $(Selector.DATETIME).each(function () {
  2657. Date._jQueryInterface.call($(this), "dateTime");
  2658. });
  2659. $(Selector.RANGEDATE).each(function () {
  2660. Date._jQueryInterface.call($(this), "dateRange");
  2661. });
  2662. $(Selector.RANGEDATETIME).each(function () {
  2663. Date._jQueryInterface.call($(this), "dateTimeRange");
  2664. });
  2665. });
  2666. /*
  2667. * jQuery API
  2668. * ====================================================
  2669. */
  2670. $.fn[NAME] = Date._jQueryInterface;
  2671. $.fn[NAME].Constructor = Date;
  2672. $.fn[NAME].noConflict = function () {
  2673. $.fn[NAME] = JQUERY_NO_CONFLICT;
  2674. return Date._jQueryInterface;
  2675. };
  2676. }((jQuery));
  2677. let VbTreeView = function ($) {
  2678. let NAME = 'VbTreeView';
  2679. let DATA_KEY = 'vb.tree_view';
  2680. //let EVENT_KEY = "." + DATA_KEY;
  2681. //let Selector = {
  2682. //}
  2683. //let ClassName = {
  2684. //}
  2685. let JQUERY_NO_CONFLICT = $.fn[NAME];
  2686. let Default = {
  2687. url: undefined,
  2688. data: undefined,
  2689. levels: 2,
  2690. showCheckbox: false,
  2691. checkedIcon: 'far fa-check-square',
  2692. uncheckedIcon: 'far fa-square',
  2693. emptyIcon: 'fas fa-square',
  2694. collapseIcon: 'fas fa-minus-square',
  2695. expandIcon: 'fas fa-plus-square',
  2696. color: '',
  2697. selectedBackColor: '',
  2698. selectedColor: '',
  2699. table: 'table',
  2700. selectFiledName: 'id',
  2701. selectFiledInput: 'keyWords'
  2702. }
  2703. let ALLOW_METHOD = [
  2704. 'init'
  2705. ];
  2706. //[
  2707. // {
  2708. // id: "1",
  2709. // text: "Parent 1",
  2710. // nodes: [
  2711. // {
  2712. // id: "1-1",
  2713. // text: "Child 1",
  2714. // nodes: [
  2715. // {
  2716. // id: "1-1-1",
  2717. // text: "Grandchild 1"
  2718. // },
  2719. // {
  2720. // id: "1-1-2",
  2721. // text: "Grandchild 2"
  2722. // }
  2723. // ]
  2724. // },
  2725. // {
  2726. // id: "1-2",
  2727. // text: "Child 2"
  2728. // }
  2729. // ]
  2730. // },
  2731. // {
  2732. // id: "2",
  2733. // text: "Parent 2"
  2734. // }
  2735. //];
  2736. let TreeView = function () {
  2737. function TreeView(element, config) {
  2738. this._element = element;
  2739. this._config = config;
  2740. this.init();
  2741. }
  2742. // Public
  2743. let _proto = TreeView.prototype;
  2744. _proto.init = function () {
  2745. let _this = this, _config = _this._config;
  2746. $.metPageCss('/Libs/bootstrap-treeview/dist/bootstrap-treeview.min.css', "dy-css-treeview");
  2747. $.metPageJs('/Libs/bootstrap-treeview/dist/bootstrap-treeview.min.js', "dy-js-treeview");
  2748. _config.onNodeSelected = _config.onNodeSelected && typeof _config.onNodeSelected == 'function' ?
  2749. function (e, data) { _config.onNodeSelected.call(_this, e, data); } : _this._onNodeSelected;
  2750. _config.onNodeUnselected = _config.onNodeUnselected && typeof _config.onNodeUnselected == 'function' ?
  2751. function (e, data) { _config.onNodeUnselected.call(_this, e, data); } : _this._onNodeUnselected;
  2752. if (_config.data) {
  2753. _this.loadTree();
  2754. } else if (_config.url) {
  2755. _this.postData();
  2756. }
  2757. };
  2758. _proto._onNodeSelected = function (e, data) {
  2759. let _this = this, _config = _this._config;
  2760. if (!data || !data[_config.selectFiledName]) {
  2761. return;
  2762. }
  2763. let $input = (typeof (_config.selectFiledInput) === 'string' ? $('#' + _config.selectFiledInput) : $(_config.selectFiledInput));
  2764. let tempId = data[_config.selectFiledName];
  2765. $input.val(tempId);
  2766. let $table = (typeof (_config.table) === 'string' ? $('#' + _config.table) : $(_config.table));
  2767. $table.VbTable('refresh', true);
  2768. };
  2769. _proto._onNodeUnselected = function () {
  2770. let _this = this, _config = _this._config;
  2771. let $input = (typeof (_config.selectFiledInput) === 'string' ? $('#' + _config.selectFiledInput) : $(_config.selectFiledInput));
  2772. $input.val('');
  2773. let $table = (typeof (_config.table) === 'string' ? $('#' + _config.table) : $(_config.table));
  2774. $table.VbTable('refresh', true);
  2775. };
  2776. _proto.loadTree = function (data) {
  2777. let _this = this;
  2778. let option = $.extend({}, _this._config);
  2779. if (data) {
  2780. option.data = data;
  2781. }
  2782. $(_this._element).treeview(option);
  2783. };
  2784. _proto.postData = function (url) {
  2785. let _this = this;
  2786. url = url || _this._config.url;
  2787. $.vbAjax({
  2788. url: window.appUrl + url,
  2789. isAlert: false,
  2790. isValidate: false,
  2791. isRefresh: false,
  2792. success: function (res) {
  2793. if (res) {
  2794. _this.loadTree(res);
  2795. }
  2796. }
  2797. });
  2798. };
  2799. TreeView._jQueryInterface = function _jQueryInterface(option) {
  2800. let value, args = Array.prototype.slice.call(arguments, 1);
  2801. this.each(function () {
  2802. let data = $(this).data(DATA_KEY);
  2803. let _options = $.extend({}, Default, $(this).data(), typeof option === 'object' && option);
  2804. if (!data) {
  2805. data = new TreeView(this, _options);
  2806. $(this).data(DATA_KEY, data);
  2807. }
  2808. if (typeof option === 'string') {
  2809. if ($.inArray(option, ALLOW_METHOD) < 0) {
  2810. throw new Error("Unknown method: " + option);
  2811. }
  2812. value = data[option].apply(data, args);
  2813. }
  2814. });
  2815. return typeof value === 'undefined' ? this : value;
  2816. };
  2817. return TreeView;
  2818. }();
  2819. /**
  2820. * jQuery API
  2821. * ====================================================
  2822. */
  2823. $.fn[NAME] = TreeView._jQueryInterface;
  2824. $.fn[NAME].Constructor = TreeView;
  2825. $.fn[NAME].noConflict = function () {
  2826. $.fn[NAME] = JQUERY_NO_CONFLICT;
  2827. return TreeView._jQueryInterface;
  2828. };
  2829. return TreeView;
  2830. }(jQuery);
  2831. let VbWangEditor = function ($) {
  2832. const NAME = 'VbWangEditor';
  2833. const DATA_KEY = 'vb.wang_editor';
  2834. const EVENT_KEY = "." + DATA_KEY;
  2835. const Selector = {
  2836. WANG_EDITOR: '[data-vb-editor="wang"]',
  2837. INPUT: '<input class="vb-wang-editor" name="{0}" type="hidden" />'
  2838. }
  2839. const Event = {
  2840. CHANGE: "change" + EVENT_KEY,
  2841. LOAD_DATA_API: "load" + EVENT_KEY
  2842. };
  2843. const JQUERY_NO_CONFLICT = $.fn[NAME];
  2844. const Default = {
  2845. name: undefined,
  2846. showFullScreen: true,
  2847. menus: undefined, excludeMenus: undefined,
  2848. colors: undefined,
  2849. /*[
  2850. '#000000',
  2851. '#eeece0',
  2852. '#1c487f',
  2853. '#4d80bf'
  2854. ],*/
  2855. fontNames: undefined,
  2856. /*[
  2857. '黑体',
  2858. '仿宋',
  2859. '楷体',
  2860. '标楷体',
  2861. '华文仿宋',
  2862. '华文楷体',
  2863. '宋体',
  2864. '微软雅黑',
  2865. 'Arial',
  2866. 'Tahoma',
  2867. 'Verdana',
  2868. 'Times New Roman',
  2869. 'Courier New',
  2870. ],*/
  2871. lineHeights: undefined,
  2872. //['1', '1.15', '1.6', '2', '2.5', '3'],
  2873. pasteFilterStyle: false, //粘贴样式的过滤
  2874. pasteIgnoreImg: true, //来忽略粘贴的图片
  2875. pasteTextHandle: undefined, // 对粘贴的文本进行处理,然后返回处理后的结果
  2876. onchange: undefined,
  2877. onblur: function () {
  2878. },
  2879. onfocus: function () {
  2880. //debug_log(ss);
  2881. },
  2882. linkImgCallback: undefined, // 插入网络图片的回调
  2883. onlineVideoCallback: undefined, // 自定义检查插入视频的回调
  2884. uploadImgServer: "", // 配置 server 接口地址
  2885. uploadImgMaxSize: 2 * 1024 * 1024, //限制大小 2M
  2886. uploadImgAccept: ['jpg', 'jpeg', 'png', 'gif', 'bmp'], //限制类型
  2887. uploadFileName: undefined, //自定义 fileName
  2888. uploadImgHeaders: undefined, //自定义 header
  2889. withCredentials: false, //跨域传递 cookie
  2890. customUploadImg: undefined, //自己实现上传图片
  2891. /*
  2892. function (resultFiles, insertImgFn) {
  2893. // resultFiles 是 input 中选中的文件列表
  2894. // insertImgFn 是获取图片 url 后,插入到编辑器的方法
  2895. // 上传图片,返回结果,将图片插入到编辑器中
  2896. insertImgFn(imgUrl)
  2897. }
  2898. */
  2899. uploadImgTimeout: 5 * 1000, //自定义 timeout 时间
  2900. uploadImgParams: undefined, //自定义上传参数
  2901. uploadImgHooks: undefined, //回调函数
  2902. /*
  2903. {
  2904. // 上传图片之前
  2905. before: function(xhr) {
  2906. console.log(xhr)
  2907. // 可阻止图片上传
  2908. return {
  2909. prevent: true,
  2910. msg: '需要提示给用户的错误信息'
  2911. }
  2912. },
  2913. // 图片上传并返回了结果,图片插入已成功
  2914. success: function(xhr) {
  2915. console.log('success', xhr)
  2916. },
  2917. // 图片上传并返回了结果,但图片插入时出错了
  2918. fail: function(xhr, editor, resData) {
  2919. console.log('fail', resData)
  2920. },
  2921. // 上传图片出错,一般为 http 请求的错误
  2922. error: function(xhr, editor, resData) {
  2923. console.log('error', xhr, resData)
  2924. },
  2925. // 上传图片超时
  2926. timeout: function(xhr) {
  2927. console.log('timeout')
  2928. },
  2929. // 图片上传并返回了结果,想要自己把图片插入到编辑器中
  2930. // 例如服务器端返回的不是 { errno: 0, data: [...] } 这种格式,可使用 customInsert
  2931. customInsert: function(insertImgFn, result) {
  2932. // result 即服务端返回的接口
  2933. console.log('customInsert', result)
  2934. // insertImgFn 可把图片插入到编辑器,传入图片 src ,执行函数即可
  2935. insertImgFn(result.data[0])
  2936. }
  2937. }
  2938. */
  2939. uploadImgMaxLength: 5, // 一次最多上传 5 个图片,
  2940. uploadImgShowBase64: true, // 可使用 base64 格式保存图片
  2941. showLinkImg: false
  2942. }
  2943. window.editor_W = {};
  2944. let E, editor = undefined;
  2945. let WangEditor = function () {
  2946. function WangEditor(element, config) {
  2947. this._element = element;
  2948. this._config = config;
  2949. $.metPageJs('/libs/wangEditor/dist/wangEditor.min.js', "dy-js-wangEditor");
  2950. E = window.wangEditor;
  2951. //this._init();
  2952. }
  2953. // Public
  2954. let _proto = WangEditor.prototype;
  2955. _proto._init = function (options) {
  2956. let _this = this, $this = $(_this._element);
  2957. options = options || {};
  2958. editor = new E(_this._element);
  2959. $this.form = $this.closest('form');
  2960. _this.createEditor(options);
  2961. }
  2962. _proto.createEditor = function (options) {
  2963. let _this = this;
  2964. let $this = $(_this._element);
  2965. options = options || {};
  2966. let _config = $.extend(true, {}, _this._config, options);
  2967. let name = _config.name || $this.data('editorName');
  2968. if (!name) {
  2969. throw new Error("请配置【name】");
  2970. }
  2971. let $Input = $this.parent().find($('#' + name));
  2972. $Input = $Input.length > 0 ? $Input : $(Selector.INPUT.format(name));
  2973. $Input.off(Event.CHANGE).on(Event.CHANGE, function () {
  2974. $this.setContent($Input.val());
  2975. });
  2976. $this.before($Input.val(""));
  2977. _config.onchange = function (html) {
  2978. // 监控变化,同步更新到 input
  2979. $Input.val(html);
  2980. }
  2981. if (!_config.excludeMenus) {
  2982. let menuStr = $this.data('editorMenu');
  2983. let menu = menuStr ? menuStr.split(',') : undefined;
  2984. if (menu) {
  2985. editor.config.menus = menu;
  2986. }
  2987. }
  2988. let opt = $this.data('editorOption');
  2989. if (!(typeof (opt) === "object" && Object.prototype.toString.call(opt).toLowerCase() === "[object object]")) {
  2990. try {
  2991. opt = opt ? JSON.parse(opt) : {};
  2992. } catch (e) {
  2993. console.log(e);
  2994. opt = {};
  2995. }
  2996. }
  2997. editor.config = $.extend({}, editor.config, _config, opt || {});
  2998. if (editor.config.excludeMenus) {
  2999. editor.config.excludeMenus = _config.excludeMenus;
  3000. }
  3001. if (!editor.config.excludeMenus && _config.menus && $.isArray(_config.menus)) {
  3002. editor.config.menus = _config.menus;
  3003. }
  3004. if (_config.colors && $.isArray(_config.colors)) {
  3005. editor.config.colors = _config.colors;
  3006. }
  3007. if (_config.fontNames && $.isArray(_config.fontNames)) {
  3008. editor.config.fontNames = _config.fontNames;
  3009. }
  3010. if (_config.lineHeights && $.isArray(_config.lineHeights)) {
  3011. editor.config.lineHeights = _config.lineHeights;
  3012. }
  3013. debug_log("WangEditor_option:", editor.config);
  3014. editor.create();
  3015. }
  3016. _proto.setContent = function (txt) {
  3017. editor.txt.html(txt);
  3018. }
  3019. WangEditor._jQueryInterface = function _jQueryInterface(option) {
  3020. let value, args = Array.prototype.slice.call(arguments, 1);
  3021. this.each(function () {
  3022. let data = $(this).data(DATA_KEY);
  3023. let _options = $.extend({}, Default, $(this).data(), typeof option === 'object' && option);
  3024. if (!data) {
  3025. data = new WangEditor(this, _options);
  3026. $(this).data(DATA_KEY, data);
  3027. }
  3028. if (typeof option === 'string') {
  3029. if (data[option] === 'undefined') {
  3030. throw new Error("Unknown method: " + option);
  3031. }
  3032. value = data[option].apply(data, args);
  3033. } else {
  3034. data['_init'].apply(data, args);
  3035. }
  3036. });
  3037. return typeof value === 'undefined' ? this : value;
  3038. };
  3039. return WangEditor;
  3040. }();
  3041. $(window).on("load" + EVENT_KEY, function () {
  3042. $("div" + Selector.WANG_EDITOR).each(function () {
  3043. WangEditor._jQueryInterface.call($(this));
  3044. });
  3045. });
  3046. /**
  3047. * jQuery API
  3048. * ====================================================
  3049. */
  3050. $.fn[NAME] = WangEditor._jQueryInterface;
  3051. $.fn[NAME].Constructor = WangEditor;
  3052. $.fn[NAME].noConflict = function () {
  3053. $.fn[NAME] = JQUERY_NO_CONFLICT;
  3054. return WangEditor._jQueryInterface;
  3055. };
  3056. return WangEditor;
  3057. }(jQuery);
  3058. exports.vbTable = VbTable;
  3059. exports.vbModal = VbModal;
  3060. exports.vbFile = VbFile;
  3061. exports.vbDate = VbDate;
  3062. exports.vbTreeView = VbTreeView;
  3063. exports.vbWangEditor = VbWangEditor;
  3064. Object.defineProperty(exports, '__esModule', { value: true });
  3065. })));
  3066. String.prototype.format = function (args) {
  3067. let result = this;
  3068. if (arguments.length > 0) {
  3069. let reg;
  3070. if (arguments.length === 1 && typeof args === "object") {
  3071. for (let key in args) {
  3072. if (args.hasOwnProperty(key)) {
  3073. if (args[key] !== undefined) {
  3074. reg = new RegExp("({" + key + "})", "g");
  3075. result = result.replace(reg, args[key]);
  3076. }
  3077. }
  3078. }
  3079. } else {
  3080. for (let i = 0; i < arguments.length; i++) {
  3081. if (arguments[i] !== undefined) {
  3082. reg = new RegExp("({[" + i + "]})", "g");
  3083. result = result.replace(reg, arguments[i]);
  3084. }
  3085. }
  3086. }
  3087. }
  3088. return result;
  3089. };
  3090. Date.prototype.format = function (fmt) {
  3091. let o = {
  3092. "M+": this.getMonth() + 1, //月份
  3093. "d+": this.getDate(), //日
  3094. "h+": this.getHours(), //小时
  3095. "m+": this.getMinutes(), //分
  3096. "s+": this.getSeconds(), //秒
  3097. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  3098. "S": this.getMilliseconds() //毫秒
  3099. };
  3100. if (/(y+)/.test(fmt))
  3101. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  3102. for (let k in o) {
  3103. if (o.hasOwnProperty(k))
  3104. if (new RegExp("(" + k + ")").test(fmt))
  3105. fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
  3106. }
  3107. return fmt;
  3108. };
  3109. Date.prototype.diff = function (diffType, endTime, startTime) {
  3110. diffType = diffType.toLowerCase();
  3111. let sTime = startTime ? (typeof startTime === 'string' ? new Date(startTime) : startTime) : this; //开始时间
  3112. let eTime = typeof endTime === 'string' ? new Date(endTime) : endTime; //结束时间
  3113. //作为除数的数字
  3114. let divNum = 1;
  3115. switch (diffType) {
  3116. case "second":
  3117. case "s":
  3118. divNum = 1000;
  3119. break;
  3120. case "minute":
  3121. case "m":
  3122. divNum = 1000 * 60;
  3123. break;
  3124. case "hour":
  3125. case "h":
  3126. divNum = 1000 * 3600;
  3127. break;
  3128. case "day":
  3129. case "d":
  3130. divNum = 1000 * 3600 * 24;
  3131. break;
  3132. default:
  3133. break;
  3134. }
  3135. return parseInt((eTime.getTime() - sTime.getTime()) / parseInt(divNum));
  3136. };
  3137. var funs;
  3138. function LoadTable(option, backFuns) {
  3139. if (!option) {
  3140. option = { table: "table" };
  3141. }
  3142. option.table = option.table ? option.table : "table";
  3143. let $table = typeof option.table === 'string' ? $('#' + option.table) : $(option.table);
  3144. if ($table.length < 1) {
  3145. throw new Error("没有发现表格" + option.table);
  3146. }
  3147. $table.VbTable(option);
  3148. backFuns = backFuns == undefined ? true : backFuns;
  3149. if (backFuns) {
  3150. return GetTableFuns($table);
  3151. }
  3152. window.funs = GetTableFuns($table);
  3153. return $table;
  3154. }
  3155. function GetTableFuns(table) {
  3156. let $table = typeof table === 'string' ? $('#' + table) : $(table);
  3157. return $table.VbTable('getToolFunctions');
  3158. }
  3159. function GetSelections(table) {
  3160. let $table = typeof table === 'string' ? $('#' + table) : $(table);
  3161. return $table.VbTable("getSelections");
  3162. }
  3163. function RefreshTable(table, isForce) {
  3164. table = table || "table";
  3165. isForce = isForce === undefined;
  3166. let $table = typeof table === 'string' ? $('#' + table) : $(table);
  3167. if ($table.length < 1) {
  3168. console.log('没有发现表格:', table);
  3169. }
  3170. try {
  3171. $table.VbTable('refresh', isForce);
  3172. } catch (e) {
  3173. debug_log("RefreshTable", e);
  3174. }
  3175. }
  3176. function BtnCreate(option) {
  3177. option = option || {};
  3178. option.table = option.table ? option.table : "table";
  3179. let $table = typeof option.table === 'string' ? $('#' + option.table) : $(option.table);
  3180. let url = option.url || $table.closest('.table-box').find('[data-vb-tool-menu-type="_btnCreate"]').data('vb-tool-menu-url') || $table.closest('.table-box').find('[data-vb-tool-menu-type="_btnCreate"]').data('vb-tool-menu-url');
  3181. option.type = 'post';
  3182. $table.VbTable('create', url, option);
  3183. }
  3184. function BtnUpdate(option, row) {
  3185. option = option || {};
  3186. option.table = option.table ? option.table : "table";
  3187. let $table = typeof option.table === 'string' ? $('#' + option.table) : $(option.table);
  3188. let url = option.url || $table.closest('.table-box').find('[data-vb-tool-menu-type="btnUpdate"]').data('vb-tool-menu-url');
  3189. row = row || option.row || $table.VbTable("getSelection");
  3190. option.data = option.data || row;
  3191. option.type = 'post';
  3192. $table.VbTable('update', url, option, row);
  3193. }
  3194. function BtnDelete(option, row) {
  3195. option = option || {};
  3196. option.table = option.table ? option.table : "table";
  3197. let $table = typeof option.table === 'string' ? $('#' + option.table) : $(option.table);
  3198. let url = option.url || $table.closest('.table-box').find('[data-vb-tool-menu-type="btnDelete"]').data('vb-tool-menu-url');
  3199. row = row || option.row || $table.VbTable("getSelection");
  3200. option.type = 'post';
  3201. $table.VbTable('delete', url, option, row);
  3202. }
  3203. function BtnConfirm(message, title, url, rowOrTableId, data) {
  3204. let row, $table;
  3205. if (!data) {
  3206. if (rowOrTableId) {
  3207. if (typeof rowOrTableId === 'object' && !(rowOrTableId instanceof jQuery)) {
  3208. row = rowOrTableId;
  3209. } else {
  3210. $table = typeof rowOrTableId === 'string' ? $('#' + rowOrTableId) : $(rowOrTableId);
  3211. row = $table.bootstrapTable("getSelections")[0];
  3212. }
  3213. } else {
  3214. row = $("#table").bootstrapTable("getSelections")[0];
  3215. }
  3216. if (row) {
  3217. data = { Id: row.id };
  3218. }
  3219. } else {
  3220. $table = typeof rowOrTableId === 'string' ? $('#' + rowOrTableId) : $(rowOrTableId);
  3221. }
  3222. if (data) {
  3223. MsgConfirm(message, title, function () {
  3224. $.vbAjax1({ url: url, data: data, table: $table });
  3225. });
  3226. } else
  3227. abp.message.warn(abp.localization.iwbZero('SelectRecordOperation'));
  3228. }
  3229. function MsgConfirm(message, title, callback, opt) {
  3230. abp.message.confirm(message, title, function (isConfirmed) {
  3231. if (isConfirmed && callback) {
  3232. callback(opt);
  3233. }
  3234. });
  3235. }
  3236. function OpenModal(opt) {
  3237. opt = opt || {};
  3238. let ele = opt.modal ? opt.modal : "modal";
  3239. let $modal = typeof ele === 'string' ? $('#' + ele) : $(ele);
  3240. if ($modal.length < 1) {
  3241. console.log('没有发现模态框:', ele);
  3242. }
  3243. try {
  3244. $modal.VbModal(opt);
  3245. } catch (e) {
  3246. debug_log("OpenModal", e);
  3247. }
  3248. }
  3249. function ShowModal(ele) {
  3250. ele = ele || "modal";
  3251. let $modal = typeof ele === 'string' ? $('#' + ele) : $(ele);
  3252. if ($modal.length < 1) {
  3253. console.log('没有发现模态框:', ele);
  3254. }
  3255. try {
  3256. $modal.VbModal('show');
  3257. } catch (e) {
  3258. debug_log("ShowModal", e);
  3259. }
  3260. }
  3261. let queryModalTarget = '';
  3262. function ShowQueryModal(ele, target) {
  3263. ele = ele || "modal";
  3264. queryModalTarget = !target ? '' : target.indexOf('.') === 0 ? target : target.indexOf('#') === 0 ? target : '#' + target;
  3265. let $modal = typeof ele === 'string' ? $('#' + ele) : $(ele);
  3266. if ($modal.length < 1) {
  3267. console.log('没有发现模态框:', ele);
  3268. }
  3269. try {
  3270. let modalId = $modal.attr("id");//, treeField = $modal.data('search-tree-field'), searchBindFunc = `SearchList_${modalId}` //$modal.data('search-bind-func');
  3271. let _shown = function () {
  3272. let show = `${modalId}Search`;
  3273. if (show && window[show] && typeof window[show] == "function") {
  3274. window[show].call();
  3275. }
  3276. }
  3277. $modal.VbModal('show', {
  3278. shown: _shown,
  3279. needForm: false
  3280. });
  3281. } catch (e) {
  3282. debug_log("ShowModal", e);
  3283. }
  3284. }
  3285. function ClearSearchValue(target, clear, that) {
  3286. let $target = $(!target ? $(that) : target.indexOf('.') === 0 ? target : target.indexOf('#') === 0 ? target : '#' + target);
  3287. let arr = clear.split(",");
  3288. arr.forEach(function (v) {
  3289. if (v) {
  3290. let vStr = v.indexOf('.') === 0 ? v : v.indexOf('#') === 0 ? v : '#' + v;
  3291. let $t = $target.find(vStr);
  3292. $t.val('');
  3293. if ($t.is("select")) {
  3294. $t.trigger('change');
  3295. }
  3296. }
  3297. });
  3298. }
  3299. function ChangAjaxSelectValue($this, val, name) {
  3300. if (name && val) {
  3301. let option = new Option(name, val);
  3302. $this.html(option).trigger('change');
  3303. } else if (val) {
  3304. let key = $this.data('param-key');
  3305. $.vbAjax41({
  3306. url: abp.appUrl + "Query/AcInfo",
  3307. data: {
  3308. CodeKey: key,
  3309. ValueKey: val
  3310. },
  3311. success: function (res) {
  3312. if (res) {
  3313. let option = new Option(res.nameKey, res.valueKey);
  3314. $this.html(option).trigger('change');
  3315. }
  3316. }
  3317. });
  3318. }
  3319. }
  3320. function AddDynamicBox(that) {
  3321. let $that = $(that).closest('.vb-dynamic-box'), html = $that.clone().prop("outerHTML");
  3322. html = html.replace('btn-add', 'btn-delete');
  3323. html = html.replace('AddDynamicBox()', `$(this).closest('.vb-dynamic-box').remove();`);
  3324. html = html.replace('>增加</button', '>删除</button');
  3325. html = html.replace(new RegExp('data-select2-id="*"', "g"), '');
  3326. let $html = $(html).addClass('vb-dynamic-box-delete').removeAttr('data-select2-id');
  3327. $html.find('.select2').remove();
  3328. $html.find('select').removeAttr("id").val('');
  3329. $html.find('select:not(.tree)').select2();
  3330. $html.find('select.tree').select2tree();
  3331. $html.find('input').val('');
  3332. $that.parent().append($html);
  3333. return $html;
  3334. }
  3335. function DateFormatter(v) {
  3336. if (!v) {
  3337. return "";
  3338. }
  3339. let date = new Date(v);
  3340. let str = date.format('yyyy-MM-dd');
  3341. return str;
  3342. }
  3343. function DateTimeFormatter(v) {
  3344. if (!v) {
  3345. return "";
  3346. }
  3347. let date = new Date(v);
  3348. let str = date.format('yyyy-MM-dd hh:mm:ss');
  3349. return str;
  3350. }
  3351. //Hex-- > RGB
  3352. function HexToRgb(str) {
  3353. //replace替换查找的到的字符串
  3354. str = str.replace("#", "");
  3355. if (str.length === 3) {
  3356. str = str + str;
  3357. }
  3358. //match得到查询数组
  3359. let hxs = str.match(/../g);
  3360. for (let i = 0; i < 3; i++) hxs[i] = parseInt(hxs[i], 16);
  3361. return hxs;
  3362. }
  3363. //Hex-- > RGB
  3364. function HexToRgbStr(str) {
  3365. let hxs = HexToRgb(str);
  3366. return 'rgb(' + hxs[0] + ', ' + hxs[1] + ', ' + hxs[2] + ')';
  3367. }
  3368. //RGB-- > Hex
  3369. function RgbToHex(a, b, c) {
  3370. let hexs = [a.toString(16), b.toString(16), c.toString(16)];
  3371. for (let i = 0; i < 3; i++)
  3372. if (hexs[i].length == 1)
  3373. hexs[i] = "0" + hexs[i];
  3374. return "#" + hexs.join("");
  3375. }
  3376. $(function () {
  3377. $('select[data-select-tree="true"]').select2tree();
  3378. $('select[data-select-ajax="true"]').each(function () {
  3379. let $this = $(this);
  3380. let cKey = function () { return $this.data('param-key') },
  3381. take = function () { return $this.data('param-count') },
  3382. funResultTemplate = function () { return $this.data('result-template-function') };
  3383. debug_log("ajax-select", cKey(), take(), funResultTemplate());
  3384. $this.select2({
  3385. language: window.lang,
  3386. ajax: {
  3387. url: abp.appUrl + "Query/AcInfos",
  3388. type: "post",
  3389. dataType: 'json',
  3390. delay: 250,
  3391. data: function (params) {
  3392. let page = params.page || 1;
  3393. let queryParam = {
  3394. CodeKey: cKey(),
  3395. NameKey: params.term, // search term
  3396. Skip: (page - 1) * take(),
  3397. Take: take()
  3398. };
  3399. return queryParam;
  3400. },
  3401. processResults: function (data, params) {
  3402. debug_log("ajax-select_processResults", data, params);
  3403. params.page = params.page || 1;
  3404. let result = {
  3405. results: data.items.map(function (v) {
  3406. v.id = v.valueKey;
  3407. v.text = v.nameKey;
  3408. return v;
  3409. }),
  3410. pagination: {
  3411. more: (params.page * take()) < data.totalCount
  3412. }
  3413. };
  3414. return result;
  3415. },
  3416. transport: function (params, success, failure) {
  3417. params = params || {};
  3418. params.success = success;
  3419. params.error = failure;
  3420. let $request = $.vbAjax41(params);
  3421. return $request;
  3422. },
  3423. cache: true
  3424. },
  3425. cache: true,
  3426. minimumInputLength: 0,
  3427. templateResult: function (res) {
  3428. if (res.loading) {
  3429. return res.text;
  3430. }
  3431. let funTemplate = window[funResultTemplate()];
  3432. if (funTemplate && $.isFunction(funTemplate)) {
  3433. return funTemplate(res);
  3434. } else {
  3435. return '{0}'.format(res.text);
  3436. }
  3437. },
  3438. templateSelection: function (res) {
  3439. return res.text;
  3440. }
  3441. });
  3442. });
  3443. //Configure blockUI
  3444. if ($.blockUI) {
  3445. $.blockUI.defaults.baseZ = 2000;
  3446. }
  3447. //Configure validator
  3448. $.validator.setDefaults({
  3449. highlight: (el) => {
  3450. $(el).addClass('invalid');
  3451. $(el).removeClass('valid');
  3452. },
  3453. unhighlight: (el) => {
  3454. $(el).removeClass('invalid');
  3455. $(el).addClass('valid');
  3456. },
  3457. errorPlacement: (error, element) => {
  3458. let $el = element.closest('.d-flex').find('.invalid-feedback')
  3459. if ($el.length) {
  3460. $el.html(error).addClass('invalid-feedback-show');
  3461. }
  3462. let $tab = element.closest('.form-auto-tab');
  3463. if ($tab && $tab.length) {
  3464. $("#" + $tab.data("tab-name")).tab("show");
  3465. }
  3466. element.focus();
  3467. }
  3468. });
  3469. //serializeFormToObject plugin for jQuery
  3470. $.fn.serializeFormToObject = function (camelCased = false) {
  3471. //serialize to array
  3472. let data = $(this).serializeArray();
  3473. //add also disabled items
  3474. $(':disabled[name]', this).each(function () {
  3475. data.push({ name: this.name, value: $(this).val() });
  3476. });
  3477. //map to object
  3478. let obj = {};
  3479. data.map(function (x) { obj[x.name] = x.value; });
  3480. if (camelCased && camelCased === true) {
  3481. return convertToCamelCasedObject(obj);
  3482. }
  3483. function convertToCamelCasedObject(obj) {
  3484. let newObj, origKey, newKey, value;
  3485. if (obj instanceof Array) {
  3486. return obj.map(value => {
  3487. if (typeof value === 'object') {
  3488. value = convertToCamelCasedObject(value);
  3489. }
  3490. return value;
  3491. });
  3492. } else {
  3493. newObj = {};
  3494. for (origKey in obj) {
  3495. if (obj.hasOwnProperty(origKey)) {
  3496. newKey = (
  3497. origKey.charAt(0).toLowerCase() + origKey.slice(1) || origKey
  3498. ).toString();
  3499. value = obj[origKey];
  3500. if (
  3501. value instanceof Array || (value && value.constructor === Object)
  3502. ) {
  3503. value = convertToCamelCasedObject(value);
  3504. }
  3505. newObj[newKey] = value;
  3506. }
  3507. }
  3508. }
  3509. return newObj;
  3510. }
  3511. return obj;
  3512. };
  3513. })