sys_login_rule_list.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <template>
  2. <section style="margin-top: 0px;">
  3. <el-form
  4. :model="searchForm"
  5. :inline="true"
  6. style="border-bottom: 1px solid rgb(221, 221, 221);margin-bottom: 10px;"
  7. >
  8. <el-form-item label="学校">
  9. <el-select
  10. v-model="searchForm.rootOrgId"
  11. placeholder="请选择"
  12. filterable
  13. clearable
  14. size="small"
  15. class="w180"
  16. >
  17. <el-option
  18. v-for="item in rootOrgList"
  19. :label="item.name"
  20. :value="item.id"
  21. :key="item.id"
  22. />
  23. </el-select>
  24. </el-form-item>
  25. <el-form-item label="规则类型">
  26. <el-select
  27. v-model="searchForm.type"
  28. size="small"
  29. class="w180"
  30. placeholder="请选择"
  31. @clear="clearTypeValue"
  32. clearable
  33. >
  34. <el-option
  35. v-for="item in loginRuleTypes"
  36. :label="item.label"
  37. :value="item.value"
  38. :key="item.value"
  39. ></el-option>
  40. </el-select>
  41. </el-form-item>
  42. <el-form-item>
  43. <el-button
  44. size="small"
  45. type="primary"
  46. icon="el-icon-search"
  47. @click="doSearch(1)"
  48. >查询
  49. </el-button>
  50. <el-button size="small" icon="el-icon-refresh" @click="resetSearchForm">
  51. 重置
  52. </el-button>
  53. </el-form-item>
  54. </el-form>
  55. <div style="margin-bottom: 5px;">
  56. 操作:
  57. <el-button
  58. size="small"
  59. type="primary"
  60. icon="el-icon-plus"
  61. @click="loginRuleDialogOpen(null)"
  62. >新增
  63. </el-button>
  64. <el-button
  65. size="small"
  66. type="primary"
  67. icon="el-icon-refresh"
  68. v-show="false"
  69. @click="doRefreshRule"
  70. >刷新
  71. </el-button>
  72. <div class="page pull-right">
  73. <el-form :inline="true">
  74. <span
  75. v-for="(item, index) in topLoginRuleList"
  76. :key="index"
  77. style="padding: 0px 15px"
  78. >
  79. <el-form-item :label="'开放' + getTypeTitle(item.type)">
  80. <el-switch
  81. v-model="switchModels[index].allow"
  82. @change="updateTopRule(item.type, index)"
  83. active-color="#13ce66"
  84. inactive-color="#ff4949"
  85. ></el-switch>
  86. </el-form-item>
  87. </span>
  88. </el-form>
  89. </div>
  90. </div>
  91. <el-table
  92. v-loading="loading"
  93. :data="tableData"
  94. element-loading-text="数据加载中"
  95. style="width:100%;"
  96. border
  97. stripe
  98. >
  99. <el-table-column label="学校ID" prop="rootOrgId" width="110px" sortable />
  100. <el-table-column label="规则类型" width="150px">
  101. <template slot-scope="scope">
  102. <span>{{ getTypeTitle(scope.row.type) }} </span></template
  103. >
  104. </el-table-column>
  105. <el-table-column label="是否例外(白名单)" width="150px">
  106. <template slot-scope="scope">
  107. <span>{{ scope.row.allow ? "是" : "否" }}</span>
  108. </template>
  109. </el-table-column>
  110. <el-table-column label="创建时间" prop="creationTime" sortable />
  111. <el-table-column label="更新时间" prop="updateTime" sortable />
  112. <el-table-column label="操作" width="180px">
  113. <template slot-scope="scope">
  114. <el-button
  115. size="mini"
  116. type="primary"
  117. icon="el-icon-edit"
  118. @click="loginRuleDialogOpen(scope.row)"
  119. plain
  120. >修改
  121. </el-button>
  122. <el-button
  123. size="mini"
  124. type="danger"
  125. icon="el-icon-delete"
  126. @click="doDeleteRule(scope.row)"
  127. plain
  128. >删除
  129. </el-button>
  130. </template>
  131. </el-table-column>
  132. </el-table>
  133. <div class="page pull-right">
  134. <el-pagination
  135. @current-change="handlePagerNo"
  136. :current-page="searchForm.pageNo"
  137. @size-change="handlePagerSize"
  138. :page-size="searchForm.pageSize"
  139. :page-sizes="[10, 20, 50, 100, 200, 300]"
  140. :total="totalElements"
  141. layout="total, sizes, prev, pager, next, jumper"
  142. ></el-pagination>
  143. </div>
  144. <el-dialog
  145. :title="this.isCreate ? '规则新增' : '规则修改'"
  146. width="380px"
  147. :visible.sync="loginRuleDialog"
  148. @close="loginRuleDialogClose"
  149. >
  150. <el-form
  151. :model="loginRuleForm"
  152. ref="loginRuleForm"
  153. :rules="formRules"
  154. label-position="right"
  155. label-width="110px"
  156. inline-message
  157. >
  158. <el-form-item label="学校" prop="rootOrgId">
  159. <el-select
  160. v-model="loginRuleForm.rootOrgId"
  161. :disabled="!isCreate"
  162. placeholder="请选择"
  163. filterable
  164. clearable
  165. size="small"
  166. class="w180"
  167. >
  168. <el-option
  169. v-for="item in rootOrgList"
  170. :label="item.name"
  171. :value="item.id"
  172. :key="item.id"
  173. />
  174. </el-select>
  175. </el-form-item>
  176. <el-form-item label="规则类型" prop="type">
  177. <el-select
  178. v-model="loginRuleForm.type"
  179. :disabled="!isCreate"
  180. size="small"
  181. class="w180"
  182. placeholder="请选择"
  183. clearable
  184. >
  185. <el-option
  186. v-for="item in loginRuleTypes"
  187. :label="item.label"
  188. :value="item.value"
  189. :key="item.value"
  190. ></el-option>
  191. </el-select>
  192. </el-form-item>
  193. <el-form-item label="是否白名单" prop="allow">
  194. <el-radio-group v-model="loginRuleForm.allow" class="w180">
  195. <el-radio :label="true">是</el-radio>
  196. <el-radio :label="false">否</el-radio>
  197. </el-radio-group>
  198. </el-form-item>
  199. <div style="text-align: center">
  200. <el-button type="primary" @click="doSaveRule">确 定</el-button>
  201. <el-button @click="loginRuleDialogClose">取 消</el-button>
  202. </div>
  203. </el-form>
  204. </el-dialog>
  205. </section>
  206. </template>
  207. <script>
  208. import { mapState } from "vuex";
  209. import { CORE_API } from "@/constants/constants.js";
  210. export default {
  211. data() {
  212. return {
  213. searchForm: {
  214. rootOrgId: null,
  215. type: null,
  216. allow: null,
  217. pageNo: 1,
  218. pageSize: 10
  219. },
  220. loading: false,
  221. tableData: [],
  222. totalElements: 0,
  223. rootOrgList: [],
  224. loginRuleTypes: [
  225. { label: "考生登录", value: "STUDENT_LOGIN" },
  226. { label: "考生端登录", value: "STUDENT_CLIENT_LOGIN" },
  227. { label: "极验验证码登录", value: "GEETEST_LOGIN" }
  228. ],
  229. isCreate: true,
  230. loginRuleDialog: false,
  231. loginRuleForm: {
  232. rootOrgId: null,
  233. type: null,
  234. allow: false
  235. },
  236. formRules: {
  237. rootOrgId: [
  238. { required: true, message: "请选择学校!", trigger: "change" }
  239. ],
  240. type: [
  241. { required: true, message: "请选择规则类型!", trigger: "change" }
  242. ],
  243. allow: [
  244. { required: true, message: "请选择是否白名单!", trigger: "change" }
  245. ]
  246. },
  247. topLoginRuleList: [],
  248. switchModels: []
  249. };
  250. },
  251. methods: {
  252. getRootOrgList() {
  253. if (this.isSuperAdmin) {
  254. this.$httpWithMsg
  255. .get(CORE_API + "/org/getRootOrgList")
  256. .then(response => {
  257. this.rootOrgList = response.data;
  258. });
  259. }
  260. },
  261. getTopLoginRuleList() {
  262. this.$httpWithMsg
  263. .post(CORE_API + "/sys/xlogin/rule/top/list")
  264. .then(response => {
  265. this.topLoginRuleList = response.data;
  266. for (let n = 0; n < this.topLoginRuleList.length; n++) {
  267. let value = this.topLoginRuleList[n].allow;
  268. this.switchModels.push({ allow: value });
  269. }
  270. });
  271. },
  272. doSearch(pageNo) {
  273. this.searchForm.pageNo = pageNo;
  274. this.loading = true;
  275. let url = CORE_API + "/sys/xlogin/rule/list";
  276. this.$http.post(url, this.searchForm).then(
  277. response => {
  278. this.tableData = response.data.content;
  279. this.totalElements = response.data.totalElements;
  280. this.loading = false;
  281. },
  282. error => {
  283. console.log(error);
  284. this.loading = false;
  285. }
  286. );
  287. },
  288. loginRuleDialogOpen(row) {
  289. if (row) {
  290. this.isCreate = false;
  291. this.loginRuleForm.rootOrgId = row.rootOrgId;
  292. this.loginRuleForm.type = row.type;
  293. this.loginRuleForm.allow = row.allow;
  294. } else {
  295. this.isCreate = true;
  296. this.loginRuleForm.rootOrgId = null;
  297. this.loginRuleForm.type = null;
  298. this.loginRuleForm.allow = false;
  299. }
  300. this.loginRuleDialog = true;
  301. },
  302. loginRuleDialogClose() {
  303. this.loginRuleDialog = false;
  304. },
  305. doSaveRule() {
  306. this.$refs.loginRuleForm.validate(valid => {
  307. if (!valid) {
  308. return false;
  309. }
  310. let url = CORE_API + "/sys/xlogin/rule/save";
  311. this.$http.post(url, this.loginRuleForm).then(() => {
  312. this.$notify({
  313. type: "success",
  314. message: "保存成功"
  315. });
  316. this.doSearch();
  317. this.loginRuleDialogClose();
  318. });
  319. });
  320. },
  321. updateTopRule(type, index) {
  322. let allow = this.switchModels[index].allow;
  323. let params = { rootOrgId: -1, type: type, allow: allow };
  324. let url = CORE_API + "/sys/xlogin/rule/save";
  325. this.$http.post(url, params).then(() => {
  326. this.$notify({
  327. type: "success",
  328. message: "更新成功"
  329. });
  330. });
  331. },
  332. doDeleteRule(row) {
  333. this.$confirm("确认删除?", "提示", {
  334. confirmButtonText: "确定",
  335. cancelButtonText: "取消",
  336. type: "warning"
  337. }).then(() => {
  338. let url = CORE_API + "/sys/xlogin/rule/delete?ruleId=" + row.id;
  339. this.$http.post(url).then(() => {
  340. this.$notify({
  341. type: "success",
  342. message: "删除成功"
  343. });
  344. this.doSearch();
  345. });
  346. });
  347. },
  348. doRefreshRule() {
  349. this.$confirm("确认刷新?", "提示", {
  350. confirmButtonText: "确定",
  351. cancelButtonText: "取消",
  352. type: "warning"
  353. }).then(() => {
  354. let url = CORE_API + "/sys/xlogin/rule/refresh";
  355. this.$http.post(url).then(() => {
  356. this.$notify({
  357. type: "success",
  358. message: "刷新成功"
  359. });
  360. });
  361. });
  362. },
  363. handlePagerNo(pageNo) {
  364. this.doSearch(pageNo);
  365. },
  366. handlePagerSize(pageSize) {
  367. this.searchForm.pageSize = pageSize;
  368. this.doSearch(1);
  369. },
  370. clearTypeValue() {
  371. this.searchForm.type = null;
  372. },
  373. getTypeTitle(val) {
  374. for (let type of this.loginRuleTypes) {
  375. if (type.value == val) {
  376. return type.label;
  377. }
  378. }
  379. },
  380. resetSearchForm() {
  381. this.searchForm.rootOrgId = null;
  382. this.searchForm.type = null;
  383. this.searchForm.allow = null;
  384. this.doSearch(1);
  385. }
  386. },
  387. computed: {
  388. ...mapState({ user: state => state.user }),
  389. isSuperAdmin() {
  390. return this.user.roleList.some(role => role.roleCode == "SUPER_ADMIN");
  391. }
  392. },
  393. created() {
  394. this.getRootOrgList();
  395. this.getTopLoginRuleList();
  396. this.doSearch(1);
  397. }
  398. };
  399. </script>
  400. <style scoped>
  401. .page {
  402. margin-top: 10px;
  403. }
  404. .pull-right {
  405. float: right;
  406. }
  407. .w180 {
  408. width: 180px;
  409. }
  410. </style>