form.ftl 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>文章1</title>
  5. <#include "../../include/head-file.ftl">
  6. <script src="${base}/static/mdiy/index.js"></script>
  7. </head>
  8. <body>
  9. <div id="form" v-cloak>
  10. <el-header class="ms-header ms-tr" height="50px">
  11. <el-button type="primary" icon="iconfont icon-baocun" size="mini" @click="save()" :loading="saveDisabled">保存
  12. </el-button>
  13. <el-button size="mini" icon="iconfont icon-fanhui" plain onclick="javascript:history.go(-1)">返回
  14. </el-button>
  15. </el-header>
  16. <el-main class="ms-container" style="position:relative;">
  17. <el-scrollbar style="height: 100%;">
  18. <el-tabs v-model="activeName" style="height: calc(100% - 10px);">
  19. <el-tab-pane style="position:relative;" v-for="(item, index) in editableTabs" :key="index"
  20. :label="item.title" :name="item.name">
  21. <el-form v-if="item.title=='文章编辑'" ref="form" :model="form" :rules="rules" label-width="120px"
  22. size="mini">
  23. <el-row gutter="0" justify="start" align="top">
  24. <el-col :span="returnIsShow?'12':'24'">
  25. <el-form-item label="文章标题" prop="contentTitle">
  26. <el-input v-model="form.contentTitle"
  27. :disabled="false"
  28. :style="{width: '100%'}"
  29. :clearable="true"
  30. placeholder="请输入文章标题">
  31. </el-input>
  32. <div class="ms-form-tip">
  33. 标签:<a href="http://doc.mingsoft.net/mcms/biao-qian/wen-zhang-lie-biao-ms-arclist.html" target="_blank">${'$'}{field.title}</a>
  34. </div>
  35. </el-form-item>
  36. </el-col>
  37. <el-col span="12" v-if="returnIsShow">
  38. <el-form-item label="所属栏目" prop="categoryId">
  39. <tree-select :props="{value: 'id',label: 'categoryTitle',children: 'children'}"
  40. :options="contentCategoryIdOptions" :style="{width:'100%'}"
  41. @change="categoryChange"
  42. v-model="form.categoryId"></tree-select>
  43. <div class="ms-form-tip">
  44. 标签:<a href="http://doc.mingsoft.net/mcms/biao-qian/wen-zhang-lie-biao-ms-arclist.html" target="_blank">${'$'}{field.typetitle}</a><br/>
  45. 不能为链接和封面类型新建文章
  46. </div>
  47. </el-form-item>
  48. </el-col>
  49. </el-row>
  50. <el-row
  51. gutter="0"
  52. justify="start" align="top">
  53. <el-col span="12">
  54. <el-form-item label="文章类型" prop="contentType">
  55. <el-select v-model="form.contentType"
  56. :style="{width: '100%'}"
  57. :filterable="false"
  58. :disabled="false"
  59. :multiple="true" :clearable="true"
  60. placeholder="请选择文章类型">
  61. <el-option v-for='item in contentTypeOptions' :key="item.dictValue"
  62. :value="item.dictValue"
  63. :label="item.dictLabel"></el-option>
  64. </el-select>
  65. <div class="ms-form-tip">
  66. 用于筛选文章,在自定义字典添加
  67. </div>
  68. </el-form-item>
  69. </el-col>
  70. <el-col span="12">
  71. <el-form-item label="发布时间" prop="contentDatetime">
  72. <el-date-picker
  73. v-model="form.contentDatetime"
  74. placeholder="请选择发布时间"
  75. start-placeholder=""
  76. end-placeholder=""
  77. :readonly="false"
  78. :disabled="false"
  79. :editable="true"
  80. :clearable="true"
  81. format="yyyy-MM-dd HH:mm:ss"
  82. value-format="yyyy-MM-dd HH:mm:ss"
  83. :style="{width:'100%'}"
  84. type="datetime">
  85. </el-date-picker>
  86. <div class="ms-form-tip">
  87. 标签:<a href="http://doc.mingsoft.net/mcms/biao-qian/wen-zhang-lie-biao-ms-arclist.html" target="_blank">${'$'}{field.date?string("yyyy-MM-dd")}</a>
  88. </div>
  89. </el-form-item>
  90. </el-col>
  91. </el-row>
  92. <el-row
  93. gutter="0"
  94. justify="start" align="top">
  95. <el-col span="12">
  96. <el-form-item label="文章作者" prop="contentAuthor">
  97. <el-input v-model="form.contentAuthor"
  98. :disabled="false"
  99. :style="{width: '100%'}"
  100. :clearable="true"
  101. placeholder="请输入文章作者">
  102. </el-input>
  103. <div class="ms-form-tip">
  104. 标签:<a href="http://doc.mingsoft.net/mcms/biao-qian/wen-zhang-lie-biao-ms-arclist.html" target="_blank">${'$'}{field.author}</a>
  105. </div>
  106. </el-form-item>
  107. </el-col>
  108. <el-col span="12">
  109. <el-form-item label="文章来源" prop="contentSource">
  110. <el-input v-model="form.contentSource"
  111. :disabled="false"
  112. :style="{width: '100%'}"
  113. :clearable="true"
  114. placeholder="请输入文章来源">
  115. </el-input>
  116. <div class="ms-form-tip">
  117. 标签:<a href="http://doc.mingsoft.net/mcms/biao-qian/wen-zhang-lie-biao-ms-arclist.html" target="_blank">${'$'}{field.source}</a>
  118. </div>
  119. </el-form-item>
  120. </el-col>
  121. </el-row>
  122. <el-row
  123. gutter="0"
  124. justify="start" align="top">
  125. <el-col span="12">
  126. <el-form-item label="是否显示" prop="contentDisplay">
  127. <el-radio-group v-model="form.contentDisplay"
  128. :style="{width: ''}"
  129. :disabled="false">
  130. <el-radio :style="{display: true ? 'inline-block' : 'block'}"
  131. :label="item.value"
  132. v-for='(item, index) in contentDisplayOptions'
  133. :key="item.value + index">
  134. {{true? item.label : item.value}}
  135. </el-radio>
  136. </el-radio-group>
  137. <div class="ms-form-tip">
  138. 选择否后前端将不显示,需要重新生成才有效果
  139. </div>
  140. </el-form-item>
  141. </el-col>
  142. <el-col span="12">
  143. <el-form-item label="自定义顺序" prop="contentSort">
  144. <el-input-number
  145. v-model="form.contentSort"
  146. :disabled="false"
  147. controls-position="">
  148. </el-input-number>
  149. </el-form-item>
  150. </el-col>
  151. </el-row>
  152. <el-form-item label="文章缩略图" prop="contentImg">
  153. <el-upload
  154. :file-list="form.contentImg"
  155. :action="ms.base+'/file/upload.do'"
  156. :on-remove="contentImghandleRemove"
  157. :style="{width:''}"
  158. :limit="1"
  159. :on-exceed="contentImghandleExceed"
  160. :disabled="false"
  161. :data="{uploadPath:'/cms/content','isRename':true ,'appId':true}"
  162. :on-success="contentImgSuccess"
  163. accept="image/*"
  164. list-type="picture-card">
  165. <i class="el-icon-plus"></i>
  166. <div slot="tip" class="ms-form-tip">
  167. 标签:<a href="http://doc.mingsoft.net/mcms/biao-qian/wen-zhang-lie-biao-ms-arclist.html" target="_blank">${'$'}{field.litpic}</a><br/>
  168. 最多上传1张图片,文章缩略图,支持jpg格式
  169. </div>
  170. </el-upload>
  171. </el-form-item>
  172. <el-form-item label="关键字" prop="contentKeyword">
  173. <el-input
  174. type="textarea" :rows="5"
  175. :disabled="false"
  176. v-model="form.contentKeyword"
  177. :style="{width: '100%'}"
  178. placeholder="请输入文章关键字">
  179. </el-input>
  180. <div class="ms-form-tip">
  181. 标签:<a href="http://doc.mingsoft.net/mcms/biao-qian/wen-zhang-lie-biao-ms-arclist.html" target="_blank">${'$'}{field.keyword}</a>
  182. </div>
  183. </el-form-item>
  184. <el-form-item label="描述" prop="contentDescription">
  185. <el-input
  186. type="textarea" :rows="5"
  187. :disabled="false"
  188. v-model="form.contentDescription"
  189. :style="{width: '100%'}"
  190. placeholder="请输入对该文章的简短描述,以便用户查看文章简略">
  191. </el-input>
  192. <div class="ms-form-tip">
  193. 标签:<a href="http://doc.mingsoft.net/mcms/biao-qian/wen-zhang-lie-biao-ms-arclist.html" target="_blank">${'$'}{field.descrip}</a>
  194. </div>
  195. </el-form-item>
  196. <el-form-item label="文章内容" prop="contentDetails">
  197. <vue-ueditor-wrap style="line-height: 0px" v-model="form.contentDetails"
  198. :config="editorConfig"></vue-ueditor-wrap>
  199. <div class="ms-form-tip">
  200. 标签:<a href="http://doc.mingsoft.net/mcms/biao-qian/wen-zhang-lie-biao-ms-arclist.html" target="_blank">${'$'}{field.content}</a>
  201. </div>
  202. </el-form-item>
  203. </el-form>
  204. <div :id="'model'+index" v-else></div>
  205. </el-tab-pane>
  206. </el-tabs>
  207. </el-scrollbar>
  208. </el-main>
  209. </div>
  210. </body>
  211. </html>
  212. <script>
  213. var form = new Vue({
  214. el: '#form',
  215. data: function () {
  216. return {
  217. saveDisabled: false,
  218. activeName: 'form',
  219. //自定义模型实例
  220. model: undefined,
  221. editableTabs: [{
  222. title: '文章编辑',
  223. name: 'form'
  224. }],
  225. editorConfig: {
  226. imageScaleEnabled: true,
  227. autoHeightEnabled: true,
  228. autoFloatEnabled: false,
  229. scaleEnabled: true,
  230. compressSide: 0,
  231. maxImageSideLength: 1000,
  232. maximumWords: 100000,
  233. initialFrameWidth: '100%',
  234. initialFrameHeight: 400,
  235. serverUrl: ms.base + "/static/plugins/ueditor/1.4.3.1/jsp/editor.do?jsonConfig=%7BvideoUrlPrefix:\'" + ms.base + "\',fileUrlPrefix:\'" + ms.base + "\',imageUrlPrefix:\'" + ms.base + "\',imagePathFormat:\'/upload/${appId}/cms/content/editor/%7Btime%7D\',filePathFormat:\'/upload/${appId}/cms/content/editor/%7Btime%7D\',videoPathFormat:\'/upload/${appId}/cms/content/editor/%7Btime%7D\'%7D",
  236. UEDITOR_HOME_URL: ms.base + '/static/plugins/ueditor/1.4.3.1/'
  237. },
  238. contentCategoryIdOptions: [],
  239. returnIsShow: true,
  240. type: '',
  241. //表单数据
  242. form: {
  243. // 文章标题
  244. contentTitle: '',
  245. // 所属栏目
  246. categoryId: undefined,
  247. // 文章类型
  248. contentType: [],
  249. // 是否显示
  250. contentDisplay: '0',
  251. // 文章作者
  252. contentAuthor: '',
  253. // 文章来源
  254. contentSource: '',
  255. // 自定义顺序
  256. contentSort: 0,
  257. // 文章缩略图
  258. contentImg: [],
  259. // 描述
  260. contentDescription: '',
  261. // 关键字
  262. contentKeyword: '',
  263. // 文章内容
  264. contentDetails: '',
  265. contentDatetime: ms.util.date.fmt(Date.now(),"yyyy-MM-dd hh:mm:ss"),
  266. },
  267. contentTypeOptions: [],
  268. categoryIdOptions: [],
  269. contentDisplayOptions: [{
  270. "value": "0",
  271. "label": "是"
  272. }, {
  273. "value": "1",
  274. "label": "否"
  275. }],
  276. rules: {
  277. // 文章标题
  278. contentTitle: [{
  279. "required": true,
  280. "message": "请选择文章标题"
  281. }],
  282. // 发布时间
  283. contentDatetime: [{
  284. "required": true,
  285. "message": "发布时间不能为空"
  286. }],
  287. categoryId: [{
  288. "required": true,
  289. "message": "所属栏目不能为空"
  290. }]
  291. }
  292. };
  293. },
  294. watch: {},
  295. computed: {
  296. currCategory: function () {
  297. var that = this;
  298. return this.categoryIdOptions.find(function (value) {
  299. return value.id === that.form.categoryId;
  300. });
  301. }
  302. },
  303. methods: {
  304. save: function () {
  305. var _this = this;
  306. var that = this; //自定义模型需要验证
  307. if (this.model && !this.model.validate()) {
  308. this.activeName = 'custom-name';
  309. return;
  310. }
  311. var url = ms.manager + "/cms/content/save.do";
  312. if (that.form.id > 0) {
  313. url = ms.manager + "/cms/content/update.do";
  314. }
  315. this.$refs.form[0].validate(function (valid) {
  316. if (valid) {
  317. that.saveDisabled = true; //判断
  318. // if (that.categoryIdOptions.filter(function (f) {
  319. // return f['id'] == that.form.categoryId;
  320. // })[0].categoryType == '2' && that.returnIsShow) {
  321. // that.$notify({
  322. // title: '提示',
  323. // message: '所属栏目不能为封面',
  324. // type: 'error'
  325. // });
  326. // that.saveDisabled = false;
  327. // return;
  328. // }
  329. var data = JSON.parse(JSON.stringify(that.form));
  330. if (data.contentType) {
  331. data.contentType = data.contentType.join(',');
  332. }
  333. data.contentImg = JSON.stringify(data.contentImg);
  334. ms.http.post(url, data).then(function (data) {
  335. if (data.result) {
  336. //保存时需要赋值关联ID
  337. if (that.model) {
  338. that.model.form.linkId = data.data.id;
  339. that.model.save();
  340. }
  341. that.$notify({
  342. title: '成功',
  343. message: '保存成功',
  344. type: 'success',
  345. duration: 1000,
  346. onClose: function () {
  347. if (that.returnIsShow) {
  348. javascript: history.go(-1);
  349. } else {
  350. //如果是顶级封面或封面,则重新加载,避免文章和自定义模型重复保存
  351. location.reload();
  352. }
  353. that.saveDisabled = false;
  354. }
  355. });
  356. } else {
  357. that.$notify({
  358. title: '失败',
  359. message: data.msg,
  360. type: 'warning'
  361. });
  362. that.saveDisabled = false;
  363. }
  364. });
  365. } else {
  366. _this.activeName = 'form';
  367. return false;
  368. }
  369. });
  370. },
  371. removeModel: function () {
  372. var that = this;
  373. var model = document.getElementById('model1');
  374. var custom = document.getElementById('c_model');
  375. if (custom) {
  376. model.removeChild(custom);
  377. }
  378. that.model = undefined;
  379. },
  380. categoryChange: function () {
  381. this.changeModel();
  382. },
  383. changeModel: function () {
  384. var that = this;
  385. that.editableTabs = [that.editableTabs[0]];
  386. if (this.currCategory) {
  387. if (this.currCategory.mdiyModelId) {
  388. that.rederModel(this.currCategory.mdiyModelId)
  389. }
  390. }
  391. },
  392. rederModel: function (modelId) {
  393. var that = this;
  394. that.editableTabs.push({
  395. title: '',
  396. name: 'custom-name'
  397. });
  398. ms.mdiy.model.extend("model1", {id:modelId},{ linkId: that.form.id }).then(function(obj) {
  399. that.model = obj;
  400. that.editableTabs[1].title = obj.modelName
  401. });
  402. },
  403. getValue: function (data) {
  404. this.form.categoryId = data.id;
  405. },
  406. //获取当前文章
  407. get: function (id) {
  408. var that = this;
  409. ms.http.get(ms.manager + "/cms/content/get.do", {
  410. "id": id
  411. }).then(function (res) {
  412. if (res.result && res.data) {
  413. if (res.data.contentType && res.data.contentType != '') {
  414. res.data.contentType = res.data.contentType.split(',');
  415. } else {
  416. res.data.contentType = [];
  417. }
  418. if (res.data.contentImg) {
  419. res.data.contentImg = JSON.parse(res.data.contentImg);
  420. res.data.contentImg.forEach(function (value) {
  421. value.url = ms.base + value.path;
  422. });
  423. } else {
  424. res.data.contentImg = [];
  425. }
  426. that.form = res.data;
  427. var category = that.categoryIdOptions.filter(function (f) {
  428. return f['id'] == that.form.categoryId;
  429. });
  430. if (category.length == 1) {
  431. if (category[0].categoryType == '2') {
  432. that.returnIsShow = false;
  433. }
  434. }
  435. that.changeModel();
  436. }
  437. });
  438. },
  439. //根据封面获取当前文章
  440. getFromFengMian: function (categoryId) {
  441. var that = this;
  442. ms.http.get(ms.manager + "/cms/content/getFromFengMian.do", {
  443. "categoryId": categoryId
  444. }).then(function (res) {
  445. if (res.result) {
  446. if (res.data != null) {
  447. if (res.data.contentType && res.data.contentType != '') {
  448. res.data.contentType = res.data.contentType.split(',');
  449. } else {
  450. res.data.contentType = [];
  451. }
  452. if (res.data.contentImg) {
  453. res.data.contentImg = JSON.parse(res.data.contentImg);
  454. res.data.contentImg.forEach(function (value) {
  455. value.url = ms.base + value.path;
  456. });
  457. } else {
  458. res.data.contentImg = [];
  459. }
  460. that.form = res.data;
  461. var category = that.categoryIdOptions.filter(function (f) {
  462. return f['id'] == that.form.categoryId;
  463. });
  464. if (category.length == 1) {
  465. if (category[0].categoryType == '2') {
  466. that.returnIsShow = false;
  467. }
  468. }
  469. }
  470. that.changeModel();
  471. } else {
  472. that.$notify({
  473. title: '失败',
  474. message: "获取错误",
  475. type: 'warning'
  476. });
  477. }
  478. });
  479. },
  480. //获取contentCategoryId数据源
  481. contentCategoryIdOptionsGet: function () {
  482. var that = this;
  483. ms.http.get(ms.manager + "/cms/category/list.do", {
  484. pageSize: 9999
  485. }).then(function (res) {
  486. if (res.result) {
  487. res.data.rows.forEach(function (item) {
  488. if (item.categoryType == '2' || item.categoryType == '3') {
  489. item.isDisabled = true;
  490. }
  491. });
  492. that.contentCategoryIdOptions = ms.util.treeData(res.data.rows, 'id', 'categoryId', 'children');
  493. that.categoryIdOptions = res.data.rows;
  494. //获取到栏目数据之后再进行初始化
  495. that.init();
  496. }
  497. });
  498. },
  499. //获取contentType数据源
  500. contentTypeOptionsGet: function () {
  501. var that = this;
  502. ms.http.get(ms.base + '/mdiy/dict/list.do', {
  503. dictType: '文章属性',
  504. pageSize: 99999
  505. }).then(function (data) {
  506. if(data.result){
  507. data = data.data;
  508. that.contentTypeOptions = data.rows;
  509. }
  510. });
  511. },
  512. //contentImg文件上传完成回调
  513. contentImgSuccess: function (response, file, fileList) {
  514. if(response.result){
  515. this.form.contentImg.push({
  516. url: file.url,
  517. name: file.name,
  518. path: response.data,
  519. uid: file.uid
  520. });
  521. }else {
  522. this.$notify({
  523. title: '失败',
  524. message: response.msg,
  525. type: 'warning'
  526. });
  527. }
  528. },
  529. contentImghandleRemove: function (file, files) {
  530. var index = -1;
  531. index = this.form.contentImg.findIndex(function (text) {
  532. return text == file;
  533. });
  534. if (index != -1) {
  535. this.form.contentImg.splice(index, 1);
  536. }
  537. },
  538. //上传超过限制
  539. contentImghandleExceed: function (files, fileList) {
  540. this.$notify({
  541. title: '失败',
  542. message: '当前最多上传1个文件',
  543. type: 'warning'
  544. });
  545. },
  546. //查询列表
  547. list: function (categoryId) {
  548. var that = this;
  549. ms.http.post(ms.manager + "/cms/content/list.do", {
  550. categoryId: categoryId
  551. }).then(function (res) {
  552. if (res.result && res.data.total > 0) {
  553. if (res.data.rows[0].contentType) {
  554. res.data.rows[0].contentType = res.data.rows[0].contentType.split(',');
  555. }
  556. if (res.data.rows[0].contentImg) {
  557. res.data.rows[0].contentImg = JSON.parse(res.data.rows[0].contentImg);
  558. res.data.rows[0].contentImg.forEach(function (value) {
  559. value.url = ms.base + value.path;
  560. });
  561. } else {
  562. res.data.rows[0].contentImg = [];
  563. }
  564. that.form = res.data.rows[0];
  565. }
  566. });
  567. },
  568. //只有在渲染完栏目数据之后才会初始化
  569. init: function () {
  570. this.form.id = ms.util.getParameter("id");
  571. this.type = ms.util.getParameter("type");
  572. //在指定栏目下新增或编辑文章时
  573. var categoryId = ms.util.getParameter("categoryId");
  574. if (categoryId) {
  575. this.form.categoryId = categoryId;
  576. //如果是封面栏目直接跳转
  577. if (this.type) {
  578. this.getFromFengMian(this.form.categoryId);
  579. this.returnIsShow = false;
  580. //指定非封面栏目编辑文章
  581. }else if (this.form.id) {
  582. this.get(this.form.id);
  583. //指定栏目新增文章渲染自定义模型
  584. }else {
  585. this.changeModel();
  586. }
  587. //不指定栏目编辑文章
  588. }else if (this.form.id) {
  589. this.get(this.form.id);
  590. }//else 如果即不指定栏目新增文章,又不是编辑文章就不渲染自定义模型
  591. }
  592. },
  593. created: function () {
  594. this.contentCategoryIdOptionsGet();
  595. this.contentTypeOptionsGet();
  596. }
  597. });
  598. </script>
  599. <style>
  600. .el-select {
  601. width: 100%;
  602. }
  603. body {
  604. overflow: hidden;
  605. }
  606. #form {
  607. overflow: hidden;
  608. }
  609. .el-scrollbar__bar.is-vertical{
  610. width: 6px!important;
  611. }
  612. </style>