post.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. const util = require("../../utils/util");
  2. const app = getApp()
  3. Page({
  4. data: {
  5. postId:0,
  6. info:{},
  7. content:''
  8. },
  9. onLoad: function (options) {
  10. let postId = +options.postId||7356;
  11. this.setData({postId})
  12. },
  13. onShow: function(){
  14. this.loadData()
  15. },
  16. preview( e ){
  17. var imgs = [];
  18. let content = this.data.info.content||''
  19. content.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, function (match, capture) {
  20. imgs.push(capture);
  21. });
  22. console.log("url",content, imgs)
  23. if( imgs.length > 0 ){
  24. wx.previewImage({
  25. current: imgs[0],
  26. urls: imgs
  27. })
  28. }
  29. },
  30. download( ){
  31. let url = this.data.info.sourceUrl;
  32. if( !url ){
  33. util.showModel("下载失败", "无附件内容")
  34. return
  35. }
  36. wx.downloadFile({
  37. url: url,
  38. timeout: 0,
  39. success: (res) => {
  40. var rr=res.tempFilePath;
  41. wx.openDocument({
  42. filePath:rr,
  43. showMenu: true,
  44. success(res) {
  45. wx.showToast({
  46. title: '保存成功',
  47. icon: 'success',
  48. duration: 2000
  49. })
  50. }
  51. })
  52. },
  53. fail: (res) => {
  54. console.log("res_fail", res)
  55. },
  56. complete: (res) => {
  57. console.log("res_complete", res)
  58. },
  59. })
  60. },
  61. loadData(){
  62. let postId = this.data.postId
  63. app.formPost( "Post.getPostInfo", {postId}).then( res=>{
  64. if( res.code == 200 ){
  65. let info = res.data
  66. this.setData({info})
  67. }
  68. })
  69. },
  70. onReady(res) {
  71. this.videoContext = wx.createVideoContext('myVideo')
  72. },
  73. onShareAppMessage: function () {
  74. let {postId, title} = this.data.info;
  75. return {
  76. title: title,
  77. path: `/pages/post/post?postId=${postId}`
  78. }
  79. }
  80. })