data_previllege.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. <el-row>
  16. <el-col :span="18"
  17. ><span>{{ userName }}</span></el-col
  18. >
  19. <el-col :span="6"
  20. ><div style="margin-bottom: 10px">
  21. <el-button type="primary" size="small" @click="save"
  22. >保存</el-button
  23. >
  24. <el-button
  25. type="primary"
  26. size="small"
  27. icon="el-icon-arrow-left"
  28. @click="back"
  29. >返回</el-button
  30. >
  31. </div></el-col
  32. >
  33. </el-row>
  34. <div class="block-seperator"></div>
  35. <el-row>
  36. <el-form-item label="审核权限">
  37. <el-radio-group v-model="form.auditAuthority" class="input">
  38. <el-radio label="FIRST">初级</el-radio>
  39. <el-radio label="SECOND">中级</el-radio>
  40. <el-radio label="THIRD">高级</el-radio>
  41. </el-radio-group></el-form-item
  42. >
  43. <el-button type="primary" size="small" @click="clear"
  44. >清空</el-button
  45. >
  46. </el-row>
  47. <div class="block-seperator"></div>
  48. <el-tabs v-model="activeName" type="border-card">
  49. <el-tab-pane label="关联课程" name="tab1">
  50. <el-row class="mb-2">
  51. <el-switch
  52. v-model="form.defaultStatusCourse"
  53. active-text="全部课程"
  54. @change="(enabled) => saveDefaultStatus('Course', enabled)"
  55. ></el-switch>
  56. <div v-if="!form.defaultStatusCourse" class="float-right">
  57. <el-button
  58. size="small"
  59. type="danger"
  60. icon="el-icon-delete"
  61. :disabled="noBatchSelectedCourse"
  62. @click="deleteBatch('Course')"
  63. >删除</el-button
  64. >
  65. <el-button
  66. size="small"
  67. type="primary"
  68. icon="el-icon-plus"
  69. @click="addCourse"
  70. >添加</el-button
  71. >
  72. </div>
  73. </el-row>
  74. <el-row v-if="!form.defaultStatusCourse">
  75. <div>
  76. <el-table
  77. ref="tableCourse"
  78. :data="tableDataCourse"
  79. border
  80. resizable
  81. stripe
  82. style="width: 100%"
  83. @selection-change="selectChange"
  84. >
  85. <el-table-column
  86. type="selection"
  87. width="50"
  88. align="center"
  89. />
  90. <el-table-column width="85" label="课程ID">
  91. <span slot-scope="scope">{{ scope.row.courseId }}</span>
  92. </el-table-column>
  93. <el-table-column width="200" label="课程代码">
  94. <span slot-scope="scope">{{
  95. scope.row.courseCode
  96. }}</span>
  97. </el-table-column>
  98. <el-table-column label="课程名称">
  99. <span slot-scope="scope">{{
  100. scope.row.courseName
  101. }}</span>
  102. </el-table-column>
  103. <el-table-column width="100" label="层次">
  104. <span slot-scope="scope">{{
  105. scope.row.courseLevel
  106. }}</span
  107. >>
  108. </el-table-column>
  109. </el-table>
  110. <div class="page pull-right">
  111. <el-pagination
  112. v-if="paginationShow"
  113. :current-page="currentPageCourse"
  114. :page-size="pageSizeCourse"
  115. :page-sizes="[10, 20, 50, 100, 200, 300]"
  116. layout="total, sizes, prev, pager, next, jumper"
  117. :total="totalCourse"
  118. @current-change="handleCurrentChangeCourse"
  119. @size-change="handleSizeChangeCourse"
  120. />
  121. </div>
  122. </div>
  123. </el-row>
  124. </el-tab-pane>
  125. </el-tabs>
  126. </el-form>
  127. </div>
  128. </div>
  129. </section>
  130. <DataPrevillegeAddCourseDialog
  131. ref="addCourseDialog"
  132. :user-id="form.userId"
  133. :root-org-id="form.rootOrgId"
  134. @reload="init"
  135. />
  136. </div>
  137. </template>
  138. <script>
  139. import { mapState } from "vuex";
  140. import { QUESTION_API } from "@/constants/constants.js";
  141. import LinkTitlesCustom from "@/components/LinkTitlesCustom.vue";
  142. import { object2QueryString } from "@/utils/utils";
  143. import DataPrevillegeAddCourseDialog from "./data_previllege_add_course";
  144. export default {
  145. name: "DataPrevillege",
  146. components: {
  147. LinkTitlesCustom,
  148. DataPrevillegeAddCourseDialog,
  149. },
  150. data() {
  151. return {
  152. userName: "",
  153. rolePrivileges: {
  154. user_data_rule_setting: false,
  155. },
  156. loading: false,
  157. style: {
  158. label_width_tab1: "160px",
  159. label_width_tab2: "160px",
  160. label_width_tab3: "160px",
  161. },
  162. activeName: "tab1",
  163. toActiveName: null,
  164. form: {
  165. userId: "",
  166. rootOrgId: null,
  167. defaultStatusCourse: false,
  168. auditAuthority: "",
  169. },
  170. paginationShow: false,
  171. selectedChanged: false,
  172. tableDataCourse: [],
  173. noBatchSelectedCourse: true,
  174. currentPageCourse: 1,
  175. pageSizeCourse: 10,
  176. totalCourse: 10,
  177. };
  178. },
  179. computed: {
  180. ...mapState({ user: (state) => state.user }),
  181. },
  182. async created() {
  183. await this.initPrivileges();
  184. if (!this.rolePrivileges.user_data_rule_setting) {
  185. this.$alert("没有权限访问!", "提示", {
  186. confirmButtonText: "确定",
  187. callback: () => {
  188. this.back();
  189. },
  190. });
  191. return;
  192. }
  193. this.form.userId = this.$route.params.userId;
  194. this.form.rootOrgId = this.$route.params.rootOrgId;
  195. await this.init();
  196. this.$nextTick(function () {
  197. this.paginationShow = true;
  198. });
  199. },
  200. methods: {
  201. async save() {
  202. try {
  203. await this.$httpWithMsg.post(
  204. QUESTION_API + "/user/updateAuditAuthority",
  205. {
  206. auditAuthority: this.form.auditAuthority,
  207. id: this.form.userId,
  208. }
  209. );
  210. this.$notify({
  211. type: "success",
  212. message: "保存成功",
  213. });
  214. await this.back();
  215. } catch (error) {
  216. console.log(error);
  217. }
  218. },
  219. clear() {
  220. this.form.auditAuthority = null;
  221. },
  222. async init() {
  223. this.$httpWithMsg
  224. .get(QUESTION_API + "/user/" + this.form.userId)
  225. .then((res) => {
  226. this.userName = res.data.name + "(" + res.data.roleNamesStr + ")";
  227. this.form.auditAuthority = res.data.auditAuthority;
  228. });
  229. const reqs = [];
  230. const defaultPrevilleges = ["COURSE"];
  231. for (const defP of defaultPrevilleges) {
  232. let url =
  233. QUESTION_API +
  234. "/user/data/rule/default/status?" +
  235. `userId=${this.form.userId}&type=${defP}`;
  236. reqs.push(this.$httpWithMsg.post(url));
  237. }
  238. const preVillegeList = ["Course"];
  239. for (const defP of preVillegeList) {
  240. let url =
  241. QUESTION_API + "/user/data/rule/list/for/" + defP.toLowerCase();
  242. const pageNo = this.$data["currentPage" + defP];
  243. const pageSize = this.$data["pageSize" + defP];
  244. reqs.push(
  245. this.$httpWithMsg.post(url, {
  246. userId: this.form.userId,
  247. pageNo,
  248. pageSize,
  249. })
  250. );
  251. }
  252. try {
  253. this.loading = true;
  254. const promiseAll = await Promise.all(reqs);
  255. // console.log(promiseAll);
  256. this.form.defaultStatusCourse = promiseAll[0].data;
  257. this.tableDataCourse = promiseAll[1].data.content;
  258. this.currentPageCourse = promiseAll[1].data.number + 1;
  259. this.totalCourse = promiseAll[1].data.totalElements;
  260. } finally {
  261. this.loading = false;
  262. }
  263. },
  264. noBatchSelected(type) {
  265. if (!this.$refs[type + "Table"]) return false;
  266. console.log(this.$refs[type + "Table"].selection.length);
  267. return this.$refs[type + "Table"].selection.length;
  268. },
  269. selectChange() {
  270. this.noBatchSelectedCourse =
  271. this.$refs.tableCourse && !this.$refs.tableCourse.selection.length;
  272. },
  273. handleSizeChangeCourse(val) {
  274. this.pageSizeCourse = val;
  275. this.currentPageCourse = 1;
  276. this.init();
  277. },
  278. handleCurrentChangeCourse(val) {
  279. this.currentPageCourse = val;
  280. this.init();
  281. },
  282. back() {
  283. this.$router.back();
  284. },
  285. async saveDefaultStatus(type, enabled) {
  286. try {
  287. await this.$httpWithMsg.post(
  288. QUESTION_API +
  289. "/user/data/rule/default/status/update?" +
  290. object2QueryString({
  291. enabled,
  292. type: type.toUpperCase(),
  293. userId: this.form.userId,
  294. })
  295. );
  296. this.$notify({
  297. type: "success",
  298. message: "更新成功",
  299. });
  300. } catch (error) {
  301. this.form["defaultStatus" + type] = !enabled;
  302. }
  303. },
  304. async deleteBatch(type) {
  305. const refIds = this.$refs["table" + type].selection.map((v) => v.refId);
  306. try {
  307. await this.$httpWithMsg.post(QUESTION_API + "/user/data/rule/delete", {
  308. refIds,
  309. type: type.toUpperCase(),
  310. userId: this.form.userId,
  311. });
  312. this.$notify({
  313. type: "success",
  314. message: "删除成功",
  315. });
  316. await this.init();
  317. } catch (error) {
  318. console.log(error);
  319. }
  320. },
  321. addCourse() {
  322. this.$refs.addCourseDialog.openDialog();
  323. },
  324. async initPrivileges() {
  325. let params = new URLSearchParams();
  326. params.append(
  327. "privilegeCodes",
  328. Object.keys(this.rolePrivileges).toString()
  329. );
  330. var url = QUESTION_API + "/rolePrivilege/checkPrivileges?" + params;
  331. await this.$httpWithMsg.post(url).then((response) => {
  332. this.rolePrivileges = response.data;
  333. });
  334. },
  335. },
  336. };
  337. </script>
  338. <style scoped>
  339. .content {
  340. width: 800px;
  341. }
  342. .input >>> .el-input__inner {
  343. -webkit-appearance: button;
  344. }
  345. </style>