news.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. <template>
  2. <basic-container>
  3. <avue-crud :option="option"
  4. :table-loading="loading"
  5. :data="data"
  6. :page="page"
  7. :permission="permissionList"
  8. :before-open="beforeOpen"
  9. v-model="form"
  10. ref="crud"
  11. @row-update="rowUpdate"
  12. @row-save="rowSave"
  13. @row-del="rowDel"
  14. @search-change="searchChange"
  15. @search-reset="searchReset"
  16. @selection-change="selectionChange"
  17. @current-change="currentChange"
  18. @size-change="sizeChange"
  19. @refresh-change="refreshChange"
  20. @on-load="onLoad">
  21. <template slot="menuLeft">
  22. <el-button type="danger"
  23. size="small"
  24. icon="el-icon-delete"
  25. plain
  26. v-if="permission.newslist_delete"
  27. @click="handleDelete">删 除
  28. </el-button>
  29. </template>
  30. <template slot="content" slot-scope="{row}">
  31. <el-button size="mini" @click="showContent(row)">查看资讯内容</el-button>
  32. </template>
  33. <!-- <template slot="newsStatus" slot-scope="{row}">-->
  34. <!-- <el-switch v-model="row.newsStatus"-->
  35. <!-- :active-value=1 active-text="开启"-->
  36. <!-- :inactive-value=0 inactive-text="关闭"-->
  37. <!-- @change="statusChange(row)">-->
  38. <!-- </el-switch>-->
  39. <!-- </template>-->
  40. <!-- <template slot="isSupportComment" slot-scope="{row}">-->
  41. <!-- <el-switch v-model="row.isSupportComment"-->
  42. <!-- :active-value=1 active-text="开启"-->
  43. <!-- :inactive-value=0 inactive-text="关闭"-->
  44. <!-- @change="statusChange(row)">-->
  45. <!-- </el-switch>-->
  46. <!-- </template>-->
  47. <template slot="menu" slot-scope="{row}">
  48. <el-button type="text" size="mini" icon="el-icon-s-comment" @click="showComment(row)">评论</el-button>
  49. </template>
  50. </avue-crud>
  51. <el-dialog :visible.sync="commentVisible" width="80%" :modal-append-to-body="false" append-to-body center>
  52. <comment ref="comment" :relationId="newsId" relationType="1"></comment>
  53. </el-dialog>
  54. <!-- <el-dialog :visible.sync="show" width="30%" :modal-append-to-body="false" append-to-body center >-->
  55. <!-- <avue-ueditor v-model="form.content" :upload="upload" disabled></avue-ueditor>-->
  56. <!-- </el-dialog>-->
  57. </basic-container>
  58. </template>
  59. <script>
  60. import {getList, getDetail, add, update, remove} from "@/api/party/news";
  61. import {mapGetters} from "vuex";
  62. import comment from "@/views/party/comment.vue"
  63. // import AvueUeditor from "avue-plugin-ueditor";
  64. export default {
  65. components: {
  66. comment
  67. },
  68. props: {
  69. branchId: {
  70. type: String
  71. }
  72. },
  73. data() {
  74. return {
  75. upload: {
  76. action: '/api/blade-resource/oss/endpoint/put-file',
  77. props: {
  78. res: "data",
  79. url: "link",
  80. }
  81. },
  82. commentVisible: false,
  83. newsId: 0,
  84. show: false,
  85. form: {},
  86. query: {},
  87. loading: true,
  88. page: {
  89. pageSize: 10,
  90. currentPage: 1,
  91. total: 0
  92. },
  93. selectionList: [],
  94. option: {
  95. height:'auto',
  96. calcHeight: 30,
  97. tip: false,
  98. searchShow: true,
  99. searchMenuSpan: 6,
  100. border: true,
  101. index: false,
  102. viewBtn: true,
  103. selection: true,
  104. dialogClickModal: false,
  105. column: [
  106. {
  107. label: "资讯名称",
  108. prop: "name",
  109. row: true,
  110. search: true,
  111. rules: [{
  112. required: true,
  113. message: "请输入资讯名称",
  114. trigger: "blur"
  115. }]
  116. },
  117. {
  118. label: "资讯图片",
  119. prop: "img",
  120. type: 'upload',
  121. hide: true,
  122. row: true,
  123. listType: 'picture-img',
  124. action: '/api/blade-resource/oss/endpoint/put-file',
  125. propsHttp: {
  126. res: 'data',
  127. url: 'link',
  128. },
  129. display: true
  130. },
  131. // {
  132. // label: "资讯内容",
  133. // prop: "content",
  134. // // component: 'ueditor',
  135. // component: 'AvueUeditor',
  136. // options: {
  137. // action: '/api/blade-resource/oss/endpoint/put-file',
  138. // props: {
  139. // res: "data",
  140. // url: "link",
  141. // }
  142. // },
  143. // minRows: 6,
  144. // span: 18,
  145. // row: true,
  146. // slot: true,
  147. // rules: [{
  148. // required: true,
  149. // message: "请输入资讯内容",
  150. // trigger: "blur"
  151. // }]
  152. // },
  153. {
  154. label: "热门状态",
  155. prop: "hitStatus",
  156. type: "radio",
  157. row: true,
  158. search: true,
  159. dicUrl: "/api/blade-system/dict/dictionary?code=yes_no",
  160. dataType: "number",
  161. props: {
  162. label: "dictValue",
  163. value: "dictKey",
  164. },
  165. rules: [{
  166. required: true,
  167. message: "请选择热门状态",
  168. trigger: "blur"
  169. }]
  170. },
  171. {
  172. label: "资讯分类",
  173. prop: "classId",
  174. type: "select",
  175. row: true,
  176. search: true,
  177. dicUrl: "/api/blade-system/dict-biz/dictionary?code=party_new_class",
  178. dataType: "number",
  179. props: {
  180. label: "dictValue",
  181. value: "dictKey",
  182. },
  183. rules: [{
  184. required: true,
  185. message: "请选择资讯分类",
  186. trigger: "blur"
  187. }]
  188. },
  189. {
  190. label: "资讯状态",
  191. prop: "newsStatus",
  192. type: "select",
  193. row: true,
  194. search: true,
  195. // dicUrl: "/api/blade-system/dict/dictionary?code=on_off",
  196. dataType: "number",
  197. dicData: [
  198. {
  199. label:'下架',
  200. value: 0,
  201. },{
  202. label:'上架',
  203. value: 1
  204. }
  205. ],
  206. rules: [{
  207. required: true,
  208. message: "请选择资讯状态",
  209. trigger: "blur"
  210. }]
  211. },
  212. {
  213. label: "评论状态",
  214. prop: "isSupportComment",
  215. type: "select",
  216. row: true,
  217. search: true,
  218. // dicUrl: "/api/blade-system/dict/dictionary?code=on_off",
  219. dataType: "number",
  220. dicData: [
  221. {
  222. label: "关闭",
  223. value: 0
  224. },
  225. {
  226. label: "开启",
  227. value: 1
  228. }
  229. ],
  230. rules: [{
  231. required: true,
  232. message: "请选择是否开启评论状态",
  233. trigger: "blur"
  234. }]
  235. },
  236. // {
  237. // label: "排序",
  238. // prop: "sort",
  239. // type: "number",
  240. // rules: [{
  241. // required: true,
  242. // message: "请输入排序",
  243. // trigger: "blur"
  244. // }]
  245. // },
  246. ]
  247. },
  248. data: []
  249. };
  250. },
  251. computed: {
  252. ...mapGetters(["permission"]),
  253. permissionList() {
  254. return {
  255. addBtn: this.vaildData(this.permission.news_add, false),
  256. viewBtn: this.vaildData(this.permission.news_view, false),
  257. delBtn: this.vaildData(this.permission.news_delete, false),
  258. editBtn: this.vaildData(this.permission.news_edit, false)
  259. };
  260. },
  261. ids() {
  262. let ids = [];
  263. this.selectionList.forEach(ele => {
  264. ids.push(ele.id);
  265. });
  266. return ids.join(",");
  267. }
  268. },
  269. methods: {
  270. showComment(row){
  271. this.newsId = row.id;
  272. this.commentVisible = true;
  273. this.$nextTick(()=>{
  274. this.$refs.comment.init()
  275. })
  276. },
  277. statusChange(row) {
  278. update(row).then(() => {
  279. this.onLoad(this.page);
  280. this.$message({
  281. type: "success",
  282. message: "操作成功!"
  283. });
  284. }, error => {
  285. console.log(error);
  286. });
  287. },
  288. showContent(row){
  289. this.form = row;
  290. this.show = true;
  291. },
  292. rowSave(row, done, loading) {
  293. row.branchId = this.branchId;
  294. row.content = btoa(unescape(encodeURIComponent(row.content)));
  295. add(row).then(() => {
  296. this.onLoad(this.page);
  297. this.$message({
  298. type: "success",
  299. message: "操作成功!"
  300. });
  301. done();
  302. }, error => {
  303. loading();
  304. window.console.log(error);
  305. });
  306. },
  307. rowUpdate(row, index, done, loading) {
  308. row.content = btoa(unescape(encodeURIComponent(row.content)));
  309. update(row).then(() => {
  310. this.onLoad(this.page);
  311. this.$message({
  312. type: "success",
  313. message: "操作成功!"
  314. });
  315. done();
  316. }, error => {
  317. loading();
  318. console.log(error);
  319. });
  320. },
  321. rowDel(row) {
  322. this.$confirm("确定将选择数据删除?", {
  323. confirmButtonText: "确定",
  324. cancelButtonText: "取消",
  325. type: "warning"
  326. })
  327. .then(() => {
  328. return remove(row.id);
  329. })
  330. .then(() => {
  331. this.onLoad(this.page);
  332. this.$message({
  333. type: "success",
  334. message: "操作成功!"
  335. });
  336. });
  337. },
  338. handleDelete() {
  339. if (this.selectionList.length === 0) {
  340. this.$message.warning("请选择至少一条数据");
  341. return;
  342. }
  343. this.$confirm("确定将选择数据删除?", {
  344. confirmButtonText: "确定",
  345. cancelButtonText: "取消",
  346. type: "warning"
  347. })
  348. .then(() => {
  349. return remove(this.ids);
  350. })
  351. .then(() => {
  352. this.onLoad(this.page);
  353. this.$message({
  354. type: "success",
  355. message: "操作成功!"
  356. });
  357. this.$refs.crud.toggleSelection();
  358. });
  359. },
  360. beforeOpen(done, type) {
  361. if (["edit", "view"].includes(type)) {
  362. getDetail(this.form.id).then(res => {
  363. this.form = res.data.data;
  364. });
  365. }
  366. done();
  367. },
  368. searchReset() {
  369. this.query = {};
  370. this.onLoad(this.page);
  371. },
  372. searchChange(params, done) {
  373. this.query = params;
  374. this.page.currentPage = 1;
  375. this.onLoad(this.page, params);
  376. done();
  377. },
  378. selectionChange(list) {
  379. this.selectionList = list;
  380. },
  381. selectionClear() {
  382. this.selectionList = [];
  383. this.$refs.crud.toggleSelection();
  384. },
  385. currentChange(currentPage){
  386. this.page.currentPage = currentPage;
  387. },
  388. sizeChange(pageSize){
  389. this.page.pageSize = pageSize;
  390. },
  391. refreshChange() {
  392. this.onLoad(this.page, this.query);
  393. },
  394. onLoad(page, params = {}) {
  395. this.loading = true;
  396. this.query.branchId = this.branchId
  397. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  398. const data = res.data.data;
  399. this.page.total = data.total;
  400. this.data = data.records;
  401. this.loading = false;
  402. this.selectionClear();
  403. });
  404. }
  405. }
  406. };
  407. </script>
  408. <style>
  409. </style>