DevInfo.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. setTimeout(()=>{
  179. this.filterHiddenPosition();
  180. },200)
  181. },
  182. mounted() {
  183. },
  184. methods: {
  185. reOrder(i) {
  186. this.$emit('reOrder', i, this.index);
  187. },
  188. addEmit() {
  189. this.$emit('add');
  190. },
  191. delEmit() {
  192. this.$emit('del', this.index);
  193. },
  194. filterHiddenPosition(){
  195. const pos = this.data.position;
  196. const pArr = this.positions.map((it)=>{return it.key});
  197. const pStr = pArr.join(",");
  198. const arr=pos.filter((it)=>{
  199. return pStr.indexOf(it)>-1;
  200. });
  201. this.data.position=arr;
  202. },
  203. // 渲染内容类型
  204. renderPositions() {
  205. //显示位置枚举列表
  206. const pos = localStorage.getItem('knowledgeEnumsData');
  207. let positions = config.contentTypes;
  208. if (this.showType == 1) {
  209. // 诊断
  210. this.positions = positions.filter(item => item.key !== 2);
  211. } else if (
  212. this.showType == 3 ||
  213. this.showType == 4 ||
  214. this.showType == 5 ||
  215. this.showType == 6
  216. ) {
  217. // 检验/检查
  218. this.positions = positions.filter(item => {
  219. return item.key <= 2;
  220. });
  221. } else if (this.showType == 2 || this.showType == 7 || this.showType == 8 || this.showType == 9) {
  222. // 药品/手术
  223. this.positions = positions.filter(item => item.key === 1);
  224. } else {
  225. this.positions = positions;
  226. }
  227. }
  228. /*emitVal(){
  229. let data = this.form;
  230. let pst=this.form.position;
  231. const content = this.form.content.replace(config.imgHost,'{imageUrlPrefix}');
  232. const text = this.$refs.quillEditor;console.log(text)
  233. pst = typeof pst=='string'?pst:pst.join(',');
  234. data = Object.assign({},data,{
  235. position:this.form.position?pst:'',
  236. orderNo:this.index,
  237. text:'',
  238. content:content});
  239. this.$emit("change",this.index,data);
  240. }*/
  241. }
  242. };
  243. </script>
  244. <style lang="less" scoped>
  245. .quill-editor.ql-editor {
  246. padding-left: 0 !important;
  247. }
  248. .is-error .el-form-item__error {
  249. top: auto;
  250. }
  251. .sub-form {
  252. position: relative;
  253. }
  254. .order-btn {
  255. // position: absolute;
  256. top: 12px;
  257. right: 0;
  258. display: flex;
  259. a {
  260. margin-bottom: 20px;
  261. border: 1px solid #22ccc8;
  262. color: #22ccc8;
  263. padding: 5px 10px;
  264. border-radius: 4px;
  265. cursor: pointer;
  266. font-size: 12px;
  267. }
  268. .order-spc {
  269. margin-top: 28px;
  270. }
  271. .order-down {
  272. margin-left: 20px;
  273. }
  274. }
  275. /**富文本编辑器样式修改***/
  276. .ql-snow .ql-picker.ql-size .ql-picker-label::before,
  277. .ql-snow .ql-picker.ql-size .ql-picker-item::before,
  278. .ql-snow .ql-picker.ql-header .ql-picker-label::before,
  279. it .ql-editor,
  280. .quill-editor {
  281. padding-top: 0px !important;
  282. margin-top: -8px;
  283. min-height: 48px;
  284. p {
  285. padding-top: 8px;
  286. }
  287. }
  288. .ql-editor.ql-blank::before {
  289. padding-top: 0px;
  290. }
  291. .btns {
  292. margin-top: 20px;
  293. }
  294. </style>