BlackList.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <div>
  3. <div class="box box-primary">
  4. <div class="box-header">
  5. <h4 class="text-primary text-center">黑名单</h4>
  6. </div>
  7. <div class="box-body">
  8. <form class="form-inline" autocomplete="off" spellcheck="false">
  9. <div class="form-group form-group-sm">
  10. <button type="button" class="btn btn-sm btn-primary" @click.prevent="$router.go(-1)">
  11. <i class="fa fa-chevron-left"></i> 返回
  12. </button>
  13. </div>
  14. <span class="hidden-xs">&nbsp;&nbsp;</span>
  15. <div class="form-group form-group-sm">
  16. <label>搜索</label>
  17. <div class="input-group input-group-sm">
  18. <input type="text" class="form-control" placeholder="关键字" v-model.trim="q" @keydown.enter.prevent ref="q">
  19. <div class="input-group-btn">
  20. <button type="button" v-if="!isMobile()" class="btn btn-sm btn-default" @click.prevent="download" title="导出黑名单数据"><i class="fa fa-download"></i></button>
  21. <button type="button" v-if="!isMobile()" class="btn btn-sm btn-default" @click.prevent="$refs['uploadDlg'].show()" title="导入黑名单数据"><i class="fa fa-upload"></i></button>
  22. <button type="button" class="btn btn-sm btn-default" @click.prevent="addBlack()"><i class="fa fa-plus"></i> 添加黑名单</button>
  23. </div>
  24. </div>
  25. </div>
  26. </form>
  27. <br>
  28. <div class="clearfix"></div>
  29. <el-table :data="blackList" stripe :default-sort="{prop: 'Serial', order: 'ascending'}" @sort-change="sortChange" v-loading="loading" element-loading-text="加载中...">
  30. <el-table-column prop="Serial" label="设备国标编号" min-width="300" show-overflow-tooltip sortable="custom"></el-table-column>
  31. <el-table-column prop="Description" label="描述" min-width="200" show-overflow-tooltip sortable="custom"></el-table-column>
  32. <el-table-column prop="CreatedAt" label="创建时间" min-width="160" sortable="custom"></el-table-column>
  33. <el-table-column prop="UpdatedAt" label="更新时间" min-width="160" sortable="custom"></el-table-column>
  34. <el-table-column label="操作" min-width="150" :fixed="isMobile() ? false:'right'" class-name="opt-group">
  35. <template slot-scope="props">
  36. <div class="btn-group btn-group-xs">
  37. <button type="button" class="btn btn-warning" @click.prevent="editBlack(props.row)" v-if="userInfo">
  38. <i class="fa fa-edit"></i> 编辑
  39. </button>
  40. <button type="button" class="btn btn-danger" @click.prevent="delBlack(props.row)" v-if="userInfo">
  41. <i class="fa fa-stop"></i> 删除
  42. </button>
  43. </div>
  44. </template>
  45. </el-table-column>
  46. </el-table>
  47. </div>
  48. <div class="box-footer" v-if="total > 0">
  49. <el-pagination layout="total,prev,pager,next" :pager-count="5" class="pull-right" :total="total" :page-size.sync="pageSize" :current-page.sync="currentPage"></el-pagination>
  50. </div>
  51. <UploadDlg ref="uploadDlg" title="上传黑名单" url="/api/v1/black/import" @uploaded="uploaded"></UploadDlg>
  52. <BlackEditDlg ref="blackEditDlg" @submit="getBlackList"></BlackEditDlg>
  53. </div>
  54. </div>
  55. </template>
  56. <script>
  57. import UploadDlg from "components/UploadDlg.vue";
  58. import BlackEditDlg from "components/BlackEditDlg.vue";
  59. import _ from "lodash";
  60. import {
  61. mapState
  62. } from "vuex";
  63. export default {
  64. props: {},
  65. data() {
  66. return {
  67. q: "",
  68. total: 0,
  69. pageSize: 10,
  70. currentPage: 1,
  71. sort: "Serial",
  72. order: "asc",
  73. loading: false,
  74. blackList: [],
  75. };
  76. },
  77. components: {
  78. UploadDlg,
  79. BlackEditDlg
  80. },
  81. computed: {
  82. ...mapState(['userInfo', 'serverInfo']),
  83. },
  84. watch: {
  85. q: function (newVal, oldVal) {
  86. this.doDelaySearch();
  87. },
  88. currentPage: function (newVal, oldVal) {
  89. this.doSearch(newVal);
  90. }
  91. },
  92. mounted() {
  93. // this.getBlackList();
  94. },
  95. beforeDestroy() {
  96. },
  97. methods: {
  98. download() {
  99. window.open(`/api/v1/black/export`);
  100. },
  101. uploaded() {
  102. this.$message({
  103. type: 'success',
  104. message: "上传配置成功!"
  105. })
  106. this.getBlackList();
  107. this.$refs['uploadDlg'].hide();
  108. },
  109. doSearch(page = 1) {
  110. var query = {};
  111. if (this.q) query["q"] = this.q;
  112. this.$router.replace({
  113. path: `/black/${page}`,
  114. query: query
  115. });
  116. },
  117. doDelaySearch: _.debounce(function () {
  118. this.doSearch();
  119. }, 500),
  120. getBlackList() {
  121. this.loading = true;
  122. $.get("/api/v1/black/list", {
  123. q: this.q,
  124. start: (this.currentPage - 1) * this.pageSize,
  125. limit: this.pageSize,
  126. sort: this.sort,
  127. order: this.order
  128. })
  129. .then(ret => {
  130. this.total = ret.BlackCount;
  131. this.blackList = ret.BlackList;
  132. })
  133. .always(() => {
  134. this.loading = false;
  135. });
  136. },
  137. sortChange(data) {
  138. this.sort = data.prop;
  139. this.order = data.order == "ascending" ? "asc" : "desc";
  140. this.getBlackList();
  141. },
  142. delBlack(row) {
  143. this.$confirm(`确认删除 ${row.Serial} ?`, "提示").then(() => {
  144. $.get("/api/v1/black/remove", {
  145. serial: row.Serial,
  146. }).always(() => {
  147. this.getBlackList();
  148. });
  149. }).catch(() => {});
  150. },
  151. editBlack(row) {
  152. this.$refs["blackEditDlg"].show({
  153. serial: row.Serial,
  154. description: row.Description,
  155. });
  156. },
  157. addBlack(row) {
  158. this.$refs["blackEditDlg"].show({
  159. serial: "",
  160. description: "",
  161. });
  162. },
  163. },
  164. beforeRouteEnter(to, from, next) {
  165. next(vm => {
  166. vm.q = to.query.q || "";
  167. vm.currentPage = parseInt(to.params.page) || 1;
  168. });
  169. },
  170. beforeRouteLeave(to, from, next) {
  171. next();
  172. },
  173. beforeRouteUpdate(to, from, next) {
  174. next();
  175. this.$nextTick(() => {
  176. this.q = to.query.q || "";
  177. this.currentPage = parseInt(to.params.page) || 1;
  178. this.blackList = [];
  179. this.getBlackList();
  180. });
  181. }
  182. };
  183. </script>
  184. <style lang="less">
  185. .opt-group .cell {
  186. overflow: visible;
  187. }
  188. </style>