扩展链接高佣版

index.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // pages/link/index.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. keyword: '',
  9. searchKeyword: '',
  10. openId: '',
  11. word: '',
  12. author: '',
  13. text: ''
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. this.setData({
  20. keyword: this.options.word,
  21. openId: wx.getStorageSync('userInfo').openId,
  22. word: wx.getStorageSync('word'),
  23. author: wx.getStorageSync('author')
  24. })
  25. this.getText();
  26. // 上级目录是word时,使用保存的word
  27. if(options.from) {
  28. this.setData({
  29. keyword: wx.getStorageSync('keyword')
  30. })
  31. }
  32. !this.data.word&&this.getword(0);
  33. !this.data.author&&this.getword(1);
  34. },
  35. getText() {
  36. wx.showLoading({
  37. title: '加载中',
  38. })
  39. app.func.req('/api/app/config', 'get', {
  40. 'version': '1.0.1'
  41. }, (res) => {
  42. wx.hideLoading()
  43. if(res && res.errno == 0){
  44. this.setData({
  45. text: res.rst.platform
  46. })
  47. }else {
  48. wx.showToast({
  49. title: res.err,
  50. icon: 'none',
  51. duration: 2000
  52. })
  53. }
  54. },()=>{
  55. wx.hideLoading()
  56. })
  57. },
  58. getCopy() {
  59. var that = this;
  60. wx.getClipboardData({
  61. success (res){
  62. that.setData({
  63. keyword: res.data
  64. })
  65. }
  66. })
  67. },
  68. getKeyword(e) {
  69. this.setData({
  70. searchKeyword: e.detail.value,
  71. keyword: e.detail.value
  72. })
  73. },
  74. clearAll() {
  75. this.setData({
  76. keyword: ''
  77. })
  78. },
  79. toWord(e) {
  80. // 保存关键词
  81. wx.setStorageSync('keyword',this.data.keyword)
  82. wx.redirectTo({
  83. url: '/pages/word/word?from='+e.currentTarget.dataset.type+'&word='+this.data.word+'&author='+this.data.author
  84. })
  85. },
  86. // 获取链接
  87. getUrl(content) {
  88. var content = this.data.keyword;
  89. if(!content) {
  90. wx.showToast({
  91. title: '内容不能为空',
  92. icon: 'none'
  93. })
  94. return;
  95. }
  96. wx.showLoading({
  97. title: '加载中',
  98. })
  99. app.func.req('/api/goods/goods_info', 'post', {
  100. 'url': content
  101. }, (res) => {
  102. wx.hideLoading()
  103. if(res && res.errno == 0){
  104. //成功
  105. wx.setStorageSync('shopInfo',res.rst)
  106. setTimeout(() => {
  107. wx.redirectTo({
  108. url: '/pages/status/status'
  109. })
  110. },400)
  111. }else {
  112. wx.showToast({
  113. title: res.err?res.err:'服务器错误',
  114. icon: 'none',
  115. duration: 2000
  116. })
  117. }
  118. },()=>{
  119. wx.showToast({
  120. title: '链接转换失败',
  121. icon: 'none',
  122. duration: 2000
  123. })
  124. wx.hideLoading()
  125. })
  126. },
  127. // 没有本地词,从列表中获取----默认引导词
  128. getword(type) {
  129. app.func.req('/api/article/getGuideWords', 'get', {
  130. 'type': type
  131. }, (res) => {
  132. wx.hideLoading()
  133. if(res && res.errno == 0){
  134. if(type==0) {
  135. this.setData({
  136. word: res.rst.data[0].keyword
  137. })
  138. wx.setStorageSync('word',res.rst.data[0].keyword)
  139. }else {
  140. //成功
  141. this.setData({
  142. author: res.rst.data[0].keyword
  143. })
  144. wx.setStorageSync('author',res.rst.data[0].keyword)
  145. }
  146. }else {
  147. wx.showToast({
  148. title: res.err,
  149. icon: 'none',
  150. duration: 2000
  151. })
  152. }
  153. },()=>{
  154. wx.hideLoading()
  155. })
  156. },
  157. onShareAppMessage() {
  158. }
  159. })