index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="20">
  4. <!--栏目数据-->
  5. <el-col :span="4" :xs="24">
  6. <div class="head-container">
  7. <el-input
  8. v-model="columnName"
  9. placeholder="请输入栏目名称"
  10. clearable
  11. size="small"
  12. prefix-icon="el-icon-search"
  13. style="margin-bottom: 20px"
  14. />
  15. </div>
  16. <div class="head-container">
  17. <el-tree
  18. :data="columnOptions"
  19. :props="defaultProps"
  20. :expand-on-click-node="false"
  21. :filter-node-method="filterNode"
  22. ref="tree"
  23. node-key="id"
  24. default-expand-all
  25. highlight-current
  26. @node-click="handleNodeClick"
  27. />
  28. </div>
  29. </el-col>
  30. <!--文章数据-->
  31. <el-col :span="20" :xs="24">
  32. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
  33. label-width="68px">
  34. <el-form-item label="标题" prop="journalismName">
  35. <el-input
  36. v-model="queryParams.journalismName"
  37. placeholder="请输入标题"
  38. clearable
  39. @keyup.enter.native="handleQuery"
  40. />
  41. </el-form-item>
  42. <el-form-item>
  43. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  44. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  45. </el-form-item>
  46. </el-form>
  47. <el-row :gutter="10" class="mb8">
  48. <el-col :span="1.5">
  49. <el-button
  50. type="primary"
  51. plain
  52. icon="el-icon-plus"
  53. size="mini"
  54. @click="handleAdd"
  55. v-hasPermi="['system:article:add']"
  56. >新增
  57. </el-button>
  58. </el-col>
  59. <el-col :span="1.5">
  60. <el-button
  61. type="success"
  62. plain
  63. icon="el-icon-edit"
  64. size="mini"
  65. :disabled="single"
  66. @click="handleUpdate"
  67. v-hasPermi="['system:article:edit']"
  68. >修改
  69. </el-button>
  70. </el-col>
  71. <el-col :span="1.5">
  72. <el-button
  73. type="danger"
  74. plain
  75. icon="el-icon-delete"
  76. size="mini"
  77. :disabled="multiple"
  78. @click="handleDelete"
  79. v-hasPermi="['system:article:remove']"
  80. >删除
  81. </el-button>
  82. </el-col>
  83. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  84. </el-row>
  85. <el-table v-loading="loading" :data="articleList" @selection-change="handleSelectionChange">
  86. <el-table-column type="selection" width="55" align="center"/>
  87. <el-table-column label="标题" align="center" prop="journalismName"/>
  88. <el-table-column label="排序" align="center" prop="sort"/>
  89. <el-table-column label="栏目" align="center" prop="columnName"/>
  90. <el-table-column label="作者" align="center" prop="author"/>
  91. <el-table-column align="center" label="发布时间" prop="releaseTime" width="180">
  92. <template slot-scope="scope">
  93. <span>{{ parseTime(scope.row.releaseTime, '{y}-{m}-{d}') }}</span>
  94. </template>
  95. </el-table-column>
  96. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  97. <template slot-scope="scope">
  98. <el-button
  99. size="mini"
  100. type="text"
  101. icon="el-icon-edit"
  102. @click="handleUpdate(scope.row)"
  103. v-hasPermi="['system:article:edit']"
  104. >修改
  105. </el-button>
  106. <el-button
  107. size="mini"
  108. type="text"
  109. icon="el-icon-delete"
  110. @click="handleDelete(scope.row)"
  111. v-hasPermi="['system:article:remove']"
  112. >删除
  113. </el-button>
  114. </template>
  115. </el-table-column>
  116. </el-table>
  117. <pagination
  118. v-show="total>0"
  119. :total="total"
  120. :page.sync="queryParams.pageNum"
  121. :limit.sync="queryParams.pageSize"
  122. @pagination="getList"
  123. />
  124. </el-col>
  125. </el-row>
  126. <!-- 添加或修改文章管理对话框 -->
  127. <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
  128. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  129. <el-form-item label="标题" prop="journalismName">
  130. <el-input v-model="form.journalismName" placeholder="请输入标题" maxlength="30" show-word-limit/>
  131. </el-form-item>
  132. <el-form-item label="简介" prop="intro">
  133. <el-input v-model="form.intro" placeholder="请输入简介" maxlength="30" show-word-limit/>
  134. </el-form-item>
  135. <el-row>
  136. <el-col :span="12">
  137. <el-form-item label="发布时间" prop="releaseTime">
  138. <el-date-picker
  139. v-model="form.releaseTime"
  140. type="date"
  141. placeholder="请选择发布时间">
  142. </el-date-picker>
  143. </el-form-item>
  144. </el-col>
  145. <el-col :span="12">
  146. <el-form-item label="作者" prop="author">
  147. <el-input v-model="form.author" placeholder="请输入作者" maxlength="10" show-word-limit/>
  148. </el-form-item>
  149. </el-col>
  150. <el-col :span="12">
  151. <el-form-item label="排序" prop="sort">
  152. <el-input-number :min="1" v-model="value" placeholder="请输入排序"/>
  153. </el-form-item>
  154. </el-col>
  155. <el-col :span="12">
  156. <el-form-item label="栏目" prop="columnId">
  157. <treeselect
  158. v-model="form.columnId"
  159. :options="menuOptions"
  160. :normalizer="normalizer"
  161. :show-count="true"
  162. :disable-branch-nodes="true"
  163. placeholder="选择栏目"
  164. />
  165. </el-form-item>
  166. </el-col>
  167. </el-row>
  168. <el-form-item label="图片" prop="img">
  169. <file-upload v-model="form.img" :limit="1" :file-type="['png','jpg','jpeg']" :file-size="10"/>
  170. </el-form-item>
  171. <el-form-item label="内容" prop="journalismContent">
  172. <!-- <editor style="height: 300px" label="富文本控件" v-model="form.journalismContent" maxlength="4000" show-word-limit/>-->
  173. <MyEditor v-model="form.journalismContent" v-if="open"/>
  174. </el-form-item>
  175. </el-form>
  176. <div slot="footer" class="dialog-footer">
  177. <el-button type="primary" @click="submitForm">确 定</el-button>
  178. <el-button @click="cancel">取 消</el-button>
  179. </div>
  180. </el-dialog>
  181. </div>
  182. </template>
  183. <script>
  184. import {getArticle, listArticle, addArticle, updateArticle, delArticle} from "@/api/system/article";
  185. import {columnAllList, treeselect} from "@/api/system/column";
  186. import Treeselect from "@riophae/vue-treeselect";
  187. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  188. export default {
  189. name: "Article",
  190. components: {Treeselect},
  191. data() {
  192. return {
  193. // 遮罩层
  194. loading: true,
  195. // 选中数组
  196. ids: [],
  197. // 非单个禁用
  198. single: true,
  199. // 非多个禁用
  200. multiple: true,
  201. // 显示搜索条件
  202. showSearch: true,
  203. // 总条数
  204. total: 0,
  205. // 文章管理表格数据
  206. articleList: [],
  207. // 栏目数据
  208. columnList: [],
  209. // 栏目存储数据
  210. tickets: [],
  211. //树
  212. menuOptions: [],
  213. // 栏目名称
  214. columnName: undefined,
  215. // 栏目树选项
  216. columnOptions: undefined,
  217. // 弹出层标题
  218. title: "",
  219. // 是否显示弹出层
  220. open: false,
  221. // 查询参数
  222. queryParams: {
  223. pageNum: 1,
  224. pageSize: 10,
  225. journalismName: null,
  226. journalismContent: null,
  227. columnId: null,
  228. author: null,
  229. releaseTime: null
  230. },
  231. value: 999,
  232. // 表单参数
  233. form: {
  234. columnId: null
  235. },
  236. defaultProps: {
  237. children: "children",
  238. label: "label"
  239. },
  240. // 表单校验
  241. rules: {
  242. journalismName: [
  243. {
  244. required: true, message: "标题不能为空", trigger: "blur"
  245. }
  246. ],
  247. columnId: [
  248. {
  249. required: true, message: "栏目不能为空", trigger: "blur"
  250. }
  251. ],
  252. author: [
  253. {
  254. required: true, message: "作者不能为空", trigger: "blur"
  255. }
  256. ],
  257. releaseTime: [
  258. {
  259. required: true, message: "发布时间不能为空", trigger: "blur"
  260. }
  261. ],
  262. columnName: [
  263. {
  264. required: true, message: "栏目名称不能为空", trigger: "blur"
  265. }
  266. ],
  267. }
  268. };
  269. },
  270. watch: {
  271. // 根据名称筛选部门树
  272. columnName(val) {
  273. this.$refs.tree.filter(val);
  274. }
  275. },
  276. created() {
  277. this.getList();
  278. // this.getColumnList();
  279. this.getColumnTree();
  280. },
  281. methods: {
  282. getNowTime() {
  283. var now = new Date()
  284. var year = now.getFullYear() // 得到年份
  285. var month = now.getMonth() // 得到月份
  286. var date = now.getDate() // 得到日期
  287. month = month + 1
  288. month = month.toString().padStart(2, '0')
  289. date = date.toString().padStart(2, '0')
  290. var defaultDate = `${year}-${month}-${date}`
  291. this.$set(this.form, 'releaseTime', defaultDate)
  292. },
  293. /** 查询文章管理列表 */
  294. getList() {
  295. this.loading = true;
  296. listArticle(this.queryParams).then(response => {
  297. this.articleList = response.rows;
  298. this.total = response.total;
  299. this.loading = false;
  300. });
  301. },
  302. /** 转换菜单数据结构 */
  303. normalizer(node) {
  304. if (node.children && !node.children.length) {
  305. delete node.children;
  306. }
  307. return {
  308. id: node.columnId,
  309. label: node.columnName,
  310. children: node.children
  311. };
  312. },
  313. /** 查询栏目下拉树结构 */
  314. getTreeselect() {
  315. columnAllList().then(response => {
  316. this.menuOptions = [];
  317. const menu = {columnId: 0, columnName: '主类目', children: []};
  318. menu.children = this.handleTree(response.data, "columnId");
  319. this.menuOptions.push(menu);
  320. });
  321. },
  322. /** 查询左侧下拉树结构 */
  323. getColumnTree() {
  324. treeselect().then(response => {
  325. this.columnOptions = response.data;
  326. });
  327. },
  328. // 筛选节点
  329. filterNode(value, data) {
  330. console.log("文章value",value)
  331. console.log("文章data",data)
  332. if (!value) return true;
  333. return data.label.indexOf(value) !== -1;
  334. },
  335. // 节点单击事件
  336. handleNodeClick(data) {
  337. this.queryParams.columnId = data.id;
  338. this.form.columnId = data.id;
  339. this.handleQuery();
  340. },
  341. /** 查询文章管理全部列表 */
  342. getColumnList() {
  343. this.loading = true;
  344. columnAllList().then(response => {
  345. this.columnList = response.data;
  346. this.loading = false;
  347. });
  348. },
  349. // 取消按钮
  350. cancel() {
  351. this.open = false;
  352. this.reset();
  353. },
  354. // 表单重置
  355. reset() {
  356. this.form = {
  357. id: null,
  358. journalismName: null,
  359. journalismContent: null,
  360. createTime: null,
  361. sort: null,
  362. columnId: null,
  363. author: null,
  364. releaseTime: null,
  365. };
  366. this.resetForm("form");
  367. this.getNowTime()
  368. },
  369. /** 搜索按钮操作 */
  370. handleQuery() {
  371. this.queryParams.pageNum = 1;
  372. this.getList();
  373. // this.getColumnList();
  374. },
  375. /** 重置按钮操作 */
  376. resetQuery() {
  377. this.resetForm("queryForm");
  378. this.handleQuery();
  379. },
  380. // 多选框选中数据
  381. handleSelectionChange(selection) {
  382. this.ids = selection.map(item => item.id)
  383. this.single = selection.length !== 1
  384. this.multiple = !selection.length
  385. },
  386. /** 新增按钮操作 */
  387. handleAdd() {
  388. this.reset();
  389. this.getTreeselect();
  390. this.value = 999;
  391. this.open = true;
  392. this.title = "添加文章";
  393. this.form.columnId = this.queryParams.columnId;
  394. },
  395. /** 修改按钮操作 */
  396. handleUpdate(row) {
  397. this.reset();
  398. this.getTreeselect();
  399. const id = row.id || this.ids
  400. getArticle(id).then(response => {
  401. this.form = response.data;
  402. this.value = this.form.sort
  403. this.open = true;
  404. this.title = "修改文章";
  405. });
  406. },
  407. /** 提交按钮 */
  408. submitForm() {
  409. this.form.sort = this.value
  410. this.$refs["form"].validate(valid => {
  411. if (valid) {
  412. if (this.form.id != null) {
  413. updateArticle(this.form).then(response => {
  414. this.$modal.msgSuccess("修改成功");
  415. this.open = false;
  416. this.getList();
  417. // this.getColumnList();
  418. this.getColumnTree();
  419. });
  420. } else {
  421. addArticle(this.form).then(response => {
  422. this.$modal.msgSuccess("新增成功");
  423. this.open = false;
  424. this.getList();
  425. // this.getColumnList();
  426. this.getColumnTree();
  427. });
  428. }
  429. }
  430. });
  431. },
  432. /** 删除按钮操作 */
  433. handleDelete(row) {
  434. const ids = row.id || this.ids;
  435. this.$modal.confirm('是否确认删除此条数据项?').then(function () {
  436. return delArticle(ids);
  437. }).then(() => {
  438. this.getList();
  439. this.getColumnTree();
  440. // this.getColumnList();
  441. this.$modal.msgSuccess("删除成功");
  442. }).catch(() => {
  443. });
  444. }
  445. }
  446. }
  447. ;
  448. </script>