notice.vue 7.9 KB

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