index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="文章标题" prop="newsTitle">
  5. <el-input
  6. v-model="queryParams.newsTitle"
  7. placeholder="请输入文章标题"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="文章状态" prop="status">
  14. <el-select v-model="queryParams.status" placeholder="请选择文章状态" clearable size="small">
  15. <el-option
  16. v-for="dict in dict.type.column_news"
  17. :key="dict.value"
  18. :label="dict.label"
  19. :value="dict.value"
  20. />
  21. </el-select>
  22. </el-form-item>
  23. <!-- <el-form-item label="是否删除" prop="isDel">
  24. <el-select v-model="queryParams.status" placeholder="请选择是否删除" clearable size="small">
  25. <el-option
  26. v-for="dict in dict.type.is_del"
  27. :key="dict.value"
  28. :label="dict.label"
  29. :value="dict.value"
  30. />
  31. </el-select>
  32. </el-form-item>-->
  33. <el-form-item>
  34. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  35. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  36. </el-form-item>
  37. </el-form>
  38. <el-row :gutter="10" class="mb8">
  39. <el-col :span="1.5">
  40. <el-button
  41. type="primary"
  42. plain
  43. icon="el-icon-plus"
  44. size="mini"
  45. @click="handleAdd"
  46. v-hasPermi="['system:news:add']"
  47. >新增</el-button>
  48. </el-col>
  49. <el-col :span="1.5">
  50. <el-button
  51. type="success"
  52. plain
  53. icon="el-icon-edit"
  54. size="mini"
  55. :disabled="single"
  56. @click="handleUpdate"
  57. v-hasPermi="['system:news:edit']"
  58. >修改</el-button>
  59. </el-col>
  60. <el-col :span="1.5">
  61. <el-button
  62. type="danger"
  63. plain
  64. icon="el-icon-delete"
  65. size="mini"
  66. :disabled="multiple"
  67. @click="handleDelete"
  68. v-hasPermi="['system:news:remove']"
  69. >删除</el-button>
  70. </el-col>
  71. <el-col :span="1.5">
  72. <el-button
  73. type="warning"
  74. plain
  75. icon="el-icon-download"
  76. size="mini"
  77. @click="handleExport"
  78. v-hasPermi="['system:news:export']"
  79. >导出</el-button>
  80. </el-col>
  81. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  82. </el-row>
  83. <el-table v-loading="loading" :data="newsList" @selection-change="handleSelectionChange" :max-height="tableMaxHeight">
  84. <el-table-column type="selection" width="55" align="center" />
  85. <el-table-column label="栏目名称" align="center" prop="columnName" />
  86. <el-table-column label="文章标题" align="center" prop="newsTitle" />
  87. <el-table-column label="文章内容" align="center" prop="newsContent" width="300px" :show-overflow-tooltip="true"/>
  88. <el-table-column label="文章状态" align="center" prop="status">
  89. <template slot-scope="scope">
  90. <dict-tag :options="dict.type.column_news" :value="scope.row.status"/>
  91. </template>
  92. </el-table-column>
  93. <el-table-column label="是否头条" align="center" prop="isTop">
  94. <template slot-scope="scope">
  95. <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.sys_yes_no"/>
  96. </template>
  97. </el-table-column>
  98. <el-table-column label="驳回原因" align="center" prop="reason" />
  99. <el-table-column label="备注" align="center" prop="remark" />
  100. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  101. <template slot-scope="scope">
  102. <el-button
  103. size="mini"
  104. type="text"
  105. icon="el-icon-edit"
  106. @click="examine(scope.row)"
  107. v-hasPermi="['system:news:examine']"
  108. >通过审核</el-button>
  109. <el-button
  110. size="mini"
  111. type="text"
  112. icon="el-icon-edit"
  113. @click="reject(scope.row)"
  114. v-hasPermi="['system:news:reject']"
  115. >驳回</el-button>
  116. <el-button
  117. size="mini"
  118. type="text"
  119. icon="el-icon-edit"
  120. @click="handleUpdate(scope.row)"
  121. v-hasPermi="['system:news:edit']"
  122. >修改</el-button>
  123. <el-button
  124. size="mini"
  125. type="text"
  126. icon="el-icon-delete"
  127. @click="handleDelete(scope.row)"
  128. v-hasPermi="['system:news:remove']"
  129. >删除</el-button>
  130. </template>
  131. </el-table-column>
  132. </el-table>
  133. <pagination
  134. v-show="total>0"
  135. :total="total"
  136. :page.sync="queryParams.pageNum"
  137. :limit.sync="queryParams.pageSize"
  138. @pagination="getList"
  139. />
  140. <!-- 添加或修改文章信息对话框 -->
  141. <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
  142. <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  143. <el-row>
  144. <el-col :span="12">
  145. <el-form-item label="文章标题" prop="newsTitle">
  146. <el-input v-model="form.newsTitle" placeholder="请输入文章标题" />
  147. </el-form-item>
  148. </el-col>
  149. <el-col :span="12">
  150. <el-form-item label="选择栏目" prop="columnId">
  151. <treeselect v-model="form.columnId" :options="columnOptions" :normalizer="normalizer"
  152. placeholder="选择栏目" />
  153. </el-form-item>
  154. </el-col>
  155. <el-col :span="12">
  156. <el-form-item label="是否头条" prop="isTop">
  157. <el-select v-model="form.isTop" placeholder="请选择" style="width: 100%;">
  158. <el-option v-for="dict in dict.type.sys_yes_no" :key="dict.value" :label="dict.label"
  159. :value="dict.value"></el-option>
  160. </el-select>
  161. </el-form-item>
  162. </el-col>
  163. <el-col :span="12">
  164. <el-form-item label="备注" prop="remark">
  165. <el-input v-model="form.remark" placeholder="请输入备注" />
  166. </el-form-item>
  167. </el-col>
  168. <el-col :span="24">
  169. <el-form-item label="文章内容" prop="newsContent">
  170. <editor v-model="form.newsContent" :min-height="192" />
  171. </el-form-item>
  172. </el-col>
  173. <el-col :span="24">
  174. <el-form-item label="文章缩略图" prop="newsImage">
  175. <!-- <editor v-model="form.newsImage" :min-height="192" /> -->
  176. <imageUpload v-model="form.newsImage" />
  177. </el-form-item>
  178. </el-col>
  179. </el-row>
  180. <!-- <el-form-item label="文章状态">
  181. <el-radio-group v-model="form.status">
  182. <el-radio
  183. v-for="dict in dict.type.column_news"
  184. :key="dict.value"
  185. :label="dict.value"
  186. >{{dict.label}}</el-radio>
  187. </el-radio-group>
  188. </el-form-item>
  189. <el-form-item label="原因" prop="reason">
  190. <el-input v-model="form.reason" placeholder="请输入原因" />
  191. </el-form-item>-->
  192. <el-form-item label="备注" prop="remark">
  193. <el-input v-model="form.remark" placeholder="请输入备注" />
  194. </el-form-item>
  195. </el-form>
  196. <div slot="footer" class="dialog-footer">
  197. <el-button type="primary" @click="submitForm">确 定</el-button>
  198. <el-button @click="cancel">取 消</el-button>
  199. </div>
  200. </el-dialog>
  201. </div>
  202. </template>
  203. <script>
  204. import { listNews, getNews, delNews, addNews, updateNews,rejectNews,examineNews } from "@/api/system/news";
  205. import { listColumn } from '@/api/system/column'
  206. import Treeselect from "@riophae/vue-treeselect";
  207. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  208. export default {
  209. name: "News",
  210. dicts: ['column_news','is_del','sys_yes_no'],
  211. components: { Treeselect },
  212. data() {
  213. return {
  214. // 遮罩层
  215. loading: true,
  216. // 选中数组
  217. ids: [],
  218. // 非单个禁用
  219. single: true,
  220. // 非多个禁用
  221. multiple: true,
  222. // 显示搜索条件
  223. showSearch: true,
  224. // 总条数
  225. total: 0,
  226. // 文章信息表格数据
  227. newsList: [],
  228. //栏目树选项
  229. columnOptions: [],
  230. // 弹出层标题
  231. title: "",
  232. // 是否显示弹出层
  233. open: false,
  234. // 查询参数
  235. queryParams: {
  236. pageNum: 1,
  237. pageSize: 10,
  238. newsTitle: null,
  239. columnId: null,
  240. status: null,
  241. isDel: null,
  242. },
  243. // 表单参数
  244. form: {},
  245. // 表单校验
  246. rules: {
  247. newsTitle: [
  248. { required: true, message: "文章标题不能为空", trigger: "blur" }
  249. ],
  250. columnId: [
  251. { required: true, message: "所属栏目不能为空", trigger: "blur" }
  252. ],
  253. isTop: [
  254. { required: true, message: "是否头条不能为空", trigger: "blur" }
  255. ]
  256. },
  257. boh:{}, //驳回原因
  258. tableMaxHeight:300
  259. };
  260. },
  261. created() {
  262. this.getList();
  263. window.onresize = () => {
  264. this.changeTableMaxHeight()
  265. }
  266. this.changeTableMaxHeight()
  267. },
  268. destroyed () {
  269. window.onresize = null
  270. },
  271. mounted() {
  272. window.onresize = () => {
  273. this.changeTableMaxHeight()
  274. }
  275. this.changeTableMaxHeight()
  276. },
  277. methods: {
  278. /** 查询文章信息列表 */
  279. getList() {
  280. this.loading = true;
  281. listNews(this.queryParams).then(response => {
  282. this.newsList = response.rows;
  283. this.total = response.total;
  284. this.loading = false;
  285. });
  286. },
  287. // 取消按钮
  288. cancel() {
  289. this.open = false;
  290. this.reset();
  291. },
  292. // 表单重置
  293. reset() {
  294. this.form = {
  295. newsId: null,
  296. newsTitle: null,
  297. columnId: null,
  298. newsContent: undefined,
  299. status: "0",
  300. isTop: null,
  301. isDel: null,
  302. reason: null,
  303. createBy: null,
  304. createTime: null,
  305. updateBy: null,
  306. updateTime: null,
  307. remark: null
  308. };
  309. this.resetForm("form");
  310. },
  311. /** 搜索按钮操作 */
  312. handleQuery() {
  313. this.queryParams.pageNum = 1;
  314. this.getList();
  315. },
  316. /** 重置按钮操作 */
  317. resetQuery() {
  318. this.resetForm("queryForm");
  319. this.handleQuery();
  320. },
  321. // 多选框选中数据
  322. handleSelectionChange(selection) {
  323. this.ids = selection.map(item => item.newsId)
  324. this.single = selection.length!==1
  325. this.multiple = !selection.length
  326. },
  327. /** 新增按钮操作 */
  328. handleAdd() {
  329. this.reset();
  330. this.open = true;
  331. this.title = "添加文章信息";
  332. listColumn().then(response => {
  333. if (response.data != null) {
  334. this.columnOptions = this.handleTree(response.data, "columnId");
  335. }
  336. });
  337. },
  338. /** 修改按钮操作 */
  339. handleUpdate(row) {
  340. this.reset();
  341. const newsId = row.newsId || this.ids
  342. getNews(newsId).then(response => {
  343. this.form = response.data;
  344. this.open = true;
  345. this.title = "修改文章信息";
  346. listColumn().then(response => {
  347. if (response.data != null) {
  348. this.columnOptions = this.handleTree(response.data, "columnId");
  349. }
  350. });
  351. });
  352. },
  353. /** 审核通过按钮操作 */
  354. examine(row) {
  355. const newsId = row.newsId || this.ids
  356. examineNews(newsId).then(response => {
  357. this.$modal.msgSuccess("审核成功");
  358. this.open = false;
  359. this.getList();
  360. });
  361. },
  362. /** 驳回按钮操作 */
  363. reject(row) {
  364. const newsId = row.newsId || this.ids
  365. var that = this
  366. this.$prompt('请输入驳回原因', '提示', {
  367. confirmButtonText: '确定',
  368. cancelButtonText: '取消',
  369. inputValue: '',
  370. inputErrorMessage: '输入不能为空',
  371. showCancelButton:false,
  372. inputValidator: (value) => { // 点击按钮时,对文本框里面的值进行验证
  373. if(!value) {
  374. return '输入不能为空';
  375. }
  376. },
  377. }).then(({ value }) => {
  378. this.boh.reason = value
  379. this.boh.newsId = newsId
  380. // that.rejectNews(this.boh).then(response => {
  381. // console.log(8764)
  382. // this.$modal.msgSuccess("驳回成功");
  383. // // this.open = false;
  384. // this.getList();
  385. // });
  386. return that.nhde()
  387. })
  388. .catch(() => {
  389. // this.nhde()
  390. });
  391. },
  392. nhde(){
  393. rejectNews(this.boh).then(response => {
  394. this.$modal.msgSuccess("驳回成功");
  395. // this.open = false;
  396. this.getList();
  397. });
  398. },
  399. /** 提交按钮 */
  400. submitForm() {
  401. this.$refs["form"].validate(valid => {
  402. if (valid) {
  403. if (this.form.newsId != null) {
  404. updateNews(this.form).then(response => {
  405. this.$modal.msgSuccess("修改成功");
  406. this.open = false;
  407. this.getList();
  408. });
  409. } else {
  410. console.log(this.form,111)
  411. addNews(this.form).then(response => {
  412. this.$modal.msgSuccess("新增成功");
  413. this.open = false;
  414. this.getList();
  415. });
  416. }
  417. }
  418. });
  419. },
  420. /** 删除按钮操作 */
  421. handleDelete(row) {
  422. const newsIds = row.newsId || this.ids;
  423. this.$modal.confirm('是否确认删除文章信息编号为"' + newsIds + '"的数据项?').then(function() {
  424. return delNews(newsIds);
  425. }).then(() => {
  426. this.getList();
  427. this.$modal.msgSuccess("删除成功");
  428. }).catch(() => {});
  429. },
  430. /** 导出按钮操作 */
  431. handleExport() {
  432. this.download('system/news/export', {
  433. ...this.queryParams
  434. }, `news_${new Date().getTime()}.xlsx`)
  435. },
  436. /** 转换栏目数据结构 */
  437. normalizer(node) {
  438. if (node.children && !node.children.length) {
  439. delete node.children;
  440. }
  441. return {
  442. id: node.columnId,
  443. label: node.columnName,
  444. children: node.children
  445. };
  446. },
  447. // 获取屏幕高度
  448. showFilterForm () {
  449. this.filterActive = !this.filterActive
  450. this.changeTableMaxHeight()
  451. },
  452. changeTableMaxHeight () {
  453. let height = document.body.offsetHeight // 网页可视区域高度
  454. // if (this.filterActive) {
  455. // this.tableMaxHeight = height - 320
  456. // } else {
  457. this.tableMaxHeight = height - 250
  458. // }
  459. console.log(height)
  460. }
  461. }
  462. };
  463. </script>