data_previllege.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. <template>
  2. <div>
  3. <LinkTitlesCustom :current-paths="['用户管理', '数据权限']" />
  4. <section class="content">
  5. <div v-loading.body="loading" class="box box-info">
  6. <!-- 正文信息 -->
  7. <div class="box-body">
  8. <el-form
  9. ref="form"
  10. :inline="true"
  11. :model="form"
  12. inline-message
  13. label-position="right"
  14. >
  15. <div style="margin-bottom: 10px">
  16. <!-- <el-button type="primary" size="small">保 存</el-button> -->
  17. <el-button
  18. type="primary"
  19. size="small"
  20. icon="el-icon-arrow-left"
  21. @click="back"
  22. >返 回</el-button
  23. >
  24. </div>
  25. <el-tabs v-model="activeName" type="border-card">
  26. <el-tab-pane label="考试权限" name="tab1">
  27. <el-row class="mb-2">
  28. <el-switch
  29. v-model="form.defaultStatusExam"
  30. active-text="全部考试"
  31. @change="(enabled) => saveDefaultStatus('Exam', enabled)"
  32. ></el-switch>
  33. <div v-if="!form.defaultStatusExam" class="float-right">
  34. <el-button
  35. size="small"
  36. type="danger"
  37. icon="el-icon-delete"
  38. :disabled="noBatchSelectedExam"
  39. @click="deleteBatch('Exam')"
  40. >删除</el-button
  41. >
  42. <el-button
  43. size="small"
  44. type="primary"
  45. icon="el-icon-plus"
  46. @click="addExam"
  47. >添加</el-button
  48. >
  49. </div>
  50. </el-row>
  51. <el-row v-if="!form.defaultStatusExam">
  52. <div>
  53. <el-table
  54. ref="tableExam"
  55. :data="tableDataExam"
  56. border
  57. resizable
  58. stripe
  59. style="width: 100%"
  60. @selection-change="selectChange"
  61. >
  62. <el-table-column type="selection" width="40" />
  63. <el-table-column width="85" label="考试ID">
  64. <span slot-scope="scope">{{ scope.row.examId }}</span>
  65. </el-table-column>
  66. <el-table-column width="200" label="考试代码">
  67. <span slot-scope="scope">{{ scope.row.examCode }}</span>
  68. </el-table-column>
  69. <el-table-column label="考试名称">
  70. <span slot-scope="scope">{{ scope.row.examName }}</span>
  71. </el-table-column>
  72. <el-table-column width="100" label="考试类型">
  73. <span slot-scope="scope">{{
  74. scope.row.examType | examTypeFilter
  75. }}</span>
  76. </el-table-column>
  77. </el-table>
  78. <div class="page pull-right">
  79. <el-pagination
  80. v-if="paginationShow"
  81. :current-page="currentPageExam"
  82. :page-size="pageSizeExam"
  83. :page-sizes="[10, 20, 50, 100, 200, 300]"
  84. layout="total, sizes, prev, pager, next, jumper"
  85. :total="totalExam"
  86. @current-change="handleCurrentChangeExam"
  87. @size-change="handleSizeChangeExam"
  88. />
  89. </div>
  90. </div>
  91. </el-row>
  92. </el-tab-pane>
  93. <el-tab-pane label="课程权限" name="tab2">
  94. <el-row class="mb-2">
  95. <el-switch
  96. v-model="form.defaultStatusCourse"
  97. active-text="全部课程"
  98. @change="(enabled) => saveDefaultStatus('Course', enabled)"
  99. ></el-switch>
  100. <div v-if="!form.defaultStatusCourse" class="float-right">
  101. <el-button
  102. size="small"
  103. type="danger"
  104. icon="el-icon-delete"
  105. :disabled="noBatchSelectedCourse"
  106. @click="deleteBatch('Course')"
  107. >删除</el-button
  108. >
  109. <el-button
  110. size="small"
  111. type="primary"
  112. icon="el-icon-plus"
  113. @click="addCourse"
  114. >添加</el-button
  115. >
  116. </div>
  117. </el-row>
  118. <el-row v-if="!form.defaultStatusCourse">
  119. <div>
  120. <el-table
  121. ref="tableCourse"
  122. :data="tableDataCourse"
  123. border
  124. resizable
  125. stripe
  126. style="width: 100%"
  127. @selection-change="selectChange"
  128. >
  129. <el-table-column type="selection" width="40" />
  130. <el-table-column width="85" label="课程ID">
  131. <span slot-scope="scope">{{ scope.row.courseId }}</span>
  132. </el-table-column>
  133. <el-table-column width="200" label="课程代码">
  134. <span slot-scope="scope">{{
  135. scope.row.courseCode
  136. }}</span>
  137. </el-table-column>
  138. <el-table-column label="课程名称">
  139. <span slot-scope="scope">{{
  140. scope.row.courseName
  141. }}</span>
  142. </el-table-column>
  143. <el-table-column width="100" label="层次">
  144. <span slot-scope="scope">{{
  145. scope.row.courseLevel
  146. }}</span
  147. >>
  148. </el-table-column>
  149. </el-table>
  150. <div class="page pull-right">
  151. <el-pagination
  152. v-if="paginationShow"
  153. :current-page="currentPageCourse"
  154. :page-size="pageSizeCourse"
  155. :page-sizes="[10, 20, 50, 100, 200, 300]"
  156. layout="total, sizes, prev, pager, next, jumper"
  157. :total="totalCourse"
  158. @current-change="handleCurrentChangeCourse"
  159. @size-change="handleSizeChangeCourse"
  160. />
  161. </div>
  162. </div>
  163. </el-row>
  164. </el-tab-pane>
  165. <el-tab-pane label="学习中心权限" name="tab3">
  166. <el-row class="mb-2">
  167. <el-switch
  168. v-model="form.defaultStatusOrg"
  169. active-text="全部学习中心"
  170. @change="(enabled) => saveDefaultStatus('Org', enabled)"
  171. ></el-switch>
  172. <div v-if="!form.defaultStatusOrg" class="float-right">
  173. <el-button
  174. size="small"
  175. type="danger"
  176. icon="el-icon-delete"
  177. :disabled="noBatchSelectedOrg"
  178. @click="deleteBatch('Org')"
  179. >删除</el-button
  180. >
  181. <el-button
  182. size="small"
  183. type="primary"
  184. icon="el-icon-plus"
  185. @click="addOrg"
  186. >添加</el-button
  187. >
  188. </div>
  189. </el-row>
  190. <el-row v-if="!form.defaultStatusOrg">
  191. <div>
  192. <el-table
  193. ref="tableOrg"
  194. :data="tableDataOrg"
  195. border
  196. resizable
  197. stripe
  198. style="width: 100%"
  199. @selection-change="selectChange"
  200. >
  201. <el-table-column type="selection" width="40" />
  202. <el-table-column width="85" label="中心ID">
  203. <span slot-scope="scope">{{ scope.row.orgId }}</span>
  204. </el-table-column>
  205. <el-table-column width="200" label="中心代码">
  206. <span slot-scope="scope">{{ scope.row.orgCode }}</span>
  207. </el-table-column>
  208. <el-table-column label="中心名称">
  209. <span slot-scope="scope">{{ scope.row.orgName }}</span>
  210. </el-table-column>
  211. <el-table-column width="100" label="负责人">
  212. <span slot-scope="scope">{{ scope.row.contacts }}</span
  213. >>
  214. </el-table-column>
  215. </el-table>
  216. <div class="page pull-right">
  217. <el-pagination
  218. v-if="paginationShow"
  219. :current-page="currentPageOrg"
  220. :page-size="pageSizeOrg"
  221. :page-sizes="[10, 20, 50, 100, 200, 300]"
  222. layout="total, sizes, prev, pager, next, jumper"
  223. :total="totalOrg"
  224. @current-change="handleCurrentChangeOrg"
  225. @size-change="handleSizeChangeOrg"
  226. />
  227. </div>
  228. </div>
  229. </el-row>
  230. </el-tab-pane>
  231. </el-tabs>
  232. </el-form>
  233. </div>
  234. </div>
  235. </section>
  236. <DataPrevillegeAddExamDialog
  237. ref="addExamDialog"
  238. :user-id="userId"
  239. :root-org-id="$route.query.rootOrgId"
  240. @reload="init"
  241. />
  242. <DataPrevillegeAddCourseDialog
  243. ref="addCourseDialog"
  244. :user-id="userId"
  245. :root-org-id="$route.query.rootOrgId"
  246. @reload="init"
  247. />
  248. <DataPrevillegeAddOrgDialog
  249. ref="addOrgDialog"
  250. :user-id="userId"
  251. :root-org-id="$route.query.rootOrgId"
  252. @reload="init"
  253. />
  254. </div>
  255. </template>
  256. <script>
  257. import { mapState } from "vuex";
  258. import { CORE_API } from "@/constants/constants.js";
  259. import LinkTitlesCustom from "@/components/LinkTitlesCustom.vue";
  260. import { object2QueryString } from "@/utils/utils";
  261. import DataPrevillegeAddExamDialog from "./data_previllege_add_exam";
  262. import DataPrevillegeAddCourseDialog from "./data_previllege_add_course";
  263. import DataPrevillegeAddOrgDialog from "./data_previllege_add_org";
  264. export default {
  265. name: "DataPrevillege",
  266. components: {
  267. LinkTitlesCustom,
  268. DataPrevillegeAddExamDialog,
  269. DataPrevillegeAddCourseDialog,
  270. DataPrevillegeAddOrgDialog,
  271. },
  272. data() {
  273. return {
  274. rolePrivileges: {
  275. user_data_rule_setting: false,
  276. },
  277. loading: false,
  278. style: {
  279. label_width_tab1: "160px",
  280. label_width_tab2: "160px",
  281. label_width_tab3: "160px",
  282. },
  283. activeName: "tab1",
  284. toActiveName: null,
  285. form: {
  286. defaultStatusExam: false,
  287. defaultStatusCourse: false,
  288. defaultStatusOrg: false,
  289. },
  290. userId: "",
  291. paginationShow: false,
  292. selectedChanged: false,
  293. tableDataExam: [],
  294. noBatchSelectedExam: true,
  295. currentPageExam: 1,
  296. pageSizeExam: 10,
  297. totalExam: 10,
  298. tableDataCourse: [],
  299. noBatchSelectedCourse: true,
  300. currentPageCourse: 1,
  301. pageSizeCourse: 10,
  302. totalCourse: 10,
  303. tableDataOrg: [],
  304. noBatchSelectedOrg: true,
  305. currentPageOrg: 1,
  306. pageSizeOrg: 10,
  307. totalOrg: 10,
  308. };
  309. },
  310. computed: {
  311. ...mapState({ user: (state) => state.user }),
  312. },
  313. async created() {
  314. await this.initPrivileges();
  315. if (!this.rolePrivileges.user_data_rule_setting) {
  316. this.$alert("没有权限访问!", "提示", {
  317. confirmButtonText: "确定",
  318. callback: () => {
  319. this.back();
  320. },
  321. });
  322. return;
  323. }
  324. this.userId = this.$route.params.userId;
  325. await this.init();
  326. this.$nextTick(function () {
  327. this.paginationShow = true;
  328. });
  329. },
  330. methods: {
  331. async init() {
  332. const reqs = [];
  333. const defaultPrevilleges = ["EXAM", "COURSE", "ORG"];
  334. for (const defP of defaultPrevilleges) {
  335. let url =
  336. CORE_API +
  337. "/user/data/rule/default/status?" +
  338. `userId=${this.userId}&type=${defP}`;
  339. reqs.push(this.$httpWithMsg.post(url));
  340. }
  341. const preVillegeList = ["Exam", "Course", "Org"];
  342. for (const defP of preVillegeList) {
  343. let url = CORE_API + "/user/data/rule/list/for/" + defP.toLowerCase();
  344. const pageNo = this.$data["currentPage" + defP];
  345. const pageSize = this.$data["pageSize" + defP];
  346. reqs.push(
  347. this.$httpWithMsg.post(url, {
  348. userId: this.userId,
  349. pageNo,
  350. pageSize,
  351. })
  352. );
  353. }
  354. try {
  355. this.loading = true;
  356. const promiseAll = await Promise.all(reqs);
  357. // console.log(promiseAll);
  358. this.form.defaultStatusExam = promiseAll[0].data;
  359. this.form.defaultStatusCourse = promiseAll[1].data;
  360. this.form.defaultStatusOrg = promiseAll[2].data;
  361. this.tableDataExam = promiseAll[3].data.content;
  362. this.tableDataCourse = promiseAll[4].data.content;
  363. this.tableDataOrg = promiseAll[5].data.content;
  364. this.totalExam = promiseAll[3].data.totalElements;
  365. this.totalCourse = promiseAll[4].data.totalElements;
  366. this.totalOrg = promiseAll[5].data.totalElements;
  367. } finally {
  368. this.loading = false;
  369. }
  370. },
  371. noBatchSelected(type) {
  372. if (!this.$refs[type + "Table"]) return false;
  373. console.log(this.$refs[type + "Table"].selection.length);
  374. return this.$refs[type + "Table"].selection.length;
  375. },
  376. selectChange() {
  377. this.noBatchSelectedExam =
  378. this.$refs.tableExam && !this.$refs.tableExam.selection.length;
  379. this.noBatchSelectedCourse =
  380. this.$refs.tableCourse && !this.$refs.tableCourse.selection.length;
  381. this.noBatchSelectedOrg =
  382. this.$refs.tableOrg && !this.$refs.tableOrg.selection.length;
  383. },
  384. handleSizeChangeExam(val) {
  385. this.pageSizeExam = val;
  386. this.currentPageExam = 1;
  387. this.init();
  388. },
  389. handleCurrentChangeExam(val) {
  390. this.currentPageExam = val;
  391. this.init();
  392. },
  393. handleSizeChangeCourse(val) {
  394. this.pageSizeCourse = val;
  395. this.currentPageCourse = 1;
  396. this.init();
  397. },
  398. handleCurrentChangeCourse(val) {
  399. this.currentPageCourse = val;
  400. this.init();
  401. },
  402. handleSizeChangeOrg(val) {
  403. this.pageSizeOrg = val;
  404. this.currentPageOrg = 1;
  405. this.init();
  406. },
  407. handleCurrentChangeOrg(val) {
  408. this.currentPageOrg = val;
  409. this.init();
  410. },
  411. back() {
  412. this.$router.back();
  413. },
  414. async saveDefaultStatus(type, enabled) {
  415. try {
  416. await this.$httpWithMsg.post(
  417. CORE_API +
  418. "/user/data/rule/default/status/update?" +
  419. object2QueryString({
  420. enabled,
  421. type: type.toUpperCase(),
  422. userId: this.userId,
  423. })
  424. );
  425. this.$notify({
  426. type: "success",
  427. message: "更新成功",
  428. });
  429. } catch (error) {
  430. this.form["defaultStatus" + type] = !enabled;
  431. }
  432. },
  433. addExam() {
  434. this.$refs.addExamDialog.openDialog();
  435. },
  436. async deleteBatch(type) {
  437. const refIds = this.$refs["table" + type].selection.map((v) => v.refId);
  438. try {
  439. await this.$httpWithMsg.post(CORE_API + "/user/data/rule/delete", {
  440. refIds,
  441. type: type.toUpperCase(),
  442. userId: this.userId,
  443. });
  444. this.$notify({
  445. type: "success",
  446. message: "删除成功",
  447. });
  448. await this.init();
  449. } catch (error) {
  450. console.log(error);
  451. }
  452. },
  453. addCourse() {
  454. this.$refs.addCourseDialog.openDialog();
  455. },
  456. addOrg() {
  457. this.$refs.addOrgDialog.openDialog();
  458. },
  459. async initPrivileges() {
  460. let params = new URLSearchParams();
  461. params.append(
  462. "privilegeCodes",
  463. Object.keys(this.rolePrivileges).toString()
  464. );
  465. var url = CORE_API + "/rolePrivilege/checkPrivileges?" + params;
  466. await this.$httpWithMsg.post(url).then((response) => {
  467. this.rolePrivileges = response.data;
  468. });
  469. },
  470. },
  471. };
  472. </script>
  473. <style scoped>
  474. .content {
  475. width: 800px;
  476. }
  477. .input {
  478. width: 440px;
  479. }
  480. .input >>> .el-input__inner {
  481. -webkit-appearance: button;
  482. }
  483. </style>