CaseInfo.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <template>
  2. <el-form
  3. :rules="rules"
  4. :model="data"
  5. ref="form"
  6. class="sub-form"
  7. size="mini"
  8. :validate-on-rule-change="false"
  9. >
  10. <el-form-item label="段落标题:" prop="title" label-width="160px" class="is-required">
  11. <el-input v-model="data.title"></el-input>
  12. </el-form-item>
  13. <el-form-item label="内容" prop="content" label-width="160px" ref="editor">
  14. <quillEditor
  15. v-model="data.content"
  16. :options="editorOption"
  17. class="ql-editor"
  18. ref="quillEditor"
  19. ></quillEditor>
  20. </el-form-item>
  21. <div class="move_btn">
  22. <div
  23. v-if="index !== 0"
  24. @mouseover="moveTopHover = true"
  25. @mouseout="moveTopHover = false"
  26. title="上升"
  27. @click="reOrder(1)"
  28. >
  29. <img
  30. :src="
  31. moveTopHover
  32. ? require('@/images/icon_hover_top.png')
  33. : require('@/images/icon_default_top.png')
  34. "
  35. alt
  36. />
  37. </div>
  38. <div
  39. v-if="index !== total - 1"
  40. @mouseover="moveBottomHover = true"
  41. @mouseout="moveBottomHover = false"
  42. title="下降"
  43. @click="reOrder(0)"
  44. >
  45. <img
  46. :src="
  47. moveBottomHover
  48. ? require('@/images/icon_hover_down.png')
  49. : require('@/images/icon_default_down.png')
  50. "
  51. alt
  52. />
  53. </div>
  54. </div>
  55. <el-form-item label-width="160px" class="btns">
  56. <div class="change_btns">
  57. <div @click="addEmit">添加段落</div>
  58. <div @click="delEmit">删除本段落</div>
  59. </div>
  60. </el-form-item>
  61. </el-form>
  62. </template>
  63. <script>
  64. import api from '@api/knowledgeTree.js';
  65. import 'quill/dist/quill.core.css';
  66. import 'quill/dist/quill.snow.css';
  67. import 'quill/dist/quill.bubble.css';
  68. import { quillEditor, Quill } from 'vue-quill-editor';
  69. import config from '@api/config';
  70. import { container, ImageExtend, QuillWatch } from 'quill-image-extend-module';
  71. Quill.register('modules/ImageExtend', ImageExtend);
  72. export default {
  73. props: ['data', 'index', 'isEdit', 'isCopy', 'total', 'showType','positionMap','positionList'],
  74. name: 'CaseInfo',
  75. components: {
  76. quillEditor
  77. },
  78. data() {
  79. return {
  80. moveTopHover: false,
  81. moveBottomHover: false,
  82. toolbars: [
  83. [
  84. ['bold', 'underline', 'strike'],
  85. [{ list: 'ordered' }, { list: 'bullet' }],
  86. [{ script: 'sub' }, { script: 'super' }],
  87. [{ color: [] }, { background: [] }],
  88. [{ align: [] }],
  89. ['image']
  90. ]
  91. ],
  92. toolbarMode: 0,
  93. editorOption: {
  94. modules: {
  95. ImageExtend: {
  96. loading: true,
  97. name: 'upfile',
  98. size: 1,
  99. sizeError: () => {
  100. this.$message({
  101. showClose: true,
  102. message: '请上传 1M 以内的图片!',
  103. type: 'warning'
  104. });
  105. },
  106. action: config.urls.promptServer,
  107. response: res => {
  108. if (res.code == '0') {
  109. return config.imgHost + res.data.url;
  110. } else {
  111. this.$message({
  112. showClose: true,
  113. message: res.msg,
  114. type: 'warning'
  115. });
  116. }
  117. }
  118. },
  119. toolbar: {
  120. container: container,
  121. handlers: {
  122. image: function() {
  123. QuillWatch.emit(this.quill.id);
  124. }
  125. }
  126. }
  127. }
  128. },
  129. form: {
  130. orderNo: 0
  131. },
  132. rules: {}
  133. };
  134. },
  135. watch: {
  136. 'data.content': function() {
  137. if (this.data.content !== '') {
  138. this.$refs.editor && this.$refs.editor.clearValidate(); // 清除校验
  139. }
  140. if (this.data.content === '') {
  141. // console.log('内容为空');
  142. this.$refs['form'].validateField('content'); // 手动校验
  143. }
  144. this.data.text = this.$refs.quillEditor.quill.root.innerText;
  145. }
  146. },
  147. created() {
  148. this.editorOption.modules.toolbar.container = this.toolbars[
  149. this.toolbarMode
  150. ];
  151. if (this.isEdit || this.isCopy) {
  152. setTimeout(() => {
  153. this.rules = {
  154. title: [
  155. {
  156. validator: (rule, value, callback) => {
  157. if (!value.trim()) {
  158. callback(new Error('请输入段落标题'));
  159. } else {
  160. callback();
  161. }
  162. },
  163. trigger: 'change'
  164. },
  165. { max: 30, message: '标题名称不能超过30字', trigger: 'change' }
  166. ],
  167. content: [
  168. { required: true, message: '请输入段落内容', trigger: 'change' }
  169. ]
  170. };
  171. }, 100);
  172. } else {
  173. this.rules = {
  174. title: [
  175. {
  176. validator: (rule, value, callback) => {
  177. if (!value.trim()) {
  178. callback(new Error('请输入段落标题'));
  179. } else {
  180. callback();
  181. }
  182. },
  183. trigger: 'change'
  184. },
  185. { max: 30, message: '标题名称不能超过30字', trigger: 'change' }
  186. ],
  187. content: [
  188. { required: true, message: '请输入段落内容', trigger: 'change' }
  189. ]
  190. };
  191. }
  192. },
  193. mounted() {
  194. let quill = this.$refs.quillEditor.quill;
  195. quill.root.addEventListener(
  196. 'paste',
  197. evt => {
  198. console.log('evt', evt);
  199. if (
  200. evt.clipboardData &&
  201. evt.clipboardData.files &&
  202. evt.clipboardData.files.length
  203. ) {
  204. console.log('ddadada');
  205. evt.preventDefault();
  206. [].forEach.call(evt.clipboardData.files, file => {
  207. console.log('file', file);
  208. if (!file.type.match(/^image\/(gif|jpe?g|a?png|bmp)/i)) return;
  209. if (file.size > 1024 * 1000) return;
  210. let formData = new FormData();
  211. formData.append('upfile', file);
  212. api.uploadFile(formData).then(res => {
  213. console.log('formData', res);
  214. if (res.data.code == '0') {
  215. let imgUrl = config.imgHost + res.data.data.url;
  216. var range = quill.getSelection();
  217. console.log('range', range);
  218. if (range) {
  219. // this.uploadAttachment(res, file, null);
  220. let length = quill.getSelection().index;
  221. quill.insertEmbed(length, 'image', imgUrl);
  222. quill.setSelection(length + 1);
  223. // 将光标移动到图片后面
  224. this.$refs.quillEditor.quill.setSelection(range.index + 1);
  225. }
  226. } else {
  227. this.$message({
  228. showClose: true,
  229. message: res.msg,
  230. type: 'warning'
  231. });
  232. }
  233. });
  234. });
  235. }
  236. },
  237. false
  238. );
  239. },
  240. methods: {
  241. reOrder(i) {
  242. this.$emit('reOrder', i, this.index);
  243. },
  244. addEmit() {
  245. this.$emit('add');
  246. },
  247. delEmit() {
  248. this.$emit('del', this.index);
  249. },
  250. }
  251. };
  252. </script>
  253. <style lang="less" scoped>
  254. .quill-editor.ql-editor {
  255. padding-left: 0 !important;
  256. }
  257. .is-error .el-form-item__error {
  258. top: auto;
  259. }
  260. .sub-form {
  261. position: relative;
  262. }
  263. .order-btn {
  264. // position: absolute;
  265. top: 12px;
  266. right: 0;
  267. display: flex;
  268. a {
  269. margin-bottom: 20px;
  270. border: 1px solid #22ccc8;
  271. color: #22ccc8;
  272. padding: 5px 10px;
  273. border-radius: 4px;
  274. cursor: pointer;
  275. font-size: 12px;
  276. }
  277. .order-spc {
  278. margin-top: 28px;
  279. }
  280. .order-down {
  281. margin-left: 20px;
  282. }
  283. }
  284. /**富文本编辑器样式修改***/
  285. .ql-snow .ql-picker.ql-size .ql-picker-label::before,
  286. .ql-snow .ql-picker.ql-size .ql-picker-item::before,
  287. .ql-snow .ql-picker.ql-header .ql-picker-label::before,
  288. it .ql-editor,
  289. .quill-editor {
  290. padding-top: 0px !important;
  291. margin-top: -8px;
  292. min-height: 48px;
  293. p {
  294. padding-top: 8px;
  295. }
  296. }
  297. .ql-editor.ql-blank::before {
  298. padding-top: 0px;
  299. }
  300. .btns {
  301. margin-top: 20px;
  302. }
  303. .move_btn {
  304. position: absolute;
  305. top: 12px;
  306. right: 0;
  307. font-size: 14px;
  308. margin-left: 10px;
  309. display: flex;
  310. div {
  311. width: 12px;
  312. height: 16px;
  313. margin-right: 8px;
  314. img {
  315. width: 100%;
  316. height: 100%;
  317. cursor: pointer;
  318. }
  319. }
  320. }
  321. /deep/ .el-form-item.is-success .el-input__inner,
  322. .el-form-item.is-success .el-textarea__inner {
  323. border-color: #c9c9c9 !important;
  324. }
  325. /deep/ .el-form-item.is-success .el-textarea__inner {
  326. border-color: #c9c9c9 !important;
  327. }
  328. /deep/ .el-form-item.is-success .el-textarea__inner {
  329. border-color: #c9c9c9 !important;
  330. }
  331. .change_btns {
  332. // width: 100%;
  333. margin-top: 10px;
  334. display: flex;
  335. box-sizing: border-box;
  336. div {
  337. width: 90px;
  338. height: 30px;
  339. line-height: 30px;
  340. text-align: center;
  341. border-radius: 2px;
  342. border: 1px solid #21cbc7;
  343. color: #21cbc7;
  344. font-size: 14px;
  345. margin-right: 30px;
  346. cursor: pointer;
  347. &:nth-child(1) {
  348. &:hover {
  349. background: rgba(97, 218, 215, 0.1);
  350. }
  351. }
  352. &:nth-child(2) {
  353. border-color: #ff5b5b;
  354. color: #ff5b5b;
  355. &:hover {
  356. background: rgba(255, 91, 91, 0.1);
  357. }
  358. }
  359. }
  360. }
  361. </style>