shareAppMessage.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import {objectToUrlParams} from "./utils";
  2. import request from "../core/request.js";
  3. import api from "../core/appOnLaunch.js";
  4. import $store from "../store/index.js";
  5. const shareAppMessage = function(args) {
  6. console.log(args);
  7. args = args || {
  8. title: '这是一个分享页面',
  9. path: '/pages/index/index',
  10. params: {}
  11. };
  12. if (typeof args.params === 'undefined') {
  13. args.params = {};
  14. }
  15. // #ifdef MP-ALIPAY
  16. if (typeof args.imageUrl !== 'undefined') {
  17. args.bgImgUrl = args.imageUrl;
  18. }
  19. // #endif
  20. let user_id = 0;
  21. if (this.$user.isLogin() && this.$store.state.user.info) {
  22. user_id = this.$store.state.user.info.options.user_id;
  23. }
  24. if (typeof args.path === 'undefined' || (args.path === '/pages/index/index' && typeof args.params.page_id === 'undefined')) {
  25. args.path = `/pages/index/index?user_id=${user_id}`;
  26. if (Object.keys(args.params).length != 0) {
  27. args.path += `&` + objectToUrlParams(args.params);
  28. }
  29. } else {
  30. args.params.path = args.path;
  31. args.params.user_id = user_id;
  32. args.path = `/pages/index/index?scene=share&user_id=${user_id}&params=${JSON.stringify(args.params)}`;
  33. }
  34. setTimeout(() => {
  35. request({
  36. url: api.coupon.share_coupon,
  37. }).then(response => {
  38. if (response.code === 0) {
  39. let coupon = {
  40. list: response.data.list,
  41. type: 'share'
  42. };
  43. $store.dispatch('page/actionSetCoupon', coupon);
  44. }
  45. }).catch(e => {
  46. });
  47. },1000);
  48. console.log(args);
  49. return args;
  50. };
  51. export default shareAppMessage;