article.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <basic-container>
  3. <avue-crud :option="option"
  4. :table-loading="loading"
  5. :data="data"
  6. :page.sync="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.article_delete"
  27. @click="handleDelete">删 除
  28. </el-button>
  29. </template>
  30. </avue-crud>
  31. <avue-ueditor>
  32. </avue-ueditor>
  33. </basic-container>
  34. </template>
  35. <script>
  36. import {getList, getDetail, add, update, remove} from "@/api/estate/article";
  37. import {mapGetters} from "vuex";
  38. export default {
  39. data() {
  40. return {
  41. form: {},
  42. query: {},
  43. loading: true,
  44. page: {
  45. pageSize: 10,
  46. currentPage: 1,
  47. total: 0
  48. },
  49. selectionList: [],
  50. option: {
  51. height:'auto',
  52. calcHeight: 30,
  53. tip: false,
  54. searchShow: true,
  55. searchMenuSpan: 6,
  56. border: true,
  57. index: true,
  58. viewBtn: true,
  59. selection: true,
  60. dialogClickModal: false,
  61. column: [
  62. {
  63. label: "园区名称",
  64. prop: "agencyId",
  65. type: 'select',
  66. search: true,
  67. // overHidden: true,
  68. // remote: true,
  69. // cascaderItem: ['residentialId'],
  70. // dicUrl: "/api/agency/agency/select?size=10&agencyName={{key}}",
  71. // props: {
  72. // label: "agencyName",
  73. // value: "id"
  74. // },
  75. rules: [{
  76. required: true,
  77. message: "请选择园区名称",
  78. trigger: "blur"
  79. }]
  80. },
  81. {
  82. label: "文章标题",
  83. prop: "title",
  84. rules: [{
  85. required: true,
  86. message: "请输入文章标题",
  87. trigger: "blur"
  88. }]
  89. },
  90. {
  91. label: "图片",
  92. prop: "image",
  93. type: 'upload',
  94. listType: 'picture-img',
  95. span: 12,
  96. propsHttp: {
  97. url: "data"
  98. },
  99. action: "/api/upload/putfile",
  100. rules: [{
  101. required: true,
  102. message: "请输入图片",
  103. trigger: "blur"
  104. }]
  105. },
  106. {
  107. label: "阅读数量",
  108. prop: "reader",
  109. rules: [{
  110. required: false,
  111. message: "请输入阅读数量",
  112. trigger: "blur"
  113. }]
  114. },
  115. {
  116. label: "动态内容",
  117. prop: "content",
  118. component: 'avueUeditor',
  119. overHidden: true,
  120. span:24,
  121. hide: true,
  122. rules: [{
  123. required: true,
  124. message: "请输入动态内容",
  125. trigger: "blur"
  126. }]
  127. },
  128. ]
  129. },
  130. data: []
  131. };
  132. },
  133. computed: {
  134. ...mapGetters(["permission"]),
  135. permissionList() {
  136. return {
  137. addBtn: this.vaildData(this.permission.article_add, false),
  138. viewBtn: this.vaildData(this.permission.article_view, false),
  139. delBtn: this.vaildData(this.permission.article_delete, false),
  140. editBtn: this.vaildData(this.permission.article_edit, false)
  141. };
  142. },
  143. ids() {
  144. let ids = [];
  145. this.selectionList.forEach(ele => {
  146. ids.push(ele.id);
  147. });
  148. return ids.join(",");
  149. }
  150. },
  151. methods: {
  152. rowSave(row, done, loading) {
  153. add(row).then(() => {
  154. let Base64 = require('js-base64').Base64;
  155. row.content =Base64.encode(row.content);
  156. this.onLoad(this.page);
  157. this.$message({
  158. type: "success",
  159. message: "操作成功!"
  160. });
  161. done();
  162. }, error => {
  163. loading();
  164. window.console.log(error);
  165. });
  166. },
  167. rowUpdate(row, index, done, loading) {
  168. let Base64 = require('js-base64').Base64;
  169. row.content =Base64.encode(row.content);
  170. update(row).then(() => {
  171. this.onLoad(this.page);
  172. this.$message({
  173. type: "success",
  174. message: "操作成功!"
  175. });
  176. done();
  177. }, error => {
  178. loading();
  179. console.log(error);
  180. });
  181. },
  182. rowDel(row) {
  183. this.$confirm("确定将选择数据删除?", {
  184. confirmButtonText: "确定",
  185. cancelButtonText: "取消",
  186. type: "warning"
  187. })
  188. .then(() => {
  189. return remove(row.id);
  190. })
  191. .then(() => {
  192. this.onLoad(this.page);
  193. this.$message({
  194. type: "success",
  195. message: "操作成功!"
  196. });
  197. });
  198. },
  199. handleDelete() {
  200. if (this.selectionList.length === 0) {
  201. this.$message.warning("请选择至少一条数据");
  202. return;
  203. }
  204. this.$confirm("确定将选择数据删除?", {
  205. confirmButtonText: "确定",
  206. cancelButtonText: "取消",
  207. type: "warning"
  208. })
  209. .then(() => {
  210. return remove(this.ids);
  211. })
  212. .then(() => {
  213. this.onLoad(this.page);
  214. this.$message({
  215. type: "success",
  216. message: "操作成功!"
  217. });
  218. this.$refs.crud.toggleSelection();
  219. });
  220. },
  221. beforeOpen(done, type) {
  222. if (["edit", "view"].includes(type)) {
  223. getDetail(this.form.id).then(res => {
  224. this.form = res.data.data;
  225. });
  226. }
  227. done();
  228. },
  229. searchReset() {
  230. this.query = {};
  231. this.onLoad(this.page);
  232. },
  233. searchChange(params, done) {
  234. this.query = params;
  235. this.page.currentPage = 1;
  236. this.onLoad(this.page, params);
  237. done();
  238. },
  239. selectionChange(list) {
  240. this.selectionList = list;
  241. },
  242. selectionClear() {
  243. this.selectionList = [];
  244. this.$refs.crud.toggleSelection();
  245. },
  246. currentChange(currentPage){
  247. this.page.currentPage = currentPage;
  248. },
  249. sizeChange(pageSize){
  250. this.page.pageSize = pageSize;
  251. },
  252. refreshChange() {
  253. this.onLoad(this.page, this.query);
  254. },
  255. onLoad(page, params = {}) {
  256. this.loading = true;
  257. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  258. const data = res.data.data;
  259. this.page.total = data.total;
  260. this.data = data.records;
  261. this.loading = false;
  262. this.selectionClear();
  263. });
  264. }
  265. }
  266. };
  267. </script>
  268. <style>
  269. </style>