小程序链接助手

index.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // pages/subscription/index.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. warrantFlag:false,
  9. wxList: [],
  10. pages: 1,
  11. page: 1,
  12. keyword: '',
  13. total: 0
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. this.getList();
  20. },
  21. getList(e) {
  22. e&&(this.setData({
  23. page: 1,
  24. wxList: []
  25. }))
  26. wx.showLoading({
  27. title: '加载中',
  28. })
  29. app.func.req('/api/historyLink/list', 'get', {
  30. 'keyword': this.data.keyword,
  31. 'page': this.data.page,
  32. 'page_size': 20,
  33. }, (res) => {
  34. wx.hideLoading()
  35. if(res && res.errno == 0){
  36. //成功
  37. this.setData({
  38. wxList: this.data.wxList.concat(res.rst.data),
  39. page: res.rst.pageInfo.page,
  40. pages: res.rst.pageInfo.pages,
  41. total: res.rst.pageInfo.total
  42. })
  43. }else {
  44. wx.showToast({
  45. title: res.err,
  46. icon: 'none',
  47. duration: 2000
  48. })
  49. }
  50. },()=>{
  51. wx.hideLoading()
  52. })
  53. },
  54. toDel(e) {
  55. wx.showLoading({
  56. title: '加载中',
  57. })
  58. app.func.req('/api/historyLink/delete', 'get', {
  59. 'link_id': e.currentTarget.dataset.link
  60. }, (res) => {
  61. wx.hideLoading()
  62. if(res && res.errno == 0){
  63. //成功
  64. wx.showToast({
  65. title: '删除成功',
  66. })
  67. this.setData({
  68. page: 1,
  69. wxList: []
  70. })
  71. this.getList();
  72. }else {
  73. wx.showToast({
  74. title: res.err?res.err:'服务器错误',
  75. icon: 'none',
  76. duration: 2000
  77. })
  78. }
  79. },()=>{
  80. console.log(res)
  81. wx.hideLoading()
  82. })
  83. },
  84. getKeyword(e) {
  85. this.setData({
  86. keyword: e.detail.value
  87. })
  88. },
  89. copyEvent(e){//点击复制
  90. var that = this;
  91. if(!e.currentTarget.dataset.link) {
  92. wx.showToast({
  93. title: '无效链接',
  94. icon: 'none'
  95. })
  96. return;
  97. }
  98. wx.setClipboardData({
  99. data: e.currentTarget.dataset.link,
  100. success: function (res) {
  101. wx.getClipboardData({
  102. success: function (res) {
  103. wx.showToast({
  104. title: '复制成功'
  105. })
  106. that.setData({
  107. isShow: false
  108. })
  109. }
  110. })
  111. }
  112. })
  113. },
  114. deleteEvent(){//删除
  115. wx.showModal({
  116. title: '提示',
  117. content: '确定要删除此商品?',
  118. success (res) {
  119. if (res.confirm) {
  120. console.log('用户点击确定')
  121. } else if (res.cancel) {
  122. console.log('用户点击取消')
  123. }
  124. }
  125. })
  126. },
  127. /**
  128. * 页面上拉触底事件的处理函数
  129. */
  130. onReachBottom: function () {
  131. this.setData({
  132. page:Number(this.data.page)+1
  133. })
  134. if(this.data.pages>=this.data.page) {
  135. this.getList();
  136. }
  137. },
  138. onShareAppMessage() {
  139. }
  140. })