post.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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.post_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, getDetail, add, update, remove} from "@/api/system/post";
  39. import {mapGetters} from "vuex";
  40. import website from "@/config/website";
  41. export default {
  42. data() {
  43. return {
  44. form: {},
  45. query: {},
  46. loading: true,
  47. page: {
  48. pageSize: 10,
  49. currentPage: 1,
  50. total: 0
  51. },
  52. selectionList: [],
  53. option: {
  54. height: 'auto',
  55. calcHeight: 30,
  56. tip: false,
  57. searchShow: true,
  58. searchMenuSpan: 6,
  59. border: true,
  60. index: true,
  61. viewBtn: true,
  62. selection: true,
  63. dialogClickModal: false,
  64. column: [
  65. {
  66. label: "所属租户",
  67. prop: "tenantId",
  68. type: "tree",
  69. dicUrl: "/api/blade-system/tenant/select",
  70. addDisplay: false,
  71. editDisplay: false,
  72. viewDisplay: website.tenantMode,
  73. span: 24,
  74. props: {
  75. label: "tenantName",
  76. value: "tenantId"
  77. },
  78. hide: !website.tenantMode,
  79. rules: [{
  80. required: true,
  81. message: "请输入所属租户",
  82. trigger: "click"
  83. }]
  84. },
  85. {
  86. label: "岗位类型",
  87. prop: "category",
  88. type: "select",
  89. dicUrl: "/api/blade-system/dict/dictionary?code=post_category",
  90. props: {
  91. label: "dictValue",
  92. value: "dictKey"
  93. },
  94. dataType: "number",
  95. slot: true,
  96. search: true,
  97. rules: [{
  98. required: true,
  99. message: "请选择岗位类型",
  100. trigger: "blur"
  101. }]
  102. },
  103. {
  104. label: "岗位编号",
  105. prop: "postCode",
  106. search: true,
  107. rules: [{
  108. required: true,
  109. message: "请输入岗位编号",
  110. trigger: "blur"
  111. }]
  112. },
  113. {
  114. label: "岗位名称",
  115. prop: "postName",
  116. search: true,
  117. rules: [{
  118. required: true,
  119. message: "请输入岗位名称",
  120. trigger: "blur"
  121. }]
  122. },
  123. {
  124. label: "岗位排序",
  125. prop: "sort",
  126. type: "number",
  127. rules: [{
  128. required: true,
  129. message: "请输入岗位排序",
  130. trigger: "blur"
  131. }]
  132. },
  133. {
  134. label: "岗位描述",
  135. prop: "remark",
  136. type: "textarea",
  137. span: 24,
  138. minRows: 6,
  139. hide: true,
  140. },
  141. ]
  142. },
  143. data: []
  144. };
  145. },
  146. computed: {
  147. ...mapGetters(["permission"]),
  148. permissionList() {
  149. return {
  150. addBtn: this.vaildData(this.permission.post_add, false),
  151. viewBtn: this.vaildData(this.permission.post_view, false),
  152. delBtn: this.vaildData(this.permission.post_delete, false),
  153. editBtn: this.vaildData(this.permission.post_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. handleDelete() {
  209. if (this.selectionList.length === 0) {
  210. this.$message.warning("请选择至少一条数据");
  211. return;
  212. }
  213. this.$confirm("确定将选择数据删除?", {
  214. confirmButtonText: "确定",
  215. cancelButtonText: "取消",
  216. type: "warning"
  217. })
  218. .then(() => {
  219. return remove(this.ids);
  220. })
  221. .then(() => {
  222. this.onLoad(this.page);
  223. this.$message({
  224. type: "success",
  225. message: "操作成功!"
  226. });
  227. this.$refs.crud.toggleSelection();
  228. });
  229. },
  230. beforeOpen(done, type) {
  231. if (["edit", "view"].includes(type)) {
  232. getDetail(this.form.id).then(res => {
  233. this.form = res.data.data;
  234. });
  235. }
  236. done();
  237. },
  238. searchReset() {
  239. this.query = {};
  240. this.onLoad(this.page);
  241. },
  242. searchChange(params, done) {
  243. this.query = params;
  244. this.page.currentPage = 1;
  245. this.onLoad(this.page, params);
  246. done();
  247. },
  248. selectionChange(list) {
  249. this.selectionList = list;
  250. },
  251. selectionClear() {
  252. this.selectionList = [];
  253. this.$refs.crud.toggleSelection();
  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. this.loading = true;
  266. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  267. const data = res.data.data;
  268. this.page.total = data.total;
  269. this.data = data.records;
  270. this.loading = false;
  271. this.selectionClear();
  272. });
  273. }
  274. }
  275. };
  276. </script>
  277. <style>
  278. </style>