articleCreate.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <div class="app-container">
  3. <div class="common-card a-card-margin-top">
  4. <TinymceEditor v-model="content"></TinymceEditor>
  5. </div>
  6. <div>
  7. <a-form
  8. :form="form"
  9. :label-col="{ span: 10 }"
  10. :wrapper-col="{ span: 5 }"
  11. @submit="handleSubmit"
  12. >
  13. <a-form-item label="文章标题">
  14. <a-input
  15. placeholder="请输入文章标题"
  16. :maxLength="100"
  17. v-decorator="[
  18. 'name',
  19. {
  20. rules: [{ required: true, message: '请输入文章标题' }],
  21. },
  22. ]"
  23. />
  24. </a-form-item>
  25. <a-form-item label="文章描述">
  26. <a-input
  27. placeholder="请输入文章描述"
  28. :maxLength="100"
  29. v-decorator="[
  30. 'description',
  31. {
  32. rules: [{ required: true, message: '请输入文章描述' }],
  33. },
  34. ]"
  35. />
  36. </a-form-item>
  37. <a-form-item label="文章分类">
  38. <!-- 文章分类父类 -->
  39. <a-select
  40. v-decorator="[
  41. 'articleParentClass',
  42. {
  43. rules: [{ required: true, message: '请选择文章分类父类' }],
  44. },
  45. ]"
  46. @change="articleClassParentChange"
  47. >
  48. <a-select-option
  49. v-for="(item, index) in articleParentClassArr"
  50. :key="index"
  51. >{{ articleParentClassArr[index].name }}</a-select-option
  52. >
  53. </a-select>
  54. </a-form-item>
  55. <a-form-item label="文章子类">
  56. <!-- 文章分类子类 -->
  57. <a-select
  58. v-decorator="[
  59. 'articleChildClass',
  60. {
  61. rules: [{ required: true, message: '请选择文章分类子类' }],
  62. },
  63. ]"
  64. @change="articleClassChildChange"
  65. >
  66. <a-select-option
  67. v-for="(item, index) in articleChildClassArr"
  68. :key="index"
  69. >{{ articleChildClassArr[index].name }}</a-select-option
  70. >
  71. </a-select>
  72. </a-form-item>
  73. <a-form-item label="工种类别">
  74. <a-select
  75. v-decorator="[
  76. 'engineerType',
  77. {
  78. rules: [{ required: true, message: '请选择工种' }],
  79. },
  80. ]"
  81. @change="engineerTypeChange"
  82. >
  83. <a-select-option
  84. v-for="(item, index) in engineerTypeArray"
  85. :key="index"
  86. >{{ engineerTypeArray[index].name }}</a-select-option
  87. >
  88. </a-select>
  89. </a-form-item>
  90. <a-form-item label="必学日期:">
  91. <a-date-picker @change="learnDateChoose" />
  92. </a-form-item>
  93. <a-form-item :wrapper-col="{ span: 20, offset: 10 }">
  94. <a-button type="primary" html-type="submit">提交</a-button>
  95. <a-button :style="{ marginLeft: '160px' }" @click="preview"
  96. >预览</a-button
  97. >
  98. </a-form-item>
  99. </a-form>
  100. </div>
  101. <!-- 预览弹出框 -->
  102. <a-drawer
  103. title
  104. placement="left"
  105. :closable="true"
  106. :visible="previewVisible"
  107. @close="closepreview"
  108. width="30%"
  109. >
  110. <p v-html="content">{{ content }}</p>
  111. </a-drawer>
  112. </div>
  113. </template>
  114. <script>
  115. import { formatePathParams } from "@/filters";
  116. export default {
  117. name: "articleCreate",
  118. props: {},
  119. components: {
  120. // components: (reslove) => {
  121. // require(['', reslove]);
  122. // }
  123. },
  124. data() {
  125. return {
  126. content: "输入内容",
  127. // 展示预览
  128. previewVisible: false,
  129. form: this.$form.createForm(this, { name: "articleCreate" }),
  130. articleParentClassArr: [],
  131. articleChildClassArr: [],
  132. engineerTypeArray: [],
  133. articleParentClass: {},
  134. articleChildClass: {},
  135. engineerType: "",
  136. learnDate: ""
  137. };
  138. },
  139. created() {
  140. this.initDataFun(); //初始化数据
  141. },
  142. mounted() {},
  143. beforeDestroy() {},
  144. watch: {},
  145. computed: {},
  146. methods: {
  147. //初始化数据
  148. initDataFun() {
  149. this.getArticleParentClass();
  150. this.getEngineersWork();
  151. },
  152. // 查询文章分类父级
  153. getArticleParentClass() {
  154. this.$_http
  155. .get(this.$_API.INTERFACE_GET_CATEGORIES)
  156. .then(res => {
  157. console.log("--parent--" + JSON.stringify(res));
  158. this.articleParentClassArr = res.data;
  159. this.loading = false;
  160. })
  161. .catch(() => {
  162. this.loading = false;
  163. });
  164. },
  165. // 查询文章分类子集
  166. getArticleChildClass() {
  167. let pathParamsData = { categoryId: this.articleParentClass.id };
  168. this.$_http
  169. .get(
  170. formatePathParams(
  171. this.$_API.INTERFACE_GET_CATEGORIES_CATEGROYID,
  172. pathParamsData
  173. )
  174. )
  175. .then(res => {
  176. if (res && res.data.length !== 0) {
  177. res.data.shift();
  178. this.articleChildClassArr = res.data;
  179. }
  180. this.loading = false;
  181. })
  182. .catch(() => {
  183. this.loading = false;
  184. });
  185. },
  186. // 查询工作类别
  187. getEngineersWork() {
  188. this.$_http
  189. .get(this.$_API.INTERFACE_GET_ENGINEERINGWORK_LIST)
  190. .then(res => {
  191. this.engineerTypeArray = res.data;
  192. });
  193. },
  194. // 文章分类父类变化
  195. articleClassParentChange(value) {
  196. this.articleParentClass = this.articleParentClassArr[value];
  197. // 子类选项清空
  198. this.articleChildClassArr = [];
  199. this.form.setFieldsValue({
  200. articleChildClass: ""
  201. });
  202. // 获取子类的值
  203. this.getArticleChildClass();
  204. },
  205. // 文章分类子类变化
  206. articleClassChildChange(value) {
  207. this.articleChildClass = this.articleChildClassArr[value];
  208. },
  209. // 工种变化
  210. engineerTypeChange(value) {
  211. this.engineerType = this.engineerTypeArray[value];
  212. },
  213. // 必学日期选择
  214. learnDateChoose(date, dateString) {
  215. this.learnDate = dateString;
  216. },
  217. // 提交表单
  218. handleSubmit(e) {
  219. e.preventDefault();
  220. this.form.setFieldsValue({
  221. articleParentClass: this.articleParentClass.name
  222. });
  223. this.form.setFieldsValue({
  224. articleChildClass: this.articleChildClass.name
  225. });
  226. this.form.setFieldsValue({
  227. engineerType: this.engineerType.name
  228. });
  229. this.form.validateFields((err, values) => {
  230. if (!err) {
  231. // 新建文章
  232. console.log("--submit--" + JSON.stringify(values));
  233. let that = this;
  234. that.$confirm({
  235. title: "新建文章",
  236. content: `确认新建文章吗?`,
  237. okText: "确认",
  238. cancelText: "取消",
  239. onOk() {
  240. that.loading = true;
  241. let params = {
  242. name: values.name,
  243. description: values.description,
  244. type: "ARTICLE",
  245. contents: that.content,
  246. tages: [that.learnDate],
  247. engineerTypes: [that.engineerType],
  248. links: []
  249. };
  250. that.$_http
  251. .post(that.$_API.INTERFACE_POST_ADMIN_MATERIALS, params)
  252. .then(res => {
  253. that.$message.success("新建文章成功");
  254. console.log("---上传文章----" + JSON.stringify(res));
  255. });
  256. },
  257. onCancel() {}
  258. });
  259. }
  260. });
  261. },
  262. // 预览
  263. preview() {
  264. this.previewVisible = true;
  265. },
  266. // 关闭预览
  267. closepreview() {
  268. this.previewVisible = false;
  269. }
  270. }
  271. };
  272. </script>
  273. <style lang="less"></style>
  274. <style lang="less" scoped>
  275. .app-container {
  276. overflow: auto;
  277. }
  278. </style>