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