123456789101112131415161718192021222324252627282930313233343536373839
  1. /*获取当前页url*/
  2. function getCurrentPageUrl() {
  3. var pages = getCurrentPages() //获取加载的页面
  4. var currentPage = pages[pages.length - 1] //获取当前页面的对象
  5. var url = currentPage.route //当前页面url
  6. return url
  7. }
  8. /*获取当前页参数*/
  9. function getCurrentPageOptions() {
  10. var pages = getCurrentPages() //获取加载的页面
  11. var currentPage = pages[pages.length - 1] //获取当前页面的对象
  12. var options = currentPage.options //当前页面所有参数
  13. return options
  14. }
  15. /*获取当前页带参数的url*/
  16. function getCurrentPageUrlWithArgs() {
  17. var pages = getCurrentPages() //获取加载的页面
  18. var currentPage = pages[pages.length - 1] //获取当前页面的对象
  19. var url = currentPage.route //当前页面url
  20. var options = currentPage.options //如果要获取url中所带的参数可以查看options
  21. //拼接url的参数
  22. var urlWithArgs = url + '?'
  23. for (var key in options) {
  24. var value = options[key]
  25. urlWithArgs += key + '=' + value + '&'
  26. }
  27. urlWithArgs = urlWithArgs.substring(0, urlWithArgs.length - 1)
  28. return urlWithArgs
  29. }
  30. module.exports = {
  31. getCurrentPageUrl: getCurrentPageUrl,
  32. getCurrentPageUrlWithArgs: getCurrentPageUrlWithArgs,
  33. getCurrentPageOptions: getCurrentPageOptions
  34. }