doTask.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import MESSAGE_ENUM from '@/uilts/messageCenter/iframe/messageEnum'
  2. import messageCenter from '@/uilts/messageCenter/iframe'
  3. import { getQueryString } from '@/uilts/help'
  4. const iframeId = getQueryString('iframeId')
  5. // 做任务
  6. const doTask = {
  7. createTweet({ tweetId }, overTime) {
  8. return new Promise((res, rej) => {
  9. messageCenter.send({
  10. info: {
  11. actionType: MESSAGE_ENUM.IFRAME_DO_TASK_CREATE_TWEET,
  12. iframeId //用于告诉父窗口会传消息给哪个iframe
  13. },
  14. data: {
  15. tweetId
  16. },
  17. overTime,
  18. callback: (data) => {
  19. res(data);
  20. },
  21. failback: (e) => {
  22. rej(e)
  23. }
  24. })
  25. })
  26. },
  27. like({ tweetId }, overTime) {
  28. return new Promise((res, rej) => {
  29. messageCenter.send({
  30. info: {
  31. actionType: MESSAGE_ENUM.IFRAME_DO_TASK_LIKE,
  32. iframeId //用于告诉父窗口会传消息给哪个iframe
  33. },
  34. data: {
  35. tweetId,
  36. },
  37. overTime,
  38. callback: (data) => {
  39. res(data);
  40. },
  41. failback: (e) => {
  42. rej(e)
  43. }
  44. })
  45. })
  46. },
  47. follows({ follow_name, twitterUserId }, overTime) {
  48. return new Promise((res, rej) => {
  49. messageCenter.send({
  50. info: {
  51. actionType: MESSAGE_ENUM.IFRAME_DO_TASK_FOLLOWS,
  52. iframeId //用于告诉父窗口会传消息给哪个iframe
  53. },
  54. data: {
  55. follow_name,
  56. twitterUserId
  57. },
  58. overTime,
  59. callback: (data) => {
  60. res(data);
  61. },
  62. failback: (e) => {
  63. rej(e)
  64. }
  65. })
  66. })
  67. },
  68. reTweet({ tweetId }, overTime) {
  69. return new Promise((res, rej) => {
  70. messageCenter.send({
  71. info: {
  72. actionType: MESSAGE_ENUM.IFRAME_DO_TASK_RETWEET,
  73. iframeId //用于告诉父窗口会传消息给哪个iframe
  74. },
  75. data: {
  76. tweetId
  77. },
  78. overTime,
  79. callback: (data) => {
  80. res(data);
  81. },
  82. failback: (e) => {
  83. rej(e)
  84. }
  85. })
  86. })
  87. }
  88. }
  89. export default doTask
  90. // iframe > dom id
  91. // iframe > createTweet dom id