WhiteList.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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="addWhite()"><i class="fa fa-plus"></i> 添加白名单</button>
  23. </div>
  24. </div>
  25. </div>
  26. </form>
  27. <br>
  28. <el-table :data="whiteList" stripe :default-sort="{prop: 'Serial', order: 'ascending'}" @sort-change="sortChange" v-loading="loading" element-loading-text="加载中...">
  29. <el-table-column prop="Serial" label="设备国标编号" min-width="300" show-overflow-tooltip sortable="custom"></el-table-column>
  30. <el-table-column prop="Password" label="接入密码" min-width="200" 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="editWhite(props.row)" v-if="userInfo">
  38. <i class="fa fa-edit"></i> 编辑
  39. </button>
  40. <button type="button" class="btn btn-danger" @click.prevent="delWhite(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/white/import" @uploaded="uploaded"></UploadDlg>
  52. <WhiteEditDlg ref="whiteEditDlg" @submit="getWhiteList"></WhiteEditDlg>
  53. </div>
  54. </div>
  55. </template>
  56. <script>
  57. import UploadDlg from "components/UploadDlg.vue";
  58. import WhiteEditDlg from "components/WhiteEditDlg.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. whiteList: [],
  75. };
  76. },
  77. components: {
  78. UploadDlg,
  79. WhiteEditDlg
  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.getWhiteList();
  94. },
  95. beforeDestroy() {
  96. },
  97. methods: {
  98. download() {
  99. window.open(`/api/v1/white/export`);
  100. },
  101. uploaded() {
  102. this.$message({
  103. type: 'success',
  104. message: "上传配置成功!"
  105. })
  106. this.getWhiteList();
  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: `/white/${page}`,
  114. query: query
  115. });
  116. },
  117. doDelaySearch: _.debounce(function () {
  118. this.doSearch();
  119. }, 500),
  120. getWhiteList() {
  121. this.loading = true;
  122. $.get("/api/v1/white/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.WhiteCount;
  131. this.whiteList = ret.WhiteList;
  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.getWhiteList();
  141. },
  142. delWhite(row) {
  143. this.$confirm(`确认删除 ${row.Serial} ?`, "提示").then(() => {
  144. $.get("/api/v1/white/remove", {
  145. serial: row.Serial,
  146. }).always(() => {
  147. this.getWhiteList();
  148. });
  149. }).catch(() => {});
  150. },
  151. editWhite(row) {
  152. this.$refs["whiteEditDlg"].show({
  153. serial: row.Serial,
  154. password: row.Password,
  155. description: row.Description,
  156. });
  157. },
  158. addWhite(row) {
  159. this.$refs["whiteEditDlg"].show({
  160. serial: "",
  161. password: "",
  162. description: "",
  163. });
  164. },
  165. },
  166. beforeRouteEnter(to, from, next) {
  167. next(vm => {
  168. vm.q = to.query.q || "";
  169. vm.currentPage = parseInt(to.params.page) || 1;
  170. });
  171. },
  172. beforeRouteLeave(to, from, next) {
  173. next();
  174. },
  175. beforeRouteUpdate(to, from, next) {
  176. next();
  177. this.$nextTick(() => {
  178. this.q = to.query.q || "";
  179. this.currentPage = parseInt(to.params.page) || 1;
  180. this.whiteList = [];
  181. this.getWhiteList();
  182. });
  183. }
  184. };
  185. </script>
  186. <style lang="less">
  187. .opt-group .cell {
  188. overflow: visible;
  189. }
  190. </style>