wxshare.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import util from './util';
  2. /**
  3. * 微信小程序分享功能。
  4. */
  5. var cfg = function(){
  6. let config = {
  7. ...(this.$tm.vx.store.state.tmVuetify.wxshareConfig_miniMp || {})
  8. };
  9. if (typeof config.query !== 'object') config.query = {};
  10. //获取当前路径。
  11. if(!config.path){
  12. let cur = getCurrentPages();
  13. config.path = cur[cur.length-1].route;
  14. config.path = (config.path[0]=='/'?'' : '/') + config.path;
  15. config.copyLink = config.path;
  16. }
  17. // util.httpUrlAddKey
  18. let query = ''
  19. for (const key in config.query) {
  20. if (config.hasOwnProperty.call(config.query, key)) {
  21. const element = config.query[key];
  22. query = util.httpUrlAddKey(query,key,element)
  23. }
  24. }
  25. config.copyLink = config.path = config.path+query;
  26. config.query = query;
  27. return config;
  28. }
  29. var sharebywx = {
  30. onShareAppMessage() {
  31. let cg = cfg.call(this)||{};
  32. return { ...cg}
  33. },
  34. onShareTimeline() {
  35. let cg = cfg.call(this) || {};
  36. return { ...cg }
  37. }
  38. }
  39. export default { sharebywx }