notice.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <basic-container>
  3. <avue-crud :option="option"
  4. :table-loading="loading"
  5. :data="data"
  6. :page.sync="page"
  7. ref="crud"
  8. @row-del="rowDel"
  9. v-model="form"
  10. :permission="permissionList"
  11. @row-update="rowUpdate"
  12. @row-save="rowSave"
  13. :before-open="beforeOpen"
  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.notice_delete"
  27. @click="handleDelete">删 除
  28. </el-button>
  29. </template>
  30. <template slot-scope="{row}"
  31. slot="category">
  32. <el-tag>{{row.categoryName}}</el-tag>
  33. </template>
  34. </avue-crud>
  35. </basic-container>
  36. </template>
  37. <script>
  38. import {getList, remove, update, add, getNotice} from "@/api/desk/notice";
  39. import {mapGetters} from "vuex";
  40. export default {
  41. data() {
  42. return {
  43. form: {},
  44. query: {},
  45. loading: true,
  46. page: {
  47. pageSize: 10,
  48. currentPage: 1,
  49. total: 0
  50. },
  51. selectionList: [],
  52. option: {
  53. height: 'auto',
  54. calcHeight: 30,
  55. dialogWidth: 950,
  56. tip: false,
  57. searchShow: true,
  58. searchMenuSpan: 6,
  59. border: true,
  60. index: true,
  61. viewBtn: true,
  62. selection: true,
  63. excelBtn: true,
  64. dialogClickModal: false,
  65. column: [
  66. {
  67. label: "通知标题",
  68. prop: "title",
  69. span: 24,
  70. row: true,
  71. search: true,
  72. rules: [{
  73. required: true,
  74. message: "请输入通知标题",
  75. trigger: "blur"
  76. }]
  77. },
  78. {
  79. label: "通知类型",
  80. type: "select",
  81. dicUrl: "/api/blade-system/dict/dictionary?code=notice",
  82. props: {
  83. label: "dictValue",
  84. value: "dictKey"
  85. },
  86. dataType: "number",
  87. slot: true,
  88. prop: "category",
  89. search: true,
  90. rules: [{
  91. required: true,
  92. message: "请输入通知类型",
  93. trigger: "blur"
  94. }]
  95. },
  96. {
  97. label: "通知时间",
  98. prop: "releaseTimeRange",
  99. type: "datetime",
  100. format: "yyyy-MM-dd hh:mm:ss",
  101. valueFormat: "yyyy-MM-dd hh:mm:ss",
  102. searchRange:true,
  103. hide: true,
  104. addDisplay: false,
  105. editDisplay: false,
  106. viewDisplay: false,
  107. search: true,
  108. rules: [{
  109. required: true,
  110. message: "请输入通知时间",
  111. trigger: "blur"
  112. }]
  113. },
  114. {
  115. label: "通知日期",
  116. prop: "releaseTime",
  117. type: "date",
  118. format: "yyyy-MM-dd hh:mm:ss",
  119. valueFormat: "yyyy-MM-dd hh:mm:ss",
  120. rules: [{
  121. required: true,
  122. message: "请输入通知日期",
  123. trigger: "click"
  124. }]
  125. },
  126. {
  127. label: "通知内容",
  128. prop: "content",
  129. component: 'AvueUeditor',
  130. options: {
  131. action: '/api/blade-resource/oss/endpoint/put-file',
  132. props: {
  133. res: "data",
  134. url: "link",
  135. }
  136. },
  137. hide: true,
  138. minRows: 6,
  139. span: 24,
  140. }
  141. ]
  142. },
  143. data: []
  144. };
  145. },
  146. computed: {
  147. ...mapGetters(["permission"]),
  148. permissionList() {
  149. return {
  150. addBtn: this.vaildData(this.permission.notice_add, false),
  151. viewBtn: this.vaildData(this.permission.notice_view, false),
  152. delBtn: this.vaildData(this.permission.notice_delete, false),
  153. editBtn: this.vaildData(this.permission.notice_edit, false)
  154. };
  155. },
  156. ids() {
  157. let ids = [];
  158. this.selectionList.forEach(ele => {
  159. ids.push(ele.id);
  160. });
  161. return ids.join(",");
  162. }
  163. },
  164. methods: {
  165. rowSave(row, done, loading) {
  166. add(row).then(() => {
  167. this.onLoad(this.page);
  168. this.$message({
  169. type: "success",
  170. message: "操作成功!"
  171. });
  172. done();
  173. }, error => {
  174. window.console.log(error);
  175. loading();
  176. });
  177. },
  178. rowUpdate(row, index, done, loading) {
  179. update(row).then(() => {
  180. this.onLoad(this.page);
  181. this.$message({
  182. type: "success",
  183. message: "操作成功!"
  184. });
  185. done();
  186. }, error => {
  187. window.console.log(error);
  188. loading();
  189. });
  190. },
  191. rowDel(row) {
  192. this.$confirm("确定将选择数据删除?", {
  193. confirmButtonText: "确定",
  194. cancelButtonText: "取消",
  195. type: "warning"
  196. })
  197. .then(() => {
  198. return remove(row.id);
  199. })
  200. .then(() => {
  201. this.onLoad(this.page);
  202. this.$message({
  203. type: "success",
  204. message: "操作成功!"
  205. });
  206. });
  207. },
  208. searchReset() {
  209. this.query = {};
  210. this.onLoad(this.page);
  211. },
  212. searchChange(params, done) {
  213. this.query = params;
  214. this.page.currentPage = 1;
  215. this.onLoad(this.page, params);
  216. done();
  217. },
  218. selectionChange(list) {
  219. this.selectionList = list;
  220. },
  221. selectionClear() {
  222. this.selectionList = [];
  223. this.$refs.crud.toggleSelection();
  224. },
  225. handleDelete() {
  226. if (this.selectionList.length === 0) {
  227. this.$message.warning("请选择至少一条数据");
  228. return;
  229. }
  230. this.$confirm("确定将选择数据删除?", {
  231. confirmButtonText: "确定",
  232. cancelButtonText: "取消",
  233. type: "warning"
  234. })
  235. .then(() => {
  236. return remove(this.ids);
  237. })
  238. .then(() => {
  239. this.onLoad(this.page);
  240. this.$message({
  241. type: "success",
  242. message: "操作成功!"
  243. });
  244. this.$refs.crud.toggleSelection();
  245. });
  246. },
  247. beforeOpen(done, type) {
  248. if (["edit", "view"].includes(type)) {
  249. getNotice(this.form.id).then(res => {
  250. this.form = res.data.data;
  251. });
  252. }
  253. done();
  254. },
  255. currentChange(currentPage) {
  256. this.page.currentPage = currentPage;
  257. },
  258. sizeChange(pageSize) {
  259. this.page.pageSize = pageSize;
  260. },
  261. refreshChange() {
  262. this.onLoad(this.page, this.query);
  263. },
  264. onLoad(page, params = {}) {
  265. const {releaseTimeRange} = this.query;
  266. let values = {
  267. ...params,
  268. };
  269. if (releaseTimeRange) {
  270. values = {
  271. ...params,
  272. releaseTime_datege: releaseTimeRange[0],
  273. releaseTime_datelt: releaseTimeRange[1],
  274. ...this.query
  275. };
  276. values.releaseTimeRange = null;
  277. }
  278. this.loading = true;
  279. getList(page.currentPage, page.pageSize, values).then(res => {
  280. const data = res.data.data;
  281. this.page.total = data.total;
  282. this.data = data.records;
  283. this.loading = false;
  284. this.selectionClear();
  285. });
  286. }
  287. }
  288. };
  289. </script>
  290. <style>
  291. </style>