小程序链接助手

appletEdit.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // pages/appletEdit/appletEdit.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. itemObj: {},
  9. imgUrl: '',
  10. word: '',
  11. author: '',
  12. path: 'pages/index/index',
  13. b64: '',
  14. canvasWidth: '',
  15. canvasHeight: ''
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. if(options.from) {
  22. this.setData({
  23. word: wx.getStorageSync('word'),
  24. author: wx.getStorageSync('author'),
  25. itemObj: wx.getStorageSync('programObj'),
  26. b64: wx.getStorageSync('proImg'),
  27. path: wx.getStorageSync('path'),
  28. })
  29. }else {
  30. !this.data.word&&this.getword(0);
  31. !this.data.author&&this.getword(1);
  32. }
  33. this.setData({
  34. itemObj: wx.getStorageSync('itemObj'),
  35. word: wx.getStorageSync('word'),
  36. author: wx.getStorageSync('author'),
  37. })
  38. wx.setNavigationBarTitle({
  39. title: this.data.itemObj.app_name
  40. })
  41. this.getSetting()
  42. },
  43. toStatus() {
  44. if(!this.data.path) {
  45. wx.showToast({
  46. icon: 'none',
  47. title: '小程序路径不能为空',
  48. })
  49. return;
  50. }
  51. wx.setStorageSync('word',this.data.word)
  52. wx.setStorageSync('author',this.data.author)
  53. wx.setStorageSync('programObj',this.data.itemObj)
  54. wx.redirectTo({
  55. url: '/pages/status/status?post='+(this.data.b64?this.data.b64:this.data.imgUrl)+'&app_id='+this.data.itemObj.app_id+'&path='+this.data.path
  56. })
  57. },
  58. // 上传
  59. fetch() {
  60. wx.chooseImage({
  61. success: res => {
  62. wx.showLoading({
  63. title: '上传中',
  64. icon: 'none'
  65. })
  66. wx.getFileSystemManager().readFile({
  67. filePath: res.tempFilePaths[0], //选择图片返回的相对路径
  68. encoding: 'base64', //编码格式
  69. success: res => { //成功的回调
  70. this.getUrl('data:image/png;base64,' + res.data)
  71. },
  72. fail(error) {
  73. console.log(error)
  74. }
  75. })
  76. }
  77. })
  78. },
  79. getUrl(url) {
  80. app.func.req('/api/upload/img', 'post', {
  81. 'img': url
  82. }, (res) => {
  83. wx.hideLoading()
  84. if(res && res.errno == 0){
  85. if(!res.rst.file_path) {
  86. wx.showToast({
  87. title: '图片上传失败',
  88. icon: 'none'
  89. })
  90. return;
  91. }
  92. //成功
  93. this.setData({
  94. b64: res.rst.file_path
  95. })
  96. }else {
  97. wx.showToast({
  98. title: res.err,
  99. icon: 'none',
  100. duration: 2000
  101. })
  102. }
  103. },()=>{
  104. wx.hideLoading()
  105. })
  106. },
  107. // 没有本地词,从列表中获取----默认引导词
  108. getword(type) {
  109. app.func.req('/api/article/getGuideWords', 'get', {
  110. 'type': type
  111. }, (res) => {
  112. wx.hideLoading()
  113. if(res && res.errno == 0){
  114. if(type==0) {
  115. this.setData({
  116. word: res.rst.data[0].keyword
  117. })
  118. wx.setStorageSync('word',res.rst.data[0].keyword)
  119. }else {
  120. //成功
  121. this.setData({
  122. author: res.rst.data[0].keyword
  123. })
  124. wx.setStorageSync('author',res.rst.data[0].keyword)
  125. }
  126. }else {
  127. wx.showToast({
  128. title: res.err,
  129. icon: 'none',
  130. duration: 2000
  131. })
  132. }
  133. },()=>{
  134. wx.hideLoading()
  135. })
  136. },
  137. toWord(e) {
  138. // 保存关键词
  139. wx.setStorageSync('proImg',this.data.b64)
  140. wx.setStorageSync('keyword',this.data.keyword)
  141. wx.setStorageSync('path',this.data.path)
  142. wx.setStorageSync('programObj',this.data.itemObj)
  143. wx.redirectTo({
  144. url: '/pages/word/word?from='+e.currentTarget.dataset.type+'&word='+this.data.word+'&author='+this.data.author+'&type=program'
  145. })
  146. },
  147. getKeyword(e) {
  148. this.setData({
  149. path: e.detail.value
  150. })
  151. },
  152. getSetting(e) {
  153. wx.showLoading({
  154. title: '加载中',
  155. })
  156. app.func.req('/api/weapp/config', 'get',{
  157. }, (res) => {
  158. wx.hideLoading()
  159. if(res && res.errno == 0){
  160. //成功
  161. this.setData({
  162. imgUrl: res.rst.def_main_img
  163. })
  164. }else {
  165. wx.showToast({
  166. title: res.err,
  167. icon: 'none',
  168. duration: 2000
  169. })
  170. }
  171. },()=>{
  172. wx.hideLoading()
  173. })
  174. },
  175. onShareAppMessage() {
  176. }
  177. })