api.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  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.fixTabBar = function(el){
  485. if(!u.isElement(el)){
  486. console.warn('$api.fixTabBar Function need el param, el param must be DOM Element');
  487. return 0;
  488. }
  489. el.style.paddingBottom = api.safeArea.bottom + 'px';
  490. return el.offsetHeight;
  491. };
  492. u.toast = function(title, text, time) {
  493. var opts = {};
  494. var show = function(opts, time) {
  495. api.showProgress(opts);
  496. setTimeout(function() {
  497. api.hideProgress();
  498. }, time);
  499. };
  500. if (arguments.length === 1) {
  501. var time = time || 500;
  502. if (typeof title === 'number') {
  503. time = title;
  504. } else {
  505. opts.title = title + '';
  506. }
  507. show(opts, time);
  508. } else if (arguments.length === 2) {
  509. var time = time || 500;
  510. var text = text;
  511. if (typeof text === "number") {
  512. var tmp = text;
  513. time = tmp;
  514. text = null;
  515. }
  516. if (title) {
  517. opts.title = title;
  518. }
  519. if (text) {
  520. opts.text = text;
  521. }
  522. show(opts, time);
  523. }
  524. if (title) {
  525. opts.title = title;
  526. }
  527. if (text) {
  528. opts.text = text;
  529. }
  530. time = time || 500;
  531. show(opts, time);
  532. };
  533. u.post = function( /*url,data,fnSuc,dataType*/ ) {
  534. var argsToJson = parseArguments.apply(null, arguments);
  535. var json = {};
  536. var fnSuc = argsToJson.fnSuc;
  537. argsToJson.url && (json.url = argsToJson.url);
  538. argsToJson.data && (json.data = argsToJson.data);
  539. if (argsToJson.dataType) {
  540. var type = argsToJson.dataType.toLowerCase();
  541. if (type == 'text' || type == 'json') {
  542. json.dataType = type;
  543. }
  544. } else {
  545. json.dataType = 'json';
  546. }
  547. json.method = 'post';
  548. api.ajax(json,
  549. function(ret, err) {
  550. if (ret) {
  551. fnSuc && fnSuc(ret);
  552. }
  553. }
  554. );
  555. };
  556. u.get = function( /*url,fnSuc,dataType*/ ) {
  557. var argsToJson = parseArguments.apply(null, arguments);
  558. var json = {};
  559. var fnSuc = argsToJson.fnSuc;
  560. argsToJson.url && (json.url = argsToJson.url);
  561. //argsToJson.data && (json.data = argsToJson.data);
  562. if (argsToJson.dataType) {
  563. vartype = argsToJson.dataType.toLowerCase();
  564. if (type == 'text' || type == 'json') {
  565. json.dataType = type;
  566. }
  567. } else {
  568. json.dataType = 'text';
  569. }
  570. json.method = 'get';
  571. api.ajax(json,
  572. function(ret, err) {
  573. if (ret) {
  574. fnSuc && fnSuc(ret);
  575. }
  576. }
  577. );
  578. };
  579. /*end*/
  580. window.$api = u;
  581. setFixStatusBar = function() {
  582. var systemType = api.systemType;
  583. var systemVersion = api.systemVersion;
  584. var h = api.safeArea.top + 'px';
  585. if (systemType == 'ios') {
  586. $api.fixStatusBar($api.dom('body'));
  587. $('.topbar').css("height", h);
  588. $('.page').css("margin-top", h);
  589. $('body').css("margin-top", "-0.05rem");
  590. } else {
  591. $api.fixStatusBar($api.dom('body'));
  592. $('.topbar').css("height", h);
  593. $('.page').css("margin-top", h);
  594. $('body').css("margin-top", "-0.05rem");
  595. }
  596. }
  597. setIosTopBar = function() {
  598. var systemType = api.systemType;
  599. var systemVersion = api.systemVersion;
  600. var h = api.safeArea.top + 'px';
  601. if (systemType == 'ios') {
  602. $api.fixStatusBar($api.dom('body'));
  603. $('.topbar').css("height", h);
  604. $('.page').css("margin-top", h);
  605. $('body').css("margin-top", "-0.05rem");
  606. } else {
  607. $api.fixStatusBar($api.dom('body'));
  608. $('.topbar').css("height", h);
  609. $('.page').css("margin-top", h);
  610. $('body').css("margin-top", "-0.05rem");
  611. }
  612. }
  613. setBackDisable = function() {
  614. var systemType = api.systemType;
  615. if (systemType == 'ios') {
  616. api.setWinAttr({
  617. slidBackEnabled: false
  618. });
  619. } else {
  620. var backSecond = 0;
  621. api.addEventListener({
  622. name: 'keyback'
  623. }, function(ret, err) {
  624. var curSecond = (new Date().getTime()) / 1000;
  625. if (Math.abs(curSecond - backSecond) > 2) {
  626. backSecond = curSecond;
  627. api.toast({
  628. msg: '再按一次退出',
  629. duration: 2000,
  630. location: 'bottom'
  631. });
  632. } else {
  633. api.closeWidget({
  634. id: 'A6007457911931',
  635. retData: { name: 'closeWidget' },
  636. silent: true
  637. });
  638. }
  639. });
  640. }
  641. }
  642. setTimeCloseWin = function(winname) {
  643. setTimeout(function() { api.closeWin({ name: winname }); }, 800);
  644. }
  645. limitNumber = function(txt, num) {
  646. var str = txt;
  647. str = str.substr(0, num) + '...';
  648. return str;
  649. }
  650. statInputNum = function (textArea, numItem) {
  651. // body...
  652. var max = numItem.text(), curLength;
  653. textArea[0].setAttribute("maxlength", max);
  654. curLength = textArea.val().length;
  655. numItem.text(max - curLength);
  656. textArea.on('input propertychange', function() {
  657. numItem.text(max - $(this).val().length);
  658. })
  659. }
  660. errcode = function (res, code) {
  661. // console.log(code)
  662. switch (code) {
  663. case 2000:
  664. $api.rmStorage("storeid");
  665. $api.rmStorage("memberid");
  666. $api.rmStorage("agent_id");
  667. $api.rmStorage("accesstoken");
  668. api.openWin({
  669. name: 'login',
  670. url: 'widget://login.html',
  671. bounces: false,
  672. pageParam: {
  673. keyid: true
  674. }
  675. })
  676. // api.closeWin({ name: 'index' });
  677. // api.closeWin({ name: 'hotelindex' });
  678. // api.closeWin({ name: 'agentindex' });
  679. // api.closeWin();
  680. // console.log(res)
  681. break;
  682. case 1001:
  683. api.toast({ msg: res.msg })
  684. break;
  685. case 3000:
  686. console.log(res)
  687. api.toast({ msg: '系统开小差了' })
  688. break;
  689. case 999:
  690. console.log(res)
  691. api.toast({ msg: res.msg })
  692. break;
  693. default:
  694. console.log(res)
  695. api.toast({ msg: '发生了不知名的错误'+code })
  696. break;
  697. }
  698. }
  699. gallery_qz = function (img) {
  700. img = img.replace('thumb/', '');
  701. var _html = '<div class="weui-gallery" data-imgurl="'+img+'" style="display: block;">';
  702. _html += '<span class="weui-gallery__img" style="background-image: url(' + img + ');"></span>';
  703. _html += '<div class="weui-gallery__opr">';
  704. _html += '<a href="javascript:$(\'.weui-gallery\').remove()" class="weui-gallery__del">';
  705. _html += '<i class="weui-icon-cancel" style="font-size: 1rem;"></i></a></div></div>';
  706. $("body").prepend(_html);
  707. }
  708. gallery_adv = function (img, function_name, id, oid) {
  709. // body...
  710. var _html = '<div class="weui-gallery" style="display: block;background-color: rgba(0, 0, 0, 0.18);">';
  711. _html += '<a href="javascript:'+function_name+'('+id+', '+oid+')"><span class="weui-gallery__img" style="background-image: url('+img+');"></span></a>';
  712. _html += '<div class="weui-gallery__opr" style="background-color: rgba(0, 0, 0, 0);">';
  713. _html += '<a href="javascript:color()" class="weui-gallery__del">';
  714. _html += '<i class="weui-icon-cancel" style="font-size: 1rem;"></i></a></div></div>';
  715. $("body").prepend(_html);
  716. }
  717. toast_weui = function (e) {
  718. // body...
  719. var _html = '<div class="js_dialog" id="iosDialog2_qz" style="display: block;">';
  720. _html += '<div class="weui-mask"></div>';
  721. _html += '<div class="weui-dialog">';
  722. _html += '<div class="weui-dialog__bd">购物前请确认<h2 style="margin: 8px 0;color: #d9251c;">'+e+'</h2>是否是您入住的酒店</div>';
  723. _html += '<div class="weui-dialog__ft">';
  724. _html += '<a href="javascript:api.closeWin();" class="weui-dialog__btn m-bottom back-btn weui-dialog__btn_default" style="background: #777;">返回确认</a>';
  725. _html += '<a href="javascript:$(\'#iosDialog2_qz\').remove();" class="weui-dialog__btn m-bottom weui-dialog__btn_primary">确认无误</a></div></div></div>';
  726. $("body").prepend(_html);
  727. }
  728. toast_loding_show = function (e) {
  729. var _html = '<div id="loadingToast_k" class="loadingToast_k">';
  730. _html += '<div class="weui-mask_transparent"></div>';
  731. _html += '<div class="weui-toast">';
  732. _html += '<i class="weui-loading weui-icon_toast"></i>';
  733. _html += '<p class="weui-toast__content">数据加载中</p></div></div>';
  734. $("body").prepend(_html);
  735. }
  736. toast_loding_hide = function () {
  737. $(".loadingToast_k").remove();
  738. }
  739. hasPermission = function (one_per) {
  740. var perms = new Array();
  741. if(one_per){
  742. perms.push(one_per);
  743. } else {
  744. api.toast({ msg: '系统开小差了' });
  745. return;
  746. }
  747. var rets = api.hasPermission({
  748. list: perms
  749. });
  750. if(!one_per){
  751. api.toast({ msg: '判断结果:' + JSON.stringify(rets) });
  752. return;
  753. }
  754. return rets;
  755. }
  756. reqPermission = function (one_per, callback){
  757. var perms = new Array();
  758. if(one_per){
  759. perms.push(one_per);
  760. } else {
  761. api.toast({ msg: '系统开小差了' });
  762. return;
  763. }
  764. api.requestPermission({
  765. list: perms,
  766. code: 100001
  767. }, function(ret, err){
  768. if(callback){
  769. callback(ret);
  770. return;
  771. }
  772. console.log(JSON.stringify(ret));
  773. })
  774. }
  775. function_name = function () {
  776. $('body').imagesLoaded()
  777. .always( function( instance ) {
  778. // console.log('all images loaded');
  779. })
  780. .done( function( instance ) {
  781. // console.log('all images successfully loaded');
  782. })
  783. .fail( function() {
  784. // console.log('all images loaded, at least one is broken');
  785. })
  786. .progress( function( instance, image ) {
  787. // var result = image.isLoaded ? 'loaded' : 'broken';
  788. // console.log( 'image is ' + result + ' for ' + image.img.src );
  789. // console.log(image)
  790. // image.img.parentNode.className = image.isLoaded ? '' : 'is-broken';
  791. if ( !image.isLoaded ) {
  792. // image.img.className = 'is-broken';
  793. image.img.src = 'http://www2.qzaiwang.com/static/home/images/logo2.png'
  794. }
  795. });
  796. }
  797. qz_update = function () {
  798. var mam = api.require('mam');
  799. mam.checkUpdate(function(ret, err){
  800. if (ret) {
  801. var result = ret.result;
  802. if (result.update == true && result.closed == false) {
  803. var str = '新版本号:' + result.version +';更新提示语:'+result.updateTip;
  804. api.confirm({
  805. title: '有新的版本,是否下载并安装',
  806. msg: str,
  807. buttons: ['确定', '取消']
  808. }, function(ret, err) {
  809. var index = ret.buttonIndex;
  810. if ( api.systemType == "android" ) {
  811. api.download({
  812. url: result.source,
  813. report: true
  814. }, function(ret, err) {
  815. if (ret && 0 == ret.state) {
  816. api.toast({
  817. msg: "正在下载"+ ret.percent + "%",
  818. duration: 2000
  819. })
  820. }
  821. })
  822. }
  823. })
  824. } else {
  825. api.toast({
  826. msg: "已经是最新版本"
  827. })
  828. }
  829. } else {
  830. alert(JSON.stringify(err));
  831. }
  832. })
  833. }
  834. })(window);
  835. // var siteurl = 'http://www2.qzaiwang.com/';
  836. var siteurl = 'https://www.qzaiwang.com/';
  837. // var rooturl = 'http://www2.qzaiwang.com/api/index.php';
  838. var rooturl = 'https://www.qzaiwang.com/api/index.php';
  839. var version = '1.01';