MedicineInfoPg.vue 7.6 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">
  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: ["data", "index", "isEdit", "total", "showType"],
  65. name: "MedicineInfoParagraph",
  66. components: {
  67. quillEditor,
  68. },
  69. data() {
  70. return {
  71. toolbars: [
  72. [
  73. ["bold", "underline", "strike"],
  74. [{ list: "ordered" }, { list: "bullet" }],
  75. [{ script: "sub" }, { script: "super" }],
  76. [{ color: [] }, { background: [] }],
  77. [{ align: [] }],
  78. ["image"],
  79. ],
  80. ],
  81. toolbarMode: 0,
  82. editorOption: {
  83. modules: {
  84. ImageExtend: {
  85. loading: true,
  86. name: "upfile",
  87. size: 1,
  88. sizeError: () => {
  89. this.$message({
  90. showClose: true,
  91. message: "请上传 1M 以内的图片!",
  92. type: "warning",
  93. });
  94. },
  95. action: config.urls.promptServer,
  96. response: (res) => {
  97. if (res.code == "0") {
  98. return config.imgHost + res.data.url;
  99. } else {
  100. this.$message({
  101. showClose: true,
  102. message: res.msg,
  103. type: "warning",
  104. });
  105. }
  106. },
  107. },
  108. toolbar: {
  109. container: container,
  110. handlers: {
  111. image: function () {
  112. QuillWatch.emit(this.quill.id);
  113. },
  114. },
  115. },
  116. },
  117. },
  118. form: {
  119. position: [],
  120. orderNo: 0,
  121. },
  122. positions: [], //位置列表
  123. rules: {},
  124. };
  125. },
  126. watch: {
  127. "data.content": function () {
  128. if (this.data.content !== "") {
  129. this.$refs.editor && this.$refs.editor.clearValidate(); // 清除校验
  130. }
  131. if (this.data.content === "") {
  132. // console.log('内容为空');
  133. this.$refs["form"].validateField("content"); // 手动校验
  134. }
  135. this.data.text = this.$refs.quillEditor.quill.root.innerText;
  136. },
  137. },
  138. created() {
  139. // console.log(this.showType, 'showType','需要显示的类型');
  140. this.editorOption.modules.toolbar.container =
  141. this.toolbars[this.toolbarMode];
  142. this.zskgetDict();
  143. if (this.isEdit) {
  144. setTimeout(() => {
  145. this.rules = {
  146. position: [
  147. { required: true, message: "请选择内容类型", trigger: "change" },
  148. ],
  149. title: [
  150. { required: true, message: "请输入段落标题", trigger: "change" },
  151. { max: 30, message: "标题名称不能超过30字", trigger: "change" },
  152. ],
  153. content: [
  154. { required: true, message: "请输入段落内容", trigger: "change" },
  155. ],
  156. };
  157. }, 100);
  158. } else {
  159. this.rules = {
  160. position: [
  161. { required: true, message: "请选择内容类型", trigger: "change" },
  162. ],
  163. title: [
  164. { required: true, message: "请输入段落标题", trigger: "change" },
  165. { max: 30, message: "标题名称不能超过30字", trigger: "change" },
  166. ],
  167. content: [
  168. { required: true, message: "请输入段落内容", trigger: "change" },
  169. ],
  170. };
  171. }
  172. setTimeout(() => {
  173. this.filterHiddenPosition();
  174. }, 200);
  175. },
  176. mounted() {
  177. // console.log("MedicineInfoPgData", this.data);
  178. },
  179. methods: {
  180. zskgetDict() {
  181. api
  182. .zskgetDict()
  183. .then((res) => {
  184. if (res.data.code == "0") {
  185. const data = res.data.data;
  186. this.positions = data["50"];
  187. this.renderPositions(data["50"], data["51"]);
  188. }
  189. })
  190. .catch((error) => {
  191. console.log(error);
  192. });
  193. },
  194. reOrder(i) {
  195. this.$emit("reOrder", i, this.index);
  196. },
  197. // 添加段落
  198. addEmit() {
  199. this.$emit("add");
  200. },
  201. // 删除段落
  202. delEmit() {
  203. this.$emit("del", this.index);
  204. },
  205. filterHiddenPosition() {
  206. const pos = this.data.position;
  207. const pArr = this.positions.map((it) => {
  208. return it.val;
  209. });
  210. const pStr = pArr.join(",");
  211. const arr = pos.filter((it) => {
  212. return pStr.indexOf(it) > -1;
  213. });
  214. this.data.position = arr;
  215. },
  216. // 渲染内容类型
  217. renderPositions(data1, data2) {
  218. //显示位置枚举列表
  219. if (this.showType > 0) {
  220. data2 = data2.filter((item) => item.name == this.showType);
  221. let val = data2[0].val.split(",");
  222. this.positions = data1.filter((it) => {
  223. let arr = val.map((v) => v);
  224. return arr.includes(it.val);
  225. });
  226. }
  227. },
  228. },
  229. };
  230. </script>
  231. <style lang="less">
  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. a {
  246. margin-bottom: 20px;
  247. border: 1px solid #22ccc8;
  248. color: #22ccc8;
  249. padding: 5px 10px;
  250. border-radius: 4px;
  251. cursor: pointer;
  252. font-size: 12px;
  253. }
  254. .order-spc {
  255. margin-top: 28px;
  256. }
  257. .order-down {
  258. margin-left: 20px;
  259. }
  260. }
  261. /**富文本编辑器样式修改***/
  262. .ql-snow .ql-picker.ql-size .ql-picker-label::before,
  263. .ql-snow .ql-picker.ql-size .ql-picker-item::before,
  264. .ql-snow .ql-picker.ql-header .ql-picker-label::before,
  265. it .ql-editor,
  266. .quill-editor {
  267. padding-top: 0px !important;
  268. margin-top: -8px;
  269. min-height: 48px;
  270. p {
  271. padding-top: 8px;
  272. }
  273. }
  274. .ql-editor.ql-blank::before {
  275. padding-top: 0px;
  276. }
  277. .btns {
  278. margin-top: 20px;
  279. }
  280. </style>