小程序链接助手

status.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // pages/status/status.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. type: 1,//1:有倒计时
  9. openId: '',
  10. target: '',//生成的连接
  11. url: '',//上级页面时二维码时,只需要有图片地址
  12. word: '',
  13. post: '',//上级页面是小程序,主图
  14. app_id: '',
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. this.setData({
  21. openId: wx.getStorageSync('userInfo').openId,
  22. url: options.url,
  23. word:wx.getStorageSync('introduce'),
  24. post:options.post,
  25. app_id:options.app_id,
  26. path:options.path
  27. })
  28. this.getUrl();
  29. },
  30. getUrl() {
  31. var info = wx.getStorageSync('shopInfo')
  32. var item = {};
  33. if(this.data.url) {
  34. item = {
  35. title: this.data.word,
  36. author: '👇👇👇',
  37. digest: '',
  38. content_source_url: '',
  39. thumb_url: this.data.url,
  40. content: ('<div style="text-align:center;"><img data-src="'+this.data.url+'" src="'+this.data.url+'" alt="" style="height:auto;"><div>↑↑ 长按上方识别二维码 ↑↑</div></div>')
  41. }
  42. }else {
  43. item = {
  44. title: wx.getStorageSync('word'),
  45. author: wx.getStorageSync('author'),
  46. digest: '',
  47. content_source_url: '',
  48. thumb_url: info.imageUrl
  49. }
  50. var infoObj = wx.getStorageSync('programObj')
  51. if(this.data.post) {
  52. item.thumb_url = this.data.post
  53. item.content = '<div class="shop" style="padding: 20px 12px;"><img data-cropselx1="0" data-cropselx2="400" data-cropsely1="0" data-cropsely2="400" data-ratio="1" data-s="300,640" style="width:calc(100vw - 24px);height: auto;" src="'+this.data.post+'" alt="" class="icon"><div class="info" style="display: flex;justify-content: space-between;line-height: 40px;margin: 10px 0;"><section style="width:100%;overflow:hidden;margin-bottom: 20px;background: #f7f7f7;height: 72px;border-radius: 2px;line-height: 50px;font-size: 17px;"><img class="rich_pages" data-cropselx1="0" data-cropselx2="400" data-cropsely1="0" data-cropsely2="400" data-ratio="1" data-s="300,640" data-w="800" data-src="'+infoObj.app_logo_url+'" style="border-radius: 50px; margin-top: 11px; margin-left: 13px; pointer-events: none; width: 50px!important; height: auto!important; visibility: visible !important;" src="'+infoObj.app_logo_url+'" alt="图片"><section style="display: flex;width: 70%;white-space: nowrap;text-overflow: ellipsis;overflow: hidden;margin-top: -70px;margin-left: 76px;color:#434343;"><strong>'+infoObj.app_name+'</strong></section><a class="weapp_text_link js_weapp_entry" style="display:block;width:100%;line-height:72px;text-align: center;color:#fff;margin-top:-72px;opacity:0;" data-miniprogram-appid="'+this.data.app_id+'" data-miniprogram-path="'+this.data.path+'" href="" data-miniprogram-type="text" data-miniprogram-servicetype="">小程序跳转</a></section></div>'
  54. }else {
  55. item.content = '<div class="shop" style="padding: 20px 12px;"><img style="width:calc(100vw - 24px);height: auto;" src="'+info.imageUrl+'" alt="" class="icon"><div class="info" style="display: flex;justify-content: space-between;line-height: 40px;margin: 10px 0;"><div class="price" style="color: #ea445a;font-size: 14px;">券后​¥<span>'+info.couponAfterPrice+'</span></div><div class="type">'+info.platform+'</div></div><div class="title" style="font-size: 17px;font-weight: bold;line-height: 30px;">'+info.skuName+'</div><div style="width:100%;height:40px;border-radius:6px;background:#EA445A;color:#fff;"><a class="weapp_text_link js_weapp_entry" style="display:block;line-height:40px;text-align: center;color:#fff;" data-miniprogram-appid="'+info.xcx_app_id+'" data-miniprogram-path="'+info.xcx_url+'" data-miniprogram-nickname="'+info.platform+'" href="" data-miniprogram-type="text" data-miniprogram-servicetype="">小程序跳转</a></div></div>'
  56. }
  57. }
  58. this.setData({
  59. type: 1
  60. })
  61. app.func.req('/api/goods/resourceUrl', 'post', {
  62. 'article': item,
  63. 'openid': this.data.openId
  64. }, (res) => {
  65. wx.hideLoading()
  66. if(res && res.errno == 0){
  67. if(!res.rst.url) {
  68. this.setData({
  69. type: 3
  70. })
  71. wx.showToast({
  72. title: '链接生成错误',
  73. icon: 'none'
  74. })
  75. return;
  76. }
  77. //成功
  78. this.setData({
  79. target: res.rst.url,
  80. type: 2
  81. })
  82. }else {
  83. this.setData({
  84. type: 3
  85. })
  86. wx.showToast({
  87. title: res.err,
  88. icon: 'none'
  89. })
  90. }
  91. },()=>{
  92. wx.hideLoading()
  93. })
  94. },
  95. // 返回上个页面不刷新
  96. toBack() {
  97. if(this.data.url) {
  98. wx.redirectTo ({
  99. url: '/pages/qrcode/qrcode'
  100. })
  101. return;
  102. }else if(this.data.post) {
  103. wx.redirectTo({
  104. url: '/pages/applet/applet'
  105. })
  106. return;
  107. }
  108. wx.redirectTo ({
  109. url: '/pages/link/index'
  110. })
  111. },
  112. copy() {
  113. console.log(this.data.target)
  114. wx.setClipboardData({
  115. data: this.data.target
  116. })
  117. },
  118. onShareAppMessage() {
  119. }
  120. })