DevInfo.vue 8.1 KB

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