form.ftl 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  1. <#include "mdiy/components/ms-dict.ftl">
  2. <template type="text/x-template" id="content-form">
  3. <div id="form" v-cloak>
  4. <el-header class="ms-header ms-tr" height="50px" >
  5. <el-row type="flex" justify="space-between" align="middle" style="width: 100%;">
  6. <el-col :span=12 style="display:flex;align-items:center;">
  7. <el-tooltip v-if="form.id && categoryType=='2'" class="item" effect="dark" :content="form.id" placement="top-start">
  8. <span style="float: left; " class="header-info">编号:{{form.id}}</span>
  9. </el-tooltip>
  10. <el-button v-if="form.id && categoryType=='2'" type="primary" link style="float: left" class="el-icon-document-copy copyBtn" circle :data-clipboard-text="form.id" @click="copyString()"></el-button>
  11. </el-col>
  12. <el-col :span="12" class="ms-tr">
  13. <@shiro.hasPermission name="cms:content:save">
  14. <el-button type="primary" class="iconfont icon-baocun" size="default" @click="save()" :loading="saveDisabled">保存
  15. </el-button>
  16. </@shiro.hasPermission>
  17. <el-button v-if="categoryType!='2' || id!=null" size="default" class="iconfont icon-fanhui" plain @click="back()">返回
  18. </el-button>
  19. <el-button v-if="form.id && categoryType=='2'" size="default" type="danger" class="el-icon-delete" @click="del()" :disabled="!form.id" >删除
  20. </el-button>
  21. </el-col>
  22. </el-row>
  23. </el-header>
  24. <el-main class="ms-container" style="position:relative;">
  25. <el-scrollbar class="ms-scrollbar" style="height: 100%;">
  26. <el-tabs v-model="activeName" style="height: calc(100% - 10px);">
  27. <el-tab-pane style="position:relative;" v-for="(item, index) in editableTabs" :key="index"
  28. :label="item.title" :name="item.name">
  29. <el-form v-if="item.title=='文章编辑'" ref="form" :model="form" :rules="rules" label-width="120px"
  30. size="default">
  31. <el-row :gutter=0 justify="start" align="top">
  32. <el-col :span=12>
  33. <el-form-item label="文章标题" prop="contentTitle">
  34. <el-input v-model="form.contentTitle"
  35. :disabled="false"
  36. :style="{width: '100%'}"
  37. :clearable="true"
  38. placeholder="请输入文章标题">
  39. </el-input>
  40. <div class="ms-form-tip">
  41. 标签:<a href="http://doc.mingsoft.net/mcms/biao-qian/wen-zhang-lie-biao-ms-arclist.html" target="_blank">${'$'}{field.title}</a>
  42. </div>
  43. </el-form-item>
  44. </el-col>
  45. <el-col :span=12 >
  46. <el-form-item label="所属栏目" prop="categoryId">
  47. <el-tree-select
  48. v-model="form.categoryId"
  49. :disabled="!categoryChangeEnabled"
  50. :data="contentCategoryIdOptions"
  51. :props="{value: 'id',label: 'categoryTitle',children: 'children'}"
  52. :render-after-expand="false"
  53. :check-strictly="false"
  54. :default-expand-all="false"
  55. @change="categoryChange"
  56. filterable
  57. ></el-tree-select>
  58. <div class="ms-form-tip">
  59. 标签:<a href="http://doc.mingsoft.net/mcms/biao-qian/wen-zhang-lie-biao-ms-arclist.html" target="_blank">${'$'}{field.typetitle}</a>
  60. 不能选择单篇、链接类型的栏目,不能选择父栏目
  61. </div>
  62. </el-form-item>
  63. </el-col>
  64. </el-row>
  65. <el-row
  66. :gutter=0
  67. justify="start" align="top">
  68. <el-col :span=12>
  69. <el-form-item label="文章副标题" prop="contentShortTitle">
  70. <el-input v-model="form.contentShortTitle"
  71. :disabled="false"
  72. :style="{width: '100%'}"
  73. :clearable="true"
  74. placeholder="请输入文章副标题">
  75. </el-input>
  76. <div class="ms-form-tip">
  77. 标签:<a href="http://doc.mingsoft.net/mcms/biao-qian/wen-zhang-lie-biao-ms-arclist.html" target="_blank">${'$'}{field.shorttitle}</a>
  78. </div>
  79. </el-form-item>
  80. </el-col>
  81. <el-col :span=12>
  82. <el-form-item label="文章外链接" prop="contentOutLink">
  83. <el-input v-model="form.contentOutLink"
  84. :disabled="false"
  85. :style="{width: '100%'}"
  86. :clearable="true"
  87. placeholder="请输入文章外链接">
  88. </el-input>
  89. <div class="ms-form-tip">
  90. 标签:<a href="http://doc.mingsoft.net/mcms/biao-qian/wen-zhang-lie-biao-ms-arclist.html"
  91. target="_blank">${'$'}{field.outlink}</a> 文章外链接必须以http或者https等开头
  92. </div>
  93. </el-form-item>
  94. </el-col>
  95. </el-row>
  96. <el-row
  97. :gutter=0
  98. justify="start" align="top">
  99. <el-col :span=12>
  100. <el-form-item label="文章类型" prop="contentType">
  101. <el-select v-model="form.contentType"
  102. :style="{width: '100%'}"
  103. :filterable="false"
  104. :disabled="false"
  105. :multiple="true" :clearable="true"
  106. placeholder="请选择文章类型">
  107. <el-option v-for='item in contentTypeOptions' :key="item.dictValue"
  108. :value="item.dictValue"
  109. :label="item.dictLabel"></el-option>
  110. </el-select>
  111. <div class="ms-form-tip">
  112. 标签:<a href="http://doc.mingsoft.net/mcms/biao-qian/wen-zhang-lie-biao-ms-arclist.html" target="_blank">${'$'}{flag}</a>
  113. 通过自定义字典可扩展,通常用在 arclist标签的flag属性上进行过滤文章
  114. </div>
  115. </el-form-item>
  116. </el-col>
  117. <el-col :span=12>
  118. <el-form-item label="发布时间" prop="contentDatetime">
  119. <el-date-picker
  120. v-model="form.contentDatetime"
  121. placeholder="请选择发布时间"
  122. start-placeholder=""
  123. end-placeholder=""
  124. :readonly="false"
  125. :disabled="false"
  126. :editable="true"
  127. :clearable="true"
  128. format="YYYY-MM-DD HH:mm:ss"
  129. value-format="YYYY-MM-DD HH:mm:ss"
  130. :style="{width:'100%'}"
  131. type="datetime">
  132. </el-date-picker>
  133. <div class="ms-form-tip">
  134. 标签:<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>
  135. </div>
  136. </el-form-item>
  137. </el-col>
  138. </el-row>
  139. <el-row
  140. :gutter=0
  141. justify="start" align="top">
  142. <el-col :span=12>
  143. <el-form-item label="文章作者" prop="contentAuthor">
  144. <el-input v-model="form.contentAuthor"
  145. :disabled="false"
  146. :style="{width: '100%'}"
  147. :clearable="true"
  148. placeholder="请输入文章作者">
  149. </el-input>
  150. <div class="ms-form-tip">
  151. 标签:<a href="http://doc.mingsoft.net/mcms/biao-qian/wen-zhang-lie-biao-ms-arclist.html" target="_blank">${'$'}{field.author}</a>
  152. </div>
  153. </el-form-item>
  154. </el-col>
  155. <el-col :span=12>
  156. <el-form-item label="文章来源" prop="contentSource">
  157. <el-input v-model="form.contentSource"
  158. :disabled="false"
  159. :style="{width: '100%'}"
  160. :clearable="true"
  161. placeholder="请输入文章来源">
  162. </el-input>
  163. <div class="ms-form-tip">
  164. 标签:<a href="http://doc.mingsoft.net/mcms/biao-qian/wen-zhang-lie-biao-ms-arclist.html" target="_blank">${'$'}{field.source}</a>
  165. </div>
  166. </el-form-item>
  167. </el-col>
  168. </el-row>
  169. <el-row
  170. :gutter=0
  171. justify="start" align="top">
  172. <el-col :span=12>
  173. <el-form-item label="是否显示" prop="contentDisplay">
  174. <el-radio-group v-model="form.contentDisplay"
  175. :style="{width: ''}"
  176. :disabled="false">
  177. <el-radio :style="{display: true ? 'inline-block' : 'block'}"
  178. :value="item.value"
  179. v-for='(item, index) in contentDisplayOptions'
  180. :key="item.value + index">
  181. {{true? item.label : item.value}}
  182. </el-radio>
  183. </el-radio-group>
  184. <div class="ms-form-tip">
  185. 选择否后前端将不显示,需要重新生成才有效果。单篇文章显示是由栏目控制。
  186. </div>
  187. </el-form-item>
  188. </el-col>
  189. <el-col :span=12>
  190. <el-form-item label="自定义顺序" prop="contentSort">
  191. <el-input-number
  192. v-model="form.contentSort"
  193. :disabled="false"
  194. controls-position="">
  195. </el-input-number>
  196. <div class="ms-form-tip">
  197. 提示:前台模板标签需要设置orderby属性为sort才能生效
  198. </div>
  199. </el-form-item>
  200. </el-col>
  201. </el-row>
  202. <el-row
  203. :gutter=0
  204. justify="start" align="top">
  205. <el-col :span=12>
  206. <el-form-item label="文章缩略图" prop="contentImg">
  207. <el-upload
  208. :file-list="form.contentImg"
  209. :action="ms.manager+'/file/upload.do'"
  210. :on-remove="contentImghandleRemove"
  211. :style="{width:''}"
  212. :multiple=true
  213. :limit="10"
  214. :on-exceed="contentImghandleExceed"
  215. :disabled="false"
  216. :data="{uploadPath:'/cms/content','isRename':true ,'appId':true}"
  217. :on-success="contentImgSuccess"
  218. :on-error="contentImgError"
  219. :on-preview="contentImgHandLePreview"
  220. accept="image/*"
  221. list-type="picture-card">
  222. <i class="el-icon-plus"></i>
  223. <template #tip>
  224. <div class="ms-form-tip">
  225. 标签:<a href="http://doc.mingsoft.net/mcms/biao-qian/wen-zhang-lie-biao-ms-arclist.html" target="_blank">${'{@ms:file field.litpic/}'}</a><br/>
  226. 一次可上传多张图片,最多可上传10张图片,文章缩略图,支持jpg格式;多图情况下,{@ms:file field.litpic/}会只取第一张缩略图,其他用法参考文档arclist标签
  227. </div>
  228. </template>
  229. </el-upload>
  230. </el-form-item>
  231. </el-col>
  232. <el-col :span=12>
  233. <el-form-item label="文章标签" prop="contentTags">
  234. <ms-dict v-model="form.contentTags"
  235. :style="{width: ''}"
  236. :filterable="true"
  237. :disabled="false"
  238. dict-type="文章标签"
  239. :multiple-limit="5"
  240. :multiple="true" :clearable="true"
  241. placeholder="请选择文章标签">
  242. </ms-dict>
  243. <div class="ms-form-tip">
  244. 标签:<a href="http://doc.mingsoft.net/mcms/biao-qian/wen-zhang-lie-biao-ms-arclist.html" target="_blank">${'$'}{field.tags}</a>
  245. 通过自定义字典可扩展数据;字典类型:文章标签
  246. </div>
  247. </el-form-item>
  248. </el-col>
  249. </el-row>
  250. <el-form-item label="关键字" prop="contentKeyword">
  251. <el-input
  252. type="textarea" :rows="5"
  253. :disabled="false"
  254. v-model="form.contentKeyword"
  255. :style="{width: '100%'}"
  256. placeholder="请输入文章关键字">
  257. </el-input>
  258. <div class="ms-form-tip">
  259. 标签:<a href="http://doc.mingsoft.net/mcms/biao-qian/wen-zhang-lie-biao-ms-arclist.html" target="_blank">${'$'}{field.keyword}</a>,用于SEO优化
  260. </div>
  261. </el-form-item>
  262. <el-form-item label="描述" prop="contentDescription">
  263. <el-input
  264. type="textarea" :rows="5"
  265. :disabled="false"
  266. v-model="form.contentDescription"
  267. :style="{width: '100%'}"
  268. placeholder="请输入对该文章的简短描述,以便用户查看文章简略">
  269. </el-input>
  270. <div class="ms-form-tip">
  271. 标签:<a href="http://doc.mingsoft.net/mcms/biao-qian/wen-zhang-lie-biao-ms-arclist.html" target="_blank">${'$'}{field.descrip}</a>,用于SEO优化
  272. </div>
  273. </el-form-item>
  274. <el-form-item label="文章内容" prop="contentDetails" v-loading="editorHidden">
  275. <vue-ueditor-wrap style="line-height: 0px"
  276. ref="editor"
  277. v-model="form.contentDetails"
  278. :config="editorConfig"></vue-ueditor-wrap>
  279. <div class="ms-form-tip">
  280. 标签:<a href="http://doc.mingsoft.net/mcms/biao-qian/wen-zhang-lie-biao-ms-arclist.html" target="_blank">${'$'}{field.content}</a> <br/>
  281. 温馨提示:推荐使用高级版本编辑器,<a href='http://store.mingsoft.net/#/detail?id=299&type=plugin' target="_blank">新版富文本编辑器</a>
  282. </div>
  283. </el-form-item>
  284. </el-form>
  285. <div :id="'model'+index" v-else>
  286. <ms-mdiy-form v-if="modelId!=null" ref="modelForm" type="model" :model-id="modelId" :id="form.id"></ms-mdiy-form>
  287. </div>
  288. </el-tab-pane>
  289. </el-tabs>
  290. </el-scrollbar>
  291. </el-main>
  292. </div>
  293. </template>
  294. <script>
  295. var contentForm = Vue.defineComponent({
  296. template: '#content-form',
  297. props:["categoryId","categoryType","id"],
  298. components:{
  299. MsDict
  300. },
  301. data: function () {
  302. var checkTags = function (rule, value, callback){
  303. if (value.length > 5){
  304. return callback(new Error('文章标签最多选择5个'));
  305. }
  306. callback();
  307. }
  308. return {
  309. editorHidden:true,
  310. saveDisabled: false,
  311. activeName: 'form',
  312. //自定义模型实例
  313. model: undefined,
  314. modelId:null,
  315. editableTabs: [{
  316. title: '文章编辑',
  317. name: 'form'
  318. }],
  319. editorConfig: {
  320. imageScaleEnabled :true,
  321. autoHeightEnabled: true,
  322. autoFloatEnabled: false,
  323. scaleEnabled: true,
  324. compressSide:0,
  325. maxImageSideLength:1000,
  326. maximumWords: 2000,
  327. initialFrameWidth: '100%',
  328. initialFrameHeight: 400,
  329. serverUrl: ms.manager + "/editor.do?version=1.4.3.3",
  330. UEDITOR_HOME_URL: ms.base + '/static/plugins/ueditor/1.4.3.3/',
  331. UEDITOR_BASE_URL: ms.base + '/static/plugins/ueditor/1.4.3.3/'
  332. },
  333. contentCategoryIdOptions: [],
  334. categoryChangeEnabled: true,
  335. // type: '',
  336. //表单数据
  337. form: {
  338. // 文章标题
  339. contentTitle: '',
  340. // 文章副标题
  341. contentShortTitle: '',
  342. // 所属栏目
  343. categoryId: undefined,
  344. // 文章类型
  345. contentType: [],
  346. // 是否显示
  347. contentDisplay: '0',
  348. // 文章作者
  349. contentAuthor: '',
  350. // 文章来源
  351. contentSource: '',
  352. // 自定义顺序
  353. contentSort: 0,
  354. // 文章标签
  355. contentTags: [],
  356. // 文章缩略图
  357. contentImg: [],
  358. // 描述
  359. contentDescription: '',
  360. // 关键字
  361. contentKeyword: '',
  362. // 文章内容
  363. contentDetails: '',
  364. //文章外链接
  365. contentOutLink: '',
  366. contentDatetime: ms.util.date.fmt(Date.now(),"yyyy-MM-dd hh:mm:ss"),
  367. id:"",
  368. },
  369. contentTypeOptions: [],
  370. contentTagsOptions: [],
  371. categoryIdOptions: [],
  372. contentDisplayOptions: [{
  373. "value": "0",
  374. "label": "是"
  375. }, {
  376. "value": "1",
  377. "label": "否"
  378. }],
  379. rules: {
  380. // 文章标题
  381. contentTitle: [{
  382. "required": true,
  383. "message": "请输入文章标题"
  384. }],
  385. // 发布时间
  386. contentDatetime: [{
  387. "required": true,
  388. "message": "发布时间不能为空"
  389. }],
  390. categoryId: [{
  391. "required": true,
  392. "message": "所属栏目不能为空"
  393. }],
  394. // 文章外链接
  395. contentOutLink: [{
  396. "pattern":'^((https|http|ftp|rtsp|mms){0,1}(:\/\/){0,1})(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])+$',
  397. "message":"文章外链接格式不匹配"},{"min":0,"max":200,"message":"文章外链接长度必须为0-200"}],
  398. // 文章标签
  399. contentTags: [{
  400. validator: checkTags, trigger: 'blur'
  401. }]
  402. },
  403. historyKey:"cms_content_history"
  404. };
  405. },
  406. watch: {
  407. "categoryId":function(n,o) {
  408. var that = this;
  409. that.activeName = "form";
  410. that.$refs.form[0].resetFields();
  411. that.contentCategoryIdOptionsGet();
  412. },
  413. },
  414. computed: {
  415. },
  416. methods: {
  417. back:function() {
  418. //如果没有back方法,说明不是从文章管理里面打开的文章表单
  419. //是文章管理的就放回对应的栏目列表
  420. //不是就路由会退一下
  421. if(this.$attrs.onBack) {
  422. this.$emit('back');
  423. } else {
  424. this.$router.go(-1);
  425. }
  426. },
  427. async save () {
  428. var that = this; //自定义模型需要验证
  429. let formValid = false;
  430. if(that.$refs.modelForm && that.$refs.modelForm.length > 0) {
  431. await that.$refs.modelForm[0].$refs.form.$refs.form.validate((valid,fields) => {
  432. formValid = valid;
  433. })
  434. if(!formValid) {
  435. this.activeName = 'custom-name';
  436. return;
  437. }
  438. }
  439. var url = ms.manager + "/cms/content/save.do";
  440. if (that.form.id > 0) {
  441. url = ms.manager + "/cms/content/update.do";
  442. } else {
  443. //新增数据重置到列表第一页
  444. sessionStorage.setItem(that.historyKey,JSON.stringify({form:{},page: {pageNo:1}}));
  445. }
  446. this.$refs.form[0].validate(function (valid) {
  447. if (valid) {
  448. that.saveDisabled = true; //判断
  449. var data = JSON.parse(JSON.stringify(that.form));
  450. // 固定属性顺序为字典顺序
  451. if (data.contentType && data.contentType.length > 0) {
  452. var orderTypes = [];
  453. that.contentTypeOptions.forEach(function (dict) {
  454. var orderType = data.contentType.find(function (type) {
  455. return type==dict.dictValue
  456. })
  457. if (orderType){
  458. orderTypes.push(orderType);
  459. }
  460. })
  461. data.contentType = orderTypes;
  462. }
  463. if (data.contentType) {
  464. data.contentType = data.contentType.join(',');
  465. }
  466. if (data.contentTags) {
  467. data.contentTags = data.contentTags.join(',');
  468. }
  469. data.contentImg = JSON.stringify(data.contentImg);
  470. ms.http.post(url, data).then(function (res) {
  471. if (res.result) {
  472. // 接受保存的文章id 避免新增单篇栏目保存不刷新时 再次修改造成多次保存
  473. that.form.id = res.data.id
  474. if(that.$refs.modelForm && that.$refs.modelForm.length > 0) {
  475. that.$refs.modelForm[0].$refs.form.form.linkId = res.data.id;
  476. that.$refs.modelForm[0].getForm().save(function (resModel) {
  477. if (resModel.result) {
  478. //模型保存成功
  479. // 这里会有异步问题,所以这里分别用了两个保存提示
  480. that.$notify({
  481. title: '成功',
  482. message: '保存成功',
  483. type: 'success',
  484. duration: 1000,
  485. onClose: function () {
  486. if (that.categoryChangeEnabled) { //如果列表新增就需要返回的列表
  487. that.$emit("back");
  488. }
  489. //为了让上传控件不显示类型警告
  490. if(res.data.contentImg=="") {
  491. res.data.contentImg =[];
  492. }
  493. }
  494. });
  495. } else {
  496. //模型保存失败
  497. that.$notify({
  498. title: '失败',
  499. message: that.$refs.modelForm[0].modelName + '拓展模型保存失败,' + resModel.msg,
  500. type: 'warning'
  501. });
  502. }
  503. })
  504. } else {
  505. that.$notify({
  506. title: '成功',
  507. message: '保存成功',
  508. type: 'success',
  509. duration: 1000,
  510. onClose: function () {
  511. if (that.categoryChangeEnabled) { //如果列表新增就需要返回的列表
  512. that.$emit("back");
  513. }
  514. //为了让上传控件不显示类型警告
  515. if(res.data.contentImg=="") {
  516. res.data.contentImg =[];
  517. }
  518. }
  519. });
  520. }
  521. that.saveDisabled = false;
  522. } else {
  523. that.$notify({
  524. title: '失败',
  525. message: res.msg,
  526. type: 'warning'
  527. });
  528. that.saveDisabled = false;
  529. }
  530. })
  531. } else {
  532. that.activeName = 'form';
  533. return false;
  534. }
  535. });
  536. },
  537. //删除
  538. del: function () {
  539. var that = this;
  540. that.$confirm('此操作将永久删除所选内容, 是否继续?', '提示', {
  541. confirmButtonText: '确定',
  542. cancelButtonText: '取消',
  543. type: 'warning'
  544. }).then(function () {
  545. var formData = JSON.parse(JSON.stringify(that.form));
  546. formData.contentImg = "";
  547. formData.contentType = "";
  548. formData.contentTags = "";
  549. ms.http.post(ms.manager + "/cms/content/delete.do", [formData], {
  550. headers: {
  551. 'Content-Type': 'application/json'
  552. }
  553. }).then(function (res) {
  554. if (res.result) {
  555. that.$notify({
  556. title:'成功',
  557. type: 'success',
  558. message: '删除成功!'
  559. });
  560. // 单篇删除 保留所属栏目
  561. var categoryId = that.form.categoryId;
  562. that.$refs.form[0].resetFields();
  563. that.form.id = "";
  564. that.form.categoryId = categoryId;
  565. that.activeName = "form";
  566. } else {
  567. that.$notify({
  568. title: '失败',
  569. message: res.msg,
  570. type: 'warning'
  571. });
  572. }
  573. });
  574. })
  575. },
  576. categoryChange: function (node) {
  577. // 新组件node就是节点id
  578. this.changeModel(node);
  579. },
  580. changeModel: function (categoryId) {
  581. var that = this;
  582. that.editableTabs = [that.editableTabs[0]];
  583. var _category = this.categoryIdOptions.filter(function (value) {
  584. return value.id === categoryId;
  585. })
  586. //如果存在自定义模型
  587. if(_category.length == 1 && _category[0].mdiyModelId) {
  588. that.editableTabs.push({title: '加载中...',name: 'custom-name'});
  589. ms.http.get(ms.manager + "/mdiy/model/get.do", {id: _category[0].mdiyModelId}).then(function (res) {
  590. if (res.result && res.data) {
  591. that.modelId = res.data.id;
  592. that.editableTabs[1].title = res.data.modelName
  593. }
  594. });
  595. }
  596. },
  597. getValue: function (data) {
  598. this.form.categoryId = data.id;
  599. },
  600. //获取当前文章
  601. get: function (id) {
  602. var that = this;
  603. ms.http.get(ms.manager + "/cms/content/get.do", {
  604. "id": id
  605. }).then(function (res) {
  606. if (res.result && res.data) {
  607. if (res.data.contentType && res.data.contentType != '') {
  608. res.data.contentType = res.data.contentType.split(',');
  609. } else {
  610. res.data.contentType = [];
  611. }
  612. if (res.data.contentTags && res.data.contentTags != '') {
  613. res.data.contentTags = res.data.contentTags.split(',');
  614. } else {
  615. res.data.contentTags = [];
  616. }
  617. if (res.data.contentImg && res.data.contentImg != '') {
  618. res.data.contentImg = JSON.parse(res.data.contentImg);
  619. res.data.contentImg.forEach(function (value) {
  620. value.url = ms.contextpath + value.url;
  621. });
  622. } else {
  623. res.data.contentImg = [];
  624. }
  625. that.form = res.data;
  626. var category = that.categoryIdOptions.filter(function (f) {
  627. return f['id'] == that.form.categoryId;
  628. });
  629. if (category.length > 0) {
  630. that.changeModel(category[0].id);
  631. }
  632. }
  633. }).catch(function (err) {
  634. console.log(err);
  635. });
  636. },
  637. //根据封面获取当前文章
  638. getFromFengMian: function (categoryId) {
  639. var that = this;
  640. ms.http.get(ms.manager + "/cms/content/getFromFengMian.do", {
  641. "categoryId": categoryId
  642. }).then(function (res) {
  643. if (res.result) {
  644. if (res.data != null) {
  645. if (res.data.contentType && res.data.contentType != '') {
  646. res.data.contentType = res.data.contentType.split(',');
  647. } else {
  648. res.data.contentType = [];
  649. }
  650. if (res.data.contentImg) {
  651. res.data.contentImg = JSON.parse(res.data.contentImg);
  652. res.data.contentImg.forEach(function (value) {
  653. value.url = ms.contextpath + value.url;
  654. });
  655. } else {
  656. res.data.contentImg = [];
  657. }
  658. if (res.data.contentTags && res.data.contentTags != '') {
  659. res.data.contentTags = res.data.contentTags.split(',');
  660. } else {
  661. res.data.contentTags = [];
  662. }
  663. that.form = res.data;
  664. // 左侧树选择单篇
  665. var category = that.categoryIdOptions.filter(function (f) {
  666. return f['id'] == that.form.categoryId;
  667. });
  668. if (category.length > 0) {
  669. that.categoryChangeEnabled = false;
  670. that.changeModel(category[0].id);
  671. }
  672. }
  673. } else {
  674. that.$notify({
  675. title: '失败',
  676. message: "获取错误",
  677. type: 'warning'
  678. });
  679. }
  680. }).catch(function (err) {
  681. console.log(err);
  682. });
  683. },
  684. //获取contentCategoryId数据源
  685. contentCategoryIdOptionsGet: function () {
  686. var that = this;
  687. ms.http.get(ms.manager + "/cms/category/list.do").then(function (res) {
  688. if (res.result) {
  689. res.data.rows.forEach(function (item) {
  690. if (item.categoryType == '2' || item.categoryType == '3') {
  691. item.disabled = true;
  692. }
  693. });
  694. that.contentCategoryIdOptions = ms.util.treeData(res.data.rows, 'id', 'categoryId', 'children');
  695. that.categoryIdOptions = res.data.rows;
  696. //获取到栏目数据之后再进行初始化
  697. that.init();
  698. }
  699. }).catch(function (err) {
  700. console.log(err);
  701. });
  702. },
  703. //获取contentType数据源
  704. contentTypeOptionsGet: function () {
  705. var that = this;
  706. ms.http.get(ms.manager +'/mdiy/dict/list.do', {
  707. dictType: '文章属性',
  708. pageSize: 99999
  709. }).then(function (data) {
  710. if(data.result){
  711. data = data.data;
  712. that.contentTypeOptions = data.rows;
  713. }
  714. }).catch(function (err) {
  715. console.log(err);
  716. });
  717. },
  718. //获取contentTag数据源
  719. contentTagsOptionsGet: function () {
  720. var that = this;
  721. ms.http.get(ms.manager + '/mdiy/dict/list.do', {
  722. dictType: '文章标签',
  723. pageSize: 99999
  724. }).then(function (data) {
  725. if(data.result){
  726. data = data.data;
  727. that.contentTagsOptions = data.rows;
  728. }
  729. });
  730. },
  731. //contentImg文件上传完成回调
  732. contentImgSuccess: function (response, file, fileList) {
  733. if(response.result){
  734. this.form.contentImg.push({
  735. url: response.data,
  736. name: file.name,
  737. uid: file.uid
  738. });
  739. }else {
  740. // 移除上传图片
  741. var index = fileList.indexOf(file);
  742. if (index > -1) {
  743. fileList.splice(index, 1);
  744. }
  745. this.$notify({
  746. title: '失败',
  747. message: response.msg,
  748. type: 'warning'
  749. });
  750. }
  751. },
  752. //contentImg文件上传失败回调
  753. contentImgError: function (response, file, fileList) {
  754. response = JSON.parse(response.message);
  755. this.$notify({
  756. title: '失败',
  757. message: response.msg,
  758. type: 'warning'
  759. });
  760. },
  761. contentImgHandLePreview:function (file) {
  762. window.open(file.url)
  763. },
  764. contentImghandleRemove: function (file, files) {
  765. var index = -1;
  766. index = this.form.contentImg.findIndex(function (text) {
  767. return text.uid == file.uid;
  768. });
  769. if (index != -1) {
  770. this.form.contentImg.splice(index, 1);
  771. }
  772. },
  773. //上传超过限制
  774. contentImghandleExceed: function (files, fileList) {
  775. this.$notify({
  776. title: '失败',
  777. message: '当前最多上传10个文件',
  778. type: 'warning'
  779. });
  780. },
  781. //只有在渲染完栏目数据之后才会初始化
  782. init: function () {
  783. var that = this;
  784. this.form.id = this.id;
  785. this.editorHidden = true;
  786. //在指定栏目下新增或编辑文章时
  787. if (this.categoryId) {
  788. this.form.categoryId = this.categoryId;
  789. //如果是封面栏目直接跳转
  790. if (this.categoryType=="2") { //封面
  791. this.getFromFengMian(this.form.categoryId);
  792. this.categoryChangeEnabled = false;
  793. //指定非封面栏目编辑文章
  794. }else if (this.form.id) {
  795. this.get(this.form.id);
  796. //指定栏目新增文章渲染自定义模型
  797. }else {
  798. this.changeModel(this.categoryId);
  799. }
  800. //不指定栏目编辑文章
  801. }else if (this.form.id) {
  802. this.get(this.form.id);
  803. }//else 如果即不指定栏目新增文章,又不是编辑文章就不渲染自定义模型
  804. setTimeout(()=>{
  805. //显示编辑器
  806. that.editorHidden = false;
  807. },200)
  808. },
  809. //复制文章id
  810. copyString: function () {
  811. var clipboard = new ClipboardJS('.copyBtn');
  812. var self = this;
  813. clipboard.on('success', function (e) {
  814. self.$notify({
  815. title: '提示',
  816. message: '已成功复制到剪切板',
  817. type: 'success'
  818. });
  819. clipboard.destroy();
  820. });
  821. },
  822. },
  823. created: function () {
  824. this.contentCategoryIdOptionsGet();
  825. this.contentTypeOptionsGet();
  826. this.contentTagsOptionsGet();
  827. }
  828. });
  829. </script>
  830. <style scoped>
  831. .el-select {
  832. width: 100%;
  833. }
  834. body {
  835. overflow: hidden;
  836. }
  837. #form {
  838. overflow: hidden;
  839. width: 100%;
  840. }
  841. .el-scrollbar__bar.is-vertical{
  842. width: 6px!important;
  843. }
  844. #form >>> .el-tabs__item {
  845. background-color: unset;
  846. }
  847. /** 解决上传组件点击冒泡,因为图片是镂空的 **/
  848. :deep(.el-icon--zoom-in),:deep(.el-icon--delete) {
  849. background-color: rgba(0, 0, 0, 0.167);
  850. }
  851. </style>