扩展链接高佣版

word.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // pages/checkTitle/checkTitle.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. myWordList: [],
  9. wordList: [],
  10. keyword: '',
  11. word: '',
  12. type: 0,
  13. author: '',
  14. from: '',//当上级页面时二维码是有值
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. this.setData({
  21. type: options.type,
  22. author: options.author,
  23. word: options.word,
  24. openId: wx.getStorageSync('userInfo').openId,
  25. from: options.from //来源 2是二维码转换 1是作者名字 0是引导词
  26. })
  27. var params = options.from==0?'word':'author'
  28. this.setData({
  29. keyword: wx.getStorageSync(params)
  30. })
  31. this.data.from=='qrcode'&&this.setData({
  32. type: 2
  33. })
  34. // type:0 引导词 1:作者名字
  35. this.getword();
  36. this.getMyWord();
  37. },
  38. getMyWord() {
  39. wx.showLoading({
  40. title: '加载中',
  41. })
  42. app.func.req('/api/article/getMyWords', 'get', {
  43. 'openid': this.data.openId
  44. }, (res) => {
  45. wx.hideLoading()
  46. if(res && res.errno == 0){
  47. //成功
  48. this.setData({
  49. myWordList: res.rst.data
  50. })
  51. }else {
  52. wx.showToast({
  53. title: res.err,
  54. icon: 'none',
  55. duration: 2000
  56. })
  57. }
  58. },()=>{
  59. wx.hideLoading()
  60. })
  61. },
  62. getword() {
  63. app.func.req('/api/article/getGuideWords', 'get', {
  64. 'type': this.data.from
  65. }, (res) => {
  66. wx.hideLoading()
  67. if(res && res.errno == 0){
  68. //成功
  69. this.setData({
  70. wordList: res.rst.data
  71. })
  72. }else {
  73. wx.showToast({
  74. title: res.err,
  75. icon: 'none',
  76. duration: 2000
  77. })
  78. }
  79. },()=>{
  80. wx.hideLoading()
  81. })
  82. },
  83. getKeyword(e) {
  84. this.setData({
  85. keyword: e.detail.value
  86. })
  87. },
  88. saveWord() {
  89. app.func.req('/api/article/addWord', 'post', {
  90. 'keyword': this.data.keyword
  91. }, (res) => {
  92. wx.hideLoading()
  93. if(res && res.errno == 0){
  94. //成功
  95. wx.showToast({
  96. title: '引导词保存成功',
  97. })
  98. this.getMyWord();
  99. }else {
  100. wx.showToast({
  101. title: res.err,
  102. icon: 'none',
  103. duration: 2000
  104. })
  105. }
  106. },()=>{
  107. wx.hideLoading()
  108. })
  109. },
  110. // 选择内容
  111. checkWord(e) {
  112. wx.pageScrollTo({
  113. scrollTop: 0,
  114. duration: 300
  115. })
  116. this.setData({
  117. keyword: e.currentTarget.dataset.word
  118. })
  119. },
  120. toLink(e) {
  121. var word = e.currentTarget.dataset.word?e.currentTarget.dataset.word:this.data.keyword
  122. switch (this.data.from) {
  123. case '0':
  124. wx.setStorageSync('word',word)
  125. wx.redirectTo({
  126. url: this.data.type=='program'?'/pages/appletEdit/appletEdit?from=word':'/pages/link/index?from=word'
  127. })
  128. break;
  129. case '1':
  130. wx.setStorageSync('author',word)
  131. wx.redirectTo({
  132. url: this.data.type=='program'?'/pages/appletEdit/appletEdit?from=word':'/pages/link/index?from=word'
  133. })
  134. break;
  135. case '2':
  136. wx.setStorageSync('introduce',word)
  137. wx.redirectTo({
  138. url: '/pages/qrcode/qrcode?from=word'
  139. })
  140. break;
  141. default:
  142. break;
  143. }
  144. },
  145. delWord(e) {
  146. app.func.req('/api/article/delWord', 'post', {
  147. 'keyword': e.currentTarget.dataset.word
  148. }, (res) => {
  149. wx.hideLoading()
  150. if(res && res.errno == 0){
  151. //成功
  152. wx.showToast({
  153. title: '删除词库成功',
  154. })
  155. this.getMyWord();
  156. }else {
  157. wx.showToast({
  158. title: res.err,
  159. icon: 'none',
  160. duration: 2000
  161. })
  162. }
  163. },()=>{
  164. wx.hideLoading()
  165. })
  166. },
  167. onShareAppMessage() {
  168. }
  169. })