datasource.vue 7.2 KB

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