addKnowledge.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <fullscreen class="mc-container">
  3. <div class="container-box">
  4. <h2>新增知识库</h2>
  5. <el-row :gutter="20" style="margin-top: 15px">
  6. <el-col :span="24"
  7. ><el-form
  8. :model="formData"
  9. :rules="rules"
  10. ref="ruleForm"
  11. label-width="50px"
  12. class="demo-ruleForm"
  13. >
  14. <el-col :span="10">
  15. <el-form-item label="标题" prop="title">
  16. <el-input
  17. v-model="formData.title"
  18. placeholder="请输入标题"
  19. ></el-input>
  20. </el-form-item>
  21. <el-form-item prop="pubType" label="类型">
  22. <el-select
  23. style="width: 100%"
  24. :popper-append-to-body="false"
  25. v-model="formData.pubType"
  26. placeholder="发布类型"
  27. clearable
  28. >
  29. <el-option
  30. v-for="item in knowledgeType"
  31. :key="item.id"
  32. :label="item.pubType"
  33. :value="item.id"
  34. >
  35. </el-option>
  36. </el-select>
  37. </el-form-item>
  38. <el-form-item label="目录" prop="catalogDesc">
  39. <div style="display: flex">
  40. <el-input
  41. v-model="formData.catalogDesc"
  42. readonly
  43. placeholder="请选择目录"
  44. ></el-input>
  45. <el-button @click="selectCatalogs">选择</el-button>
  46. </div>
  47. </el-form-item>
  48. <el-form-item label="附件" prop="catalog">
  49. <myUpload
  50. @uploadBack="uploadBack"
  51. :fileInfo="fileInfo"
  52. :fileList="fileInfo.fileList"
  53. >
  54. </myUpload>
  55. </el-form-item>
  56. <el-form-item>
  57. <el-button type="primary" @click="submitForm('ruleForm')"
  58. >立即创建</el-button
  59. >
  60. <el-button @click="resetForm('ruleForm')">取消</el-button>
  61. </el-form-item>
  62. </el-col>
  63. <el-col :span="14">
  64. <el-form-item label="内容" prop="content">
  65. <p-editor-tiny
  66. imgType="upload"
  67. v-model="formData.content"
  68. ></p-editor-tiny
  69. ></el-form-item>
  70. </el-col> </el-form
  71. ></el-col>
  72. </el-row>
  73. </div>
  74. <el-dialog
  75. title="目录树"
  76. :visible.sync="catalogDialogVisible"
  77. width="45%"
  78. :modal-append-to-body="false"
  79. >
  80. <el-tree
  81. class="filter-tree"
  82. :data="treeData"
  83. node-key="catalog"
  84. :props="defaultProps"
  85. default-expand-all
  86. :filter-node-method="filterNode"
  87. @node-click="nodeClick"
  88. ref="tree"
  89. >
  90. </el-tree>
  91. <span slot="footer" class="dialog-footer">
  92. <el-button @click="clearCatalog">取 消</el-button>
  93. <el-button type="primary" @click="trueCatalog">确 定</el-button>
  94. </span>
  95. </el-dialog>
  96. </fullscreen>
  97. </template><script>
  98. import myUpload from "../../../components/upload";
  99. export default {
  100. data() {
  101. return {
  102. catalogDialogVisible: false,
  103. departmentDialogVisible: false,
  104. formData: {
  105. title: "",
  106. catalog: "",
  107. catalogDesc: "",
  108. content: "",
  109. pubType: "",
  110. },
  111. rules: {
  112. title: [{ required: true, message: "请输入标题", trigger: "blur" }],
  113. catalogDesc: [
  114. { required: true, message: "请选择目录", trigger: "change" },
  115. ],
  116. pubType: [{ required: true, message: "请选择类型", trigger: "change" }],
  117. content: [
  118. {
  119. required: true,
  120. message: "请输入内容",
  121. trigger: "change",
  122. },
  123. ],
  124. },
  125. filterText: "",
  126. treeData: [],
  127. defaultProps: {
  128. children: "children",
  129. label: "title",
  130. },
  131. knowledgeType: [],
  132. fileInfo: {
  133. limit: 5,
  134. url: "/market/cknowledgenetatt/upload",
  135. fileList: [],
  136. },
  137. };
  138. },
  139. components: {
  140. PEditorTiny: () =>
  141. import(
  142. /* webpackChunkName: "peditor-tiny" */ "../../../components/p-editor-tiny"
  143. ),
  144. myUpload,
  145. },
  146. methods: {
  147. uploadBack(v) {
  148. this.attList = v;
  149. },
  150. // 选择完目录清空
  151. clearCatalog() {
  152. this.formData.catalogDesc = "";
  153. this.formData.catalog = "";
  154. this.catalogDialogVisible = false;
  155. },
  156. // 选择完目录确认
  157. trueCatalog() {
  158. this.catalogDialogVisible = false;
  159. },
  160. // 选择目录弹出
  161. selectCatalogs() {
  162. this.catalogDialogVisible = true;
  163. },
  164. // 选择部门弹出
  165. selectDepartment() {
  166. this.departmentDialogVisible = true;
  167. },
  168. //字典类型
  169. getListype(v) {
  170. this.$http({
  171. url: "/market/mkKnowledgePubMsgType/queryList",
  172. method: "post",
  173. headers: {
  174. "Content-Type": "application/json",
  175. },
  176. data: {
  177. dictCode: "pubType",
  178. },
  179. }).then((res) => {
  180. this.knowledgeType = res.data;
  181. });
  182. },
  183. // 树筛选
  184. filterNode(value, data) {
  185. if (!value) return true;
  186. return data.label.indexOf(value) !== -1;
  187. },
  188. async submitForm(formName) {
  189. let valid = await this.$refs[formName].validate().catch((err) => err);
  190. if (valid) {
  191. alert("submit!");
  192. } else {
  193. console.log("error submit!!");
  194. return false;
  195. }
  196. }, // 树点击
  197. nodeClick(index, data, node) {
  198. this.formData.catalogDesc = data.data.title;
  199. this.formData.catalog = data.data.id;
  200. },
  201. resetForm(formName) {
  202. this.$refs[formName].resetFields();
  203. },
  204. getData() {
  205. this.$http({
  206. url: "/market/mkKnowledgeCatalog/queryList",
  207. method: "post",
  208. headers: {
  209. "Content-Type": "application/json",
  210. },
  211. data: {},
  212. }).then((res) => {
  213. this.treeData = res.data;
  214. });
  215. },
  216. },
  217. mounted() {
  218. this.getData();
  219. this.getListype();
  220. },
  221. watch: {
  222. filterText(val) {
  223. this.$refs.tree.filter(val);
  224. },
  225. },
  226. };
  227. </script>
  228. <style>
  229. .mc-container {
  230. margin: 15px;
  231. background: #fff;
  232. border-radius: 5px;
  233. height: calc(100vh - 150px);
  234. margin-bottom: 0;
  235. }
  236. .mc-container .container-box {
  237. width: 100%;
  238. height: 100%;
  239. max-height: 96vh;
  240. margin-top: 20px;
  241. padding: 0 20px 0 20px;
  242. overflow-x: hidden !important;
  243. padding-top: 20px;
  244. }
  245. .tinymce-editor {
  246. height: 300px;
  247. }
  248. .mc-container .el-upload{
  249. width:100%
  250. }
  251. .mc-container .el-upload-dragger{
  252. width: 100%;
  253. }
  254. </style>