api.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  1. /*
  2. * APICloud JavaScript Library
  3. * Copyright (c) 2014 apicloud.com
  4. */
  5. (function(window) {
  6. var u = {};
  7. var isAndroid = (/android/gi).test(navigator.appVersion);
  8. var uzStorage = function() {
  9. var ls = window.localStorage;
  10. if (isAndroid) {
  11. ls = os.localStorage();
  12. }
  13. return ls;
  14. };
  15. function parseArguments(url, data, fnSuc, dataType) {
  16. if (typeof(data) == 'function') {
  17. dataType = fnSuc;
  18. fnSuc = data;
  19. data = undefined;
  20. }
  21. if (typeof(fnSuc) != 'function') {
  22. dataType = fnSuc;
  23. fnSuc = undefined;
  24. }
  25. return {
  26. url: url,
  27. data: data,
  28. fnSuc: fnSuc,
  29. dataType: dataType
  30. };
  31. }
  32. u.trim = function(str) {
  33. if (String.prototype.trim) {
  34. return str == null ? "" : String.prototype.trim.call(str);
  35. } else {
  36. return str.replace(/(^\s*)|(\s*$)/g, "");
  37. }
  38. };
  39. u.trimAll = function(str) {
  40. return str.replace(/\s*/g, '');
  41. };
  42. u.isElement = function(obj) {
  43. return !!(obj && obj.nodeType == 1);
  44. };
  45. u.isArray = function(obj) {
  46. if (Array.isArray) {
  47. return Array.isArray(obj);
  48. } else {
  49. return obj instanceof Array;
  50. }
  51. };
  52. u.isEmptyObject = function(obj) {
  53. if (JSON.stringify(obj) === '{}') {
  54. return true;
  55. }
  56. return false;
  57. };
  58. u.addEvt = function(el, name, fn, useCapture) {
  59. if (!u.isElement(el)) {
  60. console.warn('$api.addEvt Function need el param, el param must be DOM Element');
  61. return;
  62. }
  63. useCapture = useCapture || false;
  64. if (el.addEventListener) {
  65. el.addEventListener(name, fn, useCapture);
  66. }
  67. };
  68. u.rmEvt = function(el, name, fn, useCapture) {
  69. if (!u.isElement(el)) {
  70. console.warn('$api.rmEvt Function need el param, el param must be DOM Element');
  71. return;
  72. }
  73. useCapture = useCapture || false;
  74. if (el.removeEventListener) {
  75. el.removeEventListener(name, fn, useCapture);
  76. }
  77. };
  78. u.one = function(el, name, fn, useCapture) {
  79. if (!u.isElement(el)) {
  80. console.warn('$api.one Function need el param, el param must be DOM Element');
  81. return;
  82. }
  83. useCapture = useCapture || false;
  84. var that = this;
  85. var cb = function() {
  86. fn && fn();
  87. that.rmEvt(el, name, cb, useCapture);
  88. };
  89. that.addEvt(el, name, cb, useCapture);
  90. };
  91. u.dom = function(el, selector) {
  92. if (arguments.length === 1 && typeof arguments[0] == 'string') {
  93. if (document.querySelector) {
  94. return document.querySelector(arguments[0]);
  95. }
  96. } else if (arguments.length === 2) {
  97. if (el.querySelector) {
  98. return el.querySelector(selector);
  99. }
  100. }
  101. };
  102. u.domAll = function(el, selector) {
  103. if (arguments.length === 1 && typeof arguments[0] == 'string') {
  104. if (document.querySelectorAll) {
  105. return document.querySelectorAll(arguments[0]);
  106. }
  107. } else if (arguments.length === 2) {
  108. if (el.querySelectorAll) {
  109. return el.querySelectorAll(selector);
  110. }
  111. }
  112. };
  113. u.byId = function(id) {
  114. return document.getElementById(id);
  115. };
  116. u.first = function(el, selector) {
  117. if (arguments.length === 1) {
  118. if (!u.isElement(el)) {
  119. console.warn('$api.first Function need el param, el param must be DOM Element');
  120. return;
  121. }
  122. return el.children[0];
  123. }
  124. if (arguments.length === 2) {
  125. return this.dom(el, selector + ':first-child');
  126. }
  127. };
  128. u.last = function(el, selector) {
  129. if (arguments.length === 1) {
  130. if (!u.isElement(el)) {
  131. console.warn('$api.last Function need el param, el param must be DOM Element');
  132. return;
  133. }
  134. var children = el.children;
  135. return children[children.length - 1];
  136. }
  137. if (arguments.length === 2) {
  138. return this.dom(el, selector + ':last-child');
  139. }
  140. };
  141. u.eq = function(el, index) {
  142. return this.dom(el, ':nth-child(' + index + ')');
  143. };
  144. u.not = function(el, selector) {
  145. return this.domAll(el, ':not(' + selector + ')');
  146. };
  147. u.prev = function(el) {
  148. if (!u.isElement(el)) {
  149. console.warn('$api.prev Function need el param, el param must be DOM Element');
  150. return;
  151. }
  152. var node = el.previousSibling;
  153. if (node.nodeType && node.nodeType === 3) {
  154. node = node.previousSibling;
  155. return node;
  156. }
  157. };
  158. u.next = function(el) {
  159. if (!u.isElement(el)) {
  160. console.warn('$api.next Function need el param, el param must be DOM Element');
  161. return;
  162. }
  163. var node = el.nextSibling;
  164. if (node.nodeType && node.nodeType === 3) {
  165. node = node.nextSibling;
  166. return node;
  167. }
  168. };
  169. u.closest = function(el, selector) {
  170. if (!u.isElement(el)) {
  171. console.warn('$api.closest Function need el param, el param must be DOM Element');
  172. return;
  173. }
  174. var doms, targetDom;
  175. var isSame = function(doms, el) {
  176. var i = 0,
  177. len = doms.length;
  178. for (i; i < len; i++) {
  179. if (doms[i].isEqualNode(el)) {
  180. return doms[i];
  181. }
  182. }
  183. return false;
  184. };
  185. var traversal = function(el, selector) {
  186. doms = u.domAll(el.parentNode, selector);
  187. targetDom = isSame(doms, el);
  188. while (!targetDom) {
  189. el = el.parentNode;
  190. if (el != null && el.nodeType == el.DOCUMENT_NODE) {
  191. return false;
  192. }
  193. traversal(el, selector);
  194. }
  195. return targetDom;
  196. };
  197. return traversal(el, selector);
  198. };
  199. u.contains = function(parent, el) {
  200. var mark = false;
  201. if (el === parent) {
  202. mark = true;
  203. return mark;
  204. } else {
  205. do {
  206. el = el.parentNode;
  207. if (el === parent) {
  208. mark = true;
  209. return mark;
  210. }
  211. } while (el === document.body || el === document.documentElement);
  212. return mark;
  213. }
  214. };
  215. u.remove = function(el) {
  216. if (el && el.parentNode) {
  217. el.parentNode.removeChild(el);
  218. }
  219. };
  220. u.attr = function(el, name, value) {
  221. if (!u.isElement(el)) {
  222. console.warn('$api.attr Function need el param, el param must be DOM Element');
  223. return;
  224. }
  225. if (arguments.length == 2) {
  226. return el.getAttribute(name);
  227. } else if (arguments.length == 3) {
  228. el.setAttribute(name, value);
  229. return el;
  230. }
  231. };
  232. u.removeAttr = function(el, name) {
  233. if (!u.isElement(el)) {
  234. console.warn('$api.removeAttr Function need el param, el param must be DOM Element');
  235. return;
  236. }
  237. if (arguments.length === 2) {
  238. el.removeAttribute(name);
  239. }
  240. };
  241. u.hasCls = function(el, cls) {
  242. if (!u.isElement(el)) {
  243. console.warn('$api.hasCls Function need el param, el param must be DOM Element');
  244. return;
  245. }
  246. if (el.className.indexOf(cls) > -1) {
  247. return true;
  248. } else {
  249. return false;
  250. }
  251. };
  252. u.addCls = function(el, cls) {
  253. if (!u.isElement(el)) {
  254. console.warn('$api.addCls Function need el param, el param must be DOM Element');
  255. return;
  256. }
  257. if ('classList' in el) {
  258. el.classList.add(cls);
  259. } else {
  260. var preCls = el.className;
  261. var newCls = preCls + ' ' + cls;
  262. el.className = newCls;
  263. }
  264. return el;
  265. };
  266. u.removeCls = function(el, cls) {
  267. if (!u.isElement(el)) {
  268. console.warn('$api.removeCls Function need el param, el param must be DOM Element');
  269. return;
  270. }
  271. if ('classList' in el) {
  272. el.classList.remove(cls);
  273. } else {
  274. var preCls = el.className;
  275. var newCls = preCls.replace(cls, '');
  276. el.className = newCls;
  277. }
  278. return el;
  279. };
  280. u.toggleCls = function(el, cls) {
  281. if (!u.isElement(el)) {
  282. console.warn('$api.toggleCls Function need el param, el param must be DOM Element');
  283. return;
  284. }
  285. if ('classList' in el) {
  286. el.classList.toggle(cls);
  287. } else {
  288. if (u.hasCls(el, cls)) {
  289. u.removeCls(el, cls);
  290. } else {
  291. u.addCls(el, cls);
  292. }
  293. }
  294. return el;
  295. };
  296. u.val = function(el, val) {
  297. if (!u.isElement(el)) {
  298. console.warn('$api.val Function need el param, el param must be DOM Element');
  299. return;
  300. }
  301. if (arguments.length === 1) {
  302. switch (el.tagName) {
  303. case 'SELECT':
  304. var value = el.options[el.selectedIndex].value;
  305. return value;
  306. break;
  307. case 'INPUT':
  308. return el.value;
  309. break;
  310. case 'TEXTAREA':
  311. return el.value;
  312. break;
  313. }
  314. }
  315. if (arguments.length === 2) {
  316. switch (el.tagName) {
  317. case 'SELECT':
  318. el.options[el.selectedIndex].value = val;
  319. return el;
  320. break;
  321. case 'INPUT':
  322. el.value = val;
  323. return el;
  324. break;
  325. case 'TEXTAREA':
  326. el.value = val;
  327. return el;
  328. break;
  329. }
  330. }
  331. };
  332. u.prepend = function(el, html) {
  333. if (!u.isElement(el)) {
  334. console.warn('$api.prepend Function need el param, el param must be DOM Element');
  335. return;
  336. }
  337. el.insertAdjacentHTML('afterbegin', html);
  338. return el;
  339. };
  340. u.append = function(el, html) {
  341. if (!u.isElement(el)) {
  342. console.warn('$api.append Function need el param, el param must be DOM Element');
  343. return;
  344. }
  345. el.insertAdjacentHTML('beforeend', html);
  346. return el;
  347. };
  348. u.before = function(el, html) {
  349. if (!u.isElement(el)) {
  350. console.warn('$api.before Function need el param, el param must be DOM Element');
  351. return;
  352. }
  353. el.insertAdjacentHTML('beforebegin', html);
  354. return el;
  355. };
  356. u.after = function(el, html) {
  357. if (!u.isElement(el)) {
  358. console.warn('$api.after Function need el param, el param must be DOM Element');
  359. return;
  360. }
  361. el.insertAdjacentHTML('afterend', html);
  362. return el;
  363. };
  364. u.html = function(el, html) {
  365. if (!u.isElement(el)) {
  366. console.warn('$api.html Function need el param, el param must be DOM Element');
  367. return;
  368. }
  369. if (arguments.length === 1) {
  370. return el.innerHTML;
  371. } else if (arguments.length === 2) {
  372. el.innerHTML = html;
  373. return el;
  374. }
  375. };
  376. u.text = function(el, txt) {
  377. if (!u.isElement(el)) {
  378. console.warn('$api.text Function need el param, el param must be DOM Element');
  379. return;
  380. }
  381. if (arguments.length === 1) {
  382. return el.textContent;
  383. } else if (arguments.length === 2) {
  384. el.textContent = txt;
  385. return el;
  386. }
  387. };
  388. u.offset = function(el) {
  389. if (!u.isElement(el)) {
  390. console.warn('$api.offset Function need el param, el param must be DOM Element');
  391. return;
  392. }
  393. var sl = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
  394. var st = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
  395. var rect = el.getBoundingClientRect();
  396. return {
  397. l: rect.left + sl,
  398. t: rect.top + st,
  399. w: el.offsetWidth,
  400. h: el.offsetHeight
  401. };
  402. };
  403. u.css = function(el, css) {
  404. if (!u.isElement(el)) {
  405. console.warn('$api.css Function need el param, el param must be DOM Element');
  406. return;
  407. }
  408. if (typeof css == 'string' && css.indexOf(':') > 0) {
  409. el.style && (el.style.cssText += ';' + css);
  410. }
  411. };
  412. u.cssVal = function(el, prop) {
  413. if (!u.isElement(el)) {
  414. console.warn('$api.cssVal Function need el param, el param must be DOM Element');
  415. return;
  416. }
  417. if (arguments.length === 2) {
  418. var computedStyle = window.getComputedStyle(el, null);
  419. return computedStyle.getPropertyValue(prop);
  420. }
  421. };
  422. u.jsonToStr = function(json) {
  423. if (typeof json === 'object') {
  424. return JSON && JSON.stringify(json);
  425. }
  426. };
  427. u.strToJson = function(str) {
  428. if (typeof str === 'string') {
  429. return JSON && JSON.parse(str);
  430. }
  431. };
  432. u.setStorage = function(key, value) {
  433. if (arguments.length === 2) {
  434. var v = value;
  435. if (typeof v == 'object') {
  436. v = JSON.stringify(v);
  437. v = 'obj-' + v;
  438. } else {
  439. v = 'str-' + v;
  440. }
  441. var ls = uzStorage();
  442. if (ls) {
  443. ls.setItem(key, v);
  444. }
  445. }
  446. };
  447. u.getStorage = function(key) {
  448. var ls = uzStorage();
  449. if (ls) {
  450. var v = ls.getItem(key);
  451. if (!v) { return; }
  452. if (v.indexOf('obj-') === 0) {
  453. v = v.slice(4);
  454. return JSON.parse(v);
  455. } else if (v.indexOf('str-') === 0) {
  456. return v.slice(4);
  457. }
  458. }
  459. };
  460. u.rmStorage = function(key) {
  461. var ls = uzStorage();
  462. if (ls && key) {
  463. ls.removeItem(key);
  464. }
  465. };
  466. u.clearStorage = function() {
  467. var ls = uzStorage();
  468. if (ls) {
  469. ls.clear();
  470. }
  471. };
  472. /*by king*/
  473. u.fixIos7Bar = function(el) {
  474. return u.fixStatusBar(el);
  475. };
  476. u.fixStatusBar = function(el) {
  477. if (!u.isElement(el)) {
  478. console.warn('$api.fixStatusBar Function need el param, el param must be DOM Element');
  479. return 0;
  480. }
  481. el.style.paddingTop = api.safeArea.top + 'px';
  482. return el.offsetHeight;
  483. };
  484. u.toast = function(title, text, time) {
  485. var opts = {};
  486. var show = function(opts, time) {
  487. api.showProgress(opts);
  488. setTimeout(function() {
  489. api.hideProgress();
  490. }, time);
  491. };
  492. if (arguments.length === 1) {
  493. var time = time || 500;
  494. if (typeof title === 'number') {
  495. time = title;
  496. } else {
  497. opts.title = title + '';
  498. }
  499. show(opts, time);
  500. } else if (arguments.length === 2) {
  501. var time = time || 500;
  502. var text = text;
  503. if (typeof text === "number") {
  504. var tmp = text;
  505. time = tmp;
  506. text = null;
  507. }
  508. if (title) {
  509. opts.title = title;
  510. }
  511. if (text) {
  512. opts.text = text;
  513. }
  514. show(opts, time);
  515. }
  516. if (title) {
  517. opts.title = title;
  518. }
  519. if (text) {
  520. opts.text = text;
  521. }
  522. time = time || 500;
  523. show(opts, time);
  524. };
  525. u.post = function( /*url,data,fnSuc,dataType*/ ) {
  526. var argsToJson = parseArguments.apply(null, arguments);
  527. var json = {};
  528. var fnSuc = argsToJson.fnSuc;
  529. argsToJson.url && (json.url = argsToJson.url);
  530. argsToJson.data && (json.data = argsToJson.data);
  531. if (argsToJson.dataType) {
  532. var type = argsToJson.dataType.toLowerCase();
  533. if (type == 'text' || type == 'json') {
  534. json.dataType = type;
  535. }
  536. } else {
  537. json.dataType = 'json';
  538. }
  539. json.method = 'post';
  540. api.ajax(json,
  541. function(ret, err) {
  542. if (ret) {
  543. fnSuc && fnSuc(ret);
  544. }
  545. }
  546. );
  547. };
  548. u.get = function( /*url,fnSuc,dataType*/ ) {
  549. var argsToJson = parseArguments.apply(null, arguments);
  550. var json = {};
  551. var fnSuc = argsToJson.fnSuc;
  552. argsToJson.url && (json.url = argsToJson.url);
  553. //argsToJson.data && (json.data = argsToJson.data);
  554. if (argsToJson.dataType) {
  555. vartype = argsToJson.dataType.toLowerCase();
  556. if (type == 'text' || type == 'json') {
  557. json.dataType = type;
  558. }
  559. } else {
  560. json.dataType = 'text';
  561. }
  562. json.method = 'get';
  563. api.ajax(json,
  564. function(ret, err) {
  565. if (ret) {
  566. fnSuc && fnSuc(ret);
  567. }
  568. }
  569. );
  570. };
  571. /*end*/
  572. window.$api = u;
  573. setFixStatusBar = function() {
  574. var systemType = api.systemType;
  575. var systemVersion = api.systemVersion;
  576. var h = api.safeArea.top + 'px';
  577. if (systemType == 'ios') {
  578. $api.fixStatusBar($api.dom('body'));
  579. $('.topbar').css("height", h);
  580. $('.page').css("margin-top", h);
  581. $('body').css("margin-top", "-0.05rem");
  582. } else {
  583. $api.fixStatusBar($api.dom('body'));
  584. $('.topbar').css("height", h);
  585. $('.page').css("margin-top", h);
  586. $('body').css("margin-top", "-0.05rem");
  587. }
  588. }
  589. setIosTopBar = function() {
  590. var systemType = api.systemType;
  591. var systemVersion = api.systemVersion;
  592. var h = api.safeArea.top + 'px';
  593. if (systemType == 'ios') {
  594. $api.fixStatusBar($api.dom('body'));
  595. $('.topbar').css("height", h);
  596. $('.page').css("margin-top", h);
  597. $('body').css("margin-top", "-0.05rem");
  598. } else {
  599. $api.fixStatusBar($api.dom('body'));
  600. $('.topbar').css("height", h);
  601. $('.page').css("margin-top", h);
  602. $('body').css("margin-top", "-0.05rem");
  603. }
  604. }
  605. setBackDisable = function() {
  606. var systemType = api.systemType;
  607. if (systemType == 'ios') {
  608. api.setWinAttr({
  609. slidBackEnabled: false
  610. });
  611. } else {
  612. var backSecond = 0;
  613. api.addEventListener({
  614. name: 'keyback'
  615. }, function(ret, err) {
  616. var curSecond = (new Date().getTime()) / 1000;
  617. if (Math.abs(curSecond - backSecond) > 2) {
  618. backSecond = curSecond;
  619. api.toast({
  620. msg: '再按一次退出',
  621. duration: 2000,
  622. location: 'bottom'
  623. });
  624. } else {
  625. api.closeWidget({
  626. id: 'A6007457911931',
  627. retData: { name: 'closeWidget' },
  628. silent: true
  629. });
  630. }
  631. });
  632. }
  633. }
  634. setTimeCloseWin = function(winname) {
  635. setTimeout(function() { api.closeWin({ name: winname }); }, 800);
  636. }
  637. limitNumber = function(txt, num) {
  638. var str = txt;
  639. str = str.substr(0, num) + '...';
  640. return str;
  641. }
  642. statInputNum = function (textArea, numItem) {
  643. // body...
  644. var max = numItem.text(), curLength;
  645. textArea[0].setAttribute("maxlength", max);
  646. curLength = textArea.val().length;
  647. numItem.text(max - curLength);
  648. textArea.on('input propertychange', function() {
  649. numItem.text(max - $(this).val().length);
  650. })
  651. }
  652. errcode = function (res, code) {
  653. // console.log(code)
  654. switch (code) {
  655. case 2000:
  656. $api.rmStorage("storeid");
  657. $api.rmStorage("memberid");
  658. $api.rmStorage("agent_id");
  659. $api.rmStorage("accesstoken");
  660. api.openWin({
  661. name: 'login',
  662. url: 'widget://login.html',
  663. bounces: false,
  664. pageParam: {
  665. keyid: true
  666. }
  667. })
  668. // api.closeWin({ name: 'index' });
  669. // api.closeWin({ name: 'hotelindex' });
  670. // api.closeWin({ name: 'agentindex' });
  671. // api.closeWin();
  672. // console.log(res)
  673. break;
  674. case 1001:
  675. api.toast({ msg: res.msg })
  676. break;
  677. case 3000:
  678. console.log(res)
  679. api.toast({ msg: '系统开小差了' })
  680. break;
  681. case 999:
  682. console.log(res)
  683. api.toast({ msg: res.msg })
  684. break;
  685. default:
  686. console.log(res)
  687. api.toast({ msg: '发生了不知名的错误'+code })
  688. break;
  689. }
  690. }
  691. gallery_qz = function (img) {
  692. img = img.replace('thumb/', '');
  693. var _html = '<div class="weui-gallery" data-imgurl="'+img+'" style="display: block;">';
  694. _html += '<span class="weui-gallery__img" style="background-image: url(' + img + ');"></span>';
  695. _html += '<div class="weui-gallery__opr">';
  696. _html += '<a href="javascript:$(\'.weui-gallery\').remove()" class="weui-gallery__del">';
  697. _html += '<i class="weui-icon-cancel" style="font-size: 1rem;"></i></a></div></div>';
  698. $("body").prepend(_html);
  699. }
  700. gallery_adv = function (img, function_name, id, oid) {
  701. // body...
  702. var _html = '<div class="weui-gallery" style="display: block;background-color: rgba(0, 0, 0, 0.18);">';
  703. _html += '<a href="javascript:'+function_name+'('+id+', '+oid+')"><span class="weui-gallery__img" style="background-image: url('+img+');"></span></a>';
  704. _html += '<div class="weui-gallery__opr" style="background-color: rgba(0, 0, 0, 0);">';
  705. _html += '<a href="javascript:color()" class="weui-gallery__del">';
  706. _html += '<i class="weui-icon-cancel" style="font-size: 1rem;"></i></a></div></div>';
  707. $("body").prepend(_html);
  708. }
  709. toast_weui = function (e) {
  710. // body...
  711. var _html = '<div class="js_dialog" id="iosDialog2_qz" style="display: block;">';
  712. _html += '<div class="weui-mask"></div>';
  713. _html += '<div class="weui-dialog">';
  714. _html += '<div class="weui-dialog__bd">购物前请确认<h2 style="margin: 8px 0;color: #d9251c;">'+e+'</h2>是否是您入住的酒店</div>';
  715. _html += '<div class="weui-dialog__ft">';
  716. _html += '<a href="javascript:api.closeWin();" class="weui-dialog__btn m-bottom back-btn weui-dialog__btn_default" style="background: #777;">返回确认</a>';
  717. _html += '<a href="javascript:$(\'#iosDialog2_qz\').remove();" class="weui-dialog__btn m-bottom weui-dialog__btn_primary">确认无误</a></div></div></div>';
  718. $("body").prepend(_html);
  719. }
  720. toast_loding_show = function (e) {
  721. var _html = '<div id="loadingToast_k" class="loadingToast_k">';
  722. _html += '<div class="weui-mask_transparent"></div>';
  723. _html += '<div class="weui-toast">';
  724. _html += '<i class="weui-loading weui-icon_toast"></i>';
  725. _html += '<p class="weui-toast__content">数据加载中</p></div></div>';
  726. $("body").prepend(_html);
  727. }
  728. toast_loding_hide = function () {
  729. $(".loadingToast_k").remove();
  730. }
  731. hasPermission = function (one_per) {
  732. var perms = new Array();
  733. if(one_per){
  734. perms.push(one_per);
  735. } else {
  736. api.toast({ msg: '系统开小差了' });
  737. return;
  738. }
  739. var rets = api.hasPermission({
  740. list: perms
  741. });
  742. if(!one_per){
  743. api.toast({ msg: '判断结果:' + JSON.stringify(rets) });
  744. return;
  745. }
  746. return rets;
  747. }
  748. reqPermission = function (one_per, callback){
  749. var perms = new Array();
  750. if(one_per){
  751. perms.push(one_per);
  752. } else {
  753. api.toast({ msg: '系统开小差了' });
  754. return;
  755. }
  756. api.requestPermission({
  757. list: perms,
  758. code: 100001
  759. }, function(ret, err){
  760. if(callback){
  761. callback(ret);
  762. return;
  763. }
  764. console.log(JSON.stringify(ret));
  765. })
  766. }
  767. function_name = function () {
  768. $('body').imagesLoaded()
  769. .always( function( instance ) {
  770. // console.log('all images loaded');
  771. })
  772. .done( function( instance ) {
  773. // console.log('all images successfully loaded');
  774. })
  775. .fail( function() {
  776. // console.log('all images loaded, at least one is broken');
  777. })
  778. .progress( function( instance, image ) {
  779. // var result = image.isLoaded ? 'loaded' : 'broken';
  780. // console.log( 'image is ' + result + ' for ' + image.img.src );
  781. // console.log(image)
  782. // image.img.parentNode.className = image.isLoaded ? '' : 'is-broken';
  783. if ( !image.isLoaded ) {
  784. // image.img.className = 'is-broken';
  785. image.img.src = 'http://www2.qzaiwang.com/static/home/images/logo2.png'
  786. }
  787. });
  788. }
  789. qz_update = function () {
  790. var mam = api.require('mam');
  791. mam.checkUpdate(function(ret, err){
  792. if (ret) {
  793. var result = ret.result;
  794. if (result.update == true && result.closed == false) {
  795. var str = '新版本号:' + result.version +';更新提示语:'+result.updateTip;
  796. api.confirm({
  797. title: '有新的版本,是否下载并安装',
  798. msg: str,
  799. buttons: ['确定', '取消']
  800. }, function(ret, err) {
  801. var index = ret.buttonIndex;
  802. if ( api.systemType == "android" ) {
  803. api.download({
  804. url: result.source,
  805. report: true
  806. }, function(ret, err) {
  807. if (ret && 0 == ret.state) {
  808. api.toast({
  809. msg: "正在下载"+ ret.percent + "%",
  810. duration: 2000
  811. })
  812. }
  813. })
  814. }
  815. })
  816. } else {
  817. api.toast({
  818. msg: "已经是最新版本"
  819. })
  820. }
  821. } else {
  822. alert(JSON.stringify(err));
  823. }
  824. })
  825. }
  826. })(window);
  827. // var siteurl = 'http://www2.qzaiwang.com/';
  828. var siteurl = 'https://www.qzaiwang.com/';
  829. // var rooturl = 'http://www2.qzaiwang.com/api/index.php';
  830. var rooturl = 'https://www.qzaiwang.com/api/index.php';
  831. var version = '1.01';