index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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. </el-form-item>
  174. </el-form>
  175. <div slot="footer" class="dialog-footer">
  176. <el-button type="primary" @click="submitForm">确 定</el-button>
  177. <el-button @click="cancel">取 消</el-button>
  178. </div>
  179. </el-dialog>
  180. </div>
  181. </template>
  182. <script>
  183. import {getArticle, listArticle, addArticle, updateArticle, delArticle} from "@/api/system/article";
  184. import {columnAllList, treeselect} from "@/api/system/column";
  185. import Treeselect from "@riophae/vue-treeselect";
  186. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  187. export default {
  188. name: "Article",
  189. components: {Treeselect},
  190. data() {
  191. return {
  192. // 遮罩层
  193. loading: true,
  194. // 选中数组
  195. ids: [],
  196. // 非单个禁用
  197. single: true,
  198. // 非多个禁用
  199. multiple: true,
  200. // 显示搜索条件
  201. showSearch: true,
  202. // 总条数
  203. total: 0,
  204. // 文章管理表格数据
  205. articleList: [],
  206. // 栏目数据
  207. columnList: [],
  208. // 栏目存储数据
  209. tickets: [],
  210. //树
  211. menuOptions: [],
  212. // 栏目名称
  213. columnName: undefined,
  214. // 栏目树选项
  215. columnOptions: undefined,
  216. // 弹出层标题
  217. title: "",
  218. // 是否显示弹出层
  219. open: false,
  220. // 查询参数
  221. queryParams: {
  222. pageNum: 1,
  223. pageSize: 10,
  224. journalismName: null,
  225. journalismContent: null,
  226. columnId: null,
  227. author: null,
  228. releaseTime: null
  229. },
  230. value: 999,
  231. // 表单参数
  232. form: {
  233. columnId: null
  234. },
  235. defaultProps: {
  236. children: "children",
  237. label: "label"
  238. },
  239. // 表单校验
  240. rules: {
  241. journalismName: [
  242. {
  243. required: true, message: "标题不能为空", trigger: "blur"
  244. }
  245. ],
  246. columnId: [
  247. {
  248. required: true, message: "栏目不能为空", trigger: "blur"
  249. }
  250. ],
  251. author: [
  252. {
  253. required: true, message: "作者不能为空", trigger: "blur"
  254. }
  255. ],
  256. releaseTime: [
  257. {
  258. required: true, message: "发布时间不能为空", trigger: "blur"
  259. }
  260. ],
  261. columnName: [
  262. {
  263. required: true, message: "栏目名称不能为空", trigger: "blur"
  264. }
  265. ],
  266. }
  267. };
  268. },
  269. watch: {
  270. // 根据名称筛选部门树
  271. columnName(val) {
  272. this.$refs.tree.filter(val);
  273. }
  274. },
  275. created() {
  276. this.getList();
  277. // this.getColumnList();
  278. this.getColumnTree();
  279. },
  280. methods: {
  281. getNowTime() {
  282. var now = new Date()
  283. var year = now.getFullYear() // 得到年份
  284. var month = now.getMonth() // 得到月份
  285. var date = now.getDate() // 得到日期
  286. month = month + 1
  287. month = month.toString().padStart(2, '0')
  288. date = date.toString().padStart(2, '0')
  289. var defaultDate = `${year}-${month}-${date}`
  290. this.$set(this.form, 'releaseTime', defaultDate)
  291. },
  292. /** 查询文章管理列表 */
  293. getList() {
  294. this.loading = true;
  295. listArticle(this.queryParams).then(response => {
  296. this.articleList = response.rows;
  297. this.total = response.total;
  298. this.loading = false;
  299. });
  300. },
  301. /** 转换菜单数据结构 */
  302. normalizer(node) {
  303. if (node.children && !node.children.length) {
  304. delete node.children;
  305. }
  306. return {
  307. id: node.columnId,
  308. label: node.columnName,
  309. children: node.children
  310. };
  311. },
  312. /** 查询栏目下拉树结构 */
  313. getTreeselect() {
  314. columnAllList().then(response => {
  315. this.menuOptions = [];
  316. const menu = {columnId: 0, columnName: '主类目', children: []};
  317. menu.children = this.handleTree(response.data, "columnId");
  318. this.menuOptions.push(menu);
  319. });
  320. },
  321. /** 查询左侧下拉树结构 */
  322. getColumnTree() {
  323. treeselect().then(response => {
  324. this.columnOptions = response.data;
  325. });
  326. },
  327. // 筛选节点
  328. filterNode(value, data) {
  329. console.log("文章value",value)
  330. console.log("文章data",data)
  331. if (!value) return true;
  332. return data.label.indexOf(value) !== -1;
  333. },
  334. // 节点单击事件
  335. handleNodeClick(data) {
  336. this.queryParams.columnId = data.id;
  337. this.form.columnId = data.id;
  338. this.handleQuery();
  339. },
  340. /** 查询文章管理全部列表 */
  341. getColumnList() {
  342. this.loading = true;
  343. columnAllList().then(response => {
  344. this.columnList = response.data;
  345. this.loading = false;
  346. });
  347. },
  348. // 取消按钮
  349. cancel() {
  350. this.open = false;
  351. this.reset();
  352. },
  353. // 表单重置
  354. reset() {
  355. this.form = {
  356. id: null,
  357. journalismName: null,
  358. journalismContent: null,
  359. createTime: null,
  360. sort: null,
  361. columnId: null,
  362. author: null,
  363. releaseTime: null,
  364. };
  365. this.resetForm("form");
  366. this.getNowTime()
  367. },
  368. /** 搜索按钮操作 */
  369. handleQuery() {
  370. this.queryParams.pageNum = 1;
  371. this.getList();
  372. // this.getColumnList();
  373. },
  374. /** 重置按钮操作 */
  375. resetQuery() {
  376. this.resetForm("queryForm");
  377. this.handleQuery();
  378. },
  379. // 多选框选中数据
  380. handleSelectionChange(selection) {
  381. this.ids = selection.map(item => item.id)
  382. this.single = selection.length !== 1
  383. this.multiple = !selection.length
  384. },
  385. /** 新增按钮操作 */
  386. handleAdd() {
  387. this.reset();
  388. this.getTreeselect();
  389. this.value = 999;
  390. this.open = true;
  391. this.title = "添加文章";
  392. this.form.columnId = this.queryParams.columnId;
  393. },
  394. /** 修改按钮操作 */
  395. handleUpdate(row) {
  396. this.reset();
  397. this.getTreeselect();
  398. const id = row.id || this.ids
  399. getArticle(id).then(response => {
  400. this.form = response.data;
  401. this.value = this.form.sort
  402. this.open = true;
  403. this.title = "修改文章";
  404. });
  405. },
  406. /** 提交按钮 */
  407. submitForm() {
  408. this.form.sort = this.value
  409. this.$refs["form"].validate(valid => {
  410. if (valid) {
  411. if (this.form.id != null) {
  412. updateArticle(this.form).then(response => {
  413. this.$modal.msgSuccess("修改成功");
  414. this.open = false;
  415. this.getList();
  416. // this.getColumnList();
  417. this.getColumnTree();
  418. });
  419. } else {
  420. addArticle(this.form).then(response => {
  421. this.$modal.msgSuccess("新增成功");
  422. this.open = false;
  423. this.getList();
  424. // this.getColumnList();
  425. this.getColumnTree();
  426. });
  427. }
  428. }
  429. });
  430. },
  431. /** 删除按钮操作 */
  432. handleDelete(row) {
  433. const ids = row.id || this.ids;
  434. this.$modal.confirm('是否确认删除此条数据项?').then(function () {
  435. return delArticle(ids);
  436. }).then(() => {
  437. this.getList();
  438. this.getColumnTree();
  439. // this.getColumnList();
  440. this.$modal.msgSuccess("删除成功");
  441. }).catch(() => {
  442. });
  443. }
  444. }
  445. }
  446. ;
  447. </script>