request.js 20 KB

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