notice.vue 8.0 KB

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