nova.wxs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. var novapath = function (tab,type) {
  2. var path = tab.pagePath;
  3. // 外部应用,检测Scheme:https:// http:// wxapp://
  4. if(path.indexOf("http")!=-1){
  5. switch (type) {
  6. case "module":
  7. return "h5view"
  8. break;
  9. case "path":
  10. return path
  11. break;
  12. default:
  13. break;
  14. }
  15. return false
  16. }
  17. if(path.indexOf("wxapp")!=-1){
  18. }
  19. // 内部应用,截取path第一位为module,后续为路径,?为参数
  20. // var plist = path.split("/")
  21. var rpath = path.split("?")[0]
  22. var paramstr = path.split("?")[1]
  23. if(type=="module"){
  24. return "comp"
  25. }
  26. if(type=="path"){
  27. return rpath
  28. }
  29. if(type=="tag"){ // 如:"/nova-zhiliang/pages/my/index" 转为组件名 "nova-zhiliang-pages-my-index"
  30. var tag = rpath.split("/").slice(1).join("-");
  31. return tag
  32. }
  33. if(type=="params"){
  34. if(paramstr){
  35. return params2Json(paramstr)
  36. }else{
  37. return {}
  38. }
  39. }
  40. return false
  41. }
  42. var params2Json = function(paramstr){
  43. var obj = {}, pairs = paramstr.split('&'), d = decodeURIComponent, name, value;
  44. pairs.forEach(function (pair) {
  45. pair = pair.split('=');
  46. name = d(pair[0]);
  47. value = d(pair[1]);
  48. obj[name] = value;
  49. });
  50. return obj;
  51. };
  52. var isDiypage = function (path){
  53. return path
  54. }
  55. var imageExtensions = ['.mp4', '.mov', '.m4v', '.3gp','.avi','.m3u8','.webm'];
  56. function isVideo(url) {
  57. var ext = url.slice(url.lastIndexOf('.')).toLowerCase();
  58. return imageExtensions.indexOf(ext) > -1;
  59. }
  60. module.exports = {
  61. novapath: novapath,
  62. isDiypage: isDiypage,
  63. isVideo:isVideo
  64. }