common.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  1. // 头部返回按钮事件
  2. $('.j-header .header-left').on('click', function () {
  3. window.history.back()
  4. })
  5. window.afterClickBack = function () {
  6. console.log('afterClickBack', location.href)
  7. }
  8. var vTools = {
  9. // 公共前缀url
  10. baseUrl: '/entniche',
  11. // 公共header
  12. commonHeader: {
  13. 'version': 'v2.9.6'
  14. },
  15. errorCodeMap: {
  16. 1001: '需要重新登录',
  17. 1002: '缺失参数',
  18. 1003: '没有权限',
  19. },
  20. $env: {},
  21. loadingTransition: 300,
  22. redirectURi: [
  23. '/phone/bind',
  24. '/phone/sendidentcode',
  25. '/ent/myents',
  26. '/ent/entinfo',
  27. '/ent/selectent',
  28. '/ent/association',
  29. '/power/persons',
  30. '/department/persons',
  31. '/department/add',
  32. '/department/update',
  33. '/department/delete',
  34. '/department/detail',
  35. '/department/move',
  36. '/department/childrens',
  37. '/department/setadmin',
  38. '/person/manager',
  39. '/person/add',
  40. '/person/detail',
  41. '/person/delete',
  42. '/person/update',
  43. '/person/move',
  44. '/framework/delete',
  45. '/framework/move',
  46. '/power/set',
  47. '/ent/framework',
  48. '/ent/add',
  49. '/person/pcManager'
  50. ],
  51. // 公共ajax封装
  52. ajax: function (options) {
  53. var that = this
  54. // var options = {
  55. // url: url, String
  56. // data: data, Object
  57. // type: type, String: 'GET'/'POST'
  58. // contentType: contentType, String: 'application/x-www-form-urlencoded'/'application/json;charset=UTF-8'
  59. // success: success, Function
  60. // beforeSend: beforeSend, Function
  61. // error: error, Function,
  62. // loading: {
  63. // content: '加载中...',
  64. // bgc: 'black'
  65. // }, Object
  66. // }
  67. options.contentType = options.contentType || 'application/json;charset=UTF-8'
  68. if (options.contentType === 'application/json;charset=UTF-8') {
  69. options.data = JSON.stringify(options.data) || '{}'
  70. } else {
  71. options.data = options.data || {}
  72. }
  73. if (options.loading) {
  74. var loading = this.jLoading(options.loading)
  75. }
  76. // 页面baseUrl重写
  77. var inRedirectUriArr = false;
  78. var newUrl = options.url;
  79. if(options.url.indexOf('?') > -1){
  80. newUrl = options.url.split('?')[0];
  81. }
  82. for (var i = 0; i < this.redirectURi.length; i++) {
  83. if (newUrl == this.redirectURi[i]) {
  84. inRedirectUriArr = true
  85. break
  86. }
  87. }
  88. if (inRedirectUriArr) {
  89. this.baseUrl = '/entbase'
  90. } else {
  91. this.baseUrl = '/entnicheNew'
  92. }
  93. // 执行请求
  94. $.ajax({
  95. url: this.baseUrl + options.url,
  96. type: options.type,
  97. dataType: 'json',
  98. contentType: options.contentType || 'application/json;charset=UTF-8',
  99. headers: this.commonHeader,
  100. // processData: options.processData || true,
  101. data: options.data,
  102. beforeSend: function (res) {
  103. options.beforeSend && options.beforeSend(res)
  104. },
  105. success: function (res) {
  106. if (options.loading) {
  107. loading.hide(function(){
  108. options.success && options.success(res);
  109. })
  110. } else {
  111. options.success && options.success(res);
  112. }
  113. },
  114. error: function (res) {
  115. loading.hide(function () {
  116. that.jLoading({
  117. iconHide: true,
  118. content: '请求失败',
  119. duration: 1500,
  120. callback: function() {
  121. options.error && options.error(res);
  122. }
  123. })
  124. })
  125. },
  126. complete: function () {
  127. if (options.loading) {
  128. loading.hide(function() {
  129. options.complete && options.complete();
  130. })
  131. } else {
  132. options.complete && options.complete();
  133. }
  134. }
  135. });
  136. },
  137. // 传入你要获取的参数的名字
  138. getParam: function (name) {
  139. var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  140. var r = window.location.search.substr(1).match(reg); //获取url中'?'符后的字符串并正则匹配
  141. var context = '';
  142. if (r != null) context = r[2];
  143. // 释放变量
  144. reg = null;
  145. r = null;
  146. return context == null || context == '' || context == 'undefined' ? '' : context;
  147. },
  148. // 数组对象根据某一个值进行冒泡排序
  149. // arr 数组
  150. // value 字符串
  151. bSort: function (arr, value) {
  152. var len = arr.length;
  153. for (var i = 0; i < len - 1; i++) {
  154. for (var j = 0; j < len - 1 - i; j++) {
  155. // 相邻元素两两对比,元素交换,大的元素交换到后面
  156. if (arr[j][value] > arr[j + 1][value]) {
  157. var temp = arr[j];
  158. arr[j] = arr[j + 1];
  159. arr[j + 1] = temp;
  160. }
  161. }
  162. }
  163. return arr;
  164. },
  165. // 格式化金钱的函数
  166. // s: 金额(number) 必传
  167. // n: 保留小数的位数(int:0-100)
  168. formatMoney: function (s, n) {
  169. if (n === undefined) {
  170. n = -1
  171. } else {
  172. n = n > 0 && n <= 20 ? n : 2;
  173. }
  174. var intS = parseInt(s)
  175. var point = '.'
  176. var left;
  177. var right;
  178. s = parseFloat((s + '').replace(/[^\d\.-]/g, ''))
  179. // 没传n,默认(如果为整数,则不保留小数。如果为浮点数,则保留两位小数)
  180. if (n === -1) {
  181. if (s === intS) {
  182. n = 0
  183. right = ''
  184. point = ''
  185. } else {
  186. n = 2
  187. s = s.toFixed(n);
  188. right = s.split('.')[1];
  189. }
  190. s = s + ''
  191. left = s.split('.')[0].split('').reverse();
  192. } else {
  193. s = parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(n) + '';
  194. left = s.split('.')[0].split('').reverse();
  195. right = s.split('.')[1];
  196. }
  197. t = '';
  198. for (i = 0; i < left.length; i++) {
  199. t += left[i] + ((i + 1) % 3 == 0 && (i + 1) != left.length ? ',' : '');
  200. }
  201. var money = t.split('').reverse().join('') + point + right;
  202. return money;
  203. },
  204. // 解决ios返回不刷新页面的问题
  205. iosBackRefresh: function () {
  206. var isPageHide = false;
  207. window.addEventListener('pageshow', function () {
  208. if (isPageHide) {
  209. location.reload();
  210. }
  211. });
  212. window.addEventListener('pagehide', function () {
  213. isPageHide = true;
  214. });
  215. },
  216. // 解决移动端软键盘弹起遮挡输入框及ios下软键盘关闭后底部留白问题
  217. // 解决键盘弹起'.j-footer'往上顶的问题
  218. // 原始代码在:jianyuMobile:vip_subscribe分支/trial_info.html
  219. initScrollView: function (options) {
  220. options.inputClassName = options.inputClassName || 'input'
  221. options.bottom = options.bottom || '.j-footer'
  222. options.exclude = options.exclude || 'exclude'
  223. /*
  224. options = {
  225. // 输入框公共类名 String(为css选择器): 如'.j-input'
  226. inputClassName: inputClassName,
  227. // 底部按钮 String(为css选择器): 如'.j-footer'
  228. bottom: bottomContainer,
  229. // 排除的底部区域的button String(为字符串): 如'exclude',默认为'exclude'
  230. // 如果底部区域是隐藏的,此时键盘弹起在收起,就会显示,加上一个排除的类名,就不会进行隐藏了
  231. exclude: exclude
  232. // =========废弃=========>
  233. // view属性废弃,view属性是在底部元素使用定位时候用的
  234. // 滚动区域 String(为css选择器): 如'.container'
  235. // view: scrollView
  236. // ======================>
  237. }
  238. */
  239. var u = navigator.userAgent, app = navigator.appVersion;
  240. var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1;
  241. // var clientHeight = $(options.view).height()
  242. // var clientHeight = document.documentElement.clientHeight || document.body.clientHeight
  243. // function change() {
  244. // $(options.view || document.body).height(clientHeight)
  245. // }
  246. var clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
  247. // change函数参考: https://blog.csdn.net/andyfine/article/details/82695236
  248. function change() {
  249. var footer = $(options.bottom)
  250. // 首先判断footer此时有没有options.exclude的类名,有此类名则不会隐藏
  251. // $('.ele').is(':hidden')
  252. // $('.ele').is(':visible')
  253. if (footer.hasClass(options.exclude)) return
  254. if (document.body.scrollHeight < clientHeight) {
  255. footer.hide()
  256. } else {
  257. footer.show()
  258. }
  259. }
  260. // 给所有input绑定一个focus事件,用来判断键盘弹起。执行完成就解绑该事件
  261. function focusOnce() {
  262. $(options.inputClassName).on('focus', function (e) {
  263. e.target.scrollIntoView({ 'block': 'center' })
  264. $(options.inputClassName).off('focus')
  265. })
  266. }
  267. if (isAndroid) {
  268. // 在安卓中键盘弹起会触发window.onresize事件
  269. // ios中则不会触发window.resize事件
  270. change();
  271. window.addEventListener('resize', change);
  272. } else {
  273. // 进入页面绑定,触发一次就解绑
  274. focusOnce()
  275. }
  276. $(options.inputClassName).on('blur', function (e) {
  277. setTimeout(function() {
  278. var dom = document.activeElement;
  279. if (dom.className.includes(options.inputClassName.replace(/\./g))) {
  280. if (isAndroid) {
  281. dom.scrollIntoView({ 'block': 'center' })
  282. } else {
  283. // dom.scrollIntoView({'block': 'bottom'})
  284. }
  285. } else {
  286. window.scroll(0, 0)
  287. // 当页面上没有获得焦点的input时候就说明键盘收起来了。
  288. // 给input绑定focus事件用来监听其弹起
  289. focusOnce()
  290. }
  291. }, 50)
  292. })
  293. },
  294. // 通过userAgent获取用户手机操作系统类型
  295. androidOrIOS: function () {
  296. var u = navigator.userAgent.toLowerCase();
  297. var app = navigator.appVersion;
  298. var agent = null;
  299. if (/iphone|ipod|ipad|ios/.test(u)) {
  300. agent = 'ios'
  301. } else {
  302. agent = 'android'
  303. }
  304. return agent
  305. },
  306. // 带动画的weui picker的显示隐藏
  307. pickerAnimatedShow: function (selector, f) {
  308. if (f) {
  309. // 添加进场动画,并显示
  310. $(selector).find('.weui-mask').removeClass('weui-animate-fade-out').addClass('weui-animate-fade-in')
  311. $(selector).find('.weui-picker').removeClass('weui-animate-slide-down').addClass('weui-animate-slide-up')
  312. $(selector).show(300);
  313. } else {
  314. // 添加离场动画,并隐藏
  315. $(selector).find('.weui-mask').removeClass('weui-animate-fade-in').addClass('weui-animate-fade-out')
  316. $(selector).find('.weui-picker').removeClass('weui-animate-slide-up').addClass('weui-animate-slide-down')
  317. $(selector).hide(300);
  318. }
  319. },
  320. // 键盘弹起和收起的事件(只在安卓有效果)
  321. keyboardUpAndDown: function (upCallBack, downCallBack) {
  322. var clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
  323. $(window).on('resize', function () {
  324. var nowClientHeight = document.documentElement.clientHeight || document.body.clientHeight;
  325. if (clientHeight > nowClientHeight) {
  326. // 键盘弹出的事件处理
  327. upCallBack && upCallBack()
  328. console.log('键盘弹出')
  329. }
  330. else {
  331. // 键盘收起的事件处理
  332. downCallBack && downCallBack()
  333. console.log('键盘收起')
  334. }
  335. });
  336. },
  337. // 取[m, n]随机数
  338. getRandomNumber: function (min, max) {
  339. return Math.floor(Math.random() * (max - min + 1) + min);
  340. },
  341. // 获取唯一的uuid
  342. // https://www.kancloud.cn/ifeng/js100/622666
  343. getRandomUuid: function () {
  344. var s = [];
  345. var hexDigits = "0123456789abcdef";
  346. for (var i = 0; i < 36; i++) {
  347. s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
  348. }
  349. s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
  350. s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
  351. s[8] = s[13] = s[18] = s[23] = "-";
  352. var uuid = s.join("");
  353. return uuid;
  354. },
  355. // 获取随机字符串
  356. // 不传参数则获取长度不固定的字符串
  357. getRandomString: function (len) {
  358. var randomString = '';
  359. if (len) {
  360. /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
  361. var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
  362. var maxPos = $chars.length;
  363. for (i = 0; i < len; i++) {
  364. randomString += $chars.charAt(Math.floor(Math.random() * maxPos));
  365. }
  366. } else {
  367. // Math.random() 生成随机数字, eg: 0.123456
  368. // .toString(36) 转化成36进制 : "0.4fzyo82mvyr"
  369. // .substring(2) 去掉前面两位 : "yo82mvyr"
  370. // .slice(-8) 截取最后八位 : "yo82mvyr"
  371. randomString = Math.random().toString(36).substring(2)
  372. }
  373. return randomString;
  374. },
  375. // FROM: https://www.jianshu.com/p/90ed8b728975
  376. // 比较两个兑现是否相等
  377. // 返回true为相等,返回false为不相等
  378. deepCompare: function (x, y) {
  379. var i, l, leftChain, rightChain;
  380. function compare2Objects(x, y) {
  381. var p;
  382. // remember that NaN === NaN returns false
  383. // and isNaN(undefined) returns true
  384. if (isNaN(x) && isNaN(y) && typeof x === 'number' && typeof y === 'number') {
  385. return true;
  386. }
  387. // Compare primitives and functions.
  388. // Check if both arguments link to the same object.
  389. // Especially useful on the step where we compare prototypes
  390. if (x === y) {
  391. return true;
  392. }
  393. // Works in case when functions are created in constructor.
  394. // Comparing dates is a common scenario. Another built-ins?
  395. // We can even handle functions passed across iframes
  396. if ((typeof x === 'function' && typeof y === 'function') ||
  397. (x instanceof Date && y instanceof Date) ||
  398. (x instanceof RegExp && y instanceof RegExp) ||
  399. (x instanceof String && y instanceof String) ||
  400. (x instanceof Number && y instanceof Number)) {
  401. return x.toString() === y.toString();
  402. }
  403. // At last checking prototypes as good as we can
  404. if (!(x instanceof Object && y instanceof Object)) {
  405. return false;
  406. }
  407. if (x.isPrototypeOf(y) || y.isPrototypeOf(x)) {
  408. return false;
  409. }
  410. if (x.constructor !== y.constructor) {
  411. return false;
  412. }
  413. if (x.prototype !== y.prototype) {
  414. return false;
  415. }
  416. // Check for infinitive linking loops
  417. if (leftChain.indexOf(x) > -1 || rightChain.indexOf(y) > -1) {
  418. return false;
  419. }
  420. // Quick checking of one object being a subset of another.
  421. // todo: cache the structure of arguments[0] for performance
  422. for (p in y) {
  423. if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {
  424. return false;
  425. } else if (typeof y[p] !== typeof x[p]) {
  426. return false;
  427. }
  428. }
  429. for (p in x) {
  430. if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {
  431. return false;
  432. } else if (typeof y[p] !== typeof x[p]) {
  433. return false;
  434. }
  435. switch (typeof (x[p])) {
  436. case 'object':
  437. case 'function':
  438. leftChain.push(x);
  439. rightChain.push(y);
  440. if (!compare2Objects(x[p], y[p])) {
  441. return false;
  442. }
  443. leftChain.pop();
  444. rightChain.pop();
  445. break;
  446. default:
  447. if (x[p] !== y[p]) {
  448. return false;
  449. }
  450. break;
  451. }
  452. }
  453. return true;
  454. }
  455. if (arguments.length < 1) {
  456. return true; //Die silently? Don't know how to handle such case, please help...
  457. // throw "Need two or more arguments to compare";
  458. }
  459. for (i = 1, l = arguments.length; i < l; i++) {
  460. leftChain = []; //Todo: this can be cached
  461. rightChain = [];
  462. if (!compare2Objects(arguments[0], arguments[i])) {
  463. return false;
  464. }
  465. }
  466. return true;
  467. },
  468. // 全局loading框
  469. jLoading: function(options) {
  470. // 设置options参数的默认值
  471. options.content = options.content || 'loading...'
  472. options.bgc = options.bgc || 'transparent'
  473. options.icon = options.icon || 'j-loading-icon'
  474. options.duration = options.duration || 0
  475. // 将其拼接成width: 5rem;的形式
  476. options.width = options.width ? 'width:' + options.width + ';' : ''
  477. // 结构
  478. // <div class="j-loading">
  479. // <div class="j-mask"></div>
  480. // <div class="j-toast">
  481. // <i class="j-toast_icon j-loading-icon"></i>
  482. // <p class="j-toast_content">loading</p>
  483. // </div>
  484. // </div>
  485. var that = this
  486. var bgcClassMap = {
  487. transparent: '',
  488. black: 'black'
  489. }
  490. var icon = options.iconHide ? '' : 'icon';
  491. var html = '<div class="j-loading"><div class="j-mask ' + bgcClassMap[options.bgc] + '"></div><div class="j-toast '+ icon +'" style="' + options.width + '"><i class="j-toast_icon ' + options.icon + '"></i><p class="j-toast_content">' + options.content + '</p></div></div>'
  492. var _html = $(html)
  493. $('body').append(_html)
  494. _html.fadeIn(this.loadingTransition)
  495. var _loading = {
  496. _html: _html,
  497. hide: function(callback) {
  498. this._html.fadeOut(that.loadingTransition, function() {
  499. this.remove()
  500. callback && callback()
  501. })
  502. }
  503. }
  504. if (options.duration > 0) {
  505. setTimeout(function() {
  506. _loading.hide(options.callback)
  507. }, options.duration)
  508. }
  509. return _loading
  510. },
  511. splitPhone: function(phone) {
  512. return String(phone).replace(/\s/g, '').replace(/(?=(\d{4})+$)/g, ' ')
  513. },
  514. // https://blog.csdn.net/jacoox/article/details/80719456
  515. // https://github.com/Advanced-Frontend/Daily-Interview-Question/issues/129、https://segmentfault.com/a/1190000012490380
  516. // 防抖: 其中 func 为需要进行防抖操作的函数(如发送联想请求的函数),delay 为延迟时间
  517. debounce: function(func, delay) {
  518. var timer = null
  519. return function() {
  520. var _this = this
  521. var _arg = arguments
  522. clearTimeout(timer)
  523. timer = setTimeout(function() {
  524. func.apply(_this, _arg)
  525. }, delay)
  526. }
  527. },
  528. // 节流: 其中 func 为需要进行节流操作的函数,wait为等待时间
  529. throttle: function(func, wait) {
  530. var lastTime = 0
  531. return function(e) {
  532. var now = +new Date()
  533. if (now - lastTime > wait) {
  534. func.apply(this, arguments)
  535. lastTime = now
  536. }
  537. }
  538. },
  539. isWeiXinBrower: function() {
  540. var ua = navigator.userAgent.toLowerCase();
  541. if(ua.match(/MicroMessenger/i) == 'micromessenger') {
  542. return true;
  543. } else {
  544. return false;
  545. }
  546. },
  547. // 解决 客户端2.9.5 replace失效问题
  548. locationReplace: function (url){
  549. if(history.replaceState){
  550. history.replaceState(null, document.title, url);
  551. history.go(0);
  552. }else{
  553. location.replace(url);
  554. }
  555. },
  556. iosAppFns: function () {
  557. window.JyObjMessage = new Object()
  558. window.JyObj = {
  559. //清除 JyObjMessage
  560. clearMessage:function(){
  561. JyObjMessage = new Object();
  562. },
  563. //隐藏显示底部菜单栏 0:隐藏;1:显示
  564. hiddenBottom:function(val){
  565. JyObjMessage["hidden"]=val;
  566. window.webkit.messageHandlers.hiddenBottom.postMessage(JyObjMessage);
  567. JyObj.clearMessage();
  568. },
  569. //刷新到指定的webview
  570. //name 对应的值:search 搜索 subscribe 订阅 box 百宝箱 me 我的
  571. //type 对应的值:0:当前页 1:一级页面
  572. refreshAppointTab: function (name,type) {
  573. JyObjMessage.name = name
  574. JyObjMessage.type = type
  575. window.webkit.messageHandlers.refreshAppointTab.postMessage(JyObjMessage)
  576. JyObj.clearMessage()
  577. },
  578. //微信登录
  579. loginByWeixin:function(){
  580. window.webkit.messageHandlers.loginByWeixin.postMessage(JyObjMessage);
  581. JyObj.clearMessage();
  582. },
  583. //分享功能
  584. share:function(type,title,content,link){
  585. JyObjMessage["type"]=type
  586. JyObjMessage["title"]=title
  587. JyObjMessage["content"]=content
  588. JyObjMessage["link"]=link
  589. window.webkit.messageHandlers.share.postMessage(JyObjMessage);
  590. JyObj.clearMessage();
  591. },
  592. //保存用户token
  593. saveUserToken:function(val){
  594. JyObjMessage["token"]=val;
  595. window.webkit.messageHandlers.saveUserToken.postMessage(JyObjMessage);
  596. JyObj.clearMessage();
  597. },
  598. //获取用户token
  599. getUserToken:function(){
  600. return JyObj.IosCall("getUserToken")
  601. },
  602. //移除用户token
  603. removeUserToken:function(){
  604. window.webkit.messageHandlers.removeUserToken.postMessage(JyObjMessage);
  605. JyObj.clearMessage();
  606. },
  607. //查看开关状态 是否接受消息
  608. checkNoticePermission:function(){
  609. return JyObj.IosCall("checkNoticePermission")
  610. },
  611. //打开接受消息开关
  612. openSystemNotification:function(){
  613. window.webkit.messageHandlers.openSystemNotification.postMessage(JyObjMessage);
  614. JyObj.clearMessage();
  615. },
  616. //获取极光推送id
  617. getPushRid:function(){
  618. return JyObj.IosCall("getPushRid")
  619. },
  620. //跳转外部链接
  621. openExternalLink:function(url,title){
  622. JyObjMessage["url"]=url
  623. JyObjMessage["title"]=title
  624. window.webkit.messageHandlers.openExternalLink.postMessage(JyObjMessage);
  625. JyObj.clearMessage();
  626. },
  627. //获取当前版本号
  628. getVersion:function(){
  629. return JyObj.IosCall("getVersion")
  630. },
  631. alert:function(content){
  632. JyObjMessage["content"]=content
  633. window.webkit.messageHandlers.alert.postMessage(JyObjMessage);
  634. JyObj.clearMessage();
  635. },
  636. //是否安装了微信
  637. isInstallWeixin:function(){
  638. return JyObj.IosCall("isInstallWeixin")
  639. },
  640. //登录加密
  641. getCipherText:function(val){
  642. JyObjMessage["phone"]=val
  643. return JyObj.IosCall("getCipherText",JyObjMessage)
  644. },
  645. //刷新首页和订阅页面
  646. checkLab:function(){
  647. window.webkit.messageHandlers.checkLab.postMessage(JyObjMessage);
  648. JyObj.clearMessage();
  649. },
  650. //登录成功后向客户端传参
  651. loginSuccess:function(status){
  652. JyObjMessage["status"]=status
  653. window.webkit.messageHandlers.loginSuccess.postMessage(JyObjMessage);
  654. JyObj.clearMessage();
  655. },
  656. //客户端登录页面点击返回 跳转到搜索首页
  657. backUrl:function(val){
  658. JyObjMessage["status"] = val;
  659. window.webkit.messageHandlers.backUrl.postMessage(JyObjMessage);
  660. JyObj.clearMessage();
  661. },
  662. //清空通知栏消息
  663. clearPushMessage:function(){
  664. window.webkit.messageHandlers.clearPushMessage.postMessage(JyObjMessage);
  665. JyObj.clearMessage();
  666. },
  667. //隐藏小红点
  668. hideRedSpotOnMenu:function(menu){
  669. JyObjMessage["menu"] = menu;
  670. window.webkit.messageHandlers.hideRedSpotOnMenu.postMessage(JyObjMessage);
  671. JyObj.clearMessage();
  672. },
  673. //显示小红点
  674. showRedSpotOnMenu:function(menu){
  675. JyObjMessage["menu"] = menu;
  676. window.webkit.messageHandlers.showRedSpotOnMenu.postMessage(JyObjMessage);
  677. JyObj.clearMessage();
  678. },
  679. //微信支付
  680. wxPay:function(order){
  681. JyObjMessage["order"] = order;
  682. window.webkit.messageHandlers.wxPay.postMessage(JyObjMessage);
  683. JyObj.clearMessage();
  684. },
  685. //支付宝支付
  686. aliPay:function(order){
  687. JyObjMessage["order"] = order;
  688. window.webkit.messageHandlers.aliPay.postMessage(JyObjMessage);
  689. JyObj.clearMessage();
  690. },
  691. //获取原生的推送id
  692. getOtherPushRid:function(){
  693. return JyObj.IosCall("getOtherPushRid")
  694. },
  695. //获取手机型号
  696. getPhoneBrand:function(){
  697. return JyObj.IosCall("getPhoneBrand")
  698. },
  699. //获取定位
  700. getLocation:function(){
  701. return JyObj.IosCall("getLocation")
  702. },
  703. //切换菜单
  704. chooseTab:function(indexTab){
  705. JyObjMessage["indexTab"] = indexTab;
  706. window.webkit.messageHandlers.chooseTab.postMessage(JyObjMessage);
  707. JyObj.clearMessage();
  708. },
  709. //打开照相机
  710. skipCamera:function(){
  711. window.webkit.messageHandlers.skipCamera.postMessage(JyObjMessage);
  712. JyObj.clearMessage();
  713. },
  714. //打开相册
  715. skipAlbum:function(){
  716. window.webkit.messageHandlers.skipAlbum.postMessage(JyObjMessage);
  717. JyObj.clearMessage();
  718. },
  719. //点击返回调用
  720. judgeIsHidden:function(referer){
  721. JyObjMessage["referer"] = referer;
  722. window.webkit.messageHandlers.judgeIsHidden.postMessage(JyObjMessage);
  723. JyObj.clearMessage();
  724. },
  725. //返回值 处理
  726. IosCall: function (functionName,args){
  727. if (args!=""&&args!=undefined){
  728. JyObj.clearMessage();
  729. }
  730. var payload = {"jsName": functionName, "arguments": args};
  731. var res = prompt(JSON.stringify(payload));
  732. if (res!=""){
  733. var resObj=JSON.parse(res)
  734. var type = resObj.type
  735. switch (type){
  736. case "int":
  737. return parseInt(resObj.value)
  738. case "string":
  739. return resObj.value
  740. case "bool":
  741. if(resObj.value=="true"){
  742. return true
  743. }
  744. return false
  745. default:
  746. return ""
  747. }
  748. }
  749. return ""
  750. }
  751. }
  752. },
  753. // getRefer: function () {
  754. // var recordPathSource = {
  755. // me: {
  756. // // 从这几个页面中来
  757. // from: [
  758. // '/jyapp/front/myOrder/toMyOrder'
  759. // ],
  760. // // 到哪里去
  761. // to: '/jyapp/free/me'
  762. // },
  763. // treasure: {
  764. // from: [
  765. // '/page_entniche/page/add_ent/add_ent.html',
  766. // '/page_entniche/page/user/bind_result.html',
  767. // '/page_entniche/page/user/selected_ent.html',
  768. // '/page_entniche/page/user/selected_ent.html',
  769. // ],
  770. // to: '/jyapp/jylab/index'
  771. // }
  772. // }
  773. // var uri = ''
  774. // if (window.URL) {
  775. // uri = new URL(document.referrer)
  776. // } else {
  777. // var uri = document.createElement('a')
  778. // uri.href = document.referrer
  779. // }
  780. // console.log(document.referrer)
  781. // console.log(uri)
  782. // var pathName = uri.pathname
  783. // for (var key in recordPathSource) {
  784. // var r = recordPathSource[key].from.indexOf(pathName)
  785. // if (r !== -1) {
  786. // sessionStorage.setItem('paySuccessNextStepLink', recordPathSource[key].to)
  787. // }
  788. // }
  789. // }
  790. }
  791. vTools.$env = {
  792. inWeiXin: vTools.isWeiXinBrower(),
  793. platform: vTools.isWeiXinBrower() ? 'wx' : 'app',
  794. operateSystem: vTools.androidOrIOS()
  795. }
  796. // iosApp全局注册内置方法
  797. if (!vTools.$env.inWeiXin && vTools.$env.operateSystem === 'ios') {
  798. vTools.iosAppFns()
  799. vTools.iosBackRefresh()
  800. }
  801. /*
  802. * 时间格式化函数(将时间格式化为,2019年08月12日,2019-08-12,2019/08/12的形式)
  803. *
  804. *
  805. * pattern参数(想要什么格式的数据就传入什么格式的数据)
  806. * · 'yyyy-MM-dd' ---> 输出如2019-09-20
  807. * · 'yyyy-MM-dd hh:mm' ---> 输出如2019-09-20 08:20
  808. * · 'yyyy-MM-dd hh:mm:ss' ---> 输出如2019-09-20 08:20:23
  809. * · 'yyyy/MM/dd' ---> 输出如2019/09/20
  810. * · 'yyyy年MM月dd日' ---> 输出如2019年09月20日
  811. * · 'yyyy年MM月dd日 hh时mm分' ---> 输出如2019年09月20日 08时20分
  812. * · 'yyyy年MM月dd日 hh时mm分ss秒' ---> 输出如2019年09月20日 08时20分23秒
  813. * · 'yyyy年MM月dd日 hh时mm分ss秒 EE' ---> 输出如2019年09月20日 08时20分23秒 周二
  814. * · 'yyyy年MM月dd日 hh时mm分ss秒 EEE' ---> 输出如2019年09月20日 08时20分23秒 星期二
  815. *
  816. * 参考: https://www.cnblogs.com/mr-wuxiansheng/p/6296646.html
  817. */
  818. Date.prototype.pattern = function (fmt) {
  819. var o = {
  820. 'y+': this.getFullYear(),
  821. 'M+': this.getMonth() + 1, //月份
  822. 'd+': this.getDate(), //日
  823. 'h+': this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, //小时
  824. 'H+': this.getHours(), //小时
  825. 'm+': this.getMinutes(), //分
  826. 's+': this.getSeconds(), //秒
  827. 'q+': Math.floor((this.getMonth() + 3) / 3), //季度
  828. 'S': this.getMilliseconds(), //毫秒
  829. 'E+': this.getDay(), // 周
  830. };
  831. var week = {
  832. '0': '日',
  833. '1': '一',
  834. '2': '二',
  835. '3': '三',
  836. '4': '四',
  837. '5': '五',
  838. '6': '六'
  839. };
  840. if (/(y+)/.test(fmt)) {
  841. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
  842. }
  843. if (/(E+)/.test(fmt)) {
  844. fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? '星期' : '周') : '') + week[
  845. this.getDay() + '']);
  846. }
  847. for (var k in o) {
  848. if (new RegExp('(' + k + ')').test(fmt)) {
  849. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k])
  850. .length)));
  851. }
  852. }
  853. return fmt;
  854. }