sys_login_rule_list.vue 11 KB

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