sys_login_rule_list.vue 12 KB

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