add.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <script>
  2. // import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  3. // Vue.use( CKEditor );
  4. import RoundedTitle from "../../../components/public/roundedTitle.vue";
  5. import PopCard from "../../../components/public/popCard.vue";
  6. import ImageTable from "../../../components/public/imageTable.vue";
  7. import Pop from "../../../components/public/pop.vue";
  8. let ClassicEditor;
  9. // let MyCustomPlugin;
  10. if (process.client) {
  11. ClassicEditor = require('../../../model/ckeditor/ckeditor');
  12. // ClassicEditor = require('@ckeditor/ckeditor5-build-classic');
  13. console.log(ClassicEditor);
  14. // MyCustomPlugin = require('../../../until/customCkeditorPlugin');
  15. }
  16. export default {
  17. name: "add",
  18. components: {
  19. Pop,
  20. ImageTable,
  21. PopCard,
  22. RoundedTitle
  23. // Use the <ckeditor> component in this view.
  24. },
  25. data(){
  26. return {
  27. editor: ClassicEditor,
  28. editorData: '<p>在此输入文章内容</p>',
  29. editorConfig: {
  30. language: 'zh',
  31. customText: "插入图片",
  32. },
  33. imagePopShow: false,
  34. imagePopLoading: false,
  35. }
  36. },
  37. beforeMount() {
  38. // this.editorConfig.toolbar.push('customButton');
  39. // 插入toolbar
  40. this.editorConfig.customFunction = () => {
  41. console.log('customFunction2');
  42. this.openImageSelect();
  43. };
  44. },
  45. mounted() {
  46. // 插入按钮
  47. },
  48. methods:{
  49. openImageSelect(){
  50. console.log('尝试打开图片选择窗口');
  51. this.imagePopShow = true;
  52. },
  53. okHandle(fileData){
  54. console.log('okHandle');
  55. console.log(fileData);
  56. this.imagePopShow = false;
  57. // 将图片新增至编辑器中,允许调整图片大小
  58. this.editorData += `<img src="${fileData.filePath}" alt="${fileData.fileName}">`;
  59. console.log(this.editorData);
  60. },
  61. }
  62. }
  63. </script>
  64. <template>
  65. <div class="w-full p-2">
  66. <rounded-title class="text-xl">
  67. <span>新增文章</span>
  68. <a href="/manger/news"
  69. class="px-10 h-full ml-5 rounded bg-blue-400 text-white cursor-pointer
  70. hover:text-orange-500 ">文章中心</a>
  71. </rounded-title>
  72. <div class="page-content-box w-full mt-2 p-0.5 rounded bg-white">
  73. <ckeditor ref="ckeditor" :editor="editor" v-model="editorData" :config="editorConfig"></ckeditor>
  74. </div>
  75. <pop :show="imagePopShow" :loading="imagePopLoading">
  76. <pop-card>
  77. <template slot="header">
  78. <span>选择需要插入的图片</span>
  79. </template>
  80. <image-table
  81. class="w-full h-full"
  82. @cancel="imagePopShow = false"
  83. @ok="okHandle">
  84. </image-table>
  85. </pop-card>
  86. </pop>
  87. </div>
  88. </template>
  89. <style scoped>
  90. .page-content-box{
  91. min-height: 500px;
  92. }
  93. </style>