preview-panel.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. var PreviewPanel = {
  2. template: '<div class="preview-wrap">\
  3. <p class="c-t-center c-bold">{{modelName}}</p>\
  4. <div v-html="content" class="mtb10 c-333"></div>\
  5. <div v-for="(url,i) in imgs" class="mtb10"><img :src="url" width="100%" /></div>\
  6. <div class="foot-btns">\
  7. <a class="back-btn c-t-center mr15" @click="goBack">\
  8. 返回\
  9. </a>\
  10. </div>\
  11. </div>',
  12. props: [],
  13. data: function() {
  14. return {
  15. content: "",
  16. modelName:"",
  17. createTime: "",
  18. imgs: []
  19. }
  20. },
  21. // beforeRouteEnter: function (to, from, next) {
  22. // next(function(vm) {
  23. // var query = vm.$route.query
  24. // if(query && query.modelCode) {
  25. // vm.modelCode = query.modelCode
  26. // vm.listDetail()
  27. // }
  28. // })
  29. // },
  30. created: function() {
  31. var vm = this
  32. EventBus.$on('preview-template', function(data) {
  33. var regN = /\n/g;
  34. vm.content = data.content.replace(regN,"<br/>").replace(/ /g, "&nbsp;");
  35. vm.modelName = data.modelName
  36. vm.imgs = data.imgs
  37. })
  38. },
  39. methods: {
  40. listDetail: function() {
  41. var vm = this
  42. guidanceAPI.listDetail({
  43. modelCode: vm.modelCode
  44. }).then(function(res) {
  45. var data = res.data
  46. if(data) {
  47. var regN = /\n/g;
  48. vm.content = data.content.replace(regN,"<br/>").replace(/ /g, "&nbsp;");
  49. vm.modelName = data.modelName
  50. vm.createTime = data.createTime
  51. vm.imgs = _.map(data.imagesUrls, function(s) {
  52. return httpRequest.getImgUrl(s)
  53. })
  54. }
  55. })
  56. },
  57. getDetail: function (){
  58. var regN = /\n/g;
  59. var regRN = /\r\n/g;
  60. var content = detail.content.replace(/ /g, "&nbsp;");
  61. content = content.replace(regN,"<br/>");
  62. var p = "<p class='c-f14 c-333'>"+content+"</p>",
  63. images = "";
  64. for(i=0; i<detail.images.length; i++){
  65. var src = detail.images[i];
  66. if(!(src.indexOf("file://") > -1)){
  67. src = getImgUrl(detail.images[i]);
  68. }
  69. images += "<div class='mtb10'><img src='"+src+"' width='100%'></div>";
  70. }
  71. $(".content").append(p+images);
  72. },
  73. goBack: function() {
  74. this.$router.back()
  75. }
  76. }
  77. }