微信

util.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import wechatConfig from '@/config/index'
  2. const toolClass = {
  3. dateFormat: (timestamp) => {
  4. let date = new Date(timestamp)
  5. let y = date.getFullYear()
  6. let m = date.getMonth() + 1
  7. let d = date.getDate()
  8. let h = date.getHours()
  9. let min = date.getMinutes()
  10. if (m < 10) {
  11. m = '0' + m
  12. }
  13. if (d < 10) {
  14. d = '0' + d
  15. }
  16. if (h < 10) {
  17. h = '0' + h
  18. }
  19. if (min < 10) {
  20. min = '0' + min
  21. }
  22. return y + '-' + m + '-' + d + ' ' + h + ':' + min
  23. },
  24. dateFormatM: (timestamp) => {
  25. let date = new Date(timestamp)
  26. let m = date.getMonth() + 1
  27. let d = date.getDate()
  28. let h = date.getHours()
  29. let min = date.getMinutes()
  30. if (m < 10) {
  31. m = '0' + m
  32. }
  33. if (d < 10) {
  34. d = '0' + d
  35. }
  36. if (h < 10) {
  37. h = '0' + h
  38. }
  39. if (min < 10) {
  40. min = '0' + min
  41. }
  42. return m + '-' + d + ' ' + h + ':' + min
  43. },
  44. UrlSearch: (urls) => {
  45. let url = urls // 获取url中"?"符后的字串
  46. let theRequest = {}
  47. if (url.indexOf('?') !== -1) {
  48. let str = url.substr(1)
  49. let strs = str.split('&')
  50. for (var i = 0; i < strs.length; i++) {
  51. theRequest[strs[i].split('=')[0]] = unescape(strs[i].split('=')[1])
  52. }
  53. }
  54. return theRequest
  55. },
  56. getCode: (appid) => {
  57. let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${wechatConfig.redirect_uri}&response_type=${wechatConfig.response_type}&scope=${wechatConfig.scope}&state=${wechatConfig.state}#wechat_redirect`
  58. window.location.href = url
  59. }
  60. }
  61. export default toolClass