CaseInfo.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <el-form
  3. :rules="rules"
  4. :model="data"
  5. ref="form"
  6. class="sub-form"
  7. :validate-on-rule-change="false"
  8. >
  9. <!--<el-input v-model="form.orderNo" :value="index" type="hidden"></el-input>-->
  10. <!-- <el-form-item label="是否属于诊断依据:" prop="isReason" label-width="160px">
  11. <el-select v-model="data.isReason" placeholder="请选择">
  12. <el-option label="否" :value="0"></el-option>
  13. <el-option label="是" :value="1"></el-option>
  14. </el-select>
  15. </el-form-item>-->
  16. <el-form-item label="段落标题:" prop="title" label-width="160px">
  17. <el-input v-model="data.title"></el-input>
  18. </el-form-item>
  19. <el-form-item label="内容" prop="content" label-width="160px" ref="editor">
  20. <quillEditor
  21. v-model="data.content"
  22. :options="editorOption"
  23. class="ql-editor"
  24. ref="quillEditor"
  25. ></quillEditor>
  26. </el-form-item>
  27. <div class="order-btn">
  28. <a v-if="index!==0" :class="index===total-1?'order-spc':'order-up'" @click="reOrder(1)">上升</a>
  29. <a v-if="index!==total-1" :class="index===0?'order-spc':'order-down'" @click="reOrder(0)">下降</a>
  30. </div>
  31. <el-form-item label-width="160px" class="btns">
  32. <el-button @click="addEmit">添加段落</el-button>
  33. <el-button @click="delEmit" type="info">删除本段落</el-button>
  34. </el-form-item>
  35. </el-form>
  36. </template>
  37. <script>
  38. import 'quill/dist/quill.core.css';
  39. import 'quill/dist/quill.snow.css';
  40. import 'quill/dist/quill.bubble.css';
  41. import { quillEditor, Quill } from 'vue-quill-editor';
  42. import config from '@api/config';
  43. import api from '@api/knowledgeLib.js';
  44. import { container, ImageExtend, QuillWatch } from 'quill-image-extend-module';
  45. Quill.register('modules/ImageExtend', ImageExtend);
  46. export default {
  47. props: ['data', 'index', 'isEdit', 'total', 'showType'],
  48. name: 'MedicineInfoParagraph',
  49. components: {
  50. quillEditor
  51. },
  52. data() {
  53. return {
  54. toolbars: [
  55. [
  56. ['bold', 'underline', 'strike'],
  57. [{ list: 'ordered' }, { list: 'bullet' }],
  58. [{ script: 'sub' }, { script: 'super' }],
  59. [{ color: [] }, { background: [] }],
  60. [{ align: [] }],
  61. ['image']
  62. ]
  63. ],
  64. toolbarMode: 0,
  65. editorOption: {
  66. modules: {
  67. ImageExtend: {
  68. loading: true,
  69. name: 'upfile',
  70. size: 1,
  71. sizeError: () => {
  72. this.$message({
  73. showClose: true,
  74. message: '请上传 1M 以内的图片!',
  75. type: 'warning'
  76. });
  77. },
  78. action: config.urls.promptServer,
  79. response: res => {
  80. if (res.code == '0') {
  81. return config.imgHost + res.data.url;
  82. } else {
  83. this.$message({
  84. showClose: true,
  85. message: res.msg,
  86. type: 'warning'
  87. });
  88. }
  89. }
  90. },
  91. toolbar: {
  92. container: container,
  93. handlers: {
  94. image: function() {
  95. QuillWatch.emit(this.quill.id);
  96. }
  97. }
  98. }
  99. }
  100. },
  101. form: {
  102. position: [],
  103. orderNo: 0
  104. },
  105. positions: [], //位置列表
  106. rules: {}
  107. };
  108. },
  109. watch: {
  110. 'data.content': function() {
  111. if (this.data.content !== '') {
  112. this.$refs.editor && this.$refs.editor.clearValidate(); // 清除校验
  113. }
  114. if (this.data.content === '') {
  115. // console.log('内容为空');
  116. this.$refs['form'].validateField('content'); // 手动校验
  117. }
  118. this.data.text = this.$refs.quillEditor.quill.root.innerText;
  119. }
  120. },
  121. created() {
  122. // console.log(this.showType, 'showType','需要显示的类型');
  123. this.editorOption.modules.toolbar.container = this.toolbars[
  124. this.toolbarMode
  125. ];
  126. this.zskgetDict();
  127. if (this.isEdit) {
  128. setTimeout(() => {
  129. this.rules = {
  130. position: [
  131. { required: true, message: '请选择内容类型', trigger: 'change' }
  132. ],
  133. title: [
  134. { required: true, message: '请输入段落标题', trigger: 'change' },
  135. { max: 30, message: '标题名称不能超过30字', trigger: 'change' }
  136. ],
  137. content: [
  138. { required: true, message: '请输入段落内容', trigger: 'change' }
  139. ]
  140. };
  141. }, 100);
  142. } else {
  143. this.rules = {
  144. position: [
  145. { required: true, message: '请选择内容类型', trigger: 'change' }
  146. ],
  147. title: [
  148. { required: true, message: '请输入段落标题', trigger: 'change' },
  149. { max: 30, message: '标题名称不能超过30字', trigger: 'change' }
  150. ],
  151. content: [
  152. { required: true, message: '请输入段落内容', trigger: 'change' }
  153. ]
  154. };
  155. }
  156. setTimeout(() => {
  157. this.filterHiddenPosition();
  158. }, 200);
  159. },
  160. mounted() {},
  161. methods: {
  162. zskgetDict() {
  163. api
  164. .zskgetDict()
  165. .then(res => {
  166. if (res.data.code == '0') {
  167. const data = res.data.data;
  168. this.positions = data['50'];
  169. this.renderPositions(data['50'], data['51']);
  170. }
  171. })
  172. .catch(error => {
  173. console.log(error);
  174. });
  175. },
  176. reOrder(i) {
  177. this.$emit('reOrder', i, this.index);
  178. },
  179. // 添加段落
  180. addEmit() {
  181. this.$emit('add');
  182. },
  183. // 删除段落
  184. delEmit() {
  185. this.$emit('del', this.index);
  186. },
  187. filterHiddenPosition() {
  188. const pos = this.data.position;
  189. const pArr = this.positions.map(it => {
  190. return it.val;
  191. });
  192. const pStr = pArr.join(',');
  193. const arr = pos.filter(it => {
  194. return pStr.indexOf(it) > -1;
  195. });
  196. this.data.position = arr;
  197. },
  198. // 渲染内容类型
  199. renderPositions(data1,data2) {
  200. //显示位置枚举列表
  201. if (this.showType>0) {
  202. data2 = data2.filter(item => item.name == this.showType);
  203. let val = data2[0].val.split(',');
  204. this.positions = data1.filter(it => {
  205. let arr = val.map(v => v);
  206. return arr.includes(it.val);
  207. });
  208. }
  209. }
  210. }
  211. };
  212. </script>
  213. <style lang="less">
  214. .quill-editor.ql-editor {
  215. padding-left: 0 !important;
  216. }
  217. .is-error .el-form-item__error {
  218. top: auto;
  219. }
  220. .sub-form {
  221. position: relative;
  222. }
  223. .order-btn {
  224. position: absolute;
  225. top: 12px;
  226. right: 0;
  227. a {
  228. margin-bottom: 20px;
  229. border: 1px solid #22ccc8;
  230. color: #22ccc8;
  231. padding: 5px 10px;
  232. border-radius: 4px;
  233. cursor: pointer;
  234. font-size: 12px;
  235. }
  236. .order-spc {
  237. margin-top: 28px;
  238. }
  239. .order-down {
  240. margin-left: 20px;
  241. }
  242. }
  243. /**富文本编辑器样式修改***/
  244. .ql-snow .ql-picker.ql-size .ql-picker-label::before,
  245. .ql-snow .ql-picker.ql-size .ql-picker-item::before,
  246. .ql-snow .ql-picker.ql-header .ql-picker-label::before,
  247. it .ql-editor,
  248. .quill-editor {
  249. padding-top: 0px !important;
  250. margin-top: -8px;
  251. min-height: 48px;
  252. p {
  253. padding-top: 8px;
  254. }
  255. }
  256. .ql-editor.ql-blank::before {
  257. padding-top: 0px;
  258. }
  259. .btns {
  260. margin-top: 20px;
  261. }
  262. </style>