request.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. const app = getApp();
  2. const env = {
  3. NODE_ENV: 'dev',
  4. dev: {
  5. apiUrl: 'https://apitest.tongyu99.com'
  6. },
  7. prd: {
  8. apiUrl: 'https://apimall.zhiqiyun.com'
  9. // apiUrl: 'https://wlapi-pro-smartcity.123cx.com'
  10. },
  11. pota: {
  12. // apiUrl: 'http://192.168.110.248:7012' //y
  13. // apiUrl: 'http://192.168.110.97:7012' ,//w
  14. apiUrl:'http://192.168.110.109:7012',//w
  15. }
  16. }
  17. var header = {
  18. 'content-type': 'application/x-www-form-urlencoded',
  19. 'appId': 'ZQfMJBmiKkUKE0g',
  20. }
  21. /**小程序配置 */
  22. const publicss = {
  23. WX_GZH_APPID: 'wxc01ea0423e91d9e0',
  24. // WX_GZH_URI: 'http://zhly.zhiqiyun.com/pages/authorize/authorize', //本地
  25. WX_GZH_URI: 'http://lcweb.tongyu99.com/pages/authorize/authorize', //线上
  26. // domain_head:' http://zhly.zhiqiyun.com',
  27. domain_head: 'http://lcweb.tongyu99.com',
  28. picUrls: 'https://zhiqiyun.oss-cn-hangzhou.aliyuncs.com/static/', //图片地址
  29. 'mapLBSKEY': 'LVABZ-ZRC36-BWWS3-E6WJB-BVKZK-7DFP4',
  30. 'homeTopBgCode': '1001', //公共服务平台首页顶部banner位
  31. 'teseTopBgCode': '3001', //特色频道顶部banner位
  32. 'foodBannerCode': '5001', //特色美食顶部banner位
  33. 'hotelBannerCode': '4001', //酒店预订顶部banner位
  34. //产品的分类类型
  35. 'mpOtc': '20', //门票
  36. //信息发布code
  37. 'zwtz': 'zwtz_2', //政务通知
  38. 'ksggCode':'003',//考试公告
  39. 'zysxCode':'005'//注意事项
  40. }
  41. /*
  42. * 获取token
  43. */
  44. const getToken = (success) => {
  45. // let token = 'NYSQdiwsrMjGY2tGBqpSQjzeu34zXDUZw';
  46. let token = getStorage('AUTH_TOKENS');
  47. if (token) {
  48. success.call(this, token);
  49. return false;
  50. } else {
  51. loadToken(data => {
  52. success.call(this, data);
  53. });
  54. }
  55. }
  56. const loadToken = (success) => {
  57. let that = this
  58. uni.request({
  59. url: env[env.NODE_ENV].apiUrl + '/api/access_token',
  60. data: {},
  61. method: 'get',
  62. header: header,
  63. success(json) {
  64. if (json.statusCode !== 200) return msg(json.data.message);
  65. if (json.data.code !== 0) return msg(json.data.msg)
  66. setStorage('AUTH_TOKENS', json.data.data);
  67. success.call(that, json.data.data);
  68. },
  69. fail() {
  70. msg('access_token 获取失败');
  71. }
  72. })
  73. }
  74. const clearValueEmpty = (data) => {
  75. let keyValue = {};
  76. for (let key in data) {
  77. let value = typeof data[key];
  78. if (value == 'string' && value) {
  79. if (data[key] != 'undefined' && data[key] != " " && data[key] != undefined && data[key] != null) {
  80. keyValue[key] = data[key];
  81. }
  82. // keyValue[key] = data[key];
  83. } else if (value == 'number' && value != null) {
  84. keyValue[key] = data[key];
  85. } else if (value == 'boolean') {
  86. keyValue[key] = data[key];
  87. } else {
  88. if (data[key]) keyValue[key] = data[key];
  89. }
  90. }
  91. return keyValue;
  92. }
  93. /**
  94. * 公共请求
  95. *
  96. * @param {*} url 请求url
  97. * @param {*} data 请求参数
  98. * @param {*} method 请求方法
  99. * @param {*} success 成功函数
  100. * @param {*} isLoad 是否显示加载提示
  101. */
  102. const baseRequest = (url, data, method, success, isLoad) => {
  103. getToken(token => {
  104. if (isLoad) {
  105. loadIng('加载中');
  106. };
  107. header.authorityToken = token;
  108. if (url.indexOf('/v3') != -1) {
  109. header['content-type'] = 'application/json;charset=UTF-8'
  110. }
  111. if (url.indexOf('manage/v3') != -1) {
  112. header.authorityToken = getStorage('admin_authToken');
  113. }
  114. uni.request({
  115. url: env[env.NODE_ENV].apiUrl + url,
  116. // url: url,
  117. data: clearValueEmpty(data),
  118. method: method,
  119. header: header,
  120. success(json) {
  121. if (isLoad) {
  122. uni.hideLoading();
  123. }
  124. if (json.statusCode !== 200) return msg(json.data.message);
  125. if (json.data.code === 10021 || json.data.code === 10020) {
  126. removeStorage('AUTH_TOKENS');
  127. return redirectIndex();
  128. }
  129. if(json.data.code!==0&&json.data.msg=='答题次数已用完'){
  130. console.log('答题次数已用完')
  131. return alertMsg(json.data.msg,()=>{
  132. removeStorage('AUTH_TOKENS');
  133. redirectIndex();
  134. })
  135. }
  136. if (json.data.code !== 0) {
  137. return msg(json.data.msg)
  138. }
  139. let data = json.data.data;
  140. if (typeof data === 'string' && data.indexOf("{") === 0) {
  141. data = JSON.parse(data);
  142. }
  143. if (data == null) {
  144. data = {};
  145. }
  146. success.call(this, data);
  147. },
  148. fail() {
  149. if (isLoad) {
  150. uni.hideLoading();
  151. }
  152. },
  153. })
  154. })
  155. }
  156. const loadIng = (msg) => {
  157. uni.showLoading({
  158. title: msg,
  159. mask: true
  160. })
  161. }
  162. /**POST请求 */
  163. const postRequest = (url, data, success, isLoad) => {
  164. header['content-type'] = 'application/x-www-form-urlencoded'
  165. baseRequest(url, data, 'post', success, isLoad);
  166. }
  167. const postRequestLoding = (url, data, success, isLoding) => {
  168. header['content-type'] = 'application/x-www-form-urlencoded'
  169. baseRequest(url, data, 'post', success, false, isLoding);
  170. }
  171. /**GET请求 */
  172. const getRequest = (url, data, success, isLoad) => {
  173. header['content-type'] = 'application/x-www-form-urlencoded'
  174. baseRequest(url, data, 'get', success, isLoad);
  175. }
  176. /**Put请求 */
  177. const putRequest = (url, data, success, isLoad) => {
  178. header['content-type'] = 'application/x-www-form-urlencoded'
  179. baseRequest(url, data, 'put', success, isLoad)
  180. }
  181. const putRequestJson = (url, data, success, isLoad) => {
  182. header['content-type'] = 'application/json;charset=UTF-8'
  183. baseRequest(url, data, 'put', success, isLoad)
  184. }
  185. /**
  186. * 上传文件
  187. * @param {*} url 请求url
  188. * @param {*} data 携带数据
  189. * @param {*} success 请求成功函数
  190. */
  191. const uploadFile = (url, data, success, isLoad) => {
  192. // console.log(env[env.NODE_ENV].apiUrl + url, data)
  193. getToken(token => {
  194. if (isLoad) {
  195. loadIng('加载中');
  196. };
  197. uni.uploadFile({
  198. url: env[env.NODE_ENV].apiUrl + url,
  199. filePath: data,
  200. name: 'file',
  201. header: {
  202. 'appId': header['appId'],
  203. 'authorityToken': token
  204. },
  205. success(res) {
  206. uni.hideLoading();
  207. if (res.statusCode !== 200) {
  208. return msg('文件上传失败');
  209. }
  210. let data = JSON.parse(res.data);
  211. if (data.code !== 0) {
  212. return msg(data.msg);
  213. }
  214. success.call(this, data.data);
  215. },
  216. })
  217. })
  218. }
  219. /**弹窗 */
  220. const msg = (title, success) => {
  221. if (title) {
  222. uni.showToast({
  223. title: title,
  224. icon: 'none',
  225. success() {
  226. if (success) success.call(this);
  227. }
  228. });
  229. }
  230. return false;
  231. }
  232. const msgConfirm = (msg, success, cancel) => {
  233. uni.showModal({
  234. title: '提示',
  235. content: msg,
  236. success(res) {
  237. if (res.confirm) {
  238. success.call(this);
  239. } else {
  240. if (cancel) cancel.call(this);
  241. }
  242. }
  243. })
  244. }
  245. const msgConfirmText = (msg, confirmText, success, cancel) => {
  246. uni.showModal({
  247. title: '提示',
  248. content: msg,
  249. confirmText: confirmText,
  250. success(res) {
  251. if (res.confirm) {
  252. success.call(this);
  253. } else {
  254. if (cancel) cancel.call(this);
  255. }
  256. }
  257. })
  258. }
  259. const alertMsg = (msg, success) => {
  260. uni.showModal({
  261. title: '提示',
  262. content: msg,
  263. showCancel: false,
  264. success(res) {
  265. if (success) success.call(this);
  266. }
  267. })
  268. return false;
  269. }
  270. const load = msg => {
  271. uni.showLoading({
  272. title: msg,
  273. mask: true
  274. })
  275. }
  276. const g = (url, success, isLoad) => {
  277. getRequest(url, {}, success, isLoad)
  278. }
  279. const p = (url, success, isLoad) => {
  280. postRequest(url, {}, success, isLoad)
  281. }
  282. const send = (url, mobile, success, error) => {
  283. if (!mobile) {
  284. return msg('手机号码不能为空', error);
  285. }
  286. postRequest(url, {
  287. phone: mobile
  288. }, json => {
  289. if (json.code !== 0) {
  290. return msg(json.msg, error);
  291. }
  292. let time = 60;
  293. const initTime = setInterval(() => {
  294. time--;
  295. if (time > 0) {
  296. success.call(this, time + '秒后获取');
  297. } else {
  298. clearInterval(initTime);
  299. success.call(this, '获取验证码');
  300. }
  301. }, 1000)
  302. })
  303. }
  304. // 登陆拦截
  305. const redirectIndex = (params) => {
  306. uni.clearStorageSync();
  307. var pages = getCurrentPages();
  308. let currentUrl;
  309. if (pages) {
  310. var currentPage = pages[pages.length - 1];
  311. if (currentPage) {
  312. currentUrl = currentPage.route;
  313. let query = currentPage.query;
  314. if (query) {
  315. for (let key in query) {
  316. const fo = key + '=' + query[key];
  317. currentUrl += currentUrl.indexOf('?') > -1 ? '&' + fo : '?' + fo;
  318. }
  319. }
  320. if (currentUrl) {
  321. console.log('currentUrl》》》》》', currentUrl);
  322. setStorage("REDIRECT_URL", '/' + currentUrl)
  323. if (currentUrl == 'pages/login/login') {
  324. console.log('当前已经处于登录页面,不在向下执行跳转');
  325. return
  326. }
  327. }
  328. }
  329. }
  330. let redirectUrl = '/pages/login/login' + (params ? params : '');
  331. uni.reLaunch({
  332. url: redirectUrl
  333. })
  334. return false;
  335. }
  336. const saveImage = (url) => {
  337. uni.saveImageToPhotosAlbum({
  338. filePath: url,
  339. success() {
  340. msg('图片保存成功');
  341. }
  342. })
  343. }
  344. const saveImageToPhotosAlbum = (url) => {
  345. if (!url) return msg('小程序码不存在');
  346. uni.getImageInfo({
  347. src: url,
  348. success(json) {
  349. // uni.getSetting({
  350. // success(res) {
  351. // if (!res.authSetting['scope.writePhotosAlbum']) {
  352. // uni.authorize({
  353. // scope: 'scope.writePhotosAlbum',
  354. // success() {
  355. // saveImage(json.path);
  356. // }
  357. // })
  358. // } else {
  359. // saveImage(json.path);
  360. // }
  361. // }
  362. // })
  363. }
  364. })
  365. }
  366. const getConfig = (config, id) => {
  367. let con = {};
  368. config.info.forEach(inf => {
  369. // console.log(inf.version, inf.version ? inf.version.indexOf(id) : '-')
  370. if (inf.isSet && (!inf.version || inf.version.indexOf(id) > -1))
  371. con[inf.setName] = inf.setDefault;
  372. });
  373. config.card.forEach(inf => {
  374. if (inf.isSet && (!inf.version || inf.version.indexOf(id) > -1))
  375. con[inf.setName] = inf.setDefault;
  376. });
  377. config.realTime.forEach(inf => {
  378. if (inf.isSet && (!inf.version || inf.version.indexOf(id) > -1))
  379. con[inf.setName] = inf.setDefault;
  380. });
  381. return con;
  382. }
  383. const isLogin = async (error) => {
  384. let userInfo = getStorage('userInfo');
  385. if (!userInfo || !userInfo.id) {
  386. if (error) return false;
  387. // console.log("第一次执行")
  388. return redirectIndex();
  389. }
  390. return true;
  391. }
  392. //检测是否登录
  393. const isLogins = (isGoLogin) => {
  394. let userInfo = getStorage('userInfo');
  395. if (!userInfo) {
  396. if (isGoLogin) {
  397. redirectIndex();
  398. }
  399. return false;
  400. }
  401. return true;
  402. }
  403. /**
  404. * 退出登录
  405. */
  406. const outLogin = () => {
  407. uni.clearStorageSync();
  408. isLogins(true);
  409. }
  410. const setStorage = (key, value) => {
  411. uni.setStorageSync(env.NODE_ENV + "_" + key, value)
  412. }
  413. const getStorage = (key) => {
  414. return uni.getStorageSync(env.NODE_ENV + "_" + key)
  415. }
  416. const removeStorage = (key) => {
  417. return uni.removeStorageSync(env.NODE_ENV + "_" + key);
  418. }
  419. function isWeixin() {
  420. let ua = window.navigator.userAgent.toLowerCase()
  421. // 通过正则表达式匹配ua中是否含有MicroMessenger字符串
  422. if (ua.match(/MicroMessenger/i) == 'micromessenger') {
  423. return true;
  424. } else {
  425. return false;
  426. }
  427. }
  428. const payOrder = (id, type, success) => {
  429. let isShowLoading = false;
  430. if (!isShowLoading) {
  431. loadIng('加载中');
  432. isShowLoading = true;
  433. }
  434. var loctionAddressMap = getStorage('loctionAddressMap');
  435. var datas = {
  436. id: id
  437. };
  438. if (loctionAddressMap) {
  439. datas.province = loctionAddressMap.province;
  440. datas.city = loctionAddressMap.city;
  441. };
  442. datas.payChannel = 'wx_pub';
  443. postRequest('/api/order/weixin/pay', datas, json => {
  444. //下单完成后,调用验证
  445. if (isWeixin()) {
  446. checkWXJs(id, json, type, success);
  447. }
  448. })
  449. }
  450. //微信支付订单公共方法
  451. // const payOrder = (id, success) => {
  452. // let isShowLoading = false;
  453. // if (!isShowLoading) {
  454. // loadIng('加载中');
  455. // isShowLoading = true;
  456. // }
  457. // var loctionAddressMap = getStorage('loctionAddressMap');
  458. // var datas = {
  459. // id: id
  460. // };
  461. // if (loctionAddressMap) {
  462. // datas.province = loctionAddressMap.province;
  463. // datas.city = loctionAddressMap.city;
  464. // };
  465. // postRequest('/api/order/weixin/pay', datas, json => {
  466. // // console.log(json)
  467. // if (json.type === 2 || json.type === 3) {
  468. // //调用后台判断订单是否支付成功
  469. // let i = 0;
  470. // let timer = setInterval(() => {
  471. // postRequest('/api/order/check', {
  472. // id: id
  473. // }, res => {
  474. // if (res.isSuccess || i === 4) {
  475. // clearInterval(timer);
  476. // success.call(this, res.isSuccess);
  477. // } else {
  478. // i++;
  479. // }
  480. // }, true)
  481. // }, 200);
  482. // // success.call(this);
  483. // return false;
  484. // }
  485. // uni.requestPayment({
  486. // timeStamp: json.timeStamp,
  487. // nonceStr: json.nonceStr,
  488. // package: json.packages,
  489. // signType: json.signType,
  490. // paySign: json.sign,
  491. // success: function() {
  492. // console.log('支付成功')
  493. // let i = 0;
  494. // let timer = setInterval(() => {
  495. // postRequest('/api/order/check', {
  496. // id: id
  497. // }, res => {
  498. // console.log(i)
  499. // if (res.isSuccess || i === 5) {
  500. // clearInterval(timer);
  501. // success.call(this, res.isSuccess);
  502. // } else {
  503. // i++;
  504. // }
  505. // }, true)
  506. // }, 500);
  507. // },
  508. // fail: function(res) {
  509. // console.log('支付失败')
  510. // postRequest('/api/order/cancelPay', {
  511. // id: id
  512. // }, data => {
  513. // uni.redirectTo({
  514. // url: '/mine/orderDet/orderDet?id=' + id,
  515. // })
  516. // })
  517. // console.log(res);
  518. // }
  519. // })
  520. // if (isShowLoading) {
  521. // uni.hideLoading();
  522. // isShowLoading = false;
  523. // }
  524. // })
  525. // }
  526. const authSetting = (authority, success, error) => {
  527. // console.log(authority,success)
  528. // #ifndef H5
  529. uni.getSetting({
  530. success(res) {
  531. if (res.authSetting[authority]) {
  532. success.call(this);
  533. return false;
  534. }
  535. uni.authorize({
  536. scope: authority,
  537. success() {
  538. success.call(this);
  539. },
  540. fail: function(res) {
  541. error.call(this);
  542. }
  543. })
  544. }
  545. })
  546. // #endif
  547. }
  548. const getLocation = (suss) => {
  549. // #ifndef H5
  550. authSetting('scope.userLocation', () => {
  551. // load('定位中…');
  552. uni.getLocation({
  553. type: 'gcj02',
  554. isHighAccuracy: true,
  555. success: function(res) {
  556. // uni.hideLoading();
  557. setStorage('cLocation', res);
  558. console.log(res, "789")
  559. suss.call(this, res);
  560. },
  561. fail: function(res) {
  562. console.log("调用失败", res)
  563. suss.call(this, 2)
  564. // uni.hideLoading();
  565. }
  566. })
  567. }, () => {
  568. // uni.hideLoading();
  569. console.log("取消")
  570. suss.call(this, 1)
  571. });
  572. // #endif
  573. // #ifdef H5
  574. uni.getLocation({
  575. type: 'gcj02',
  576. isHighAccuracy: true,
  577. success: function(res) {
  578. console.log("缓存当前位置的经纬度>>>>>>>", res)
  579. //缓存当前位置的经纬度
  580. setStorage('cLocation', res);
  581. suss.call(this, res, "789");
  582. },
  583. fail: function(res) {
  584. console.log("调用失败", res)
  585. suss.call(this, 2)
  586. }
  587. })
  588. // #endif
  589. }
  590. const scopeAddress = (success) => {
  591. authSetting('scope.address', () => {
  592. uni.chooseAddress({
  593. success: function(res) {
  594. success.call(this, res);
  595. },
  596. })
  597. }, () => {
  598. msg('未设置开放权限')
  599. });
  600. }
  601. const isAuth = () => {
  602. const user = getStorage('userInfo');
  603. return user && user.id;
  604. }
  605. // 去掉字符串中的特殊字符和转义字符
  606. const excludeSpecial = (s) => {
  607. // 去掉转义字符
  608. // s = s.replace(/[\'\"\\\/\b\f\n\r\t]/g, '');
  609. const pattern = /[`~!@#$^&*()=|{}':;',\\\[\]\.<>\/?~!@#¥……&*()——|{}【】';:""' + - - _ % 。,、?\s]/g;
  610. if (s != undefined || s != null) {
  611. s = s.replace(pattern, "")
  612. }
  613. return s;
  614. }
  615. const checkWXJs = (id, payJson, payType, success) => {
  616. var url = window.location.href;
  617. console.log('当前URL地址数据====', url);
  618. getRequest('/api/getWeiXinJsApiInfo', {
  619. url: url
  620. }, res => {
  621. jWeixin.config({
  622. debug: false, // 开启调试模式
  623. appId: res.appId, // 必填,公众号的唯一标识
  624. timestamp: res.timestamp, // 必填,生成签名的时间戳
  625. nonceStr: res.nonceStr, // 必填,生成签名的随机串
  626. signature: res.signature, // 必填,签名
  627. jsApiList: [
  628. 'chooseWXPay', //
  629. ]
  630. });
  631. jWeixin.ready(function() {
  632. jWeixin.chooseWXPay({
  633. timestamp: payJson
  634. .timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
  635. nonceStr: payJson.nonceStr, // 支付签名随机串,不长于 32 位
  636. package: payJson.packages, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
  637. signType: payJson.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
  638. paySign: payJson.sign, // 支付签名
  639. success: function(res) {
  640. console.log('支付成功')
  641. // 支付成功后的回调函数
  642. try {
  643. let i = 0;
  644. let timer = setInterval(() => {
  645. postRequest('/api/order/check', {
  646. id: id
  647. }, res => {
  648. console.log(i)
  649. if (res.isSuccess || i === 5) {
  650. clearInterval(timer);
  651. uni.hideLoading();
  652. success.call(this, res.isSuccess);
  653. } else {
  654. i++;
  655. }
  656. }, true)
  657. }, 500);
  658. } catch (e) {
  659. uni.hideLoading();
  660. }
  661. },
  662. fail: function(res) {
  663. uni.hideLoading();
  664. console.log('支付失败', res)
  665. postRequest('/api/order/cancelPay', {
  666. id: id
  667. }, data => {
  668. if (payType == 'activity') {
  669. } else {
  670. uni.redirectTo({
  671. url: '/mine/orderDet/orderDet?id=' + id,
  672. })
  673. }
  674. })
  675. }
  676. });
  677. });
  678. },
  679. true
  680. );
  681. }
  682. // 获取用户行为操作
  683. const getBehavior = (id, behavior, type, success) => {
  684. let params = {
  685. bindId: id,
  686. behavior: behavior,
  687. type: type
  688. }
  689. getRequest('/api/v3/behavior/have', params, res => {
  690. success.call(this, res)
  691. })
  692. }
  693. // 获取用户行为操作数量
  694. const getBehaviorCount = (id, behavior, type, success) => {
  695. let params = {
  696. bindId: id,
  697. behavior: behavior,
  698. type: type
  699. }
  700. getRequest('/api/v3/behavior/count', params, res => {
  701. success.call(this, res)
  702. })
  703. }
  704. //格式化时间
  705. const dateFormat = (dat)=>{
  706. var dat = new Date(dat)
  707. //获取年月日,时间
  708. var year = dat.getFullYear();
  709. var mon = (dat.getMonth()+1) < 10 ? "0"+(dat.getMonth()+1) : dat.getMonth()+1;
  710. var data = dat.getDate() < 10 ? "0"+(dat.getDate()) : dat.getDate();
  711. var hour = dat.getHours() < 10 ? "0"+(dat.getHours()) : dat.getHours();
  712. var min = dat.getMinutes() < 10 ? "0"+(dat.getMinutes()) : dat.getMinutes();
  713. var seon = dat.getSeconds() < 10 ? "0"+(dat.getSeconds()) : dat.getSeconds();
  714. var a = new Array("日", "一", "二", "三", "四", "五", "六");
  715. var week = dat.getDay();
  716. var str = "星期"+ a[week];
  717. // 获取当前小时
  718. var hours = dat.getHours();
  719. // 设置默认文字
  720. var text = ``;
  721. console.log(hours)
  722. // 判断当前时间段
  723. if (hours >= 0 && hours <= 9) {
  724. text = `早上`;
  725. } else if (hours > 9 && hours <= 13) {
  726. text = `中午`;
  727. } else if (hours > 13 && hours <= 17) {
  728. text = `下午`;
  729. } else if (hours > 17 && hours <= 24) {
  730. text = `晚上`;
  731. }
  732. var newDate = {
  733. v1:year +"-"+ mon +"-"+ data +" "+ hour +":"+ min +":"+ seon,
  734. v2:year +"/"+ mon +"/"+ data +" "+ hour +":"+ min +":"+ seon,
  735. v3:year +"/"+ mon +"/"+ data,
  736. v4:year +"年"+ mon +"月"+ data +"日",
  737. v5:year +"-"+ mon +"-"+ data,
  738. week:str,
  739. text:text
  740. };
  741. return newDate;
  742. }
  743. module.exports = {
  744. setStorage: setStorage,
  745. getStorage: getStorage,
  746. postRequest: postRequest,
  747. postRequestLoding: postRequestLoding,
  748. getRequest: getRequest,
  749. putRequest: putRequest,
  750. putRequestJson: putRequestJson,
  751. msg: msg,
  752. g: g,
  753. p: p,
  754. env: env,
  755. send: send,
  756. redirectIndex: redirectIndex,
  757. saveImage: saveImage,
  758. saveImageToPhotosAlbum: saveImageToPhotosAlbum,
  759. uploadFile: uploadFile,
  760. msgConfirm: msgConfirm,
  761. getConfig: getConfig,
  762. load: load,
  763. isLogin: isLogin,
  764. isLogins: isLogins,
  765. payOrder: payOrder,
  766. getLocation: getLocation,
  767. scopeAddress: scopeAddress,
  768. isAuth: isAuth,
  769. alertMsg: alertMsg,
  770. getToken: getToken,
  771. loadIng: loadIng,
  772. removeStorage: removeStorage,
  773. public: publicss,
  774. header: header,
  775. excludeSpecial: excludeSpecial,
  776. msgConfirmText: msgConfirmText,
  777. isWeixin: isWeixin,
  778. checkWXJs: checkWXJs,
  779. getBehavior: getBehavior,
  780. getBehaviorCount: getBehaviorCount,
  781. outLogin: outLogin,
  782. dateFormat:dateFormat
  783. }