form.ftl 42 KB

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